Search in sources :

Example 6 with CancellationAwareTask

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

the class ClientExecutorServiceCancelTest method testCancel_submitRandom.

private void testCancel_submitRandom(boolean smartRouting) throws ExecutionException, InterruptedException, IOException {
    HazelcastInstance client = createClient(smartRouting);
    IExecutorService executorService = client.getExecutorService(randomString());
    Future<Boolean> future = executorService.submit(new CancellationAwareTask(SLEEP_TIME));
    boolean cancelled = future.cancel(true);
    assertTrue(cancelled);
    future.get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) CancellationAwareTask(com.hazelcast.client.test.executor.tasks.CancellationAwareTask)

Example 7 with CancellationAwareTask

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

the class ClientExecutorServiceCancelTest method testCancel_submitToMember.

private void testCancel_submitToMember(boolean smartRouting, HazelcastInstance server, boolean waitTaskStart) throws ExecutionException, InterruptedException, IOException {
    HazelcastInstance client = createClient(smartRouting);
    IExecutorService executorService = client.getExecutorService(randomString());
    Future<Boolean> future = executorService.submitToMember(new CancellationAwareTask(SLEEP_TIME), server.getCluster().getLocalMember());
    if (waitTaskStart) {
        awaitTaskStartAtMember(server, 1);
    }
    boolean cancelled = future.cancel(true);
    assertTrue(cancelled);
    awaitTaskCancelAtMember(server, 1);
    future.get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) CancellationAwareTask(com.hazelcast.client.test.executor.tasks.CancellationAwareTask)

Example 8 with CancellationAwareTask

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

the class ClientExecutorServiceTest method testCancelFutureAfterCancellationAwareTaskTimeOut.

@Test
@Ignore("https://github.com/hazelcast/hazelcast/issues/4677")
public // Ignored because fixing it requires extensive refactoring see ClientExecutorServiceCancelTest
void testCancelFutureAfterCancellationAwareTaskTimeOut() throws InterruptedException, ExecutionException {
    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.test.executor.tasks.CancellationAwareTask) TimeoutException(java.util.concurrent.TimeoutException) Ignore(org.junit.Ignore) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with CancellationAwareTask

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

the class ClientExecutorServiceTest method testFutureAfterCancellationAwareTaskTimeOut.

@Test
public void testFutureAfterCancellationAwareTaskTimeOut() throws InterruptedException, ExecutionException {
    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.test.executor.tasks.CancellationAwareTask) TimeoutException(java.util.concurrent.TimeoutException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CancellationAwareTask (com.hazelcast.client.test.executor.tasks.CancellationAwareTask)9 IExecutorService (com.hazelcast.core.IExecutorService)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 Future (java.util.concurrent.Future)4 TimeoutException (java.util.concurrent.TimeoutException)3 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)2 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)1 MigrationInterceptor (com.hazelcast.internal.partition.impl.MigrationInterceptor)1 Ignore (org.junit.Ignore)1