Search in sources :

Example 1 with Health

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());
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) HealthServiceManager(io.pravega.shared.health.HealthServiceManager) Health(io.pravega.shared.health.Health) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) Cleanup(lombok.Cleanup) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) Test(org.junit.Test)

Example 2 with Health

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;
}
Also used : Health(io.pravega.shared.health.Health) ContributorNotFoundException(io.pravega.shared.health.ContributorNotFoundException) NonNull(lombok.NonNull)

Example 3 with 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());
}
Also used : Health(io.pravega.shared.health.Health) HealthyContributor(io.pravega.shared.health.TestHealthContributors.HealthyContributor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 4 with Health

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());
}
Also used : ThrowingContributor(io.pravega.shared.health.TestHealthContributors.ThrowingContributor) Health(io.pravega.shared.health.Health) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 5 with Health

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());
}
Also used : Health(io.pravega.shared.health.Health) Test(org.junit.Test)

Aggregations

Health (io.pravega.shared.health.Health)14 Test (org.junit.Test)11 Cleanup (lombok.Cleanup)6 Status (io.pravega.shared.health.Status)5 HealthContributor (io.pravega.shared.health.HealthContributor)2 HealthyContributor (io.pravega.shared.health.TestHealthContributors.HealthyContributor)2 lombok.val (lombok.val)2 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)1 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)1 CacheManagerHealthContributor (io.pravega.segmentstore.server.CacheManager.CacheManagerHealthContributor)1 PassingTokenVerifier (io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier)1 SegmentContainerRegistryHealthContributor (io.pravega.segmentstore.server.host.health.SegmentContainerRegistryHealthContributor)1 ContributorNotFoundException (io.pravega.shared.health.ContributorNotFoundException)1 HealthServiceManager (io.pravega.shared.health.HealthServiceManager)1 FailingContributor (io.pravega.shared.health.TestHealthContributors.FailingContributor)1 ThrowingContributor (io.pravega.shared.health.TestHealthContributors.ThrowingContributor)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AsyncResponse (javax.ws.rs.container.AsyncResponse)1