Search in sources :

Example 1 with GREEN

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);
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) Date(java.util.Date) WebServer(org.sonar.server.platform.WebServer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GREEN(org.sonar.server.health.Health.GREEN) Random(java.util.Random) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NodeHealth.newNodeHealthBuilder(org.sonar.process.cluster.health.NodeHealth.newNodeHealthBuilder) Health.newHealthCheckBuilder(org.sonar.server.health.Health.newHealthCheckBuilder) ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) WebService(org.sonar.api.server.ws.WebService) Collections.singleton(java.util.Collections.singleton) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) NodeDetails(org.sonar.process.cluster.health.NodeDetails) HealthChecker(org.sonar.server.health.HealthChecker) Health(org.sonar.server.health.Health) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) UserSessionRule(org.sonar.server.tester.UserSessionRule) ImmutableSet(com.google.common.collect.ImmutableSet) Collections.emptySet(java.util.Collections.emptySet) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) System(org.sonarqube.ws.System) ClusterHealth(org.sonar.server.health.ClusterHealth) NodeDetails.newNodeDetailsBuilder(org.sonar.process.cluster.health.NodeDetails.newNodeDetailsBuilder) List(java.util.List) Rule(org.junit.Rule) SystemPasscode(org.sonar.server.user.SystemPasscode) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Collections(java.util.Collections) TestResponse(org.sonar.server.ws.TestResponse) Mockito.mock(org.mockito.Mockito.mock) ArrayList(java.util.ArrayList) Date(java.util.Date) System(org.sonarqube.ws.System) NodeHealth(org.sonar.process.cluster.health.NodeHealth) ClusterHealth(org.sonar.server.health.ClusterHealth) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Collections.emptySet (java.util.Collections.emptySet)1 Collections.singleton (java.util.Collections.singleton)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Random (java.util.Random)1 IntStream (java.util.stream.IntStream)1 RandomStringUtils (org.apache.commons.lang.RandomStringUtils)1 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)1 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang.RandomStringUtils.randomAlphanumeric)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 ThrowingCallable (org.assertj.core.api.ThrowableAssert.ThrowingCallable)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1