Search in sources :

Example 16 with IAtomicLong

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

the class SmallClusterTest method submitToAllMembers_runnable.

@Test
public void submitToAllMembers_runnable() {
    ResponseCountingMultiExecutionCallback callback = new ResponseCountingMultiExecutionCallback(instances.length);
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService("testSubmitToAllMembersRunnable");
        service.submitToAllMembers(new IncrementAtomicLongRunnable("testSubmitToAllMembersRunnable"), callback);
    }
    assertOpenEventually(callback.getLatch());
    IAtomicLong result = instances[0].getAtomicLong("testSubmitToAllMembersRunnable");
    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.core.IAtomicLong) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with IAtomicLong

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

the class DurableSmallClusterTest method submitToSeveralNodes_runnable.

@Test
public void submitToSeveralNodes_runnable() throws Exception {
    for (HazelcastInstance instance : instances) {
        DurableExecutorService service = instance.getDurableExecutorService("testExecuteMultipleNode");
        int rand = new Random().nextInt(100);
        Future<Integer> future = service.submit(new IncrementAtomicLongRunnable("count"), rand);
        assertEquals(Integer.valueOf(rand), future.get());
    }
    IAtomicLong count = instances[0].getAtomicLong("count");
    assertEquals(instances.length, count.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Random(java.util.Random) IAtomicLong(com.hazelcast.core.IAtomicLong) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with IAtomicLong

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

the class SmallClusterTest method submitToSeveralNodes_runnable.

@Test
public void submitToSeveralNodes_runnable() throws Exception {
    for (HazelcastInstance instance : instances) {
        IExecutorService service = instance.getExecutorService("testExecuteMultipleNode");
        int rand = new Random().nextInt(100);
        Future<Integer> future = service.submit(new IncrementAtomicLongRunnable("count"), rand);
        assertEquals(Integer.valueOf(rand), future.get());
    }
    IAtomicLong count = instances[0].getAtomicLong("count");
    assertEquals(instances.length, count.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Random(java.util.Random) IExecutorService(com.hazelcast.core.IExecutorService) IAtomicLong(com.hazelcast.core.IAtomicLong) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with IAtomicLong

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

the class ExecutorServiceTest method testExecuteMultipleNode.

@Test
public void testExecuteMultipleNode() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
    HazelcastInstance[] instances = factory.newInstances(new Config());
    for (int i = 0; i < NODE_COUNT; i++) {
        IExecutorService service = instances[i].getExecutorService("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].getAtomicLong("count");
    assertEquals(NODE_COUNT, count.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Random(java.util.Random) ExecutorConfig(com.hazelcast.config.ExecutorConfig) Config(com.hazelcast.config.Config) IExecutorService(com.hazelcast.core.IExecutorService) 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 20 with IAtomicLong

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

the class DurableRetrieveResultTest method testSingleExecution_WhenMigratedAfterCompletion_WhenOwnerMemberKilled.

@Test
@Ignore
public void testSingleExecution_WhenMigratedAfterCompletion_WhenOwnerMemberKilled() throws Exception {
    String name = randomString();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance1 = factory.newHazelcastInstance();
    HazelcastInstance instance2 = factory.newHazelcastInstance();
    factory.newHazelcastInstance();
    String key = generateKeyOwnedBy(instance1);
    String runCounterName = "runCount";
    IAtomicLong runCount = instance2.getAtomicLong(runCounterName);
    DurableExecutorService executorService = instance1.getDurableExecutorService(name);
    IncrementAtomicLongRunnable task = new IncrementAtomicLongRunnable(runCounterName);
    DurableExecutorServiceFuture future = executorService.submitToKeyOwner(task, key);
    // Wait for it to finish
    future.get();
    instance1.getLifecycleService().terminate();
    executorService = instance2.getDurableExecutorService(name);
    Future<Object> newFuture = executorService.retrieveResult(future.getTaskId());
    // Make sure its completed
    newFuture.get();
    assertEquals(1, runCount.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IAtomicLong(com.hazelcast.core.IAtomicLong) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Ignore(org.junit.Ignore) 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