private void incrementAllTimeServices(long time, TimeUnit unit) { for (ControlledTimeService cts : Arrays.asList(ts0, ts1, ts2)) { cts.advance(unit.toMillis(time)); } }
@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 testSimpleExpirationMaxIdle() throws Exception { for (int i = 0; i < SIZE; i++) { cache.put("key-" + i, "value-" + i,-1, null, 1, TimeUnit.MILLISECONDS); } timeService.advance(2); assertEquals(0, cache.size()); }
public void testEntryExpired() { String key = "some-key"; Object value = cache.get(key); assertEquals(SimpleLoader.VALUE, value); // Should expire the in memory entry timeService.advance(TimeUnit.SECONDS.toMillis(2)); value = cache.get(key); assertEquals(SimpleLoader.VALUE, value); }
public void testExpirationLifespanInExec() throws Exception { for (int i = 0; i < SIZE; i++) { cache.put("key-" + i, "value-" + i, 1, TimeUnit.MILLISECONDS); } timeService.advance(2); for (int i = 0; i < SIZE; i++) { cache.getAdvancedCache().getDataContainer().executeTask(KeyFilter.ACCEPT_ALL_FILTER, (k, ice) -> { throw new RuntimeException("No task should be executed on expired entry"); }); } }
public void testSimpleExpirationLifespan() throws Exception { for (int i = 0; i < SIZE; i++) { cache.put("key-" + i, "value-" + i, 1, TimeUnit.MILLISECONDS); } timeService.advance(2); assertEquals(0, cache.size()); }
public void testKeySetAfterExpiryInPut(Method m) throws Exception { Cache<Integer, String> cache = cm.getCache(); Map dataIn = new HashMap(); dataIn.put(1, v(m, 1)); dataIn.put(2, v(m, 2)); final long lifespan = EXPIRATION_TIMEOUT; cache.putAll(dataIn, lifespan, TimeUnit.MILLISECONDS); timeService.advance(lifespan + 100); assertEquals(0, cache.keySet().size()); }
public void testVisitGetAllCommand() throws Throwable { GetAllCommand command = new GetAllCommand(Collections.singleton(KEY), 0, false, null); InvocationStage stage = makeStage(interceptor.visitGetAllCommand(ctx, command)); assertFalse(stage.isDone()); timeService.advance(1); nextInterceptor.completeLastInvocation(Collections.emptyMap()); assertEquals(Collections.emptyMap(), stage.get()); assertEquals(1, interceptor.getAverageReadTime()); }
@Override public void testReplaceExpiredEntry() throws Exception { cl.write(marshalledEntry(internalCacheEntry("k1", "v1", 100l))); timeService.advance(1101); assertNull(cl.load("k1")); long start = System.currentTimeMillis(); cl.write(marshalledEntry(internalCacheEntry("k1", "v2", 100l))); assertTrue(cl.load("k1").getValue().equals("v2") || TestingUtil.moreThanDurationElapsed(start, 100)); } }
public void testVisitGetAllCommandException() throws Throwable { GetAllCommand command = new GetAllCommand(Collections.singleton(KEY), 0, false, null); InvocationStage stage = makeStage(interceptor.visitGetAllCommand(ctx, command)); assertFalse(stage.isDone()); timeService.advance(1); nextInterceptor.completeLastInvocationExceptionally(new TestException()); expectInvocationException(stage); assertEquals(1, interceptor.getAverageReadTime()); }
public void testExpirationMaxIdleInOps() throws Exception { for (int i = 0; i < SIZE; i++) { cache.put("key-" + i, "value-" + i,-1, null, 1, TimeUnit.MILLISECONDS); } timeService.advance(2); for (int i = 0; i < SIZE; i++) { assertFalse(cache.containsKey("key-" + 1)); assertNull(cache.get("key-" + i)); assertNull(cache.remove("key-" + i)); } }
public void testExpirationLifespanInOps() throws Exception { for (int i = 0; i < SIZE; i++) { cache.put("key-" + i, "value-" + i, 1, TimeUnit.MILLISECONDS); } timeService.advance(2); for (int i = 0; i < SIZE; i++) { assertFalse(cache.containsKey("key-" + 1)); assertNull(cache.get("key-" + i)); assertNull(cache.remove("key-" + i)); } }
public void testExpiredEntriesCleared() { cache.put("key-" + 0, "value-" + 1, -1, null, 0, TimeUnit.MILLISECONDS); cache.put("key-" + 1, "value-" + 1, -1, null, 1, TimeUnit.MILLISECONDS); // This should expire 1 of the entries timeService.advance(1); cache.clear(); assertEquals(0, cache.getAdvancedCache().getDataContainer().sizeIncludingExpired()); } }
public void testVisitGetCacheEntryCommandException() throws Throwable { GetCacheEntryCommand command = new GetCacheEntryCommand(KEY, 0, 0, null); InvocationStage stage = makeStage(interceptor.visitGetCacheEntryCommand(ctx, command)); assertFalse(stage.isDone()); timeService.advance(1); nextInterceptor.completeLastInvocationExceptionally(new TestException()); expectInvocationException(stage); assertEquals(1, interceptor.getAverageReadTime()); }
public void testVisitPutKeyValueCommandException() throws Throwable { PutKeyValueCommand command = new PutKeyValueCommand(KEY, VALUE, false, null, null, 0, 0, null); InvocationStage stage = makeStage(interceptor.visitPutKeyValueCommand(ctx, command)); assertFalse(stage.isDone()); timeService.advance(1); nextInterceptor.completeLastInvocationExceptionally(new TestException()); expectInvocationException(stage); assertEquals(1, interceptor.getAverageWriteTime()); }
public void testVisitRemoveCommand() throws Throwable { RemoveCommand command = new RemoveCommand(KEY, null, null, 0, 0, null); InvocationStage stage = makeStage(interceptor.visitRemoveCommand(ctx, command)); assertFalse(stage.isDone()); timeService.advance(1); nextInterceptor.completeLastInvocation(VALUE); assertEquals(VALUE, stage.get()); assertEquals(1, interceptor.getAverageRemoveTime()); }
public void testVisitEvictCommandException() throws Throwable { EvictCommand command = new EvictCommand(KEY, null, 0, 0, null, null); InvocationStage stage = makeStage(interceptor.visitEvictCommand(ctx, command)); assertFalse(stage.isDone()); timeService.advance(1); nextInterceptor.completeLastInvocationExceptionally(new TestException()); expectInvocationException(stage); assertEquals(1, interceptor.getEvictions()); }
public void testVisitPutKeyValueCommand() throws Throwable { PutKeyValueCommand command = new PutKeyValueCommand(KEY, VALUE, false, null, null, 0, 0, null); InvocationStage stage = makeStage(interceptor.visitPutKeyValueCommand(ctx, command)); assertFalse(stage.isDone()); timeService.advance(1); nextInterceptor.completeLastInvocation(null); assertNull(stage.get()); assertEquals(1, interceptor.getAverageWriteTime()); }
public void testVisitGetKeyValueCommand() throws Throwable { GetKeyValueCommand command = new GetKeyValueCommand(KEY, 0, 0); InvocationStage stage = makeStage(interceptor.visitGetKeyValueCommand(ctx, command)); assertFalse(stage.isDone()); timeService.advance(1); nextInterceptor.completeLastInvocation(null); assertNull(stage.get()); assertEquals(1, interceptor.getAverageReadTime()); }
public void testBiasTimesOut() throws Exception { rpcManager0.excludeCommands(ExceptionAckCommand.class); MagicKey key = new MagicKey(cache(0)); cache(1).put(key, "v0"); assertTrue(biasManager(1).hasLocalBias(key)); timeService.advance(BIAS_LIFESPAN + 1); rpcManager0.expectCommand(RevokeBiasCommand.class).send().receiveAll(); // The local bias is invalidated synchronously with the sync command, but it may take few moments // to remove the remote bias. assertFalse(biasManager(1).hasLocalBias(key)); eventuallyEquals(null, () -> biasManager(0).getRemoteBias(key)); }