Package org.dozer.cache

Examples of org.dozer.cache.Cache


*/
public class DozerCacheTest extends AbstractDozerTest {

  @Test
  public void testPutGetFromCache() throws Exception {
    Cache cache = new DozerCache(getRandomString(), 50);
    int numCacheEntriesToAdd = 45;
    for (int i = 0; i < numCacheEntriesToAdd; i++) {
      Object key = String.valueOf(i);

      assertNull("cache entry should not already exist", cache.get(key));

      cache.put(key, "testvalue" + i);

      String value = (String) cache.get(key);
      assertEquals("cache entries should be equal", value, "testvalue" + i);
    }
    assertEquals("invlid cache size", numCacheEntriesToAdd, cache.getSize());
  }
View Full Code Here


  }

  @Test
  public void testMaximumCacheSize() throws Exception {
    int maxSize = 25;
    Cache cache = new DozerCache(getRandomString(), maxSize);
    // Add a bunch of entries to cache to verify the cache doesnt grow larger than specified max size
    for (int i = 0; i < maxSize + 125; i++) {
      cache.put("testkey" + i, "testvalue" + i);
    }
    assertEquals("cache size should not exceed max size", maxSize, cache.getSize());
  }
View Full Code Here

  }

  @Test(expected = IllegalArgumentException.class)
  public void testMaximumCacheSize_Zero() throws Exception {
    int maxSize = 0;
    Cache cache = new DozerCache(getRandomString(), maxSize);
    // Add a bunch of entries to cache to verify the cache doesnt grow larger than specified max size
    for (int i = 0; i < maxSize + 5; i++) {
      cache.put("testkey" + i, "testvalue" + i);
    }
    assertEquals("cache size should not exceed max size", maxSize, cache.getSize());
  }
View Full Code Here

  }

  @Test
  public void testGetMaxSize() {
    int maxSize = 550;
    Cache cache = new DozerCache(getRandomString(), maxSize);

    assertEquals("invalid max size", maxSize, cache.getMaxSize());
  }
View Full Code Here

    assertEquals("invalid max size", maxSize, cache.getMaxSize());
  }

  @Test(expected = IllegalArgumentException.class)
  public void testGetNull() {
    Cache cache = new DozerCache(getRandomString(), 5);
    cache.get(null);
  }
View Full Code Here

    cache.get(null);
  }

  @Test(expected = IllegalArgumentException.class)
  public void testPutNull() {
    Cache cache = new DozerCache(getRandomString(), 5);
    cache.put(null, null);
  }
View Full Code Here

    cacheMgr.addCache(cacheName, 1);

    boolean cacheExists = cacheMgr.cacheExists(cacheName);
    assertTrue("cache should exist", cacheExists);

    Cache cache = cacheMgr.getCache(cacheName);
    assertNotNull("cache should not be null", cache);
    assertEquals("cache should be empty", cache.getSize(), 0);
    assertEquals("invalid cache name", cacheName, cache.getName());
  }
View Full Code Here

    cacheMgr2.addCache(cacheName, 1);

    assertTrue("cache should exist in cache mgr1", cacheMgr.cacheExists(cacheName));
    assertTrue("cache should also exist in cache mgr2", cacheMgr2.cacheExists(cacheName));

    Cache cache1 = cacheMgr.getCache(cacheName);
    Cache cache2 = cacheMgr2.getCache(cacheName);

    assertFalse("caches should not be the same instance", cache1 == cache2);
    assertEquals("invalid cache name", cacheName, cache1.getName());
    assertEquals("invalid cache name for cache2", cacheName, cache2.getName());
  }
View Full Code Here

*/
public class DozerCacheTest extends AbstractDozerTest {

  @Test
  public void testPutGetFromCache() throws Exception {
    Cache cache = new DozerCache(getRandomString(), 50);
    int numCacheEntriesToAdd = 45;
    for (int i = 0; i < numCacheEntriesToAdd; i++) {
      Object key = String.valueOf(i);

      assertNull("cache entry should not already exist", cache.get(key));

      cache.put(key, "testvalue" + i);

      String value = (String) cache.get(key);
      assertEquals("cache entries should be equal", value, "testvalue" + i);
    }
    assertEquals("invlid cache size", numCacheEntriesToAdd, cache.getSize());
  }
View Full Code Here

  }

  @Test
  public void testMaximumCacheSize() throws Exception {
    int maxSize = 25;
    Cache cache = new DozerCache(getRandomString(), maxSize);
    // Add a bunch of entries to cache to verify the cache doesnt grow larger than specified max size
    for (int i = 0; i < maxSize + 125; i++) {
      cache.put("testkey" + i, "testvalue" + i);
    }
    assertEquals("cache size should not exceed max size", maxSize, cache.getSize());
  }
View Full Code Here

TOP

Related Classes of org.dozer.cache.Cache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.