Search in sources :

Example 41 with ExecutionCallback

use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.

the class AbstractInvocationFuture_AndThenTest method whenExceptionalResponseAvailableAfterSomeWaiting_MemberLeftException.

@Test
public void whenExceptionalResponseAvailableAfterSomeWaiting_MemberLeftException() {
    final ExecutionCallback callback = mock(ExecutionCallback.class);
    future.andThen(callback);
    final MemberLeftException ex = new MemberLeftException();
    future.complete(ex);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            verify(callback).onFailure(ex);
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) ExecutionCallback(com.hazelcast.core.ExecutionCallback) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) MemberLeftException(com.hazelcast.core.MemberLeftException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 42 with ExecutionCallback

use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.

the class AbstractInvocationFuture_AndThenTest method whenResponseAvailableAfterSomeWaiting.

@Test
public void whenResponseAvailableAfterSomeWaiting() {
    final ExecutionCallback callback = mock(ExecutionCallback.class);
    future.andThen(callback);
    sleepSeconds(5);
    verifyZeroInteractions(callback);
    future.complete(value);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            verify(callback).onResponse(value);
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) ExecutionCallback(com.hazelcast.core.ExecutionCallback) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 43 with ExecutionCallback

use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.

the class AbstractInvocationFuture_AndThenTest method whenCustomerExecutor.

@Test
public void whenCustomerExecutor() {
    Executor defaultExecutor = mock(Executor.class);
    Executor customExecutor = mock(Executor.class);
    TestFuture future = new TestFuture(defaultExecutor, logger);
    final ExecutionCallback callback = mock(ExecutionCallback.class);
    future.andThen(callback, customExecutor);
    future.complete(value);
    verify(customExecutor).execute(any(Runnable.class));
    verifyZeroInteractions(defaultExecutor);
}
Also used : Executor(java.util.concurrent.Executor) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 44 with ExecutionCallback

use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.

the class AbstractInvocationFuture_ClosedExecutorTest method whenCompleteBeforeShutdown_thenCallback.

@Test
public void whenCompleteBeforeShutdown_thenCallback() {
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    TestFuture future = new TestFuture(executorService, logger);
    future.complete(new Object());
    executorService.shutdown();
    final AtomicBoolean onFailure = new AtomicBoolean();
    future.andThen(new ExecutionCallback() {

        @Override
        public void onResponse(Object response) {
        }

        @Override
        public void onFailure(Throwable t) {
            if (t instanceof RejectedExecutionException) {
                onFailure.set(true);
            }
        }
    });
    assertTrue(onFailure.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutorService(java.util.concurrent.ExecutorService) ExecutionCallback(com.hazelcast.core.ExecutionCallback) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ExecutionCallback (com.hazelcast.core.ExecutionCallback)44 QuickTest (com.hazelcast.test.annotation.QuickTest)39 Test (org.junit.Test)39 ParallelTest (com.hazelcast.test.annotation.ParallelTest)37 CountDownLatch (java.util.concurrent.CountDownLatch)24 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)11 IMap (com.hazelcast.core.IMap)10 IExecutorService (com.hazelcast.core.IExecutorService)9 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)9 MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)8 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 Member (com.hazelcast.core.Member)7 AssertTask (com.hazelcast.test.AssertTask)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 MemberLeftException (com.hazelcast.core.MemberLeftException)4 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)4 ExecutionException (java.util.concurrent.ExecutionException)4 Config (com.hazelcast.config.Config)3 DurableExecutorService (com.hazelcast.durableexecutor.DurableExecutorService)3