diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-07-22 15:38:33 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-07-29 20:04:50 +0000 |
commit | 5dd693fb86fb9a0e6335de1c9dbabab7dbd89ce6 (patch) | |
tree | 460f5f8174ac9b8fada498961cdfd90e198c525b /server/sonar-main/src/test | |
parent | c9676adac645c042119fa267bc98179f53f80169 (diff) | |
download | sonarqube-5dd693fb86fb9a0e6335de1c9dbabab7dbd89ce6.tar.gz sonarqube-5dd693fb86fb9a0e6335de1c9dbabab7dbd89ce6.zip |
SONAR-15231 Pool ES status in clusters
Diffstat (limited to 'server/sonar-main/src/test')
-rw-r--r-- | server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java index 16bbb81773b..16dce4d4bc7 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterAppStateImplTest.java @@ -21,6 +21,7 @@ package org.sonar.application.cluster; import java.net.InetAddress; import java.util.Optional; +import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.junit.Rule; import org.junit.Test; import org.junit.rules.DisableOnDebug; @@ -41,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.sonar.process.cluster.hz.HazelcastObjects.CLUSTER_NAME; import static org.sonar.process.cluster.hz.HazelcastObjects.SONARQUBE_VERSION; @@ -78,6 +80,24 @@ public class ClusterAppStateImplTest { } @Test + public void check_if_elasticsearch_is_operational_on_cluster() { + AppStateListener listener = mock(AppStateListener.class); + EsConnector esConnectorMock = mock(EsConnector.class); + when(esConnectorMock.getClusterHealthStatus()) + .thenReturn(Optional.empty()) + .thenReturn(Optional.of(ClusterHealthStatus.RED)) + .thenReturn(Optional.of(ClusterHealthStatus.GREEN)); + try (ClusterAppStateImpl underTest = createClusterAppState(esConnectorMock)) { + underTest.addListener(listener); + + underTest.isOperational(ProcessId.ELASTICSEARCH, false); + + //wait until undergoing thread marks ES as operational + verify(listener, timeout(20_000)).onAppStateOperational(ProcessId.ELASTICSEARCH); + } + } + + @Test public void constructor_checks_appNodesClusterHostsConsistency() { AppNodesClusterHostsConsistency clusterHostsConsistency = mock(AppNodesClusterHostsConsistency.class); try (ClusterAppStateImpl underTest = new ClusterAppStateImpl(new TestAppSettings(), newHzMember(), @@ -164,7 +184,11 @@ public class ClusterAppStateImplTest { } private ClusterAppStateImpl createClusterAppState() { - return new ClusterAppStateImpl(new TestAppSettings(), newHzMember(), mock(EsConnector.class), mock(AppNodesClusterHostsConsistency.class)); + return createClusterAppState(mock(EsConnector.class)); + } + + private ClusterAppStateImpl createClusterAppState(EsConnector esConnector) { + return new ClusterAppStateImpl(new TestAppSettings(), newHzMember(), esConnector, mock(AppNodesClusterHostsConsistency.class)); } private static HazelcastMember newHzMember() { |