Search in sources :

Example 21 with IAtomicLong

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

the class PartitionControlledIdTest method testAtomicLong.

@Test
public void testAtomicLong() throws Exception {
    String partitionKey = "hazelcast";
    HazelcastInstance hz = getHazelcastInstance(partitionKey);
    IAtomicLong atomicLong = hz.getAtomicLong("atomiclong@" + partitionKey);
    atomicLong.incrementAndGet();
    assertEquals("atomiclong@" + partitionKey, atomicLong.getName());
    assertEquals(partitionKey, atomicLong.getPartitionKey());
    AtomicLongService service = getNodeEngine(hz).getService(AtomicLongService.SERVICE_NAME);
    assertTrue(service.containsAtomicLong(atomicLong.getName()));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicLongService(com.hazelcast.concurrent.atomiclong.AtomicLongService) IAtomicLong(com.hazelcast.core.IAtomicLong) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with IAtomicLong

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

the class HazelcastOSGiInstanceTest method getAtomicLongCalledSuccessfullyOverOSGiInstance.

@Test
public void getAtomicLongCalledSuccessfullyOverOSGiInstance() {
    IAtomicLong mockAtomicLong = mock(IAtomicLong.class);
    HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
    HazelcastOSGiInstance hazelcastOSGiInstance = HazelcastOSGiTestUtil.createHazelcastOSGiInstance(mockHazelcastInstance);
    when(mockHazelcastInstance.getAtomicLong("my-atomiclong")).thenReturn(mockAtomicLong);
    assertEquals(mockAtomicLong, hazelcastOSGiInstance.getAtomicLong("my-atomiclong"));
    verify(mockHazelcastInstance).getAtomicLong("my-atomiclong");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IAtomicLong(com.hazelcast.core.IAtomicLong) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 23 with IAtomicLong

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

the class MBeanTest method testAtomicLong.

@Test
public void testAtomicLong() throws Exception {
    IAtomicLong atomicLong = holder.getHz().getAtomicLong("atomiclong");
    atomicLong.incrementAndGet();
    holder.assertMBeanExistEventually("IAtomicLong", atomicLong.getName());
}
Also used : IAtomicLong(com.hazelcast.core.IAtomicLong) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with IAtomicLong

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

the class MBeanDestroyTest method testAtomicLong.

@Test
public void testAtomicLong() throws Exception {
    IAtomicLong atomicLong = holder.getHz().getAtomicLong("atomiclong");
    atomicLong.incrementAndGet();
    holder.assertMBeanExistEventually("IAtomicLong", atomicLong.getName());
    destroyObjectAndAssert(atomicLong, "IAtomicLong");
}
Also used : IAtomicLong(com.hazelcast.core.IAtomicLong) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with IAtomicLong

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

the class ScheduledExecutorServiceSlowTest method schedule_withStatefulRunnable_durable.

@Test
public void schedule_withStatefulRunnable_durable() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = createClusterWithCount(4);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    int waitStateSyncPeriodToAvoidPassiveState = 2000;
    String key = generateKeyOwnedBy(instances[1]);
    ICountDownLatch latch = instances[0].getCountDownLatch("latch");
    IAtomicLong runC = instances[0].getAtomicLong("runC");
    IAtomicLong loadC = instances[0].getAtomicLong("loadC");
    latch.trySetCount(1);
    IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new StatefulRunnableTask("latch", "runC", "loadC"), key, 10, 10, SECONDS);
    // Wait for task to get scheduled and start
    latch.await(11, SECONDS);
    Thread.sleep(waitStateSyncPeriodToAvoidPassiveState);
    instances[1].getLifecycleService().shutdown();
    // Reset latch - task should be running on a replica now
    latch.trySetCount(7);
    latch.await(70, SECONDS);
    future.cancel(false);
    assertEquals(getPartitionService(instances[0]).getPartitionId(key), future.getHandler().getPartitionId());
    assertEquals(8, runC.get(), 1);
    assertEquals(1, loadC.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) IAtomicLong(com.hazelcast.core.IAtomicLong) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) 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