Search in sources :

Example 11 with IAtomicLong

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

the class DurableRetrieveResultTest method testSingleExecution_WhenMigratedAfterCompletion_WhenOwnerMemberKilled.

@Test
public void testSingleExecution_WhenMigratedAfterCompletion_WhenOwnerMemberKilled() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance[] instances = factory.newInstances(smallInstanceConfig());
    HazelcastInstance first = instances[0];
    HazelcastInstance second = instances[1];
    waitAllForSafeState(instances);
    String key = generateKeyOwnedBy(first);
    String runCounterName = "runCount";
    IAtomicLong runCount = second.getCPSubsystem().getAtomicLong(runCounterName);
    String name = randomString();
    DurableExecutorService executorService = first.getDurableExecutorService(name);
    IncrementAtomicLongRunnable task = new IncrementAtomicLongRunnable(runCounterName);
    DurableExecutorServiceFuture<?> future = executorService.submitToKeyOwner(task, key);
    // Wait for it to finish
    future.get();
    // Avoid race between PutResult & SHUTDOWN
    sleepSeconds(3);
    first.getLifecycleService().terminate();
    executorService = second.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.cp.IAtomicLong) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with IAtomicLong

use of com.hazelcast.cp.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].getCPSubsystem().getAtomicLong("count");
    assertEquals(instances.length, count.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Random(java.util.Random) IAtomicLong(com.hazelcast.cp.IAtomicLong) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with IAtomicLong

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

the class RestCPSubsystemTest method test_forceDestroyDefaultCPGroup.

@Test
public void test_forceDestroyDefaultCPGroup() throws IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    IAtomicLong long1 = instance1.getCPSubsystem().getAtomicLong("long1");
    ConnectionResponse response = new HTTPCommunicator(instance1).forceDestroyCPGroup(DEFAULT_GROUP_NAME, clusterName, null);
    assertEquals(200, response.responseCode);
    exception.expect(CPGroupDestroyedException.class);
    long1.set(5);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IAtomicLong(com.hazelcast.cp.IAtomicLong) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 14 with IAtomicLong

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

the class ClusterScopedInterceptor method preDestroy.

@PreDestroy
Object preDestroy(InvocationContext invocationContext) throws Exception {
    Class<?> beanClass = invocationContext.getTarget().getClass().getSuperclass();
    Clustered clusteredAnnotation = getAnnotation(beanManager, beanClass);
    clusteredLookup.setClusteredSessionKeyIfNotSet(beanClass, clusteredAnnotation);
    IAtomicLong count = clusteredLookup.getClusteredUsageCount();
    if (count.decrementAndGet() <= 0) {
        clusteredLookup.destroy();
    } else if (!clusteredAnnotation.callPreDestoyOnDetach()) {
        return null;
    }
    return invocationContext.proceed();
}
Also used : Clustered(fish.payara.cluster.Clustered) IAtomicLong(com.hazelcast.cp.IAtomicLong) PreDestroy(javax.annotation.PreDestroy)

Example 15 with IAtomicLong

use of com.hazelcast.cp.IAtomicLong in project chuidiang-ejemplos by chuidiang.

the class AtomicExample method main.

public static void main(String[] args) throws FileNotFoundException, InterruptedException {
    Config config = new Config();
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    IAtomicLong atomicLong = hazelcastInstance.getCPSubsystem().getAtomicLong("soy productor");
    boolean cambiado = atomicLong.compareAndSet(0, 1);
    if (cambiado) {
        produce(hazelcastInstance);
    } else {
        consume(hazelcastInstance);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) 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