Search in sources :

Example 21 with NodeHealth

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

the class NodeHealthProviderImplTest method get_returns_APPLICATION_type.

@Test
public void get_returns_APPLICATION_type() {
    setRequiredPropertiesForConstructor();
    setStartedAt();
    when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(23));
    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().getType()).isEqualTo(NodeDetails.Type.APPLICATION);
}
Also used : NodeHealth(org.sonar.process.cluster.health.NodeHealth) Test(org.junit.Test)

Example 22 with NodeHealth

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

the class NodeHealthProviderImplTest method get_returns_HEALTH_status_and_causes_from_HealthChecker_checkNode.

@Test
public void get_returns_HEALTH_status_and_causes_from_HealthChecker_checkNode() {
    setRequiredPropertiesForConstructor();
    setStartedAt();
    when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(4));
    Health.Status randomStatus = Health.Status.values()[random.nextInt(Health.Status.values().length)];
    String[] expected = IntStream.range(0, random.nextInt(4)).mapToObj(s -> randomAlphabetic(55)).toArray(String[]::new);
    Health.Builder healthBuilder = Health.newHealthCheckBuilder().setStatus(randomStatus);
    Arrays.stream(expected).forEach(healthBuilder::addCause);
    when(healthChecker.checkNode()).thenReturn(healthBuilder.build());
    NodeHealthProviderImpl underTest = new NodeHealthProviderImpl(mapSettings.asConfig(), healthChecker, server, networkUtils);
    NodeHealth nodeHealth = underTest.get();
    assertThat(nodeHealth.getStatus().name()).isEqualTo(randomStatus.name());
    assertThat(nodeHealth.getCauses()).containsOnly(expected);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) CLUSTER_NODE_HOST(org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) Test(org.junit.Test) Server(org.sonar.api.platform.Server) Mockito.when(org.mockito.Mockito.when) MapSettings(org.sonar.api.config.internal.MapSettings) CLUSTER_NODE_NAME(org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME) CLUSTER_NODE_HZ_PORT(org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) NodeHealth(org.sonar.process.cluster.health.NodeHealth) NodeDetails(org.sonar.process.cluster.health.NodeDetails) NetworkUtils(org.sonar.process.NetworkUtils) Mockito.mock(org.mockito.Mockito.mock) NodeHealth(org.sonar.process.cluster.health.NodeHealth) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Test(org.junit.Test)

Example 23 with NodeHealth

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

the class NodeHealthProviderImplTest method get_returns_host_from_property_if_set_at_constructor_time.

@Test
public void get_returns_host_from_property_if_set_at_constructor_time() {
    String host = randomAlphanumeric(4);
    mapSettings.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3));
    mapSettings.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), 1 + random.nextInt(4));
    mapSettings.setProperty(CLUSTER_NODE_HOST.getKey(), host);
    setStartedAt();
    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().getHost()).isEqualTo(host);
    // change values in properties
    mapSettings.setProperty(CLUSTER_NODE_HOST.getKey(), randomAlphanumeric(66));
    NodeHealth newNodeHealth = underTest.get();
    assertThat(newNodeHealth.getDetails().getHost()).isEqualTo(host);
}
Also used : NodeHealth(org.sonar.process.cluster.health.NodeHealth) Test(org.junit.Test)

Example 24 with NodeHealth

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

the class AppNodeClusterCheckTest method status_RED_when_two_RED_application_nodes.

@Test
public void status_RED_when_two_RED_application_nodes() {
    Set<NodeHealth> nodeHealths = nodeHealths(RED, RED).collect(toSet());
    Health check = underTest.check(nodeHealths);
    assertThat(check).forInput(nodeHealths).hasStatus(Health.Status.RED).andCauses("Status of all application nodes is RED");
}
Also used : NodeHealth(org.sonar.process.cluster.health.NodeHealth) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Test(org.junit.Test)

Example 25 with NodeHealth

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

the class AppNodeClusterCheckTest method status_YELLOW_when_two_GREEN_application_node_and_any_number_of_other_is_YELLOW_or_GREEN.

@Test
public void status_YELLOW_when_two_GREEN_application_node_and_any_number_of_other_is_YELLOW_or_GREEN() {
    Set<NodeHealth> nodeHealths = of(// at least 1 YELLOW
    of(appNodeHealth(YELLOW)), // 0 to 10 YELLOW/GREEN
    randomNumberOfAppNodeHealthOfAnyStatus(GREEN, YELLOW), // 2 GREEN
    nodeHealths(GREEN, GREEN)).flatMap(s -> s).collect(toSet());
    Health check = underTest.check(nodeHealths);
    assertThat(check).forInput(nodeHealths).hasStatus(Health.Status.YELLOW).andCauses("At least one application node is YELLOW");
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) Stream.of(java.util.stream.Stream.of) Set(java.util.Set) Random(java.util.Random) Test(org.junit.Test) RED(org.sonar.process.cluster.health.NodeHealth.Status.RED) GREEN(org.sonar.process.cluster.health.NodeHealth.Status.GREEN) Stream(java.util.stream.Stream) NodeHealth(org.sonar.process.cluster.health.NodeHealth) NodeDetails(org.sonar.process.cluster.health.NodeDetails) YELLOW(org.sonar.process.cluster.health.NodeHealth.Status.YELLOW) HealthAssert.assertThat(org.sonar.server.health.HealthAssert.assertThat) Collectors.toSet(java.util.stream.Collectors.toSet) NodeHealth(org.sonar.process.cluster.health.NodeHealth) 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