Search in sources :

Example 36 with IAtomicLong

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

Example 37 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 38 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 39 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 40 with IAtomicLong

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

Aggregations

IAtomicLong (com.hazelcast.core.IAtomicLong)50 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