Search in sources :

Example 11 with NodeHealth

use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.

the class AppNodeClusterCheckTest method status_GREEN_when_two_GREEN_application_node.

@Test
public void status_GREEN_when_two_GREEN_application_node() {
    Set<NodeHealth> nodeHealths = nodeHealths(GREEN, GREEN).collect(toSet());
    Health check = underTest.check(nodeHealths);
    assertThat(check).forInput(nodeHealths).hasStatus(Health.Status.GREEN).andCauses();
}
Also used : NodeHealth(org.sonar.process.cluster.health.NodeHealth) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Test(org.junit.Test)

Example 12 with NodeHealth

use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.

the class ClusterHealthTest method test_getNodeHealth.

@Test
public void test_getNodeHealth() {
    Health health = randomHealth();
    Set<NodeHealth> nodeHealths = new HashSet<>(Arrays.asList(newNodeHealth("foo"), newNodeHealth("bar")));
    ClusterHealth underTest = new ClusterHealth(health, nodeHealths);
    assertThat(underTest.getNodeHealth("does_not_exist")).isEmpty();
    assertThat(underTest.getNodeHealth("bar")).isPresent();
}
Also used : NodeHealth(org.sonar.process.cluster.health.NodeHealth) NodeHealth(org.sonar.process.cluster.health.NodeHealth) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with NodeHealth

use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.

the class EsStatusClusterCheckTest method check_ignores_NodeHealth_arg_and_returns_RED_with_cause_if_an_exception_occurs_checking_ES_cluster_status.

@Test
public void check_ignores_NodeHealth_arg_and_returns_RED_with_cause_if_an_exception_occurs_checking_ES_cluster_status() {
    Set<NodeHealth> nodeHealths = ImmutableSet.of(newNodeHealth(NodeHealth.Status.GREEN));
    when(esClient.clusterHealth(any())).thenThrow(new RuntimeException("Faking an exception occurring while using the EsClient"));
    Health health = new EsStatusClusterCheck(esClient).check(nodeHealths);
    assertThat(health.getStatus()).isEqualTo(Health.Status.RED);
    assertThat(health.getCauses()).containsOnly("Elasticsearch status is RED (unavailable)");
}
Also used : NodeHealth(org.sonar.process.cluster.health.NodeHealth) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Test(org.junit.Test)

Example 14 with NodeHealth

use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.

the class NodeHealthProviderImplTest method get_returns_name_and_port_from_properties_at_constructor_time.

@Test
public void get_returns_name_and_port_from_properties_at_constructor_time() {
    String name = randomAlphanumeric(3);
    int port = 1 + random.nextInt(4);
    mapSettings.setProperty(CLUSTER_NODE_NAME.getKey(), name);
    mapSettings.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), port);
    setStartedAt();
    when(healthChecker.checkNode()).thenReturn(Health.newHealthCheckBuilder().setStatus(Health.Status.values()[random.nextInt(Health.Status.values().length)]).build());
    when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(3));
    NodeHealthProviderImpl underTest = new NodeHealthProviderImpl(mapSettings.asConfig(), healthChecker, server, networkUtils);
    NodeHealth nodeHealth = underTest.get();
    assertThat(nodeHealth.getDetails().getName()).isEqualTo(name);
    assertThat(nodeHealth.getDetails().getPort()).isEqualTo(port);
    // change values in properties
    setRequiredPropertiesForConstructor();
    NodeHealth newNodeHealth = underTest.get();
    assertThat(newNodeHealth.getDetails().getName()).isEqualTo(name);
    assertThat(newNodeHealth.getDetails().getPort()).isEqualTo(port);
}
Also used : NodeHealth(org.sonar.process.cluster.health.NodeHealth) Test(org.junit.Test)

Example 15 with NodeHealth

use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.

the class NodeHealthProviderImplTest method get_returns_started_from_server_startedAt_at_constructor_time.

@Test
public void get_returns_started_from_server_startedAt_at_constructor_time() {
    setRequiredPropertiesForConstructor();
    when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(4));
    Date date = new Date();
    when(server.getStartedAt()).thenReturn(date);
    when(healthChecker.checkNode()).thenReturn(Health.newHealthCheckBuilder().setStatus(Health.Status.values()[random.nextInt(Health.Status.values().length)]).build());
    NodeHealthProviderImpl underTest = new NodeHealthProviderImpl(mapSettings.asConfig(), healthChecker, server, networkUtils);
    NodeHealth nodeHealth = underTest.get();
    assertThat(nodeHealth.getDetails().getStartedAt()).isEqualTo(date.getTime());
    // change startedAt value
    setStartedAt();
    NodeHealth newNodeHealth = underTest.get();
    assertThat(newNodeHealth.getDetails().getStartedAt()).isEqualTo(date.getTime());
}
Also used : Date(java.util.Date) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Test(org.junit.Test)

Aggregations

NodeHealth (org.sonar.process.cluster.health.NodeHealth)37 Test (org.junit.Test)33 Arrays (java.util.Arrays)6 Properties (java.util.Properties)6 Random (java.util.Random)6 IntStream (java.util.stream.IntStream)6 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang.RandomStringUtils.randomAlphanumeric)6 Props (org.sonar.process.Props)6 NodeDetails (org.sonar.process.cluster.health.NodeDetails)6 Set (java.util.Set)5 Collectors.toSet (java.util.stream.Collectors.toSet)4 Stream (java.util.stream.Stream)4 Stream.of (java.util.stream.Stream.of)4 GREEN (org.sonar.process.cluster.health.NodeHealth.Status.GREEN)4 RED (org.sonar.process.cluster.health.NodeHealth.Status.RED)4 YELLOW (org.sonar.process.cluster.health.NodeHealth.Status.YELLOW)4 HealthAssert.assertThat (org.sonar.server.health.HealthAssert.assertThat)4 Date (java.util.Date)3 HashSet (java.util.HashSet)2 List (java.util.List)2