@Test public void testGetAndRemoveExpiredElementReturnsNull() throws Exception { TestTimeSource timeSource = new TestTimeSource(); AbstractOffHeapStore<String, String> offHeapStore = createAndInitStore( timeSource, Expirations.timeToIdleExpiration(new Duration(15L, TimeUnit.MILLISECONDS))); try { assertThat(offHeapStore.getAndRemove("1"), is(nullValue())); offHeapStore.put("1", "one"); final AtomicReference<Store.ValueHolder<String>> invalidated = new AtomicReference<Store.ValueHolder<String>>(); offHeapStore.setInvalidationListener( new CachingTier.InvalidationListener<String, String>() { @Override public void onInvalidation(String key, Store.ValueHolder<String> valueHolder) { invalidated.set(valueHolder); } }); timeSource.advanceTime(20); assertThat(offHeapStore.getAndRemove("1"), is(nullValue())); assertThat(invalidated.get().value(), equalTo("one")); assertThat( invalidated.get().isExpired(timeSource.getTimeMillis(), TimeUnit.MILLISECONDS), is(true)); assertThat( getExpirationStatistic(offHeapStore) .count(StoreOperationOutcomes.ExpirationOutcome.SUCCESS), is(1L)); } finally { destroyStore(offHeapStore); } }
@Test public void testGetAndRemoveNoValue() throws Exception { TestTimeSource timeSource = new TestTimeSource(); AbstractOffHeapStore<String, String> offHeapStore = createAndInitStore(timeSource, Expirations.noExpiration()); try { assertThat(offHeapStore.getAndRemove("1"), is(nullValue())); validateStats( offHeapStore, EnumSet.of(LowerCachingTierOperationsOutcome.GetAndRemoveOutcome.MISS)); } finally { destroyStore(offHeapStore); } }