@Test public void testStoreEvictsEldestStaleEntry() { int capacity = 10; givenACacheWithEntries(capacity, 0L, capacity); assertThat(cache.remainingCapacity(), is(0)); String eldest = cache.getEldest(); String newValue = "50"; assertTrue(cache.put(Integer.valueOf(newValue), newValue)); assertNull(cache.get(Integer.valueOf(eldest))); }
@Test public void testStoreAddsNewValueIfCapacityNotReached() { int capacity = 10; givenACacheWithEntries(capacity, 0L, capacity - 1); assertThat(cache.remainingCapacity(), is(1)); String eldest = cache.getEldest(); String newValue = "50"; assertTrue(cache.put(50, newValue)); assertNotNull(cache.get(Integer.valueOf(eldest))); assertThat(cache.remainingCapacity(), is(0)); }
@Test public void testStoreFailsIfCapacityReached() { long threshold = 10; // seconds int capacity = 10; int numberOfSessions = 10; givenACacheWithEntries(capacity, threshold, numberOfSessions); assertThat(cache.remainingCapacity(), is(0)); String eldest = cache.getEldest(); String newValue = "50"; Integer key = Integer.valueOf(newValue); assertFalse(cache.put(key, newValue)); assertNull(cache.get(key)); assertNotNull(cache.get(Integer.valueOf(eldest))); }