Search in sources :

Example 1 with HazelcastMember

use of org.sonar.process.cluster.hz.HazelcastMember in project sonarqube by SonarSource.

the class SharedHealthStateImplTest method readAll_returns_all_NodeHealth_in_map_sq_health_state_for_existing_client_uuids_aged_less_than_30_seconds.

@Test
public void readAll_returns_all_NodeHealth_in_map_sq_health_state_for_existing_client_uuids_aged_less_than_30_seconds() {
    NodeHealth[] nodeHealths = IntStream.range(0, 1 + random.nextInt(6)).mapToObj(i -> randomNodeHealth()).toArray(NodeHealth[]::new);
    Map<UUID, TimestampedNodeHealth> allNodeHealths = new HashMap<>();
    Map<UUID, NodeHealth> expected = new HashMap<>();
    for (NodeHealth nodeHealth : nodeHealths) {
        UUID memberUuid = UUID.randomUUID();
        TimestampedNodeHealth timestampedNodeHealth = new TimestampedNodeHealth(nodeHealth, clusterTime - random.nextInt(30 * 1000));
        allNodeHealths.put(memberUuid, timestampedNodeHealth);
        if (random.nextBoolean()) {
            expected.put(memberUuid, nodeHealth);
        }
    }
    doReturn(allNodeHealths).when(hazelcastMember).getReplicatedMap(MAP_SQ_HEALTH_STATE);
    when(hazelcastMember.getMemberUuids()).thenReturn(expected.keySet());
    when(hazelcastMember.getClusterTime()).thenReturn(clusterTime);
    assertThat(underTest.readAll()).containsOnly(expected.values().toArray(new NodeHealth[0]));
    assertThat(logging.getLogs()).isEmpty();
}
Also used : IntStream(java.util.stream.IntStream) ImmutableSet(com.google.common.collect.ImmutableSet) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Random(java.util.Random) Test(org.junit.Test) UUID(java.util.UUID) HazelcastMember(org.sonar.process.cluster.hz.HazelcastMember) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) NodeDetails.newNodeDetailsBuilder(org.sonar.process.cluster.health.NodeDetails.newNodeDetailsBuilder) NodeHealth.newNodeHealthBuilder(org.sonar.process.cluster.health.NodeHealth.newNodeHealthBuilder) Rule(org.junit.Rule) Collections.singleton(java.util.Collections.singleton) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) LoggingRule(org.sonar.process.LoggingRule) Map(java.util.Map) Level(org.slf4j.event.Level) Mockito.doReturn(org.mockito.Mockito.doReturn) Mockito.mock(org.mockito.Mockito.mock) HashMap(java.util.HashMap) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with HazelcastMember

use of org.sonar.process.cluster.hz.HazelcastMember in project sonarqube by SonarSource.

the class AppStateFactory method create.

public AppState create() {
    if (ClusterSettings.shouldStartHazelcast(settings)) {
        EsConnector esConnector = createEsConnector(settings.getProps());
        HazelcastMember hzMember = createHzMember(settings.getProps());
        AppNodesClusterHostsConsistency appNodesClusterHostsConsistency = AppNodesClusterHostsConsistency.setInstance(hzMember, settings);
        return new ClusterAppStateImpl(settings, hzMember, esConnector, appNodesClusterHostsConsistency);
    }
    return new AppStateImpl();
}
Also used : EsConnector(org.sonar.application.es.EsConnector) AppNodesClusterHostsConsistency(org.sonar.application.cluster.AppNodesClusterHostsConsistency) ClusterAppStateImpl(org.sonar.application.cluster.ClusterAppStateImpl) HazelcastMember(org.sonar.process.cluster.hz.HazelcastMember) ClusterAppStateImpl(org.sonar.application.cluster.ClusterAppStateImpl)

Aggregations

HazelcastMember (org.sonar.process.cluster.hz.HazelcastMember)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Collections.singleton (java.util.Collections.singleton)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 UUID (java.util.UUID)1 IntStream (java.util.stream.IntStream)1 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang.RandomStringUtils.randomAlphanumeric)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 Mockito.doReturn (org.mockito.Mockito.doReturn)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)1 Mockito.when (org.mockito.Mockito.when)1 Level (org.slf4j.event.Level)1 AppNodesClusterHostsConsistency (org.sonar.application.cluster.AppNodesClusterHostsConsistency)1