use of com.hazelcast.core.IAtomicLong in project hazelcast by hazelcast.
the class ClientAtomicLongTest method applyAsync.
@Test
public void applyAsync() throws ExecutionException, InterruptedException {
IAtomicLong ref = client.getAtomicLong("apply");
ICompletableFuture<Long> future = ref.applyAsync(new AddOneFunction());
assertEquals(new Long(1), future.get());
assertEquals(0, ref.get());
}
use of com.hazelcast.core.IAtomicLong in project hazelcast by hazelcast.
the class ClientAtomicLongTest method apply_whenException.
@Test
public void apply_whenException() {
IAtomicLong ref = client.getAtomicLong("apply_whenException");
ref.set(1);
try {
ref.apply(new FailingFunction());
fail();
} catch (UndefinedErrorCodeException expected) {
assertEquals(expected.getOriginClassName(), ExpectedRuntimeException.class.getName());
}
assertEquals(1, ref.get());
}
use of com.hazelcast.core.IAtomicLong in project hazelcast by hazelcast.
the class ClientAtomicLongTest method alterAsync.
@Test
public void alterAsync() throws ExecutionException, InterruptedException {
IAtomicLong ref = client.getAtomicLong("alterAsync");
ref.set(10);
ICompletableFuture<Void> future = ref.alterAsync(new AddOneFunction());
future.get();
assertEquals(11, ref.get());
}
use of com.hazelcast.core.IAtomicLong in project hazelcast by hazelcast.
the class AtomicLongAdvancedTest method testAtomicLongFailure.
@Test
public void testAtomicLongFailure() {
int k = 4;
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(k + 1);
HazelcastInstance instance = nodeFactory.newHazelcastInstance();
String name = "testAtomicLongFailure";
IAtomicLong atomicLong = instance.getAtomicLong(name);
atomicLong.set(100);
for (int i = 0; i < k; i++) {
HazelcastInstance newInstance = nodeFactory.newHazelcastInstance();
waitAllForSafeState(nodeFactory.getAllHazelcastInstances());
IAtomicLong newAtomicLong = newInstance.getAtomicLong(name);
assertEquals((long) 100 + i, newAtomicLong.get());
newAtomicLong.incrementAndGet();
instance.shutdown();
instance = newInstance;
}
}
use of com.hazelcast.core.IAtomicLong in project hazelcast by hazelcast.
the class SmallClusterTest method submitToMembers_callable.
@Test
public void submitToMembers_callable() {
int sum = 0;
ResponseCountingMultiExecutionCallback callback = new ResponseCountingMultiExecutionCallback(instances.length);
Set<Member> membersSet = instances[0].getCluster().getMembers();
Member[] members = membersSet.toArray(new Member[membersSet.size()]);
Random random = new Random();
String name = "testSubmitToMembersCallable";
for (HazelcastInstance instance : instances) {
IExecutorService service = instance.getExecutorService(name);
int n = random.nextInt(instances.length) + 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(callback.getLatch());
IAtomicLong result = instances[0].getAtomicLong(name);
assertEquals(sum, result.get());
assertEquals(sum, callback.getCount());
}
Aggregations