use of org.sonar.server.health.Health.GREEN 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);
}
Aggregations