@Override public boolean isCancelled() { return delegate.isCancelled(); }
public void testListenerCalledOnCancelFromRunning() throws Exception { exec.execute(task); runLatch.await(); // Task has started up, cancel it while it's running. task.cancel(true); assertTrue(task.isDone()); assertTrue(task.isCancelled()); assertEquals(1, taskLatch.getCount()); // Wait for the listeners to be called. listenerLatch.await(5, TimeUnit.SECONDS); assertTrue(task.isDone()); assertTrue(task.isCancelled()); assertEquals(1, taskLatch.getCount()); } }
public void testListenerCalledOnCancelFromNotRunning() throws Exception { task.cancel(false); assertTrue(task.isDone()); assertTrue(task.isCancelled()); assertEquals(1, runLatch.getCount()); // Wait for the listeners to be called, don't rely on the same-thread exec. listenerLatch.await(5, TimeUnit.SECONDS); assertTrue(task.isDone()); assertTrue(task.isCancelled()); // Make sure we didn't run anything. assertEquals(1, runLatch.getCount()); }
public void testListenerCalledOnException() throws Exception { throwException = true; // Start up the task and unblock the latch to finish the task. exec.execute(task); runLatch.await(); taskLatch.countDown(); try { task.get(5, TimeUnit.SECONDS); fail("Should have propagated the failure."); } catch (ExecutionException e) { assertEquals(IllegalStateException.class, e.getCause().getClass()); } assertTrue(listenerLatch.await(5, TimeUnit.SECONDS)); assertTrue(task.isDone()); assertFalse(task.isCancelled()); }
public void testListenerDoesNotRunUntilTaskCompletes() throws Exception { // Test default state of not started. assertEquals(1, listenerLatch.getCount()); assertFalse(task.isDone()); assertFalse(task.isCancelled()); // Start the task to put it in the RUNNING state. Have to use a separate // thread because the task will block on the task latch after unblocking // the run latch. exec.execute(task); runLatch.await(); assertEquals(1, listenerLatch.getCount()); assertFalse(task.isDone()); assertFalse(task.isCancelled()); // Finish the task by unblocking the task latch. Then wait for the // listener to be called by blocking on the listener latch. taskLatch.countDown(); assertEquals(25, task.get().intValue()); assertTrue(listenerLatch.await(5, TimeUnit.SECONDS)); assertTrue(task.isDone()); assertFalse(task.isCancelled()); }
@Override public boolean isCancelled() { return delegate.isCancelled(); }
@Override public boolean isCancelled() { return delegate.isCancelled(); }
@Override public boolean isCancelled() { return futureTask.isCancelled(); }
public void testListenerCalledOnCancelFromRunning() throws Exception { exec.execute(task); runLatch.await(); // Task has started up, cancel it while it's running. task.cancel(true); assertTrue(task.isDone()); assertTrue(task.isCancelled()); assertEquals(1, taskLatch.getCount()); // Wait for the listeners to be called. listenerLatch.await(5, TimeUnit.SECONDS); assertTrue(task.isDone()); assertTrue(task.isCancelled()); assertEquals(1, taskLatch.getCount()); } }
public void testListenerCalledOnCancelFromNotRunning() throws Exception { task.cancel(false); assertTrue(task.isDone()); assertTrue(task.isCancelled()); assertEquals(1, runLatch.getCount()); // Wait for the listeners to be called, don't rely on the same-thread exec. listenerLatch.await(5, TimeUnit.SECONDS); assertTrue(task.isDone()); assertTrue(task.isCancelled()); // Make sure we didn't run anything. assertEquals(1, runLatch.getCount()); }
public void testListenerCalledOnException() throws Exception { throwException = true; // Start up the task and unblock the latch to finish the task. exec.execute(task); runLatch.await(); taskLatch.countDown(); try { task.get(5, TimeUnit.SECONDS); fail("Should have propagated the failure."); } catch (ExecutionException e) { assertEquals(IllegalStateException.class, e.getCause().getClass()); } assertTrue(listenerLatch.await(5, TimeUnit.SECONDS)); assertTrue(task.isDone()); assertFalse(task.isCancelled()); }
public void testListenerDoesNotRunUntilTaskCompletes() throws Exception { // Test default state of not started. assertEquals(1, listenerLatch.getCount()); assertFalse(task.isDone()); assertFalse(task.isCancelled()); // Start the task to put it in the RUNNING state. Have to use a separate // thread because the task will block on the task latch after unblocking // the run latch. exec.execute(task); runLatch.await(); assertEquals(1, listenerLatch.getCount()); assertFalse(task.isDone()); assertFalse(task.isCancelled()); // Finish the task by unblocking the task latch. Then wait for the // listener to be called by blocking on the listener latch. taskLatch.countDown(); assertEquals(25, task.get().intValue()); assertTrue(listenerLatch.await(5, TimeUnit.SECONDS)); assertTrue(task.isDone()); assertFalse(task.isCancelled()); }