Search in sources :

Example 46 with IAtomicLong

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());
}
Also used : UndefinedErrorCodeException(com.hazelcast.client.UndefinedErrorCodeException) IAtomicLong(com.hazelcast.core.IAtomicLong) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 47 with IAtomicLong

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());
}
Also used : IAtomicLong(com.hazelcast.core.IAtomicLong) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 48 with IAtomicLong

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;
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IAtomicLong(com.hazelcast.core.IAtomicLong) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 49 with IAtomicLong

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);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) IAtomicLong(com.hazelcast.core.IAtomicLong)

Aggregations

IAtomicLong (com.hazelcast.core.IAtomicLong)49 ParallelTest (com.hazelcast.test.annotation.ParallelTest)45 Test (org.junit.Test)45 QuickTest (com.hazelcast.test.annotation.QuickTest)44 HazelcastInstance (com.hazelcast.core.HazelcastInstance)21 IExecutorService (com.hazelcast.core.IExecutorService)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)9 UndefinedErrorCodeException (com.hazelcast.client.UndefinedErrorCodeException)8 Random (java.util.Random)8 Config (com.hazelcast.config.Config)6 Member (com.hazelcast.core.Member)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 ExecutionException (java.util.concurrent.ExecutionException)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 ExecutorConfig (com.hazelcast.config.ExecutorConfig)5 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)3 Map (java.util.Map)3 ICountDownLatch (com.hazelcast.core.ICountDownLatch)2 ClientCacheProxyFactory (com.hazelcast.client.cache.impl.ClientCacheProxyFactory)1 ProxyFactoryConfig (com.hazelcast.client.config.ProxyFactoryConfig)1