@Test public void testReapingOnGetWithAccessBasedAging() throws Exception { setUpAccessBaseAgingExpectations(); populate(1, 2, 3); assertSizes(3, 0); map.reapable("one"); map.reapable("three"); assertSizes(1, 2); for (int i = 0; i < 6; i++) { Thread.sleep(250); assertExpected(i == 0 ? 1 : 3); } assertSizes(1, 1); assertNull(map.get("one")); assertExpected(3); Thread.sleep(500); assertExpected(3); assertSizes(1, 1); Thread.sleep(1200); assertExpected(2); assertSizes(1, 0); assertNull(map.get("three")); }
@Test public void testReapingOnGetWithGC() throws Exception { setUpGCExpectations(5); populate(1, 2, 3); map.reapable("one"); map.reapable("three"); assertSizes(1, 2); assertExpected(3); assertSizes(1, 1); assertNull(map.get("three")); }
@Test public void testReapingWithoutGC() throws Exception { map = new ReapedMap<String, Integer>(1000); populate(1, 2, 3); assertSizes(3, 0); assertExpected(1, 2, 3); map.reapable("one"); map.reapable("three"); assertSizes(1, 2); map.reapable("one"); assertSizes(1, 2); assertExpected(1, 2, 3); assertEquals(Integer.valueOf(3), map.remove("three")); assertSizes(1, 1); assertExpected(1, 2); assertNull(map.get("three")); Thread.sleep(1100); assertExpected(1); assertNull(map.get("one")); assertExpected(2); assertSizes(1, 0); populate(4, 5); map.clear(); }
private void assertExpected(Integer... values) { for (Integer v : values) { assertEquals(v, map.get(MAPPER.getKey(v))); } }
private void assertSizes(int i, int j) { assertEquals("unexpected primary map size", i, map.size()); assertEquals("unexpected secondary map size", j, map.reapableSize()); }
private void populate(Integer... values) { for (Integer v : values) { map.put(MAPPER.getKey(v), v); } }