Search in sources :

Example 11 with MemberSelector

use of com.hazelcast.cluster.MemberSelector in project sonarqube by SonarSource.

the class HazelcastMemberSelectorsTest method selecting_web_and_app_nodes.

@Test
public void selecting_web_and_app_nodes() {
    Member member = mock(Member.class);
    MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(WEB_SERVER, APP);
    when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey());
    assertThat(underTest.select(member)).isFalse();
    when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey());
    assertThat(underTest.select(member)).isTrue();
    when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey());
    assertThat(underTest.select(member)).isTrue();
}
Also used : MemberSelector(com.hazelcast.cluster.MemberSelector) Member(com.hazelcast.cluster.Member) Test(org.junit.Test)

Example 12 with MemberSelector

use of com.hazelcast.cluster.MemberSelector in project sonarqube by SonarSource.

the class HazelcastMemberSelectorsTest method selecting_ce_nodes.

@Test
public void selecting_ce_nodes() {
    Member member = mock(Member.class);
    MemberSelector underTest = HazelcastMemberSelectors.selectorForProcessIds(COMPUTE_ENGINE);
    when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(COMPUTE_ENGINE.getKey());
    assertThat(underTest.select(member)).isTrue();
    when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(WEB_SERVER.getKey());
    assertThat(underTest.select(member)).isFalse();
    when(member.getAttribute(PROCESS_KEY.getKey())).thenReturn(APP.getKey());
    assertThat(underTest.select(member)).isFalse();
}
Also used : MemberSelector(com.hazelcast.cluster.MemberSelector) Member(com.hazelcast.cluster.Member) Test(org.junit.Test)

Example 13 with MemberSelector

use of com.hazelcast.cluster.MemberSelector in project sonarqube by SonarSource.

the class AppNodesInfoLoaderImpl method load.

public Collection<NodeInfo> load() throws InterruptedException {
    Map<String, NodeInfo> nodesByName = new HashMap<>();
    MemberSelector memberSelector = HazelcastMemberSelectors.selectorForProcessIds(ProcessId.WEB_SERVER, ProcessId.COMPUTE_ENGINE);
    DistributedAnswer<ProtobufSystemInfo.SystemInfo> distributedAnswer = hzMember.call(ProcessInfoProvider::provide, memberSelector, DISTRIBUTED_TIMEOUT_MS);
    for (Member member : distributedAnswer.getMembers()) {
        String nodeName = member.getAttribute(NODE_NAME.getKey());
        NodeInfo nodeInfo = nodesByName.computeIfAbsent(nodeName, name -> {
            NodeInfo info = new NodeInfo(name);
            info.setHost(member.getAddress().getHost());
            return info;
        });
        completeNodeInfo(distributedAnswer, member, nodeInfo);
    }
    return nodesByName.values();
}
Also used : MemberSelector(com.hazelcast.cluster.MemberSelector) ProtobufSystemInfo(org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo) HashMap(java.util.HashMap) Member(com.hazelcast.cluster.Member) HazelcastMember(org.sonar.process.cluster.hz.HazelcastMember)

Example 14 with MemberSelector

use of com.hazelcast.cluster.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.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 15 with MemberSelector

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

the class ClientExecutorServiceExecuteTest method testExecuteOnMembers_whenSelectorNull.

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

Aggregations

MemberSelector (com.hazelcast.cluster.MemberSelector)23 Test (org.junit.Test)20 QuickTest (com.hazelcast.test.annotation.QuickTest)17 IExecutorService (com.hazelcast.core.IExecutorService)11 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 SelectAllMembers (com.hazelcast.client.test.executor.tasks.SelectAllMembers)8 Member (com.hazelcast.cluster.Member)8 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)8 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)6 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 AppendCallable (com.hazelcast.client.test.executor.tasks.AppendCallable)3 ExecutionCallback (com.hazelcast.core.ExecutionCallback)3 IMap (com.hazelcast.map.IMap)3 Callable (java.util.concurrent.Callable)3 MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)2 MapPutPartitionAwareCallable (com.hazelcast.client.test.executor.tasks.MapPutPartitionAwareCallable)2 NullCallable (com.hazelcast.client.test.executor.tasks.NullCallable)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2