Search in sources :

Example 16 with ExecutionCallback

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

the class DurableSingleNodeTest method executionCallback_notifiedOnSuccess.

@Test
public void executionCallback_notifiedOnSuccess() {
    final CountDownLatch latch = new CountDownLatch(1);
    Callable<String> task = new BasicTestCallable();
    ExecutionCallback<String> executionCallback = new ExecutionCallback<String>() {

        public void onResponse(String response) {
            latch.countDown();
        }

        public void onFailure(Throwable t) {
        }
    };
    executor.submit(task).andThen(executionCallback);
    assertOpenEventually(latch);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with ExecutionCallback

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

the class InvocationBuilderTest method getTargetExecutionCallback_whenExecutionCallbackInstance.

@Test
public void getTargetExecutionCallback_whenExecutionCallbackInstance() {
    InvocationBuilder builder = new MockInvocationBuilder(null, null, 0, null);
    ExecutionCallback callback = mock(ExecutionCallback.class);
    builder.setExecutionCallback(callback);
    assertSame(callback, builder.getTargetExecutionCallback());
}
Also used : ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with ExecutionCallback

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

the class EntryProcessorTest method testSubmitToKeyWithCallback.

@Test
public void testSubmitToKeyWithCallback() throws Exception {
    HazelcastInstance instance1 = createHazelcastInstance(getConfig());
    IMap<Integer, Integer> map = instance1.getMap(MAP_NAME);
    map.put(1, 1);
    final CountDownLatch latch = new CountDownLatch(1);
    ExecutionCallback executionCallback = new ExecutionCallback() {

        @Override
        public void onResponse(Object response) {
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
        }
    };
    map.submitToKey(1, new IncrementorEntryProcessor(), executionCallback);
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    assertEquals(2, (int) map.get(1));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.EntryObject) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with ExecutionCallback

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

the class AbstractCompletableFutureTest method andThen_whenCancelled.

@Test
public void andThen_whenCancelled() {
    TestFutureImpl future = new TestFutureImpl(nodeEngine, logger);
    ExecutionCallback callback = mock(ExecutionCallback.class);
    future.cancel(false);
    future.andThen(callback, executor);
    verifyZeroInteractions(callback);
}
Also used : ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with ExecutionCallback

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

the class AbstractCompletableFutureTest method andThen_whenResultAvailable.

@Test
public void andThen_whenResultAvailable() throws Exception {
    TestFutureImpl future = new TestFutureImpl(nodeEngine, logger);
    final Object result = "result";
    final ExecutionCallback callback = mock(ExecutionCallback.class);
    future.setResult(result);
    future.andThen(callback, executor);
    assertSame(result, future.get());
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            verify(callback).onResponse(result);
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) ExecutionCallback(com.hazelcast.core.ExecutionCallback) TimeoutException(java.util.concurrent.TimeoutException) ExpectedException(org.junit.rules.ExpectedException) CancellationException(java.util.concurrent.CancellationException) 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