Search in sources :

Example 1 with MemberSelector

use of com.hazelcast.core.MemberSelector 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.core.MemberSelector) AppendCallable(com.hazelcast.client.executor.tasks.AppendCallable) SelectAllMembers(com.hazelcast.client.executor.tasks.SelectAllMembers) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.core.Member) NullCallable(com.hazelcast.client.executor.tasks.NullCallable) Callable(java.util.concurrent.Callable) MapPutPartitionAwareCallable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareCallable) AppendCallable(com.hazelcast.client.executor.tasks.AppendCallable) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with MemberSelector

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

the class ClientExecutorServiceSubmitTest method testSubmitCallable_withMemberSelector.

@Test
public void testSubmitCallable_withMemberSelector() throws Exception {
    IExecutorService service = client.getExecutorService(randomString());
    String msg = randomString();
    Callable<String> callable = new AppendCallable(msg);
    MemberSelector selectAll = new SelectAllMembers();
    Future<String> f = service.submit(callable, selectAll);
    assertEquals(msg + AppendCallable.APPENDAGE, f.get());
}
Also used : MemberSelector(com.hazelcast.core.MemberSelector) AppendCallable(com.hazelcast.client.executor.tasks.AppendCallable) SelectAllMembers(com.hazelcast.client.executor.tasks.SelectAllMembers) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with MemberSelector

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

the class ClientExecutorServiceSubmitTest method testSubmitCallableToMembers_withMemberSelector.

@Test
public void testSubmitCallableToMembers_withMemberSelector() throws Exception {
    IExecutorService service = client.getExecutorService(randomString());
    Callable<String> getUuidCallable = new GetMemberUuidTask();
    MemberSelector selectAll = new SelectAllMembers();
    Map<Member, Future<String>> map = service.submitToMembers(getUuidCallable, selectAll);
    for (Member member : map.keySet()) {
        Future<String> result = map.get(member);
        String uuid = result.get();
        assertEquals(member.getUuid(), uuid);
    }
}
Also used : GetMemberUuidTask(com.hazelcast.client.executor.tasks.GetMemberUuidTask) MemberSelector(com.hazelcast.core.MemberSelector) SelectAllMembers(com.hazelcast.client.executor.tasks.SelectAllMembers) Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with MemberSelector

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

the class ClientExecutorServiceSubmitTest method submitRunnable_withExecutionCallback.

@Test
public void submitRunnable_withExecutionCallback() {
    IExecutorService service = client.getExecutorService(randomString());
    final CountDownLatch responseLatch = new CountDownLatch(1);
    String mapName = randomString();
    Runnable runnable = new MapPutRunnable(mapName);
    MemberSelector selector = new SelectAllMembers();
    service.submit(runnable, selector, new ExecutionCallback() {

        public void onResponse(Object response) {
            responseLatch.countDown();
        }

        public void onFailure(Throwable t) {
        }
    });
    IMap map = client.getMap(mapName);
    assertOpenEventually("responseLatch", responseLatch);
    assertEquals(1, map.size());
}
Also used : IMap(com.hazelcast.core.IMap) MemberSelector(com.hazelcast.core.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.executor.tasks.SelectAllMembers) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with MemberSelector

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

the class ClientExecutorServiceExecuteTest method testExecute_withMemberSelector.

@Test
public void testExecute_withMemberSelector() {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    MemberSelector selector = new SelectAllMembers();
    service.execute(new MapPutRunnable(mapName), selector);
    IMap map = client.getMap(mapName);
    assertSizeEventually(1, map);
}
Also used : IMap(com.hazelcast.core.IMap) MemberSelector(com.hazelcast.core.MemberSelector) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) SelectAllMembers(com.hazelcast.client.executor.tasks.SelectAllMembers) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MemberSelector (com.hazelcast.core.MemberSelector)20 QuickTest (com.hazelcast.test.annotation.QuickTest)19 Test (org.junit.Test)19 ParallelTest (com.hazelcast.test.annotation.ParallelTest)12 IExecutorService (com.hazelcast.core.IExecutorService)11 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)9 SelectAllMembers (com.hazelcast.client.executor.tasks.SelectAllMembers)8 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)6 Member (com.hazelcast.core.Member)6 IMap (com.hazelcast.core.IMap)4 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AppendCallable (com.hazelcast.client.executor.tasks.AppendCallable)3 MapPutPartitionAwareCallable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareCallable)2 MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)2 NullCallable (com.hazelcast.client.executor.tasks.NullCallable)2 ExecutionCallback (com.hazelcast.core.ExecutionCallback)2 Callable (java.util.concurrent.Callable)2 GetMemberUuidTask (com.hazelcast.client.executor.tasks.GetMemberUuidTask)1 SelectNoMembers (com.hazelcast.client.executor.tasks.SelectNoMembers)1