Search in sources :

Example 11 with MemberSelector

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

the class ClientExecutorServiceExecuteTest method testExecuteOnMembers_withSelector.

@Test
public void testExecuteOnMembers_withSelector() {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    MemberSelector selector = new SelectAllMembers();
    service.executeOnMembers(new MapPutRunnable(mapName), selector);
    IMap map = client.getMap(mapName);
    assertSizeEventually(CLUSTER_SIZE, 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)

Example 12 with MemberSelector

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

the class SingleNodeTest method alwaysFalseMemberSelector_expectRejection.

@Test(expected = RejectedExecutionException.class)
public void alwaysFalseMemberSelector_expectRejection() {
    HazelcastInstanceAwareRunnable task = new HazelcastInstanceAwareRunnable();
    executor.execute(task, new MemberSelector() {

        @Override
        public boolean select(Member member) {
            return false;
        }
    });
}
Also used : MemberSelector(com.hazelcast.core.MemberSelector) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with MemberSelector

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

the class ClientExecutorServiceExecuteTest method testExecuteOnMembers_whenSelectorNull.

@Test(expected = IllegalArgumentException.class)
public void testExecuteOnMembers_whenSelectorNull() {
    IExecutorService service = client.getExecutorService(randomString());
    MemberSelector selector = null;
    service.executeOnMembers(new MapPutRunnable("task"), selector);
}
Also used : MemberSelector(com.hazelcast.core.MemberSelector) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) IExecutorService(com.hazelcast.core.IExecutorService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with MemberSelector

use of com.hazelcast.core.MemberSelector 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.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) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with MemberSelector

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

the class ClientExecutorServiceTest method testExecute_withNoMemberSelected.

@Test(expected = RejectedExecutionException.class)
public void testExecute_withNoMemberSelected() {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    MemberSelector selector = new SelectNoMembers();
    service.execute(new MapPutRunnable(mapName), selector);
}
Also used : SelectNoMembers(com.hazelcast.client.executor.tasks.SelectNoMembers) MemberSelector(com.hazelcast.core.MemberSelector) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) 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