Search in sources :

Example 1 with ListeningScheduledExecutorService

use of com.google.common.util.concurrent.ListeningScheduledExecutorService in project guava by google.

the class TestingExecutorsTest method testNoOpScheduledExecutorInvokeAll.

public void testNoOpScheduledExecutorInvokeAll() throws ExecutionException, InterruptedException {
    ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
    taskDone = false;
    Callable<Boolean> task = new Callable<Boolean>() {

        @Override
        public Boolean call() {
            taskDone = true;
            return taskDone;
        }
    };
    List<Future<Boolean>> futureList = executor.invokeAll(ImmutableList.of(task), 10, TimeUnit.MILLISECONDS);
    Future<Boolean> future = futureList.get(0);
    assertFalse(taskDone);
    assertTrue(future.isDone());
    try {
        future.get();
        fail();
    } catch (CancellationException e) {
    // pass
    }
}
Also used : ListeningScheduledExecutorService(com.google.common.util.concurrent.ListeningScheduledExecutorService) CancellationException(java.util.concurrent.CancellationException) Future(java.util.concurrent.Future) ScheduledFuture(java.util.concurrent.ScheduledFuture) Callable(java.util.concurrent.Callable)

Example 2 with ListeningScheduledExecutorService

use of com.google.common.util.concurrent.ListeningScheduledExecutorService in project guava by google.

the class TestingExecutorsTest method testNoOpScheduledExecutorShutdown.

public void testNoOpScheduledExecutorShutdown() {
    ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
    assertFalse(executor.isShutdown());
    assertFalse(executor.isTerminated());
    executor.shutdown();
    assertTrue(executor.isShutdown());
    assertTrue(executor.isTerminated());
}
Also used : ListeningScheduledExecutorService(com.google.common.util.concurrent.ListeningScheduledExecutorService)

Aggregations

ListeningScheduledExecutorService (com.google.common.util.concurrent.ListeningScheduledExecutorService)2 Callable (java.util.concurrent.Callable)1 CancellationException (java.util.concurrent.CancellationException)1 Future (java.util.concurrent.Future)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1