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 chuidiang-ejemplos by chuidiang.
the class AtomicExample method main.
public static void main(String[] args) throws FileNotFoundException, InterruptedException {
Config config = new Config();
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
IAtomicLong atomicLong = hazelcastInstance.getAtomicLong("soy productor");
boolean cambiado = atomicLong.compareAndSet(0, 1);
if (cambiado) {
produce(hazelcastInstance);
} else {
consume(hazelcastInstance);
}
}
Aggregations