public void testBasicPollInvocation() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); try { decs.submit(new SimpleCallable()); CompletableFuture<Integer> callable = decs.poll(1000, TimeUnit.MILLISECONDS); AssertJUnit.assertEquals((Integer) 1, callable.get()); } finally { des.shutdownNow(); } }
public void testDistributedCallableEverywhere() throws Exception { DefaultExecutorService des = new DefaultExecutorService(c1); DistributedExecutionCompletionService<Boolean> decs = new DistributedExecutionCompletionService<>(des); try { decs.submitEverywhere(new SimpleDistributedCallable(false)); Future<Boolean> f; int counter = 0; while ((f = decs.poll(1,TimeUnit.SECONDS)) != null) { assert f.get(); counter++; } AssertJUnit.assertTrue("Counter greater than 0", counter > 0); } finally { des.shutdownNow(); } }
public void testBasicPollInvocationWithTimeout() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); try { decs.submit(new SimpleCallable(true,5000)); CompletableFuture<Integer> callable = decs.poll(10, TimeUnit.MILLISECONDS); AssertJUnit.assertNull(callable); } finally { des.shutdownNow(); } }
public void testBasicPollInvocationWithSleepingCallable() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); try { decs.submit(new SimpleCallable(true, 5000)); CompletableFuture<Integer> callable = decs.poll(); AssertJUnit.assertNull(callable); } finally { des.shutdownNow(); } }
public void testDistributedCallableEverywhereWithKeys() throws Exception { c1.put("key1", "Manik"); c1.put("key2", "Mircea"); c1.put("key3", "Galder"); c1.put("key4", "Sanne"); DefaultExecutorService des = new DefaultExecutorService(c1); DistributedExecutionCompletionService<Boolean> decs = new DistributedExecutionCompletionService<>(des); try { decs.submitEverywhere(new SimpleDistributedCallable(true), "key1", "key2"); Future<Boolean> f; int counter = 0; while ((f = decs.poll(1,TimeUnit.SECONDS)) != null) { assert f.get(); counter++; } AssertJUnit.assertTrue("Counter greater than 0", counter > 0); } finally { des.shutdownNow(); } }