Search in sources :

Example 26 with ExecutionCallback

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

the class NearCacheTest method testAfterSubmitToKeyWithCallbackNearCacheIsInvalidated.

@Test
public void testAfterSubmitToKeyWithCallbackNearCacheIsInvalidated() throws Exception {
    int mapSize = 1000;
    String mapName = randomMapName();
    Random random = new Random();
    Config config = createNearCachedMapConfig(mapName);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, Integer> map = instance.getMap(mapName);
    populateMap(map, mapSize);
    populateNearCache(map, mapSize);
    final CountDownLatch latch = new CountDownLatch(10);
    ExecutionCallback<Integer> callback = new ExecutionCallback<Integer>() {

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

        @Override
        public void onFailure(Throwable t) {
        }
    };
    int randomKey = random.nextInt(mapSize);
    map.submitToKey(randomKey, new AbstractEntryProcessor<Integer, Integer>() {

        @Override
        public Object process(Map.Entry<Integer, Integer> entry) {
            int currentValue = entry.getValue();
            int newValue = currentValue + 1;
            entry.setValue(newValue);
            return newValue;
        }
    }, callback);
    latch.await(3, TimeUnit.SECONDS);
    assertEquals(mapSize - 1, getNearCacheStats(map).getOwnedEntryCount());
}
Also used : MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Random(java.util.Random) EntryObject(com.hazelcast.query.EntryObject) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 27 with ExecutionCallback

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

the class AbstractCompletableFutureTest method andThen_whenPendingCallback_andCancelled.

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

Example 28 with ExecutionCallback

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

the class AbstractCompletableFutureTest method andThen_whenPendingCallback.

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

Example 29 with ExecutionCallback

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

the class AbstractCompletableFutureTest method andThen_whenInitialState.

@Test
public void andThen_whenInitialState() {
    TestFutureImpl future = new TestFutureImpl(nodeEngine, logger);
    ExecutionCallback callback = mock(ExecutionCallback.class);
    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 30 with ExecutionCallback

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

the class AbstractCompletableFutureTest method setResult_whenPendingCallback_callbacksExecutedCorrectly.

public void setResult_whenPendingCallback_callbacksExecutedCorrectly(final Object result) {
    TestFutureImpl future = new TestFutureImpl(nodeEngine, logger);
    final ExecutionCallback callback1 = mock(ExecutionCallback.class);
    final ExecutionCallback callback2 = mock(ExecutionCallback.class);
    future.andThen(callback1);
    future.andThen(callback2);
    future.setResult(result);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            if (result instanceof Throwable) {
                verify(callback1).onFailure((Throwable) result);
            } else {
                verify(callback1).onResponse(result);
            }
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            if (result instanceof Throwable) {
                verify(callback2).onFailure((Throwable) result);
            } else {
                verify(callback2).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)

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