Search in sources :

Example 6 with CancellationAwareTask

use of com.hazelcast.client.executor.tasks.CancellationAwareTask in project hazelcast by hazelcast.

the class ClientExecutorServiceTest method testCancelFutureAfterCancellationAwareTaskTimeOut.

@Test
@Ignore
public //Ignored because fixing it requires extensive refactoring see ClientExecutorServiceCancelTest
void testCancelFutureAfterCancellationAwareTaskTimeOut() throws InterruptedException, ExecutionException, TimeoutException {
    IExecutorService service = client.getExecutorService(randomString());
    CancellationAwareTask task = new CancellationAwareTask(Long.MAX_VALUE);
    Future future = service.submit(task);
    try {
        future.get(1, TimeUnit.SECONDS);
    } catch (TimeoutException ignored) {
    }
    assertTrue(future.cancel(true));
    assertTrue(future.isCancelled());
    assertTrue(future.isDone());
}
Also used : Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) CancellationAwareTask(com.hazelcast.client.executor.tasks.CancellationAwareTask) TimeoutException(java.util.concurrent.TimeoutException) Ignore(org.junit.Ignore) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with CancellationAwareTask

use of com.hazelcast.client.executor.tasks.CancellationAwareTask in project hazelcast by hazelcast.

the class ClientExecutorServiceTest method testFutureAfterCancellationAwareTaskTimeOut.

@Test
public void testFutureAfterCancellationAwareTaskTimeOut() throws InterruptedException, ExecutionException, TimeoutException {
    IExecutorService service = client.getExecutorService(randomString());
    CancellationAwareTask task = new CancellationAwareTask(Long.MAX_VALUE);
    Future future = service.submit(task);
    try {
        future.get(1, TimeUnit.SECONDS);
    } catch (TimeoutException ignored) {
    }
    assertFalse(future.isDone());
    assertFalse(future.isCancelled());
}
Also used : Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) CancellationAwareTask(com.hazelcast.client.executor.tasks.CancellationAwareTask) TimeoutException(java.util.concurrent.TimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

CancellationAwareTask (com.hazelcast.client.executor.tasks.CancellationAwareTask)7 IExecutorService (com.hazelcast.core.IExecutorService)7 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Future (java.util.concurrent.Future)4 Test (org.junit.Test)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 TimeoutException (java.util.concurrent.TimeoutException)3 Ignore (org.junit.Ignore)1