use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method submitCallableToAllMembers_withMultiExecutionCallback.
@Test
public void submitCallableToAllMembers_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 callable = new AppendCallable(msg);
service.submitToAllMembers(callable, 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 submitRunnableToMembers_withExecutionCallback.
@Test
public void submitRunnableToMembers_withExecutionCallback() {
IExecutorService service = client.getExecutorService(randomString());
final CountDownLatch responseLatch = new CountDownLatch(CLUSTER_SIZE);
final CountDownLatch completeLatch = new CountDownLatch(1);
String mapName = randomString();
Runnable runnable = new MapPutRunnable(mapName);
MemberSelector selector = new SelectAllMembers();
service.submitToMembers(runnable, selector, new MultiExecutionCallback() {
public void onResponse(Member member, Object value) {
responseLatch.countDown();
}
public void onComplete(Map<Member, Object> values) {
completeLatch.countDown();
}
});
IMap map = client.getMap(mapName);
assertOpenEventually("responseLatch", responseLatch);
assertOpenEventually("completeLatch", completeLatch);
assertEquals(CLUSTER_SIZE, map.size());
}
use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class ExecutorServiceTest method testSubmitToAllMembersCallable.
@Test
public void testSubmitToAllMembersCallable() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
HazelcastInstance[] instances = factory.newInstances(smallInstanceConfig());
final AtomicInteger count = new AtomicInteger(0);
final CountDownLatch countDownLatch = new CountDownLatch(NODE_COUNT * NODE_COUNT);
MultiExecutionCallback callback = new MultiExecutionCallback() {
public void onResponse(Member member, Object value) {
count.incrementAndGet();
countDownLatch.countDown();
}
public void onComplete(Map<Member, Object> values) {
}
};
for (int i = 0; i < NODE_COUNT; i++) {
IExecutorService service = instances[i].getExecutorService("testSubmitToAllMembersCallable");
service.submitToAllMembers(new IncrementAtomicLongCallable("testSubmitToAllMembersCallable"), callback);
}
assertOpenEventually(countDownLatch);
IAtomicLong result = instances[0].getCPSubsystem().getAtomicLong("testSubmitToAllMembersCallable");
assertEquals(NODE_COUNT * NODE_COUNT, result.get());
assertEquals(NODE_COUNT * NODE_COUNT, count.get());
}
use of com.hazelcast.core.MultiExecutionCallback in project hazelcast by hazelcast.
the class SmallClusterTest method testSubmitToMembersSerializesTheTaskOnlyOnce_withSelectorAndCallback.
@Test
public void testSubmitToMembersSerializesTheTaskOnlyOnce_withSelectorAndCallback() throws InterruptedException {
IExecutorService executorService = instances[0].getExecutorService(randomName());
SerializationCountingCallable countingCallable = new SerializationCountingCallable();
CountDownLatch complete = new CountDownLatch(1);
executorService.submitToMembers(countingCallable, MemberSelectors.DATA_MEMBER_SELECTOR, 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 AbstractExecutorNullTest method testNullability.
@Test
public void testNullability() {
Runnable sampleRunnable = (Runnable & Serializable) () -> {
};
Callable<Object> sampleCallable = (Callable & Serializable) () -> "";
Member sampleMember = getDriver().getCluster().getMembers().iterator().next();
Set<Member> sampleMembers = Collections.singleton(sampleMember);
MemberSelector sampleSelector = member -> true;
ExecutionCallback<Object> sampleCallback = new ExecutionCallback<Object>() {
@Override
public void onResponse(Object response) {
}
@Override
public void onFailure(Throwable t) {
}
};
MultiExecutionCallback sampleMultiExecutionCallback = new MultiExecutionCallback() {
@Override
public void onResponse(Member member, Object value) {
}
@Override
public void onComplete(Map<Member, Object> values) {
}
};
assertThrowsNPE(s -> s.execute((Runnable) null, sampleSelector));
assertThrowsNPE(s -> s.execute(sampleRunnable, null));
assertThrowsNPE(s -> s.executeOnKeyOwner(null, ""));
assertThrowsNPE(s -> s.executeOnKeyOwner(sampleRunnable, null));
assertThrowsNPE(s -> s.executeOnMember(null, sampleMember));
assertThrowsNPE(s -> s.executeOnMember(sampleRunnable, null));
assertThrowsNPE(s -> s.executeOnMembers(null, sampleMembers));
assertThrowsNPE(s -> s.executeOnMembers(sampleRunnable, (Collection<Member>) null));
assertThrowsNPE(s -> s.executeOnMembers(null, sampleSelector));
assertThrowsNPE(s -> s.executeOnMembers(sampleRunnable, (MemberSelector) null));
assertThrowsNPE(s -> s.executeOnAllMembers(null));
System.out.println("------------1");
assertThrowsNPE(s -> s.submit((Callable) null, sampleSelector));
assertThrowsNPE(s -> s.submit(sampleCallable, (MemberSelector) null));
assertThrowsNPE(s -> s.submitToKeyOwner((Callable) null, ""));
assertThrowsNPE(s -> s.submitToKeyOwner(sampleCallable, null));
assertThrowsNPE(s -> s.submitToMember((Callable) null, sampleMember));
assertThrowsNPE(s -> s.submitToMember(sampleCallable, null));
assertThrowsNPE(s -> s.submitToMembers((Callable) null, sampleMembers));
assertThrowsNPE(s -> s.submitToMembers(sampleCallable, (Collection<Member>) null));
assertThrowsNPE(s -> s.submitToMembers((Callable) null, sampleSelector));
assertThrowsNPE(s -> s.submitToMembers(sampleCallable, (MemberSelector) null));
assertThrowsNPE(s -> s.submitToAllMembers(null));
System.out.println("------------2");
assertThrowsNPE(s -> s.submit((Runnable) null, sampleCallback));
getDriver().getExecutorService(RANDOM_NAME).submit(sampleRunnable, (ExecutionCallback) null);
assertThrowsNPE(s -> s.submit((Runnable) null, sampleSelector, sampleCallback));
assertThrowsNPE(s -> s.submit(sampleRunnable, (MemberSelector) null, sampleCallback));
getDriver().getExecutorService(RANDOM_NAME).submit(sampleRunnable, sampleSelector, (ExecutionCallback) null);
assertThrowsNPE(s -> s.submitToKeyOwner((Runnable) null, "", sampleCallback));
assertThrowsNPE(s -> s.submitToKeyOwner(sampleRunnable, null, sampleCallback));
getDriver().getExecutorService(RANDOM_NAME).submitToKeyOwner(sampleRunnable, "", (ExecutionCallback) null);
assertThrowsNPE(s -> s.submitToMember((Runnable) null, sampleMember, sampleCallback));
assertThrowsNPE(s -> s.submitToMember(sampleRunnable, null, sampleCallback));
getDriver().getExecutorService(RANDOM_NAME).submitToMember(sampleRunnable, sampleMember, (ExecutionCallback) null);
assertThrowsNPE(s -> s.submitToMembers((Runnable) null, sampleMembers, sampleMultiExecutionCallback));
assertThrowsNPE(s -> s.submitToMembers(sampleRunnable, (Collection) null, sampleMultiExecutionCallback));
assertThrowsNPE(s -> s.submitToMembers(sampleRunnable, sampleMembers, (MultiExecutionCallback) null));
assertThrowsNPE(s -> s.submitToMembers((Runnable) null, sampleSelector, sampleMultiExecutionCallback));
assertThrowsNPE(s -> s.submitToMembers(sampleRunnable, (MemberSelector) null, sampleMultiExecutionCallback));
assertThrowsNPE(s -> s.submitToMembers(sampleRunnable, sampleSelector, (MultiExecutionCallback) null));
assertThrowsNPE(s -> s.submitToAllMembers((Runnable) null, sampleMultiExecutionCallback));
assertThrowsNPE(s -> s.submitToAllMembers(sampleRunnable, null));
System.out.println("------------3");
assertThrowsNPE(s -> s.submit((Callable<Object>) null, sampleCallback));
getDriver().getExecutorService(RANDOM_NAME).submit(sampleCallable, (ExecutionCallback) null);
assertThrowsNPE(s -> s.submit((Callable) null, sampleSelector, sampleCallback));
assertThrowsNPE(s -> s.submit(sampleCallable, (MemberSelector) null, sampleCallback));
getDriver().getExecutorService(RANDOM_NAME).submit(sampleCallable, sampleSelector, (ExecutionCallback) null);
assertThrowsNPE(s -> s.submitToKeyOwner((Callable) null, "", sampleCallback));
assertThrowsNPE(s -> s.submitToKeyOwner(sampleCallable, null, sampleCallback));
getDriver().getExecutorService(RANDOM_NAME).submitToKeyOwner(sampleCallable, "", (ExecutionCallback) null);
assertThrowsNPE(s -> s.submitToMember((Callable) null, sampleMember, sampleCallback));
assertThrowsNPE(s -> s.submitToMember(sampleCallable, null, sampleCallback));
getDriver().getExecutorService(RANDOM_NAME).submitToMember(sampleCallable, sampleMember, (ExecutionCallback) null);
assertThrowsNPE(s -> s.submitToMembers((Callable) null, sampleMembers, sampleMultiExecutionCallback));
assertThrowsNPE(s -> s.submitToMembers(sampleCallable, (Collection) null, sampleMultiExecutionCallback));
assertThrowsNPE(s -> s.submitToMembers(sampleCallable, sampleMembers, (MultiExecutionCallback) null));
assertThrowsNPE(s -> s.submitToMembers((Callable) null, sampleSelector, sampleMultiExecutionCallback));
assertThrowsNPE(s -> s.submitToMembers(sampleCallable, (MemberSelector) null, sampleMultiExecutionCallback));
assertThrowsNPE(s -> s.submitToMembers(sampleCallable, sampleSelector, (MultiExecutionCallback) null));
assertThrowsNPE(s -> s.submitToAllMembers((Callable) null, sampleMultiExecutionCallback));
assertThrowsNPE(s -> s.submitToAllMembers(sampleCallable, null));
}
Aggregations