Search in sources :

Example 21 with IAtomicLong

use of com.hazelcast.cp.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[0]);
    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].getCPSubsystem().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.cp.IAtomicLong) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with IAtomicLong

use of com.hazelcast.cp.IAtomicLong in project hazelcast by hazelcast.

the class ExecutorServiceTest method testSubmitToMembersRunnable.

@Test
public void testSubmitToMembersRunnable() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
    HazelcastInstance[] instances = factory.newInstances(smallInstanceConfig());
    ResponseCountingMultiExecutionCallback callback = new ResponseCountingMultiExecutionCallback(NODE_COUNT);
    int sum = 0;
    Set<Member> membersSet = instances[0].getCluster().getMembers();
    Member[] members = membersSet.toArray(new Member[0]);
    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].getCPSubsystem().getAtomicLong("testSubmitToMembersRunnable");
    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.cp.IAtomicLong) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with IAtomicLong

use of com.hazelcast.cp.IAtomicLong in project hazelcast by hazelcast.

the class SmallClusterTest method submitToAllMembers_callable.

@Test
public void submitToAllMembers_callable() {
    ResponseCountingMultiExecutionCallback callback = new ResponseCountingMultiExecutionCallback(instances.length);
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService("testSubmitToAllMembersCallable");
        service.submitToAllMembers(new IncrementAtomicLongCallable("testSubmitToAllMembersCallable"), callback);
    }
    assertOpenEventually(callback.getLatch());
    IAtomicLong result = instances[0].getCPSubsystem().getAtomicLong("testSubmitToAllMembersCallable");
    assertEquals(instances.length * instances.length, result.get());
    assertEquals(instances.length * instances.length, callback.getCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) IAtomicLong(com.hazelcast.cp.IAtomicLong) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with IAtomicLong

use of com.hazelcast.cp.IAtomicLong in project hazelcast by hazelcast.

the class DurableExecutorServiceTest method testExecuteMultipleNode.

@Test
public void testExecuteMultipleNode() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
    HazelcastInstance[] instances = factory.newInstances(smallInstanceConfig());
    for (int i = 0; i < NODE_COUNT; i++) {
        DurableExecutorService service = instances[i].getDurableExecutorService("testExecuteMultipleNode");
        int rand = new Random().nextInt(100);
        Future<Integer> future = service.submit(new IncrementAtomicLongRunnable("count"), rand);
        assertEquals(Integer.valueOf(rand), future.get(10, TimeUnit.SECONDS));
    }
    IAtomicLong count = instances[0].getCPSubsystem().getAtomicLong("count");
    assertEquals(NODE_COUNT, count.get());
}
Also used : DistributedDurableExecutorService(com.hazelcast.durableexecutor.impl.DistributedDurableExecutorService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Random(java.util.Random) IAtomicLong(com.hazelcast.cp.IAtomicLong) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with IAtomicLong

use of com.hazelcast.cp.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;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) IAtomicLong(com.hazelcast.cp.IAtomicLong) IAtomicLong(com.hazelcast.cp.IAtomicLong)

Aggregations

IAtomicLong (com.hazelcast.cp.IAtomicLong)25 Test (org.junit.Test)20 HazelcastInstance (com.hazelcast.core.HazelcastInstance)19 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 QuickTest (com.hazelcast.test.annotation.QuickTest)17 IExecutorService (com.hazelcast.core.IExecutorService)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)8 Random (java.util.Random)8 Member (com.hazelcast.cluster.Member)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 SlowTest (com.hazelcast.test.annotation.SlowTest)4 Config (com.hazelcast.config.Config)3 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)3 ICountDownLatch (com.hazelcast.cp.ICountDownLatch)3 Map (java.util.Map)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 IScheduledExecutorService (com.hazelcast.scheduledexecutor.IScheduledExecutorService)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Address (com.hazelcast.cluster.Address)1 MapConfig (com.hazelcast.config.MapConfig)1