public void testLifespanExpiryInPut() throws InterruptedException { Cache<String, String> cache = getCache(); long lifespan = EXPIRATION_TIMEOUT; cache.put("k", "v", lifespan, MILLISECONDS); DataContainer dc = cache.getAdvancedCache().getDataContainer(); InternalCacheEntry se = dc.get("k"); assert se.getKey().equals("k"); assert se.getValue().equals("v"); assert se.getLifespan() == lifespan; assert se.getMaxIdle() == -1; assert !se.isExpired(timeService.wallClockTime()); assert cache.get("k").equals("v"); timeService.advance(lifespan + 100); assert se.isExpired(timeService.wallClockTime()); assert cache.get("k") == null; }
@Test(dependsOnMethods = "testEnableJmxStats") public void testXsiteStats() throws Exception { ControlledTimeService timeService = new ControlledTimeService(); RpcManagerImpl rpcManager = (RpcManagerImpl) TestingUtil.extractComponent(cache(0, cachename), RpcManager.class); Transport originalTransport = rpcManager.getTransport(); timeService.advance(10); responses.get(0).waitForBackupToFinish(); timeService.advance(20); responses.get(1).waitForBackupToFinish();
private void markStartTime() { startTime = timeService.wallClockTime(); }
/** * To be overridden if the store requires special time handling */ protected ControlledTimeService getTimeService() { return new ControlledTimeService(); }
private static void assertMinTimeElapsed(TestContext context, boolean expected) { assertEquals(format("Check min time has elapsed. Current time=%d. Time elapsed=%d", context.timeService.time(), context.offlineStatus.millisSinceFirstFailure()), expected, context.offlineStatus.minTimeHasElapsed()); }
@Override public long wallClockTime() { advance(1); return super.wallClockTime(); }
protected void configureTimeService() { timeService = new ControlledTimeService(14151); TestingUtil.replaceComponent(cacheManagers.get(0), TimeService.class, timeService, true); }
private void assertStatus(boolean timeout, boolean recoverable, DummyXid... xids) { GlobalTxTable globalTxTable = globalTxTable(0); for (DummyXid xid : xids) { CacheXid cacheXid = new CacheXid(fromString(cacheName()), xid); TxState state = globalTxTable.getState(cacheXid); assertEquals(recoverable, state.isRecoverable()); assertEquals(timeout, state.hasTimedOut(timeService.time())); } }
private void incrementAllTimeServices(long time, TimeUnit unit) { for (ControlledTimeService cts : Arrays.asList(ts0, ts1, ts2)) { cts.advance(unit.toMillis(time)); } }
long txTimestamp = TIME_SERVICE.wallClockTime(); if (transactional) { tm.begin(); TIME_SERVICE.advance(1);
@Override public void call() { ControlledTimeService timeService = new ControlledTimeService(); TestingUtil.replaceComponent(cm, TimeService.class, timeService, true); JCacheManager jCacheManager = createJCacheManager(cm, this); assertEquals("v1", cache.get(1)); timeService.advance(lifespan + 100);
private static void addCommunicationFailure(TestContext context) { context.offlineStatus.updateOnCommunicationFailure(context.timeService.wallClockTime()); }
@BeforeMethod public void setUp() { cm = TestCacheManagerFactory.createCacheManager(false); timeService = new ControlledTimeService(); TestingUtil.replaceComponent(cm, TimeService.class, timeService, true); }
@Override public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable { timeService.advance(TimeUnit.SECONDS.toMillis(2)); return super.visitGetKeyValueCommand(ctx, command); } }, EntryWrappingInterceptor.class);
public void testIdleExpiryInPut() throws InterruptedException { Cache<String, String> cache = getCache(); long idleTime = IDLE_TIMEOUT; cache.put("k", "v", -1, MILLISECONDS, idleTime, MILLISECONDS); DataContainer dc = cache.getAdvancedCache().getDataContainer(); InternalCacheEntry se = dc.get("k"); assert se.getKey().equals("k"); assert se.getValue().equals("v"); assert se.getLifespan() == -1; assert se.getMaxIdle() == idleTime; assert !se.isExpired(timeService.wallClockTime()); assert cache.get("k").equals("v"); timeService.advance(idleTime + 100); assertTrue(se.isExpired(timeService.wallClockTime())); assertNull(cache.get("k")); }
private void assertExpired(InternalCacheEntry entry, boolean expected) { assertEquals(entry + ".isExpired() ", expected, entry.isExpired(timeService.wallClockTime())); }
protected void injectTimeServices() { long now = System.currentTimeMillis(); ts0 = new ControlledTimeService(now); TestingUtil.replaceComponent(manager(0), TimeService.class, ts0, true); ts1 = new ControlledTimeService(now); TestingUtil.replaceComponent(manager(1), TimeService.class, ts1, true); ts2 = new ControlledTimeService(now); TestingUtil.replaceComponent(manager(2), TimeService.class, ts2, true); }
private void expectCachedThenExpired(Integer key, String value) { // Check that it doesn't expire too early controlledTimeService.advance(EXPIRATION_TIMEOUT - 1); String v = this.<Integer, String>cache().get(key); assertEquals(value, v); // But not too late either controlledTimeService.advance(2); assertNull(cache.get(key)); } }
return entry == null || entry.isExpired(timeService.wallClockTime()); assertTrue(expectedValue.equals(c.get(key)) || timeService.wallClockTime() > expectedEndTime); while (timeService.wallClockTime() <= expectedEndTime) { assertFalse("Entry evicted too soon!", condition.isSatisfied()); timeService.advance(checkPeriod); assertTrue(timeService.wallClockTime() > expectedEndTime); assertTrue(condition.isSatisfied()); Object value = c.get(key);