use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class DurableExecutorServiceTest method testSubmitToKeyOwnerRunnable.
@Test
public void testSubmitToKeyOwnerRunnable() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
HazelcastInstance[] instances = factory.newInstances();
final AtomicInteger nullResponseCount = new AtomicInteger(0);
final CountDownLatch responseLatch = new CountDownLatch(NODE_COUNT);
ExecutionCallback callback = new ExecutionCallback() {
public void onResponse(Object response) {
if (response == null) {
nullResponseCount.incrementAndGet();
}
responseLatch.countDown();
}
public void onFailure(Throwable t) {
}
};
for (int i = 0; i < NODE_COUNT; i++) {
HazelcastInstance instance = instances[i];
DurableExecutorService service = instance.getDurableExecutorService("testSubmitToKeyOwnerRunnable");
Member localMember = instance.getCluster().getLocalMember();
String uuid = localMember.getUuid();
Runnable runnable = new IncrementAtomicLongIfMemberUUIDNotMatchRunnable(uuid, "testSubmitToKeyOwnerRunnable");
int key = findNextKeyForMember(instance, localMember);
service.submitToKeyOwner(runnable, key).andThen(callback);
}
assertOpenEventually(responseLatch);
assertEquals(0, instances[0].getAtomicLong("testSubmitToKeyOwnerRunnable").get());
assertEquals(NODE_COUNT, nullResponseCount.get());
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class SingleNodeTest method executionCallback_notifiedOnFailure.
@Test
public void executionCallback_notifiedOnFailure() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
FailingTestTask task = new FailingTestTask();
ExecutionCallback<String> executionCallback = new ExecutionCallback<String>() {
public void onResponse(String response) {
}
public void onFailure(Throwable t) {
latch.countDown();
}
};
executor.submit(task, executionCallback);
assertOpenEventually(latch);
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class ExecutorServiceTest method testSubmitToKeyOwnerRunnable.
@Test
public void testSubmitToKeyOwnerRunnable() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
HazelcastInstance[] instances = factory.newInstances(new Config());
final AtomicInteger nullResponseCount = new AtomicInteger(0);
final CountDownLatch responseLatch = new CountDownLatch(NODE_COUNT);
ExecutionCallback callback = new ExecutionCallback() {
public void onResponse(Object response) {
if (response == null) {
nullResponseCount.incrementAndGet();
}
responseLatch.countDown();
}
public void onFailure(Throwable t) {
}
};
for (int i = 0; i < NODE_COUNT; i++) {
HazelcastInstance instance = instances[i];
IExecutorService service = instance.getExecutorService("testSubmitToKeyOwnerRunnable");
Member localMember = instance.getCluster().getLocalMember();
int key = findNextKeyForMember(instance, localMember);
service.submitToKeyOwner(new IncrementAtomicLongIfMemberUUIDNotMatchRunnable(localMember.getUuid(), "testSubmitToKeyOwnerRunnable"), key, callback);
}
assertOpenEventually(responseLatch);
assertEquals(0, instances[0].getAtomicLong("testSubmitToKeyOwnerRunnable").get());
assertEquals(NODE_COUNT, nullResponseCount.get());
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class ExecutorServiceTest method testSubmitToMemberRunnable.
@Test
public void testSubmitToMemberRunnable() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
HazelcastInstance[] instances = factory.newInstances(new Config());
final AtomicInteger nullResponseCount = new AtomicInteger(0);
final CountDownLatch responseLatch = new CountDownLatch(NODE_COUNT);
ExecutionCallback callback = new ExecutionCallback() {
public void onResponse(Object response) {
if (response == null) {
nullResponseCount.incrementAndGet();
}
responseLatch.countDown();
}
public void onFailure(Throwable t) {
}
};
for (int i = 0; i < NODE_COUNT; i++) {
HazelcastInstance instance = instances[i];
IExecutorService service = instance.getExecutorService("testSubmitToMemberRunnable");
Member localMember = instance.getCluster().getLocalMember();
service.submitToMember(new IncrementAtomicLongIfMemberUUIDNotMatchRunnable(localMember.getUuid(), "testSubmitToMemberRunnable"), localMember, callback);
}
assertOpenEventually(responseLatch);
assertEquals(0, instances[0].getAtomicLong("testSubmitToMemberRunnable").get());
assertEquals(NODE_COUNT, nullResponseCount.get());
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class DurableSingleNodeTest method executionCallback_notifiedOnFailure.
@Test
public void executionCallback_notifiedOnFailure() {
final CountDownLatch latch = new CountDownLatch(1);
FailingTestTask task = new FailingTestTask();
ExecutionCallback<String> executionCallback = new ExecutionCallback<String>() {
public void onResponse(String response) {
}
public void onFailure(Throwable t) {
latch.countDown();
}
};
executor.submit(task).andThen(executionCallback);
assertOpenEventually(latch);
}
Aggregations