use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.
the class HealthActionTest method response_sort_nodes_by_type_name_host_then_port_when_clustered.
@Test
public void response_sort_nodes_by_type_name_host_then_port_when_clustered() {
authenticateWithRandomMethod();
// using created field as a unique identifier. pseudo random value to ensure sorting is not based on created field
List<NodeHealth> nodeHealths = new ArrayList<>(Arrays.asList(randomNodeHealth(NodeDetails.Type.APPLICATION, "1_name", "1_host", 1, 99), randomNodeHealth(NodeDetails.Type.APPLICATION, "1_name", "2_host", 1, 85), randomNodeHealth(NodeDetails.Type.APPLICATION, "1_name", "2_host", 2, 12), randomNodeHealth(NodeDetails.Type.APPLICATION, "2_name", "1_host", 1, 6), randomNodeHealth(NodeDetails.Type.APPLICATION, "2_name", "1_host", 2, 30), randomNodeHealth(NodeDetails.Type.APPLICATION, "2_name", "2_host", 1, 75), randomNodeHealth(NodeDetails.Type.APPLICATION, "2_name", "2_host", 2, 258), randomNodeHealth(NodeDetails.Type.SEARCH, "1_name", "1_host", 1, 963), randomNodeHealth(NodeDetails.Type.SEARCH, "1_name", "1_host", 2, 1), randomNodeHealth(NodeDetails.Type.SEARCH, "1_name", "2_host", 1, 35), randomNodeHealth(NodeDetails.Type.SEARCH, "1_name", "2_host", 2, 45), randomNodeHealth(NodeDetails.Type.SEARCH, "2_name", "1_host", 1, 39), randomNodeHealth(NodeDetails.Type.SEARCH, "2_name", "1_host", 2, 28), randomNodeHealth(NodeDetails.Type.SEARCH, "2_name", "2_host", 1, 66), randomNodeHealth(NodeDetails.Type.SEARCH, "2_name", "2_host", 2, 77)));
String[] expected = nodeHealths.stream().map(s -> formatDateTime(new Date(s.getDetails().getStartedAt()))).toArray(String[]::new);
Collections.shuffle(nodeHealths);
when(webServer.isStandalone()).thenReturn(false);
when(healthChecker.checkCluster()).thenReturn(new ClusterHealth(GREEN, new HashSet<>(nodeHealths)));
System.HealthResponse response = underTest.newRequest().executeProtobuf(System.HealthResponse.class);
assertThat(response.getNodes().getNodesList()).extracting(System.Node::getStartedAt).containsExactly(expected);
}
use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.
the class SearchNodeHealthProviderTest method getReturnsHostFromNetworkUtils.
private void getReturnsHostFromNetworkUtils(@Nullable String hostPropertyValue) {
String host = randomAlphanumeric(34);
Properties properties = new Properties();
properties.setProperty(CLUSTER_NODE_NAME.getKey(), randomAlphanumeric(3));
properties.setProperty(CLUSTER_NODE_HZ_PORT.getKey(), valueOf(1 + random.nextInt(4)));
if (hostPropertyValue != null) {
properties.setProperty(CLUSTER_NODE_HOST.getKey(), hostPropertyValue);
}
when(clock.now()).thenReturn(1L + random.nextInt(87));
when(networkUtils.getHostname()).thenReturn(host);
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock);
NodeHealth nodeHealth = underTest.get();
assertThat(nodeHealth.getDetails().getHost()).isEqualTo(host);
// change now
when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(96));
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 SearchNodeHealthProviderTest method get_returns_started_from_System2_now_at_constructor_time.
@Test
public void get_returns_started_from_System2_now_at_constructor_time() {
Properties properties = new Properties();
long now = setRequiredPropertiesAndMocks(properties);
SearchNodeHealthProvider underTest = new SearchNodeHealthProvider(new Props(properties), clusterAppState, networkUtils, clock);
NodeHealth nodeHealth = underTest.get();
assertThat(nodeHealth.getDetails().getStartedAt()).isEqualTo(now);
// change now
when(clock.now()).thenReturn(now);
NodeHealth newNodeHealth = underTest.get();
assertThat(newNodeHealth.getDetails().getStartedAt()).isEqualTo(now);
}
use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.
the class EsStatusClusterCheckTest method check_ignores_NodeHealth_arg_and_returns_GREEN_without_cause_if_ES_cluster_status_is_GREEN.
@Test
public void check_ignores_NodeHealth_arg_and_returns_GREEN_without_cause_if_ES_cluster_status_is_GREEN() {
Set<NodeHealth> nodeHealths = ImmutableSet.of(newNodeHealth(NodeHealth.Status.YELLOW));
when(esClient.clusterHealth(any()).getStatus()).thenReturn(ClusterHealthStatus.GREEN);
Health health = underTest.check(nodeHealths);
assertThat(health).isEqualTo(Health.GREEN);
}
use of org.sonar.process.cluster.health.NodeHealth in project sonarqube by SonarSource.
the class NodeHealthProviderImplTest method getReturnsHostnameFromNetworkUtils.
private void getReturnsHostnameFromNetworkUtils(String hostPropertyValue) {
String host = randomAlphanumeric(3);
setRequiredPropertiesForConstructor();
if (hostPropertyValue != null) {
mapSettings.setProperty(CLUSTER_NODE_HOST.getKey(), hostPropertyValue);
}
setStartedAt();
when(healthChecker.checkNode()).thenReturn(Health.newHealthCheckBuilder().setStatus(Health.Status.values()[random.nextInt(Health.Status.values().length)]).build());
when(networkUtils.getHostname()).thenReturn(host);
NodeHealthProviderImpl underTest = new NodeHealthProviderImpl(mapSettings.asConfig(), healthChecker, server, networkUtils);
NodeHealth nodeHealth = underTest.get();
assertThat(nodeHealth.getDetails().getHost()).isEqualTo(host);
// change hostname
when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(4));
NodeHealth newNodeHealth = underTest.get();
assertThat(newNodeHealth.getDetails().getHost()).isEqualTo(host);
}
Aggregations