Search in sources :

Example 16 with MultiExecutionCallback

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

the class ClientExecutorServiceSubmitTest method submitCallableToAllMembers_withMultiExecutionCallback.

@Test
public void submitCallableToAllMembers_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 callable = new AppendCallable(msg);
    service.submitToAllMembers(callable, 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) 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 17 with MultiExecutionCallback

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

the class ClientExecutorServiceSubmitTest method submitRunnableToMembers_withExecutionCallback.

@Test
public void submitRunnableToMembers_withExecutionCallback() {
    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);
    MemberSelector selector = new SelectAllMembers();
    service.submitToMembers(runnable, selector, 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) MemberSelector(com.hazelcast.cluster.MemberSelector) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) 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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with MultiExecutionCallback

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

the class ExecutorServiceTest method testSubmitToAllMembersCallable.

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

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

        public void onComplete(Map<Member, Object> values) {
        }
    };
    for (int i = 0; i < NODE_COUNT; i++) {
        IExecutorService service = instances[i].getExecutorService("testSubmitToAllMembersCallable");
        service.submitToAllMembers(new IncrementAtomicLongCallable("testSubmitToAllMembersCallable"), callback);
    }
    assertOpenEventually(countDownLatch);
    IAtomicLong result = instances[0].getCPSubsystem().getAtomicLong("testSubmitToAllMembersCallable");
    assertEquals(NODE_COUNT * NODE_COUNT, result.get());
    assertEquals(NODE_COUNT * NODE_COUNT, count.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 19 with MultiExecutionCallback

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

the class SmallClusterTest method testSubmitToMembersSerializesTheTaskOnlyOnce_withSelectorAndCallback.

@Test
public void testSubmitToMembersSerializesTheTaskOnlyOnce_withSelectorAndCallback() throws InterruptedException {
    IExecutorService executorService = instances[0].getExecutorService(randomName());
    SerializationCountingCallable countingCallable = new 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) 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 20 with MultiExecutionCallback

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

the class AbstractExecutorNullTest method testNullability.

@Test
public void testNullability() {
    Runnable sampleRunnable = (Runnable & Serializable) () -> {
    };
    Callable<Object> sampleCallable = (Callable & Serializable) () -> "";
    Member sampleMember = getDriver().getCluster().getMembers().iterator().next();
    Set<Member> sampleMembers = Collections.singleton(sampleMember);
    MemberSelector sampleSelector = member -> true;
    ExecutionCallback<Object> sampleCallback = new ExecutionCallback<Object>() {

        @Override
        public void onResponse(Object response) {
        }

        @Override
        public void onFailure(Throwable t) {
        }
    };
    MultiExecutionCallback sampleMultiExecutionCallback = new MultiExecutionCallback() {

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

        @Override
        public void onComplete(Map<Member, Object> values) {
        }
    };
    assertThrowsNPE(s -> s.execute((Runnable) null, sampleSelector));
    assertThrowsNPE(s -> s.execute(sampleRunnable, null));
    assertThrowsNPE(s -> s.executeOnKeyOwner(null, ""));
    assertThrowsNPE(s -> s.executeOnKeyOwner(sampleRunnable, null));
    assertThrowsNPE(s -> s.executeOnMember(null, sampleMember));
    assertThrowsNPE(s -> s.executeOnMember(sampleRunnable, null));
    assertThrowsNPE(s -> s.executeOnMembers(null, sampleMembers));
    assertThrowsNPE(s -> s.executeOnMembers(sampleRunnable, (Collection<Member>) null));
    assertThrowsNPE(s -> s.executeOnMembers(null, sampleSelector));
    assertThrowsNPE(s -> s.executeOnMembers(sampleRunnable, (MemberSelector) null));
    assertThrowsNPE(s -> s.executeOnAllMembers(null));
    System.out.println("------------1");
    assertThrowsNPE(s -> s.submit((Callable) null, sampleSelector));
    assertThrowsNPE(s -> s.submit(sampleCallable, (MemberSelector) null));
    assertThrowsNPE(s -> s.submitToKeyOwner((Callable) null, ""));
    assertThrowsNPE(s -> s.submitToKeyOwner(sampleCallable, null));
    assertThrowsNPE(s -> s.submitToMember((Callable) null, sampleMember));
    assertThrowsNPE(s -> s.submitToMember(sampleCallable, null));
    assertThrowsNPE(s -> s.submitToMembers((Callable) null, sampleMembers));
    assertThrowsNPE(s -> s.submitToMembers(sampleCallable, (Collection<Member>) null));
    assertThrowsNPE(s -> s.submitToMembers((Callable) null, sampleSelector));
    assertThrowsNPE(s -> s.submitToMembers(sampleCallable, (MemberSelector) null));
    assertThrowsNPE(s -> s.submitToAllMembers(null));
    System.out.println("------------2");
    assertThrowsNPE(s -> s.submit((Runnable) null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submit(sampleRunnable, (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submit((Runnable) null, sampleSelector, sampleCallback));
    assertThrowsNPE(s -> s.submit(sampleRunnable, (MemberSelector) null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submit(sampleRunnable, sampleSelector, (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submitToKeyOwner((Runnable) null, "", sampleCallback));
    assertThrowsNPE(s -> s.submitToKeyOwner(sampleRunnable, null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submitToKeyOwner(sampleRunnable, "", (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submitToMember((Runnable) null, sampleMember, sampleCallback));
    assertThrowsNPE(s -> s.submitToMember(sampleRunnable, null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submitToMember(sampleRunnable, sampleMember, (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submitToMembers((Runnable) null, sampleMembers, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleRunnable, (Collection) null, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleRunnable, sampleMembers, (MultiExecutionCallback) null));
    assertThrowsNPE(s -> s.submitToMembers((Runnable) null, sampleSelector, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleRunnable, (MemberSelector) null, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleRunnable, sampleSelector, (MultiExecutionCallback) null));
    assertThrowsNPE(s -> s.submitToAllMembers((Runnable) null, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToAllMembers(sampleRunnable, null));
    System.out.println("------------3");
    assertThrowsNPE(s -> s.submit((Callable<Object>) null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submit(sampleCallable, (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submit((Callable) null, sampleSelector, sampleCallback));
    assertThrowsNPE(s -> s.submit(sampleCallable, (MemberSelector) null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submit(sampleCallable, sampleSelector, (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submitToKeyOwner((Callable) null, "", sampleCallback));
    assertThrowsNPE(s -> s.submitToKeyOwner(sampleCallable, null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submitToKeyOwner(sampleCallable, "", (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submitToMember((Callable) null, sampleMember, sampleCallback));
    assertThrowsNPE(s -> s.submitToMember(sampleCallable, null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submitToMember(sampleCallable, sampleMember, (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submitToMembers((Callable) null, sampleMembers, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleCallable, (Collection) null, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleCallable, sampleMembers, (MultiExecutionCallback) null));
    assertThrowsNPE(s -> s.submitToMembers((Callable) null, sampleSelector, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleCallable, (MemberSelector) null, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleCallable, sampleSelector, (MultiExecutionCallback) null));
    assertThrowsNPE(s -> s.submitToAllMembers((Callable) null, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToAllMembers(sampleCallable, null));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Member(com.hazelcast.cluster.Member) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Collection(java.util.Collection) ExceptionUtil(com.hazelcast.internal.util.ExceptionUtil) Set(java.util.Set) Test(org.junit.Test) Callable(java.util.concurrent.Callable) Serializable(java.io.Serializable) MemberSelector(com.hazelcast.cluster.MemberSelector) Consumer(java.util.function.Consumer) IExecutorService(com.hazelcast.core.IExecutorService) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) ExecutionCallback(com.hazelcast.core.ExecutionCallback) Map(java.util.Map) Collections(java.util.Collections) Callable(java.util.concurrent.Callable) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) MemberSelector(com.hazelcast.cluster.MemberSelector) Collection(java.util.Collection) Member(com.hazelcast.cluster.Member) Map(java.util.Map) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) ExecutionCallback(com.hazelcast.core.ExecutionCallback) 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