コード例 #1
0
  /** Shutting down the cluster should act as the ExecutorService shutdown */
  @Test(expected = RejectedExecutionException.class)
  public void testClusterShutdown() throws Exception {
    ExecutorService executor = createSingleNodeExecutorService("testClusterShutdown");
    shutdownNodeFactory();
    Thread.sleep(2000);

    assertNotNull(executor);
    assertTrue(executor.isShutdown());
    assertTrue(executor.isTerminated());

    // New tasks must be rejected
    Callable<String> task = new BasicTestTask();
    executor.submit(task);
  }
コード例 #2
0
 /** Shutdown-related method behaviour when the cluster is running */
 @Test
 public void testShutdownBehaviour() throws Exception {
   ExecutorService executor = createSingleNodeExecutorService("testShutdownBehaviour");
   // Fresh instance, is not shutting down
   assertFalse(executor.isShutdown());
   assertFalse(executor.isTerminated());
   executor.shutdown();
   assertTrue(executor.isShutdown());
   assertTrue(executor.isTerminated());
   // shutdownNow() should return an empty list and be ignored
   List<Runnable> pending = executor.shutdownNow();
   assertTrue(pending.isEmpty());
   assertTrue(executor.isShutdown());
   assertTrue(executor.isTerminated());
   // awaitTermination() should return immediately false
   try {
     boolean terminated = executor.awaitTermination(60L, TimeUnit.SECONDS);
     assertFalse(terminated);
   } catch (InterruptedException ie) {
     fail("InterruptedException");
   }
   assertTrue(executor.isShutdown());
   assertTrue(executor.isTerminated());
 }