use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method submitCallableToMember_withMultiExecutionCallback.
@Test
public void submitCallableToMember_withMultiExecutionCallback() {
IExecutorService service = client.getExecutorService(randomString());
final CountDownLatch responseLatch = new CountDownLatch(CLUSTER_SIZE);
final CountDownLatch completeLatch = new CountDownLatch(CLUSTER_SIZE);
final String msg = randomString();
Callable<String> callable = new AppendCallable(msg);
Collection<Member> collection = server.getCluster().getMembers();
service.submitToMembers(callable, collection, new MultiExecutionCallback() {
public void onResponse(Member member, Object value) {
if (value.equals(msg + AppendCallable.APPENDAGE)) {
responseLatch.countDown();
}
}
public void onComplete(Map<Member, Object> values) {
for (Member member : values.keySet()) {
Object value = values.get(member);
if (value.equals(msg + AppendCallable.APPENDAGE)) {
completeLatch.countDown();
}
}
}
});
assertOpenEventually("responseLatch", responseLatch);
assertOpenEventually("completeLatch", completeLatch);
}
use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method submitCallableWithNullResultToAllMembers_withMultiExecutionCallback.
@Test
public void submitCallableWithNullResultToAllMembers_withMultiExecutionCallback() {
IExecutorService service = client.getExecutorService(randomString());
final CountDownLatch responseLatch = new CountDownLatch(CLUSTER_SIZE);
final CountDownLatch completeLatch = new CountDownLatch(CLUSTER_SIZE);
Callable callable = new NullCallable();
service.submitToAllMembers(callable, new MultiExecutionCallback() {
public void onResponse(Member member, Object value) {
if (value == null) {
responseLatch.countDown();
}
}
public void onComplete(Map<Member, Object> values) {
for (Member member : values.keySet()) {
Object value = values.get(member);
if (value == null) {
completeLatch.countDown();
}
}
}
});
assertOpenEventually("responseLatch", responseLatch);
assertOpenEventually("completeLatch", completeLatch);
}
use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method submitCallableToMembers_withExecutionCallback.
@Test
public void submitCallableToMembers_withExecutionCallback() {
IExecutorService service = client.getExecutorService(randomString());
final CountDownLatch responseLatch = new CountDownLatch(CLUSTER_SIZE);
final CountDownLatch completeLatch = new CountDownLatch(1);
final String msg = randomString();
Callable callable = new AppendCallable(msg);
MemberSelector selector = new SelectAllMembers();
service.submitToMembers(callable, selector, new MultiExecutionCallback() {
public void onResponse(Member member, Object value) {
if (value.equals(msg + AppendCallable.APPENDAGE)) {
responseLatch.countDown();
}
}
public void onComplete(Map<Member, Object> values) {
completeLatch.countDown();
}
});
assertOpenEventually("responseLatch", responseLatch);
assertOpenEventually("completeLatch", completeLatch);
}
use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class ExecutionCallbackAdapterRaceTest method test.
@Test
public void test() throws Exception {
MultiExecutionCallback callback = new MultiExecutionCallbackMock();
final ExecutionCallbackAdapterFactory factory = new ExecutionCallbackAdapterFactory(logger, asList(member1, member2), callback);
// first we spawn the response for the member1
// this thread is going wait for 2 seconds in the onResponse to trigger the out of order behavior
Future future = spawn(new Runnable() {
@Override
public void run() {
factory.callbackFor(member1).onResponse("1");
}
});
factory.callbackFor(member2).onResponse("2");
future.get();
assertFalse("Race was detected", raceDetected);
}
use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class ExecutorServiceTest method testSubmitToMembersCallable.
@Test
public void testSubmitToMembersCallable() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
HazelcastInstance[] instances = factory.newInstances(smallInstanceConfig());
final AtomicInteger count = new AtomicInteger(0);
final CountDownLatch latch = new CountDownLatch(NODE_COUNT);
MultiExecutionCallback callback = new MultiExecutionCallback() {
public void onResponse(Member member, Object value) {
count.incrementAndGet();
}
public void onComplete(Map<Member, Object> values) {
latch.countDown();
}
};
int sum = 0;
Set<Member> membersSet = instances[0].getCluster().getMembers();
Member[] members = membersSet.toArray(new Member[0]);
Random random = new Random();
String name = "testSubmitToMembersCallable";
for (int i = 0; i < NODE_COUNT; i++) {
IExecutorService service = instances[i].getExecutorService(name);
int n = random.nextInt(NODE_COUNT) + 1;
sum += n;
Member[] m = new Member[n];
System.arraycopy(members, 0, m, 0, n);
service.submitToMembers(new IncrementAtomicLongCallable(name), Arrays.asList(m), callback);
}
assertOpenEventually(latch);
IAtomicLong result = instances[0].getCPSubsystem().getAtomicLong(name);
assertEquals(sum, result.get());
assertEquals(sum, count.get());
}
Aggregations