Search in sources :

Example 1 with CancellationAwareTask

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

the class ClientExecutorServiceCancelTest method testCancel_submitToKeyOwner.

private void testCancel_submitToKeyOwner(boolean smartRouting) throws ExecutionException, InterruptedException {
    HazelcastInstance client = createClient(smartRouting);
    IExecutorService executorService = client.getExecutorService(randomString());
    Future<Boolean> future = executorService.submitToKeyOwner(new CancellationAwareTask(SLEEP_TIME), randomString());
    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.executor.tasks.CancellationAwareTask)

Example 2 with CancellationAwareTask

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

the class ClientExecutorServiceTest method testGetFutureAfterCancel.

@Test(expected = CancellationException.class)
public void testGetFutureAfterCancel() 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) {
    }
    future.cancel(true);
    future.get();
}
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)

Example 3 with CancellationAwareTask

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

the class ClientExecutorServiceTest method testCancellationAwareTask_whenTimeOut.

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

Example 4 with CancellationAwareTask

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

the class ClientExecutorServiceCancelTest method testCancel_submitToMember.

private void testCancel_submitToMember(boolean smartRouting, Member member) throws ExecutionException, InterruptedException {
    HazelcastInstance client = createClient(smartRouting);
    IExecutorService executorService = client.getExecutorService(randomString());
    Future<Boolean> future = executorService.submitToMember(new CancellationAwareTask(SLEEP_TIME), member);
    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.executor.tasks.CancellationAwareTask)

Example 5 with CancellationAwareTask

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

the class ClientExecutorServiceCancelTest method testCancel_submitRandom.

private void testCancel_submitRandom(boolean smartRouting) throws ExecutionException, InterruptedException {
    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.executor.tasks.CancellationAwareTask)

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