Search in sources :

Example 1 with MultiExecutionCallback

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

the class ClientExecutorServiceSubmitTest method submitCallableToMember_withMultiExecutionCallback.

@Test
public void submitCallableToMember_withMultiExecutionCallback() {
    IExecutorService service = client.getExecutorService(randomString());
    final CountDownLatch responseLatch = new CountDownLatch(CLUSTER_SIZE);
    final CountDownLatch completeLatch = new CountDownLatch(CLUSTER_SIZE);
    final String msg = randomString();
    Callable<String> callable = new AppendCallable(msg);
    Collection<Member> collection = server.getCluster().getMembers();
    service.submitToMembers(callable, collection, new MultiExecutionCallback() {

        public void onResponse(Member member, Object value) {
            if (value.equals(msg + AppendCallable.APPENDAGE)) {
                responseLatch.countDown();
            }
        }

        public void onComplete(Map<Member, Object> values) {
            for (Member member : values.keySet()) {
                Object value = values.get(member);
                if (value.equals(msg + AppendCallable.APPENDAGE)) {
                    completeLatch.countDown();
                }
            }
        }
    });
    assertOpenEventually("responseLatch", responseLatch);
    assertOpenEventually("completeLatch", completeLatch);
}
Also used : MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) AppendCallable(com.hazelcast.client.test.executor.tasks.AppendCallable) 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)

Example 2 with MultiExecutionCallback

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

the class ClientExecutorServiceSubmitTest method submitCallableWithNullResultToAllMembers_withMultiExecutionCallback.

@Test
public void submitCallableWithNullResultToAllMembers_withMultiExecutionCallback() {
    IExecutorService service = client.getExecutorService(randomString());
    final CountDownLatch responseLatch = new CountDownLatch(CLUSTER_SIZE);
    final CountDownLatch completeLatch = new CountDownLatch(CLUSTER_SIZE);
    Callable callable = new NullCallable();
    service.submitToAllMembers(callable, new MultiExecutionCallback() {

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

        public void onComplete(Map<Member, Object> values) {
            for (Member member : values.keySet()) {
                Object value = values.get(member);
                if (value == null) {
                    completeLatch.countDown();
                }
            }
        }
    });
    assertOpenEventually("responseLatch", responseLatch);
    assertOpenEventually("completeLatch", completeLatch);
}
Also used : MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) NullCallable(com.hazelcast.client.test.executor.tasks.NullCallable) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.cluster.Member) NullCallable(com.hazelcast.client.test.executor.tasks.NullCallable) Callable(java.util.concurrent.Callable) AppendCallable(com.hazelcast.client.test.executor.tasks.AppendCallable) MapPutPartitionAwareCallable(com.hazelcast.client.test.executor.tasks.MapPutPartitionAwareCallable) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with MultiExecutionCallback

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

the class ClientExecutorServiceSubmitTest method submitCallableToMembers_withExecutionCallback.

@Test
public void submitCallableToMembers_withExecutionCallback() {
    IExecutorService service = client.getExecutorService(randomString());
    final CountDownLatch responseLatch = new CountDownLatch(CLUSTER_SIZE);
    final CountDownLatch completeLatch = new CountDownLatch(1);
    final String msg = randomString();
    Callable callable = new AppendCallable(msg);
    MemberSelector selector = new SelectAllMembers();
    service.submitToMembers(callable, selector, new MultiExecutionCallback() {

        public void onResponse(Member member, Object value) {
            if (value.equals(msg + AppendCallable.APPENDAGE)) {
                responseLatch.countDown();
            }
        }

        public void onComplete(Map<Member, Object> values) {
            completeLatch.countDown();
        }
    });
    assertOpenEventually("responseLatch", responseLatch);
    assertOpenEventually("completeLatch", completeLatch);
}
Also used : MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) MemberSelector(com.hazelcast.cluster.MemberSelector) AppendCallable(com.hazelcast.client.test.executor.tasks.AppendCallable) SelectAllMembers(com.hazelcast.client.test.executor.tasks.SelectAllMembers) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.cluster.Member) NullCallable(com.hazelcast.client.test.executor.tasks.NullCallable) Callable(java.util.concurrent.Callable) AppendCallable(com.hazelcast.client.test.executor.tasks.AppendCallable) MapPutPartitionAwareCallable(com.hazelcast.client.test.executor.tasks.MapPutPartitionAwareCallable) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with MultiExecutionCallback

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

the class ExecutionCallbackAdapterRaceTest method test.

@Test
public void test() throws Exception {
    MultiExecutionCallback callback = new MultiExecutionCallbackMock();
    final ExecutionCallbackAdapterFactory factory = new ExecutionCallbackAdapterFactory(logger, asList(member1, member2), callback);
    // first we spawn the response for the member1
    // this thread is going wait for 2 seconds in the onResponse to trigger the out of order behavior
    Future future = spawn(new Runnable() {

        @Override
        public void run() {
            factory.callbackFor(member1).onResponse("1");
        }
    });
    factory.callbackFor(member2).onResponse("2");
    future.get();
    assertFalse("Race was detected", raceDetected);
}
Also used : MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) Future(java.util.concurrent.Future) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with MultiExecutionCallback

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

the class ExecutorServiceTest method testSubmitToMembersCallable.

@Test
public void testSubmitToMembersCallable() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
    HazelcastInstance[] instances = factory.newInstances(smallInstanceConfig());
    final AtomicInteger count = new AtomicInteger(0);
    final CountDownLatch latch = new CountDownLatch(NODE_COUNT);
    MultiExecutionCallback callback = new MultiExecutionCallback() {

        public void onResponse(Member member, Object value) {
            count.incrementAndGet();
        }

        public void onComplete(Map<Member, Object> values) {
            latch.countDown();
        }
    };
    int sum = 0;
    Set<Member> membersSet = instances[0].getCluster().getMembers();
    Member[] members = membersSet.toArray(new Member[0]);
    Random random = new Random();
    String name = "testSubmitToMembersCallable";
    for (int i = 0; i < NODE_COUNT; i++) {
        IExecutorService service = instances[i].getExecutorService(name);
        int n = random.nextInt(NODE_COUNT) + 1;
        sum += n;
        Member[] m = new Member[n];
        System.arraycopy(members, 0, m, 0, n);
        service.submitToMembers(new IncrementAtomicLongCallable(name), Arrays.asList(m), callback);
    }
    assertOpenEventually(latch);
    IAtomicLong result = instances[0].getCPSubsystem().getAtomicLong(name);
    assertEquals(sum, result.get());
    assertEquals(sum, count.get());
}
Also used : IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Random(java.util.Random) 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)

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