Search in sources :

Example 21 with ExecutionCallback

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

the class AbstractInvocationFuture_AndThenTest method whenMultipleCallbacks.

@Test
public void whenMultipleCallbacks() throws ExecutionException, InterruptedException {
    List<ExecutionCallback> callbacks = new LinkedList<ExecutionCallback>();
    for (int k = 0; k < 10; k++) {
        ExecutionCallback callback = mock(ExecutionCallback.class);
        future.andThen(callback);
    }
    sleepSeconds(5);
    future.complete(value);
    for (ExecutionCallback callback : callbacks) {
        verify(callback).onResponse(value);
    }
    assertSame(value, future.getState());
}
Also used : LinkedList(java.util.LinkedList) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with ExecutionCallback

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

the class AbstractInvocationFuture_AndThenTest method whenResponseAlreadyAvailable.

@Test
public void whenResponseAlreadyAvailable() {
    future.complete(value);
    final ExecutionCallback callback = mock(ExecutionCallback.class);
    future.andThen(callback);
    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 23 with ExecutionCallback

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

the class AbstractInvocationFuture_AndThenTest method whenDefaultExecutor.

@Test
public void whenDefaultExecutor() {
    Executor defaultExecutor = mock(Executor.class);
    TestFuture future = new TestFuture(defaultExecutor, logger);
    final ExecutionCallback callback = mock(ExecutionCallback.class);
    future.andThen(callback);
    future.complete(value);
    verify(defaultExecutor).execute(any(Runnable.class));
}
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 24 with ExecutionCallback

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

the class AbstractInvocationFuture_AndThenTest method whenExceptionalResponseAvailableAfterSomeWaiting.

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

        @Override
        public void run() throws Exception {
            verify(callback).onFailure(ex);
        }
    });
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) 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 25 with ExecutionCallback

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

the class AbstractInvocationFuture_ClosedExecutorTest method whenCompleteAfterShutdown_thenCallback.

@Test
public void whenCompleteAfterShutdown_thenCallback() {
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    TestFuture future = new TestFuture(executorService, logger);
    executorService.shutdown();
    future.complete(new Object());
    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