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