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