Search in sources :

Example 26 with IAtomicLong

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

Example 27 with IAtomicLong

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

the class ScheduledExecutorServiceBasicTest method schedule_withMapChanges_durable.

@Test
public void schedule_withMapChanges_durable() throws ExecutionException, InterruptedException {
    int delay = 0;
    HazelcastInstance[] instances = createClusterWithCount(2);
    IMap<String, Integer> map = instances[1].getMap("map");
    for (int i = 0; i < 100000; i++) {
        map.put(String.valueOf(i), i);
    }
    Object key = generateKeyOwnedBy(instances[0]);
    ICountDownLatch runsCountLatch = instances[1].getCountDownLatch("runsCountLatchName");
    runsCountLatch.trySetCount(1);
    IAtomicLong runEntryCounter = instances[1].getAtomicLong("runEntryCounterName");
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    executorService.scheduleOnKeyOwner(new ICountdownLatchMapIncrementCallableTask("map", "runEntryCounterName", "runsCountLatchName"), key, delay, SECONDS);
    Thread.sleep(2000);
    instances[0].getLifecycleService().shutdown();
    runsCountLatch.await(2, TimeUnit.MINUTES);
    for (int i = 0; i < 100000; i++) {
        assertTrue(map.get(String.valueOf(i)) == (i + 1));
    }
    assertEquals(2, runEntryCounter.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) IAtomicLong(com.hazelcast.core.IAtomicLong) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 28 with IAtomicLong

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

the class ClientProxyDestroyTest method testMultipleDestroyCalls.

@Test
public void testMultipleDestroyCalls() {
    IAtomicLong proxy = newClientProxy();
    proxy.destroy();
    proxy.destroy();
}
Also used : IAtomicLong(com.hazelcast.core.IAtomicLong) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 29 with IAtomicLong

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

the class ExecutorServiceTest method testSubmitToMembersRunnable.

@Test
public void testSubmitToMembersRunnable() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
    HazelcastInstance[] instances = factory.newInstances(new Config());
    ResponseCountingMultiExecutionCallback callback = new ResponseCountingMultiExecutionCallback(NODE_COUNT);
    int sum = 0;
    Set<Member> membersSet = instances[0].getCluster().getMembers();
    Member[] members = membersSet.toArray(new Member[membersSet.size()]);
    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].getAtomicLong("testSubmitToMembersRunnable");
    assertEquals(sum, result.get());
    assertEquals(sum, callback.getCount());
}
Also used : ExecutorConfig(com.hazelcast.config.ExecutorConfig) Config(com.hazelcast.config.Config) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Random(java.util.Random) IAtomicLong(com.hazelcast.core.IAtomicLong) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with IAtomicLong

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

the class ExecutorServiceTest method testSubmitToAllMembersCallable.

@Test
public void testSubmitToAllMembersCallable() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
    HazelcastInstance[] instances = factory.newInstances(new Config());
    final AtomicInteger count = new AtomicInteger(0);
    final CountDownLatch countDownLatch = new CountDownLatch(NODE_COUNT * NODE_COUNT);
    MultiExecutionCallback callback = new MultiExecutionCallback() {

        public void onResponse(Member member, Object value) {
            count.incrementAndGet();
            countDownLatch.countDown();
        }

        public void onComplete(Map<Member, Object> values) {
        }
    };
    for (int i = 0; i < NODE_COUNT; i++) {
        IExecutorService service = instances[i].getExecutorService("testSubmitToAllMembersCallable");
        service.submitToAllMembers(new IncrementAtomicLongCallable("testSubmitToAllMembersCallable"), callback);
    }
    assertOpenEventually(countDownLatch);
    IAtomicLong result = instances[0].getAtomicLong("testSubmitToAllMembersCallable");
    assertEquals(NODE_COUNT * NODE_COUNT, result.get());
    assertEquals(NODE_COUNT * NODE_COUNT, count.get());
}
Also used : ExecutorConfig(com.hazelcast.config.ExecutorConfig) Config(com.hazelcast.config.Config) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IAtomicLong(com.hazelcast.core.IAtomicLong) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) Map(java.util.Map) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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