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());
}
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);
}
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);
}
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);
}
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);
}
}
});
}
Aggregations