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);
}
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);
}
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);
}
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");
}
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");
}
Aggregations