Example usage for org.apache.commons.jcs.access.behavior ICacheAccess put

List of usage examples for org.apache.commons.jcs.access.behavior ICacheAccess put

Introduction

In this page you can find the example usage for org.apache.commons.jcs.access.behavior ICacheAccess put.

Prototype

void put(K name, V obj, IElementAttributes attr) throws CacheException;

Source Link

Document

Description of the Method

Usage

From source file:org.openstreetmap.josm.data.cache.JCSCachedTileLoaderJobTest.java

/**
 * Test unknown host//from  www  .  ja v a 2s  .  c o  m
 * @throws IOException in case of I/O error
 */
@Test
public void testUnknownHost() throws IOException {
    String key = "key_unknown_host";
    TestCachedTileLoaderJob job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown", key);
    Listener listener = new Listener();
    job.submit(listener, true);
    synchronized (listener) {
        while (!listener.ready) {
            try {
                listener.wait();
            } catch (InterruptedException e1) {
                // do nothing, still wait
                Logging.trace(e1);
            }
        }
    }
    assertEquals(LoadResult.FAILURE, listener.result); // because response will be cached, and that is checked below
    assertEquals("java.net.UnknownHostException: unkownhost.unkownhost", listener.attributes.getErrorMessage());

    ICacheAccess<String, CacheEntry> cache = getCache();
    CacheEntry e = new CacheEntry(new byte[] { 0, 1, 2, 3 });
    CacheEntryAttributes attributes = new CacheEntryAttributes();
    attributes.setExpirationTime(2);
    cache.put(key, e, attributes);

    job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown", key);
    listener = new Listener();
    job.submit(listener, true);
    synchronized (listener) {
        while (!listener.ready) {
            try {
                listener.wait();
            } catch (InterruptedException e1) {
                // do nothing, wait
                Logging.trace(e1);
            }
        }
    }
    assertEquals(LoadResult.SUCCESS, listener.result);
    assertFalse(job.isCacheElementValid());
}