Ejemplo n.º 1
0
 @Test
 public void testFlushUpdatesAccessStats() throws CacheAccessException {
   final TestTimeSource timeSource = new TestTimeSource();
   final Expiry<Object, Object> expiry =
       Expirations.timeToIdleExpiration(new Duration(15L, TimeUnit.MILLISECONDS));
   final AbstractOffHeapStore<String, String> store = createAndInitStore(timeSource, expiry);
   try {
     final String key = "foo";
     final String value = "bar";
     store.put(key, value);
     final Store.ValueHolder<String> firstValueHolder = store.getAndFault(key);
     store.put(key, value);
     final Store.ValueHolder<String> secondValueHolder = store.getAndFault(key);
     timeSource.advanceTime(10);
     ((AbstractValueHolder) firstValueHolder)
         .accessed(timeSource.getTimeMillis(), expiry.getExpiryForAccess(key, value));
     timeSource.advanceTime(10);
     ((AbstractValueHolder) secondValueHolder)
         .accessed(timeSource.getTimeMillis(), expiry.getExpiryForAccess(key, value));
     assertThat(store.flush(key, new DelegatingValueHolder<String>(firstValueHolder)), is(false));
     assertThat(store.flush(key, new DelegatingValueHolder<String>(secondValueHolder)), is(true));
     timeSource.advanceTime(10); // this should NOT affect
     assertThat(
         store.getAndFault(key).lastAccessTime(TimeUnit.MILLISECONDS),
         is(secondValueHolder.creationTime(TimeUnit.MILLISECONDS) + 20));
   } finally {
     destroyStore(store);
   }
 }
Ejemplo n.º 2
0
 @Override
 public long creationTime(final TimeUnit unit) {
   return valueHolder.creationTime(unit);
 }