public void testLifespanExpiredOnBoth() { MagicKey key = createKey(cache0, cache1); cache0.put(key, key.toString(), 10, TimeUnit.MINUTES); assertEquals(key.toString(), cache0.get(key)); assertEquals(key.toString(), cache1.get(key)); // Now we expire on cache0, it should still exist on cache1 ts0.advance(TimeUnit.MINUTES.toMillis(10) + 1); ts1.advance(TimeUnit.MINUTES.toMillis(10) + 1); // Both should be null assertNull(cache0.get(key)); assertNull(cache1.get(key)); }
public void testMaxIdleExpiredOnBoth() { MagicKey key = createKey(cache0, cache1); cache0.put(key, key.toString(), -1, null, 10, TimeUnit.MINUTES); assertEquals(key.toString(), cache0.get(key)); assertEquals(key.toString(), cache1.get(key)); // Now we expire on cache0, it should still exist on cache1 incrementAllTimeServices(11, TimeUnit.MINUTES); // Both should be null assertNull(cache0.get(key)); assertNull(cache1.get(key)); }
private void testMaxIdleExpireExpireIteration(boolean expireOnPrimary, boolean iterateOnPrimary) { // Cache0 is always the primary and cache1 is backup MagicKey key = createKey(cache0, cache1); cache1.put(key, key.toString(), -1, null, 10, TimeUnit.SECONDS); ControlledTimeService expiredTimeService; if (expireOnPrimary) { expiredTimeService = ts0; } else { expiredTimeService = ts1; } expiredTimeService.advance(TimeUnit.SECONDS.toMillis(11)); Cache<Object, String> cacheToIterate; if (iterateOnPrimary) { cacheToIterate = cache0; } else { cacheToIterate = cache1; } // Iteration always works with max idle expired entries try (CloseableIterator<Map.Entry<Object, String>> iterator = cacheToIterate.entrySet().iterator()) { assertTrue(iterator.hasNext()); Map.Entry<Object, String> entry = iterator.next(); assertEquals(key, entry.getKey()); assertEquals(key.toString(), entry.getValue()); } }
private void testLifespanExpiredEntryRetrieval(Cache<Object, String> primaryOwner, Cache<Object, String> backupOwner, ControlledTimeService timeService, boolean expireOnPrimary) throws Exception { MagicKey key = createKey(primaryOwner, backupOwner); primaryOwner.put(key, key.toString(), 10, TimeUnit.MILLISECONDS); assertEquals(key.toString(), primaryOwner.get(key)); assertEquals(key.toString(), backupOwner.get(key)); other = otherCache; assertEquals(key.toString(), other.get(key)); assertEquals(key.toString(), expiredValue); } else { assertNull(expiredValue);
public void testGetEntry() throws Exception { Cache<MagicKey, String> cache = cache(0); MagicKey localKey = new MagicKey(cache(0)); MagicKey remoteKey = new MagicKey(cache(1)); cache.put(localKey, localKey.toString()); cache.put(remoteKey, remoteKey.toString()); assertNotNull(cache.getAdvancedCache().getCacheEntry(localKey)); assertNotNull(cache.getAdvancedCache().getCacheEntry(remoteKey)); }
cache.put(key, key.toString());
/** * This test verifies that an entry is refreshed properly when the originator thinks the entry is expired * but another node accessed recently, but not same timestamp */ public void testMaxIdleAccessSuspectedExpiredEntryRefreshesProperly() { MagicKey key = createKey(cache0, cache1); String value = key.toString(); cache0.put(key, value, -1, null, 10, TimeUnit.SECONDS); // Now proceed half way in the max idle period before we access it on backup node incrementAllTimeServices(5, TimeUnit.SECONDS); // Access it on the backup to update the last access time (primary still has old access time only) assertEquals(value, cache1.get(key)); // Note now the entry would have been expired, if not for access above incrementAllTimeServices(5, TimeUnit.SECONDS); assertEquals(value, cache0.get(key)); // Now we try to access just before it expires, but it still should be available incrementAllTimeServices(9, TimeUnit.SECONDS); assertEquals(value, cache0.get(key)); }