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 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 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 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 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(); } }