Search in sources :

Example 6 with MultiExecutionCallback

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

the class ExecutorServiceTest method testSubmitToAllMembersRunnable.

@Test
public void testSubmitToAllMembersRunnable() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
    HazelcastInstance[] instances = factory.newInstances(smallInstanceConfig());
    final AtomicInteger nullResponseCount = new AtomicInteger(0);
    final CountDownLatch responseLatch = new CountDownLatch(NODE_COUNT * NODE_COUNT);
    MultiExecutionCallback callback = new MultiExecutionCallback() {

        public void onResponse(Member member, Object value) {
            if (value == null) {
                nullResponseCount.incrementAndGet();
            }
            responseLatch.countDown();
        }

        public void onComplete(Map<Member, Object> values) {
        }
    };
    for (int i = 0; i < NODE_COUNT; i++) {
        IExecutorService service = instances[i].getExecutorService("testSubmitToAllMembersRunnable");
        service.submitToAllMembers(new IncrementAtomicLongRunnable("testSubmitToAllMembersRunnable"), callback);
    }
    assertTrue(responseLatch.await(30, TimeUnit.SECONDS));
    IAtomicLong result = instances[0].getCPSubsystem().getAtomicLong("testSubmitToAllMembersRunnable");
    assertEquals(NODE_COUNT * NODE_COUNT, result.get());
    assertEquals(NODE_COUNT * NODE_COUNT, nullResponseCount.get());
}
Also used : 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.cp.IAtomicLong) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.cluster.Member) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with MultiExecutionCallback

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

the class SmallClusterTest method submitToAllMembers_statefulCallable.

@Test
public void submitToAllMembers_statefulCallable() {
    IExecutorService executorService = instances[0].getExecutorService(randomString());
    InternallyCountingCallable internallyCountingCallable = new InternallyCountingCallable();
    final CountDownLatch completedLatch = new CountDownLatch(1);
    final AtomicBoolean failed = new AtomicBoolean();
    // local execution of callable may change the state of callable before sent to other members
    // we avoid this by serializing beforehand
    executorService.submitToAllMembers(internallyCountingCallable, new MultiExecutionCallback() {

        @Override
        public void onResponse(Member member, Object value) {
            if ((Integer) value != 1) {
                failed.set(true);
            }
        }

        @Override
        public void onComplete(Map<Member, Object> values) {
            completedLatch.countDown();
        }
    });
    assertOpenEventually(completedLatch);
    assertFalse(failed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with MultiExecutionCallback

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

the class SmallClusterTest method submitToAllMembers_NonSerializableResponse.

@Test
public void submitToAllMembers_NonSerializableResponse() {
    IExecutorService executorService = instances[0].getExecutorService(randomString());
    NonSerializableResponseCallable nonSerializableResponseCallable = new NonSerializableResponseCallable();
    final AtomicLong exceptionCount = new AtomicLong();
    final AtomicLong responseCount = new AtomicLong();
    final CountDownLatch completedLatch = new CountDownLatch(1);
    executorService.submitToAllMembers(nonSerializableResponseCallable, new MultiExecutionCallback() {

        @Override
        public void onResponse(Member member, Object value) {
            if (value instanceof HazelcastSerializationException) {
                exceptionCount.incrementAndGet();
            } else {
                responseCount.incrementAndGet();
            }
        }

        @Override
        public void onComplete(Map<Member, Object> values) {
            completedLatch.countDown();
        }
    });
    assertOpenEventually(completedLatch);
    // two exceptions from remote nodes
    assertEquals(2, exceptionCount.get());
    // one response from local node since, it does not need to serialize/deserialize the response
    assertEquals(1, responseCount.get());
}
Also used : MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) IAtomicLong(com.hazelcast.cp.IAtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with MultiExecutionCallback

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

the class SmallClusterTest method testSubmitToAllMembersSerializesTheTaskOnlyOnce_withCallback.

@Test
public void testSubmitToAllMembersSerializesTheTaskOnlyOnce_withCallback() throws InterruptedException {
    IExecutorService executorService = instances[0].getExecutorService(randomName());
    SerializationCountingCallable countingCallable = new SerializationCountingCallable();
    CountDownLatch complete = new CountDownLatch(1);
    executorService.submitToAllMembers(countingCallable, new MultiExecutionCallback() {

        @Override
        public void onResponse(Member member, Object value) {
        }

        @Override
        public void onComplete(Map<Member, Object> values) {
            complete.countDown();
        }
    });
    complete.await();
    assertEquals(1, countingCallable.getSerializationCount());
}
Also used : MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with MultiExecutionCallback

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

the class SmallClusterTest method testSubmitToMembersSerializesTheTaskOnlyOnce_withCollectionAndCallback.

@Test
public void testSubmitToMembersSerializesTheTaskOnlyOnce_withCollectionAndCallback() throws InterruptedException {
    IExecutorService executorService = instances[0].getExecutorService(randomName());
    SerializationCountingCallable countingCallable = new SerializationCountingCallable();
    CountDownLatch complete = new CountDownLatch(1);
    executorService.submitToMembers(countingCallable, instances[0].getCluster().getMembers(), new MultiExecutionCallback() {

        @Override
        public void onResponse(Member member, Object value) {
        }

        @Override
        public void onComplete(Map<Member, Object> values) {
            complete.countDown();
        }
    });
    complete.await();
    assertEquals(1, countingCallable.getSerializationCount());
}
Also used : MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)20 Test (org.junit.Test)20 Member (com.hazelcast.cluster.Member)19 IExecutorService (com.hazelcast.core.IExecutorService)19 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 QuickTest (com.hazelcast.test.annotation.QuickTest)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)6 Map (java.util.Map)5 AppendCallable (com.hazelcast.client.test.executor.tasks.AppendCallable)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 IAtomicLong (com.hazelcast.cp.IAtomicLong)4 Callable (java.util.concurrent.Callable)4 MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)3 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)3 MapPutPartitionAwareCallable (com.hazelcast.client.test.executor.tasks.MapPutPartitionAwareCallable)3 NullCallable (com.hazelcast.client.test.executor.tasks.NullCallable)3 MemberSelector (com.hazelcast.cluster.MemberSelector)3 ExecutorServiceTestSupport (com.hazelcast.executor.ExecutorServiceTestSupport)3 IMap (com.hazelcast.map.IMap)3