Search in sources :

Example 1 with NetworkUtils

use of org.sonar.process.NetworkUtils in project sonarqube by SonarSource.

the class NodeHealthModuleTest method no_broken_dependencies.

@Test
public void no_broken_dependencies() {
    SpringComponentContainer container = new SpringComponentContainer();
    Server server = mock(Server.class);
    NetworkUtils networkUtils = mock(NetworkUtils.class);
    // settings required by NodeHealthProvider
    mapSettings.setProperty("sonar.cluster.node.name", randomAlphanumeric(3));
    mapSettings.setProperty("sonar.cluster.node.port", valueOf(1 + random.nextInt(10)));
    when(server.getStartedAt()).thenReturn(new Date());
    when(networkUtils.getHostname()).thenReturn(randomAlphanumeric(12));
    // upper level dependencies
    container.add(mock(System2.class), mapSettings.asConfig(), server, networkUtils, mock(HazelcastMember.class));
    // HealthAction dependencies
    container.add(mock(HealthChecker.class));
    underTest.configure(container);
    container.startComponents();
}
Also used : SpringComponentContainer(org.sonar.core.platform.SpringComponentContainer) Server(org.sonar.api.platform.Server) NetworkUtils(org.sonar.process.NetworkUtils) System2(org.sonar.api.utils.System2) HazelcastMember(org.sonar.process.cluster.hz.HazelcastMember) Date(java.util.Date) Test(org.junit.Test)

Example 2 with NetworkUtils

use of org.sonar.process.NetworkUtils 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);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) CLUSTER_NODE_HOST(org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) Test(org.junit.Test) Server(org.sonar.api.platform.Server) Mockito.when(org.mockito.Mockito.when) MapSettings(org.sonar.api.config.internal.MapSettings) CLUSTER_NODE_NAME(org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME) CLUSTER_NODE_HZ_PORT(org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) NodeHealth(org.sonar.process.cluster.health.NodeHealth) NodeDetails(org.sonar.process.cluster.health.NodeDetails) NetworkUtils(org.sonar.process.NetworkUtils) Mockito.mock(org.mockito.Mockito.mock) NodeHealth(org.sonar.process.cluster.health.NodeHealth) NodeHealth(org.sonar.process.cluster.health.NodeHealth) Test(org.junit.Test)

Aggregations

Date (java.util.Date)2 Test (org.junit.Test)2 Server (org.sonar.api.platform.Server)2 NetworkUtils (org.sonar.process.NetworkUtils)2 Arrays (java.util.Arrays)1 Random (java.util.Random)1 IntStream (java.util.stream.IntStream)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 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 MapSettings (org.sonar.api.config.internal.MapSettings)1 System2 (org.sonar.api.utils.System2)1 SpringComponentContainer (org.sonar.core.platform.SpringComponentContainer)1 CLUSTER_NODE_HOST (org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST)1 CLUSTER_NODE_HZ_PORT (org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HZ_PORT)1 CLUSTER_NODE_NAME (org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_NAME)1 NodeDetails (org.sonar.process.cluster.health.NodeDetails)1