use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class ExecutorServiceTest method testSubmitToAllMembersRunnable.
@Test
public void testSubmitToAllMembersRunnable() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
HazelcastInstance[] instances = factory.newInstances(smallInstanceConfig());
final AtomicInteger nullResponseCount = new AtomicInteger(0);
final CountDownLatch responseLatch = new CountDownLatch(NODE_COUNT * NODE_COUNT);
MultiExecutionCallback callback = new MultiExecutionCallback() {
public void onResponse(Member member, Object value) {
if (value == null) {
nullResponseCount.incrementAndGet();
}
responseLatch.countDown();
}
public void onComplete(Map<Member, Object> values) {
}
};
for (int i = 0; i < NODE_COUNT; i++) {
IExecutorService service = instances[i].getExecutorService("testSubmitToAllMembersRunnable");
service.submitToAllMembers(new IncrementAtomicLongRunnable("testSubmitToAllMembersRunnable"), callback);
}
assertTrue(responseLatch.await(30, TimeUnit.SECONDS));
IAtomicLong result = instances[0].getCPSubsystem().getAtomicLong("testSubmitToAllMembersRunnable");
assertEquals(NODE_COUNT * NODE_COUNT, result.get());
assertEquals(NODE_COUNT * NODE_COUNT, nullResponseCount.get());
}
use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class SmallClusterTest method submitToAllMembers_statefulCallable.
@Test
public void submitToAllMembers_statefulCallable() {
IExecutorService executorService = instances[0].getExecutorService(randomString());
InternallyCountingCallable internallyCountingCallable = new InternallyCountingCallable();
final CountDownLatch completedLatch = new CountDownLatch(1);
final AtomicBoolean failed = new AtomicBoolean();
// local execution of callable may change the state of callable before sent to other members
// we avoid this by serializing beforehand
executorService.submitToAllMembers(internallyCountingCallable, new MultiExecutionCallback() {
@Override
public void onResponse(Member member, Object value) {
if ((Integer) value != 1) {
failed.set(true);
}
}
@Override
public void onComplete(Map<Member, Object> values) {
completedLatch.countDown();
}
});
assertOpenEventually(completedLatch);
assertFalse(failed.get());
}
use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class SmallClusterTest method submitToAllMembers_NonSerializableResponse.
@Test
public void submitToAllMembers_NonSerializableResponse() {
IExecutorService executorService = instances[0].getExecutorService(randomString());
NonSerializableResponseCallable nonSerializableResponseCallable = new NonSerializableResponseCallable();
final AtomicLong exceptionCount = new AtomicLong();
final AtomicLong responseCount = new AtomicLong();
final CountDownLatch completedLatch = new CountDownLatch(1);
executorService.submitToAllMembers(nonSerializableResponseCallable, new MultiExecutionCallback() {
@Override
public void onResponse(Member member, Object value) {
if (value instanceof HazelcastSerializationException) {
exceptionCount.incrementAndGet();
} else {
responseCount.incrementAndGet();
}
}
@Override
public void onComplete(Map<Member, Object> values) {
completedLatch.countDown();
}
});
assertOpenEventually(completedLatch);
// two exceptions from remote nodes
assertEquals(2, exceptionCount.get());
// one response from local node since, it does not need to serialize/deserialize the response
assertEquals(1, responseCount.get());
}
use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class SmallClusterTest method testSubmitToAllMembersSerializesTheTaskOnlyOnce_withCallback.
@Test
public void testSubmitToAllMembersSerializesTheTaskOnlyOnce_withCallback() throws InterruptedException {
IExecutorService executorService = instances[0].getExecutorService(randomName());
SerializationCountingCallable countingCallable = new SerializationCountingCallable();
CountDownLatch complete = new CountDownLatch(1);
executorService.submitToAllMembers(countingCallable, new MultiExecutionCallback() {
@Override
public void onResponse(Member member, Object value) {
}
@Override
public void onComplete(Map<Member, Object> values) {
complete.countDown();
}
});
complete.await();
assertEquals(1, countingCallable.getSerializationCount());
}
use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class SmallClusterTest method testSubmitToMembersSerializesTheTaskOnlyOnce_withCollectionAndCallback.
@Test
public void testSubmitToMembersSerializesTheTaskOnlyOnce_withCollectionAndCallback() throws InterruptedException {
IExecutorService executorService = instances[0].getExecutorService(randomName());
SerializationCountingCallable countingCallable = new SerializationCountingCallable();
CountDownLatch complete = new CountDownLatch(1);
executorService.submitToMembers(countingCallable, instances[0].getCluster().getMembers(), new MultiExecutionCallback() {
@Override
public void onResponse(Member member, Object value) {
}
@Override
public void onComplete(Map<Member, Object> values) {
complete.countDown();
}
});
complete.await();
assertEquals(1, countingCallable.getSerializationCount());
}
Aggregations