public void testDelayed(Method m) { initAndCheck(m); CountDownLatch release = new CountDownLatch(1); cache(1).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(null, release), 0); long requestStart = System.nanoTime(); assertEquals(m.getName(), cache(0).get(key)); long requestEnd = System.nanoTime(); long remoteTimeout = cache(0).getCacheConfiguration().clustering().remoteTimeout(); long delay = TimeUnit.NANOSECONDS.toMillis(requestEnd - requestStart); assertTrue(delay < remoteTimeout); release.countDown(); }
@Test(groups = "functional", expectedExceptions = { CacheException.class }) public void testSyncReplTimeout() { AdvancedCache<Object, Object> cache1 = advancedCache(0, "syncReplCache"); AdvancedCache<Object, Object> cache2 = advancedCache(1, "syncReplCache"); cache2.addInterceptor(new CommandInterceptor() { @Override protected Object handleDefault(InvocationContext ctx, VisitableCommand cmd) throws Throwable { // Add a delay Thread.sleep(100); return super.handleDefault(ctx, cmd); } }, 0); cache1.getCacheConfiguration().clustering().remoteTimeout(10); cache2.getCacheConfiguration().clustering().remoteTimeout(10); TestingUtil.blockUntilViewsReceived(10000, cache1, cache2); cache1.put("k", "v"); }
public void testOneOwnerSuspectedOtherTimeout(Method m) throws ExecutionException, InterruptedException { initAndCheck(m); CountDownLatch arrival = new CountDownLatch(2); CountDownLatch release = new CountDownLatch(1); cache(1).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(arrival, release), 0); cache(2).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(arrival, release), 0); Future<?> future = fork(() -> { long start = System.nanoTime(); Exceptions.expectException(TimeoutException.class, () -> cache(0).get(key)); long end = System.nanoTime(); long duration = TimeUnit.NANOSECONDS.toMillis(end - start); assertTrue("Request did not wait for long enough: " + duration, duration >= cache(0).getCacheConfiguration().clustering().remoteTimeout()); }); assertTrue(arrival.await(10, TimeUnit.SECONDS)); installNewView(cache(0), cache(0), cache(1)); // suspection should not fail the operation assertFalse(future.isDone()); future.get(); release.countDown(); }
public void testExceptionFromOneOwnerOtherTimeout(Method m) { initAndCheck(m); CountDownLatch release = new CountDownLatch(1); cache(1).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new FailingInterceptor(), 0); cache(2).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(null, release), 0); // It's not enough to test if the exception is TimeoutException as we want the remote get fail immediately // upon exception. // We cannot mock TimeService in ScheduledExecutor, so we have to measure if the response was fast // remoteTimeout is gracious enough (15s) to not cause false positives long requestStart = System.nanoTime(); try { expectException(RemoteException.class, CacheException.class, "Injected", () -> cache(0).get(key)); long exceptionThrown = System.nanoTime(); long remoteTimeout = cache(0).getCacheConfiguration().clustering().remoteTimeout(); long delay = TimeUnit.NANOSECONDS.toMillis(exceptionThrown - requestStart); assertTrue(delay < remoteTimeout); } finally { release.countDown(); } }
public void testLazyLoadTopology() { HotRodServerConfigurationBuilder builder = new HotRodServerConfigurationBuilder(); builder.topologyStateTransfer(false).topologyReplTimeout(43000); withClusteredServer(builder, (cfg, distSyncTimeout) -> { assertEquals(cfg.clustering().remoteTimeout(), 43000); assertTrue(cfg.clustering().stateTransfer().fetchInMemoryState()); ClusterLoaderConfiguration clcfg = ((ClusterLoaderConfiguration) cfg.persistence().stores().get(0)); assertNotNull(clcfg); assertEquals(clcfg.remoteCallTimeout(), 43000); }); }
public void testUserDefinedTimeouts() { HotRodServerConfigurationBuilder builder = new HotRodServerConfigurationBuilder(); builder.topologyLockTimeout(26000).topologyReplTimeout(31000); withClusteredServer(builder, (cfg, distSyncTimeout) -> { assertEquals(cfg.locking().lockAcquisitionTimeout(), 26000); assertEquals(cfg.clustering().remoteTimeout(), 31000); assertTrue(cfg.clustering().stateTransfer().fetchInMemoryState()); assertEquals(cfg.clustering().stateTransfer().timeout(), 31000 + distSyncTimeout); assertTrue(cfg.persistence().stores().isEmpty()); }); }
assertEquals(15000, c.clustering().remoteTimeout()); assertEquals(15000, c.clustering().remoteTimeout()); assertTrue(!c.clustering().stateTransfer().fetchInMemoryState()); assertTrue(c.clustering().stateTransfer().awaitInitialTransfer()); assertEquals(15000, c.clustering().remoteTimeout()); assertTrue(!c.clustering().stateTransfer().fetchInMemoryState()); assertTrue(c.clustering().stateTransfer().awaitInitialTransfer()); assertEquals(15000, c.clustering().remoteTimeout());
assertEquals(1200000, c.clustering().l1().lifespan()); assertEquals(4, c.clustering().hash().numOwners()); assertEquals(35000, c.clustering().remoteTimeout()); assertEquals(2, c.clustering().hash().numSegments()); assertTrue(c.clustering().hash().consistentHashFactory() instanceof SyncConsistentHashFactory);