Пример #1
0
 @Test
 public void testWithNullAsKeyAndValue() throws Exception {
   final T cache = getInstance(1000, 1000);
   assertEquals(0, (long) cache.size());
   assertFalse(cache.contains(null));
   assertNull(cache.get(null));
   // Add entry with null as key and value ...
   cache.put(null, null);
   assertEquals(1, (long) cache.size());
   assertTrue(cache.contains(null));
   assertNull(cache.get(null));
   // Add another entry ...
   cache.put(new Object(), new Object());
   assertEquals(2, (long) cache.size());
   // Remove entry with null as key ...
   assertNull(cache.remove(null).getValue());
   assertEquals(1, (long) cache.size());
   assertFalse(cache.contains(null));
   assertNull(cache.get(null));
   // Try to remove entry with null as key again ...
   assertNull(cache.remove(null));
   assertEquals(1, (long) cache.size());
   assertFalse(cache.contains(null));
   assertNull(cache.get(null));
 }
Пример #2
0
 @Test
 public void testWithMaxSize1() {
   final T cache = getInstance(1000, 1);
   final Object o1 = new Object();
   cache.put(o1, o1);
   final Object o2 = new Object();
   cache.put(o2, o2);
   assertEquals(1, (long) cache.size());
   assertFalse(cache.contains(o1));
   assertTrue(cache.contains(o2));
 }
Пример #3
0
 @Test
 public void testMaxLifeTimeSupport() throws Exception {
   final T cache = getInstance(100, 100);
   cache.put("varA", "valueA");
   cache.put("varB", "valueB");
   Thread.sleep(70);
   cache.put("varC", "valueC");
   assertEquals("valueA", cache.get("varA"));
   assertEquals("valueB", cache.get("varB"));
   assertEquals("valueC", cache.get("varC"));
   Thread.sleep(70);
   assertNull("valueA", cache.get("varA"));
   assertNull("valueB", cache.get("varB"));
   assertEquals("valueC", cache.get("varC"));
   Thread.sleep(70);
   assertNull("valueA", cache.get("varA"));
   assertNull("valueB", cache.get("varB"));
   assertNull("valueC", cache.get("varC"));
 }
Пример #4
0
 @Test
 public void testWithNullAsValue() throws Exception {
   final T cache = getInstance(1000, 1000);
   final Object o = new Object();
   assertEquals(0, (long) cache.size());
   assertFalse(cache.contains(o));
   assertNull(cache.get(o));
   // Add entry with null as value ...
   cache.put(o, null);
   assertEquals(1, (long) cache.size());
   assertTrue(cache.contains(o));
   assertNull(cache.get(o));
   // Remove entry with null as value ...
   assertNull(cache.remove(o).getValue());
   assertEquals(0, (long) cache.size());
   assertFalse(cache.contains(o));
   assertNull(cache.get(o));
   // Try to remove entry with null as value again ...
   assertNull(cache.remove(o));
   assertEquals(0, (long) cache.size());
   assertFalse(cache.contains(o));
   assertNull(cache.get(o));
 }