use of com.hazelcast.core.IAtomicLong in project hazelcast by hazelcast.
the class IAtomicLongMocks method mockIAtomicLong.
/**
* Creates mocks IAtomicLong which wraps an AtomicLong
**/
public static IAtomicLong mockIAtomicLong() {
// keeps actual value
final AtomicLong atomicLong = new AtomicLong();
IAtomicLong iAtomicLong = mock(IAtomicLong.class);
when(iAtomicLong.getAndIncrement()).then(delegateTo(atomicLong));
when(iAtomicLong.compareAndSet(anyLong(), anyLong())).then(delegateTo(atomicLong));
return iAtomicLong;
}
use of com.hazelcast.core.IAtomicLong in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_withMapChanges_durable.
@Test
public void schedule_withMapChanges_durable() throws ExecutionException, InterruptedException {
int delay = 0;
HazelcastInstance[] instances = createClusterWithCount(2);
IMap<String, Integer> map = instances[1].getMap("map");
for (int i = 0; i < 100000; i++) {
map.put(String.valueOf(i), i);
}
Object key = generateKeyOwnedBy(instances[0]);
ICountDownLatch runsCountLatch = instances[1].getCountDownLatch("runsCountLatchName");
runsCountLatch.trySetCount(1);
IAtomicLong runEntryCounter = instances[1].getAtomicLong("runEntryCounterName");
IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
executorService.scheduleOnKeyOwner(new ICountdownLatchMapIncrementCallableTask("map", "runEntryCounterName", "runsCountLatchName"), key, delay, SECONDS);
Thread.sleep(2000);
instances[0].getLifecycleService().shutdown();
runsCountLatch.await(2, TimeUnit.MINUTES);
for (int i = 0; i < 100000; i++) {
assertTrue(map.get(String.valueOf(i)) == (i + 1));
}
assertEquals(2, runEntryCounter.get());
}
use of com.hazelcast.core.IAtomicLong in project hazelcast by hazelcast.
the class ClientProxyDestroyTest method testMultipleDestroyCalls.
@Test
public void testMultipleDestroyCalls() {
IAtomicLong proxy = newClientProxy();
proxy.destroy();
proxy.destroy();
}
use of com.hazelcast.core.IAtomicLong in project hazelcast by hazelcast.
the class ExecutorServiceTest method testSubmitToMembersRunnable.
@Test
public void testSubmitToMembersRunnable() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
HazelcastInstance[] instances = factory.newInstances(new Config());
ResponseCountingMultiExecutionCallback callback = new ResponseCountingMultiExecutionCallback(NODE_COUNT);
int sum = 0;
Set<Member> membersSet = instances[0].getCluster().getMembers();
Member[] members = membersSet.toArray(new Member[membersSet.size()]);
Random random = new Random();
for (int i = 0; i < NODE_COUNT; i++) {
IExecutorService service = instances[i].getExecutorService("testSubmitToMembersRunnable");
int n = random.nextInt(NODE_COUNT) + 1;
sum += n;
Member[] m = new Member[n];
System.arraycopy(members, 0, m, 0, n);
service.submitToMembers(new IncrementAtomicLongRunnable("testSubmitToMembersRunnable"), Arrays.asList(m), callback);
}
assertOpenEventually(callback.getLatch());
IAtomicLong result = instances[0].getAtomicLong("testSubmitToMembersRunnable");
assertEquals(sum, result.get());
assertEquals(sum, callback.getCount());
}
use of com.hazelcast.core.IAtomicLong in project hazelcast by hazelcast.
the class ExecutorServiceTest method testSubmitToAllMembersCallable.
@Test
public void testSubmitToAllMembersCallable() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
HazelcastInstance[] instances = factory.newInstances(new Config());
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].getAtomicLong("testSubmitToAllMembersCallable");
assertEquals(NODE_COUNT * NODE_COUNT, result.get());
assertEquals(NODE_COUNT * NODE_COUNT, count.get());
}
Aggregations