public void testBasicLocalDistributedCallable() throws Exception { long taskTimeout = TimeUnit.SECONDS.toMillis(15); EmbeddedCacheManager cacheManager1 = manager(0); Cache<Object, Object> cache1 = cacheManager1.getCache(); // initiate task from cache1 and execute on same node DistributedExecutorService des = new DefaultExecutorService(cache1); try { SameNodeTaskFailoverPolicy sameNodeTaskFailoverPolicy = new SameNodeTaskFailoverPolicy(3); DistributedTaskBuilder<Void> builder = des .createDistributedTaskBuilder(new TestExceptionCallable()) .failoverPolicy(sameNodeTaskFailoverPolicy) .timeout(taskTimeout, TimeUnit.MILLISECONDS); CompletableFuture<Void> future = des.submit(builder.build()); expectExecutionException(TestException.class, future); assertEquals(3, sameNodeTaskFailoverPolicy.failoverCount.get()); } finally { des.shutdown(); } }
public void testDistributedCallableRandomFailoverPolicy() throws Exception { ConfigurationBuilder config = TestCacheManagerFactory.getDefaultCacheConfiguration(true); config.clustering().cacheMode(CacheMode.REPL_SYNC); EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createClusteredCacheManager(config); DistributedExecutorService des = null; try { Cache<Object, Object> cache1 = cacheManager.getCache(); cache1.put("key1", "value1"); cache1.put("key2", "value2"); //initiate task from cache1 and select cache1 as target des = new DefaultExecutorService(cache1); //the same using DistributedTask API DistributedTaskBuilder<Integer> taskBuilder = des.createDistributedTaskBuilder(new FailOnlyOnceCallable()); taskBuilder.failoverPolicy(DefaultExecutorService.RANDOM_NODE_FAILOVER); DistributedTask<Integer> task = taskBuilder.build(); assert task.getTaskFailoverPolicy().equals(DefaultExecutorService.RANDOM_NODE_FAILOVER); Future<Integer> val = des.submit(task, "key1"); val.get(); throw new IllegalStateException("Should have raised exception"); } catch (ExecutionException e){ // The failover policy throws an IllegalStateException because there are no nodes to retry on. // Verify that the distributed executor didn't wrap the exception in too many extra exceptions. AssertJUnit.assertTrue("Wrong exception: " + e, e.getCause() instanceof IllegalStateException); } finally { if (des != null) des.shutdownNow(); TestingUtil.killCacheManagers(cacheManager); } }
taskBuilder.failoverPolicy(DefaultExecutorService.RANDOM_NODE_FAILOVER);
public void testBasicTargetRemoteDistributedCallable() throws Exception { long taskTimeout = TimeUnit.SECONDS.toMillis(15); EmbeddedCacheManager cacheManager1 = manager(0); final EmbeddedCacheManager cacheManager2 = manager(1); Cache<Object, Object> cache1 = cacheManager1.getCache(); Cache<Object, Object> cache2 = cacheManager2.getCache(); DistributedExecutorService des = null; try { des = new DefaultExecutorService(cache1); Address target = cache2.getAdvancedCache().getRpcManager().getAddress(); DistributedTaskBuilder<Integer> builder = des.createDistributedTaskBuilder(new SimpleCallable()) .failoverPolicy(DefaultExecutorService.RANDOM_NODE_FAILOVER) .timeout(taskTimeout, TimeUnit.MILLISECONDS); Future<Integer> future = des.submit(target, builder.build()); AssertJUnit.assertEquals((Integer) 1, future.get()); } catch (Exception ex) { AssertJUnit.fail("Task did not failover properly " + ex); } finally { if (des != null) des.shutdown(); } }
public void testBasicTargetRemoteDistributedCallable() throws Exception { long taskTimeout = TimeUnit.SECONDS.toMillis(15); EmbeddedCacheManager cacheManager1 = manager(0); final EmbeddedCacheManager cacheManager2 = manager(1); Cache<Object, Object> cache1 = cacheManager1.getCache(); Cache<Object, Object> cache2 = cacheManager2.getCache(); // initiate task from cache1 and execute on same node DistributedExecutorService des = new DefaultExecutorService(cache1); Address target = cache2.getAdvancedCache().getRpcManager().getAddress(); try { DistributedTaskBuilder<Integer> builder = des .createDistributedTaskBuilder(new SleepingSimpleCallable()) .failoverPolicy(new RandomNodeTaskFailoverPolicy(2)) .timeout(taskTimeout, TimeUnit.MILLISECONDS); Future<Integer> future = des.submit(target, builder.build()); fork(() -> { TestingUtil.killCacheManagers(cacheManager2); latch.countDown(); }); assertEquals((Integer) 1, future.get()); } finally { des.shutdown(); } }
taskBuilder.failoverPolicy(new DistributedTaskFailoverPolicy() {
public void testDistributedCallableEmptyFailoverPolicy() throws Exception { ConfigurationBuilder config = TestCacheManagerFactory.getDefaultCacheConfiguration(true); config.clustering().cacheMode(CacheMode.REPL_SYNC); EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createClusteredCacheManager(config); DistributedExecutorService des = null; try { Cache<Object, Object> cache1 = cacheManager.getCache(); //initiate task from cache1 and select cache1 as target des = new DefaultExecutorService(cache1); //the same using DistributedTask API DistributedTaskBuilder<Integer> taskBuilder = des.createDistributedTaskBuilder(new ExceptionThrowingCallable()); taskBuilder.failoverPolicy(null); DistributedTask<Integer> task = taskBuilder.build(); assert task.getTaskFailoverPolicy().equals(DefaultExecutorService.NO_FAILOVER); Future<Integer> f = des.submit(task); expectException(ExecutionException.class, TestException.class, f::get); } finally { if (des != null) des.shutdownNow(); TestingUtil.killCacheManagers(cacheManager); } }
taskBuilder.failoverPolicy(new DistributedTaskFailoverPolicy() {
taskBuilder.failoverPolicy(new DistributedTaskFailoverPolicy() {