public void testBasicInvocation() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); try { DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); decs.submit(new SimpleCallable()); CompletableFuture<Integer> future = decs.take(); Integer r = future.get(); AssertJUnit.assertEquals(1, r.intValue()); } finally { des.shutdownNow(); } }
public void testBasicInvocationWithBlockingQueue() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); try { BlockingQueue<CompletableFuture<Integer>> queue = new ArrayBlockingQueue<>(10); DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des, queue); decs.submit(new SimpleCallable()); CompletableFuture<Integer> future = decs.take(); Integer r = future.get(); AssertJUnit.assertEquals((Integer) 1, r); } finally { des.shutdownNow(); } }
public void testBasicTakeInvocationWithSleepingCallable() throws Exception { long sleepTime = 2000; DistributedExecutorService des = new DefaultExecutorService(c1); DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); try { long start = System.currentTimeMillis(); decs.submit(new SimpleCallable(true, sleepTime)); CompletableFuture<Integer> future = decs.take(); long end = System.currentTimeMillis(); AssertJUnit.assertTrue("take() returned too soon", (end - start) >= sleepTime); AssertJUnit.assertTrue("take() returned, but future is not done yet", future.isDone()); AssertJUnit.assertEquals((Integer) 1, future.get()); } finally { des.shutdownNow(); } }
public void testBasicInvocationWithRunnable() throws Exception { DistributedExecutorService des = new DefaultExecutorService(c1); try { DistributedExecutionCompletionService<Integer> decs = new DistributedExecutionCompletionService<>(des); Integer result = 5; decs.submit(new SimpleRunnable(), result); CompletableFuture<Integer> future = decs.take(); Integer r = future.get(); AssertJUnit.assertEquals(result, r); } finally { des.shutdownNow(); } }
public void testBasicDistributedCallableWitkKeys() throws Exception { c1.put("key1", "Manik"); c1.put("key2", "Mircea"); c1.put("key3", "Galder"); c1.put("key4", "Sanne"); DistributedExecutorService des = new DefaultExecutorService(c1); DistributedExecutionCompletionService<Boolean> decs = new DistributedExecutionCompletionService<>(des); try { decs.submit(new SimpleDistributedCallable(true), "key1", "key2"); Future<Boolean> future = decs.take(); Boolean r = future.get(); assert r; } finally { des.shutdownNow(); } }