Search in sources :

Example 1 with SleepingTask

use of com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceTest method test_whenRingBufferIsFull_thenClientDurableExecutorServiceCompletedFutureIsReturned.

@Test
public void test_whenRingBufferIsFull_thenClientDurableExecutorServiceCompletedFutureIsReturned() throws Exception {
    final AtomicBoolean onResponse = new AtomicBoolean();
    final CountDownLatch onFailureLatch = new CountDownLatch(1);
    String key = randomString();
    DurableExecutorService service = client.getDurableExecutorService(SINGLE_TASK + randomString());
    service.submitToKeyOwner(new SleepingTask(100), key);
    DurableExecutorServiceFuture<String> future = service.submitToKeyOwner(new BasicTestCallable(), key);
    future.andThen(new ExecutionCallback<String>() {

        @Override
        public void onResponse(String response) {
            onResponse.set(true);
        }

        @Override
        public void onFailure(Throwable t) {
            onFailureLatch.countDown();
        }
    });
    try {
        future.get(1, TimeUnit.HOURS);
        fail("We expected that future.get() throws an ExecutionException!");
    } catch (ExecutionException ignored) {
    }
    // assert TaskId
    try {
        future.getTaskId();
        fail("We expected that future.getTaskId() throws an IllegalStateException!");
    } catch (IllegalStateException ignored) {
    }
    // assert states of ClientDurableExecutorServiceCompletedFuture
    assertFalse(future.cancel(false));
    assertFalse(future.cancel(true));
    assertFalse(future.isCancelled());
    assertTrue(future.isDone());
    // assert that onFailure() has been called and not onResponse()
    onFailureLatch.await();
    assertFalse(onResponse.get());
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SleepingTask(com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask) BasicTestCallable(com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with SleepingTask

use of com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceTest method testFullRingBuffer_WithExecutionCallback.

public void testFullRingBuffer_WithExecutionCallback() throws InterruptedException {
    String key = randomString();
    DurableExecutorService service = client.getDurableExecutorService(SINGLE_TASK + randomString());
    service.submitToKeyOwner(new SleepingTask(100), key);
    DurableExecutorServiceFuture<String> future = service.submitToKeyOwner(new BasicTestCallable(), key);
    final CountDownLatch latch = new CountDownLatch(1);
    future.andThen(new ExecutionCallback<String>() {

        @Override
        public void onResponse(String response) {
        }

        @Override
        public void onFailure(Throwable t) {
            if (t.getCause() instanceof RejectedExecutionException) {
                latch.countDown();
            }
        }
    });
    assertOpenEventually(latch);
    assertTrue(future.isDone());
    assertFalse(future.cancel(true));
    assertFalse(future.isCancelled());
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) SleepingTask(com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask) BasicTestCallable(com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 3 with SleepingTask

use of com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask in project hazelcast by hazelcast.

the class ClientDurableRetrieveResultTest method testRetrieve_WhenSubmitterMemberDown.

@Test
public void testRetrieve_WhenSubmitterMemberDown() throws Exception {
    String name = randomString();
    DurableExecutorService executorService = client.getDurableExecutorService(name);
    SleepingTask task = new SleepingTask(4);
    long taskId = executorService.submit(task).getTaskId();
    client.shutdown();
    client = hazelcastFactory.newHazelcastClient();
    executorService = client.getDurableExecutorService(name);
    Future<Boolean> future = executorService.retrieveResult(taskId);
    assertTrue(future.get());
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) SleepingTask(com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with SleepingTask

use of com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask in project hazelcast by hazelcast.

the class ClientDurableRetrieveResultTest method testRetrieveAndDispose_WhenOwnerMemberDown.

@Test
public void testRetrieveAndDispose_WhenOwnerMemberDown() throws Exception {
    String name = randomString();
    String key = generateKeyOwnedBy(instance2);
    DurableExecutorService executorService = client.getDurableExecutorService(name);
    SleepingTask task = new SleepingTask(4);
    long taskId = executorService.submitToKeyOwner(task, key).getTaskId();
    instance2.shutdown();
    Future<Boolean> future = executorService.retrieveAndDisposeResult(taskId);
    assertTrue(future.get());
    Future<Boolean> resultFuture = executorService.retrieveResult(taskId);
    assertNull(resultFuture.get());
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) SleepingTask(com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with SleepingTask

use of com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask in project hazelcast by hazelcast.

the class ClientDurableRetrieveResultTest method testRetrieveAndDispose_WhenClientDown.

@Test
public void testRetrieveAndDispose_WhenClientDown() throws Exception {
    String name = randomString();
    DurableExecutorService executorService = client.getDurableExecutorService(name);
    SleepingTask task = new SleepingTask(4);
    long taskId = executorService.submit(task).getTaskId();
    client.shutdown();
    client = hazelcastFactory.newHazelcastClient();
    executorService = client.getDurableExecutorService(name);
    Future<Boolean> future = executorService.retrieveAndDisposeResult(taskId);
    assertTrue(future.get());
    Future<Object> resultFuture = executorService.retrieveResult(taskId);
    assertNull(resultFuture.get());
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) SleepingTask(com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

DurableExecutorService (com.hazelcast.durableexecutor.DurableExecutorService)7 SleepingTask (com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask)7 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)7 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 BasicTestCallable (com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 RootCauseMatcher (com.hazelcast.util.RootCauseMatcher)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1