use of io.pravega.shared.health.Health in project pravega by pravega.
the class PravegaConnectionListenerTest method testHealth.
// Test the health status created with pravega listener.
@Test
public void testHealth() {
@Cleanup HealthServiceManager healthServiceManager = new HealthServiceManager(Duration.ofSeconds(2));
healthServiceManager.start();
int port = TestUtils.getAvailableListenPort();
@Cleanup PravegaConnectionListener listener = new PravegaConnectionListener(false, false, "localhost", port, mock(StreamSegmentStore.class), mock(TableStore.class), SegmentStatsRecorder.noOp(), TableSegmentStatsRecorder.noOp(), new PassingTokenVerifier(), null, null, true, NoOpScheduledExecutor.get(), TLS_PROTOCOL_VERSION.getDefaultValue().split(","), healthServiceManager);
listener.startListening();
Health health = listener.getHealthServiceManager().getHealthSnapshot();
Assert.assertEquals("HealthContributor should report an 'UP' Status.", Status.UP, health.getStatus());
listener.close();
health = listener.getHealthServiceManager().getHealthSnapshot();
Assert.assertEquals("HealthContributor should report an 'DOWN' Status.", Status.DOWN, health.getStatus());
}
use of io.pravega.shared.health.Health in project pravega by pravega.
the class HealthEndpointImpl method getHealth.
/**
* Validates that the {@link HealthContributor} exists and requests it's {@link Health}.
*
* @param id The id/name of the {@link HealthContributor} to check the {@link Health} of.
* @return The {@link Health} result of the {@link HealthContributor} with name 'id'. Returns NULL if 'id' does not map to
* a {@link HealthContributor}.
*/
@NonNull
@Override
public Health getHealth(String id) {
Health health;
if (id == null || id.equals(root.getName())) {
health = updater.getLatestHealth();
} else {
List<String> path = Arrays.asList(id.split(DELIMITER));
health = search(path, updater.getLatestHealth());
}
if (health == null) {
throw new ContributorNotFoundException(String.format("No HealthContributor found with name '%s'", id), 404);
}
return health;
}
use of io.pravega.shared.health.Health in project pravega by pravega.
the class HealthContributorTests method testHealth.
/**
* Perform a basic {@link Health} check.
*/
@Test
public void testHealth() {
@Cleanup HealthyContributor contributor = new HealthyContributor();
Health health = contributor.getHealthSnapshot();
Assert.assertEquals("Should exactly one detail entry.", 1, health.getDetails().size());
Assert.assertEquals("HealthContributor should report an 'UP' Status.", Status.UP, health.getStatus());
}
use of io.pravega.shared.health.Health in project pravega by pravega.
the class HealthContributorTests method testIndicatorThrows.
/**
* If the {@link AbstractHealthContributor#doHealthCheck(Health.HealthBuilder)} throws an error, test that it is caught and
* a {@link Health} result that reflects an 'unhealthy' state is returned.
*/
@Test
public void testIndicatorThrows() {
@Cleanup ThrowingContributor contributor = new ThrowingContributor();
Health health = contributor.getHealthSnapshot();
Assert.assertEquals("HealthContributor should have a 'DOWN' Status.", Status.DOWN, health.getStatus());
Assert.assertTrue("HealthContributor should be not be marked ready OR alive.", !health.isAlive() && !health.isReady());
}
use of io.pravega.shared.health.Health in project pravega by pravega.
the class HealthTests method testDefaultAliveLogic.
/**
* Tests that the default/empty {@link Health} reports the expected liveness result.
*/
@Test
public void testDefaultAliveLogic() {
Health health = Health.builder().build();
Assert.assertEquals("isAlive() should be false by default if no Status is set.", false, health.isAlive());
health = Health.builder().status(Status.UP).build();
Assert.assertEquals("isAlive() should be true by default if an UP Status is supplied.", true, health.isAlive());
}
Aggregations