Search in sources :

Example 11 with MultiExecutionCallback

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

the class ClientExecutorServiceSubmitTest method testSubmitToMembersSerializesTheTaskOnlyOnce_withSelectorAndCallback.

@Test
public void testSubmitToMembersSerializesTheTaskOnlyOnce_withSelectorAndCallback() throws InterruptedException {
    IExecutorService executorService = client.getExecutorService(randomName());
    ExecutorServiceTestSupport.SerializationCountingCallable countingCallable = new ExecutorServiceTestSupport.SerializationCountingCallable();
    CountDownLatch complete = new CountDownLatch(1);
    executorService.submitToMembers(countingCallable, MemberSelectors.DATA_MEMBER_SELECTOR, 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) ExecutorServiceTestSupport(com.hazelcast.executor.ExecutorServiceTestSupport) 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 12 with MultiExecutionCallback

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

the class ClientExecutorServiceSubmitTest method testSubmitToMembersSerializesTheTaskOnlyOnce_withCollectionAndCallback.

@Test
public void testSubmitToMembersSerializesTheTaskOnlyOnce_withCollectionAndCallback() throws InterruptedException {
    IExecutorService executorService = client.getExecutorService(randomName());
    ExecutorServiceTestSupport.SerializationCountingCallable countingCallable = new ExecutorServiceTestSupport.SerializationCountingCallable();
    CountDownLatch complete = new CountDownLatch(1);
    executorService.submitToMembers(countingCallable, client.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) ExecutorServiceTestSupport(com.hazelcast.executor.ExecutorServiceTestSupport) 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 13 with MultiExecutionCallback

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

the class ClientExecutorServiceSubmitTest method submitRunnableToMembers_withMultiExecutionCallback.

@Test
public void submitRunnableToMembers_withMultiExecutionCallback() {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    Runnable runnable = new MapPutRunnable(mapName);
    Collection<Member> collection = server.getCluster().getMembers();
    final CountDownLatch responseLatch = new CountDownLatch(CLUSTER_SIZE);
    final CountDownLatch completeLatch = new CountDownLatch(1);
    service.submitToMembers(runnable, collection, new MultiExecutionCallback() {

        public void onResponse(Member member, Object value) {
            responseLatch.countDown();
        }

        public void onComplete(Map<Member, Object> values) {
            completeLatch.countDown();
        }
    });
    Map map = client.getMap(mapName);
    assertOpenEventually("responseLatch", responseLatch);
    assertOpenEventually("completeLatch", completeLatch);
    assertEquals(CLUSTER_SIZE, map.size());
}
Also used : MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.cluster.Member) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with MultiExecutionCallback

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

the class ClientExecutorServiceSubmitTest method testSubmitToAllMembersSerializesTheTaskOnlyOnce_withCallback.

@Test
public void testSubmitToAllMembersSerializesTheTaskOnlyOnce_withCallback() throws InterruptedException {
    IExecutorService executorService = client.getExecutorService(randomName());
    ExecutorServiceTestSupport.SerializationCountingCallable countingCallable = new ExecutorServiceTestSupport.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) ExecutorServiceTestSupport(com.hazelcast.executor.ExecutorServiceTestSupport) 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 15 with MultiExecutionCallback

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

the class ClientExecutorServiceSubmitTest method submitRunnableToAllMembers_withMultiExecutionCallback.

@Test
public void submitRunnableToAllMembers_withMultiExecutionCallback() {
    IExecutorService service = client.getExecutorService(randomString());
    final CountDownLatch responseLatch = new CountDownLatch(CLUSTER_SIZE);
    final CountDownLatch completeLatch = new CountDownLatch(1);
    String mapName = randomString();
    Runnable runnable = new MapPutRunnable(mapName);
    service.submitToAllMembers(runnable, new MultiExecutionCallback() {

        public void onResponse(Member member, Object value) {
            responseLatch.countDown();
        }

        public void onComplete(Map<Member, Object> values) {
            completeLatch.countDown();
        }
    });
    IMap map = client.getMap(mapName);
    assertOpenEventually("responseLatch", responseLatch);
    assertOpenEventually("completeLatch", completeLatch);
    assertEquals(CLUSTER_SIZE, map.size());
}
Also used : MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) IMap(com.hazelcast.map.IMap) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) 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