use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method submitRunnable_withExecutionCallback.
@Test
public void submitRunnable_withExecutionCallback() {
IExecutorService service = client.getExecutorService(randomString());
final CountDownLatch responseLatch = new CountDownLatch(1);
String mapName = randomString();
Runnable runnable = new MapPutRunnable(mapName);
MemberSelector selector = new SelectAllMembers();
service.submit(runnable, selector, new ExecutionCallback() {
public void onResponse(Object response) {
responseLatch.countDown();
}
public void onFailure(Throwable t) {
}
});
IMap map = client.getMap(mapName);
assertOpenEventually("responseLatch", responseLatch);
assertEquals(1, map.size());
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method testSubmitCallableToMember_withExecutionCallback.
@Test
public void testSubmitCallableToMember_withExecutionCallback() throws Exception {
IExecutorService service = client.getExecutorService(randomString());
Callable getUuidCallable = new GetMemberUuidTask();
Member member = server.getCluster().getLocalMember();
final CountDownLatch responseLatch = new CountDownLatch(1);
final AtomicReference<Object> result = new AtomicReference<Object>();
service.submitToMember(getUuidCallable, member, new ExecutionCallback() {
@Override
public void onResponse(Object response) {
result.set(response);
responseLatch.countDown();
}
@Override
public void onFailure(Throwable t) {
}
});
assertOpenEventually("responseLatch", responseLatch);
assertEquals(member.getUuid(), result.get());
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class ClientMapNearCacheTest method testAfterSubmitToKeyWithCallbackKeyIsInvalidatedFromNearCache.
@Test
public void testAfterSubmitToKeyWithCallbackKeyIsInvalidatedFromNearCache() throws Exception {
final int mapSize = 1000;
String mapName = randomMapName("testAfterSubmitToKeyWithCallbackKeyIsInvalidatedFromNearCache");
Random random = new Random();
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(newConfig());
IMap memberMap = member.getMap(mapName);
populateMap(memberMap, mapSize);
HazelcastInstance client = getClient(hazelcastFactory, newInvalidationOnChangeEnabledNearCacheConfig(mapName));
final IMap<Integer, Integer> clientMap = client.getMap(mapName);
populateNearCache(clientMap, mapSize);
final CountDownLatch latch = new CountDownLatch(1);
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);
clientMap.submitToKey(randomKey, new IncrementEntryProcessor(), callback);
latch.await(3, TimeUnit.SECONDS);
assertTrueEventually(new AssertTask() {
public void run() {
assertThatOwnedEntryCountEquals(clientMap, mapSize - 1);
}
});
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class ClientInvocationTest method executionCallback_FailOnShutdown.
@Test
public void executionCallback_FailOnShutdown() {
HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final CountDownLatch disconnectedLatch = new CountDownLatch(1);
IMap<Object, Object> map = client.getMap(randomName());
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (event.getState() == LifecycleEvent.LifecycleState.CLIENT_DISCONNECTED) {
disconnectedLatch.countDown();
}
}
});
server.shutdown();
assertOpenEventually(disconnectedLatch);
int n = 100;
final CountDownLatch errorLatch = new CountDownLatch(n);
for (int i = 0; i < n; i++) {
try {
map.submitToKey(randomString(), new DummyEntryProcessor(), new ExecutionCallback() {
@Override
public void onResponse(Object response) {
}
@Override
public void onFailure(Throwable t) {
errorLatch.countDown();
}
});
} catch (Exception e) {
errorLatch.countDown();
}
}
assertOpenEventually("Not all of the requests failed", errorLatch);
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class TestManagedContext method testRunnableTask.
@Test
public void testRunnableTask() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
instance1.getExecutorService("test").submitToMember(new SomeRunnableTask(), instance2.getCluster().getLocalMember(), new ExecutionCallback() {
public void onResponse(Object response) {
latch.countDown();
}
public void onFailure(Throwable t) {
error.set(t);
latch.countDown();
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
Throwable throwable = error.get();
if (throwable != null) {
sneakyThrow(throwable);
}
}
Aggregations