use of com.hazelcast.cp.IAtomicLong 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());
}
use of com.hazelcast.cp.IAtomicLong 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.cp.IAtomicLong in project hazelcast by hazelcast.
the class ExecutorServiceTest method testExecuteMultipleNode.
@Test
public void testExecuteMultipleNode() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
HazelcastInstance[] instances = factory.newInstances(smallInstanceConfig());
for (int i = 0; i < NODE_COUNT; i++) {
IExecutorService service = instances[i].getExecutorService("testExecuteMultipleNode");
int rand = new Random().nextInt(100);
Future<Integer> future = service.submit(new IncrementAtomicLongRunnable("count"), rand);
assertEquals(Integer.valueOf(rand), future.get(10, TimeUnit.SECONDS));
}
IAtomicLong count = instances[0].getCPSubsystem().getAtomicLong("count");
assertEquals(NODE_COUNT, count.get());
}
use of com.hazelcast.cp.IAtomicLong in project hazelcast by hazelcast.
the class SmallClusterTest method submitToAllMembers_runnable.
@Test
public void submitToAllMembers_runnable() {
ResponseCountingMultiExecutionCallback callback = new ResponseCountingMultiExecutionCallback(instances.length);
for (HazelcastInstance instance : instances) {
IExecutorService service = instance.getExecutorService("testSubmitToAllMembersRunnable");
service.submitToAllMembers(new IncrementAtomicLongRunnable("testSubmitToAllMembersRunnable"), callback);
}
assertOpenEventually(callback.getLatch());
IAtomicLong result = instances[0].getCPSubsystem().getAtomicLong("testSubmitToAllMembersRunnable");
assertEquals(instances.length * instances.length, result.get());
assertEquals(instances.length * instances.length, callback.getCount());
}
use of com.hazelcast.cp.IAtomicLong in project hazelcast by hazelcast.
the class SmallClusterTest method submitToSeveralNodes_runnable.
@Test
public void submitToSeveralNodes_runnable() throws Exception {
for (HazelcastInstance instance : instances) {
IExecutorService service = instance.getExecutorService("testExecuteMultipleNode");
int rand = new Random().nextInt(100);
Future<Integer> future = service.submit(new IncrementAtomicLongRunnable("count"), rand);
assertEquals(Integer.valueOf(rand), future.get());
}
IAtomicLong count = instances[0].getCPSubsystem().getAtomicLong("count");
assertEquals(instances.length, count.get());
}
Aggregations