Search in sources :

Example 6 with HealthyContributor

use of io.pravega.shared.health.TestHealthContributors.HealthyContributor in project pravega by pravega.

the class HealthServiceUpdaterTests method testServiceUpdaterProperlyUpdates.

@Test
public void testServiceUpdaterProperlyUpdates() throws Exception {
    @Cleanup HealthContributor contributor = new HealthyContributor("contributor");
    service.register(contributor);
    TestHealthContributors.awaitHealthContributor(service, service.getName());
    Health health = service.getEndpoint().getHealth();
    Assert.assertEquals(Status.UP, health.getStatus());
    contributor.close();
    Assert.assertEquals("Closed contributor should no longer be listed as a child.", 0, service.getHealthSnapshot().getChildren().size());
    // We register an indicator that will return a failing result, so the next health check should contain a 'DOWN' Status.
    contributor = new FailingContributor("failing");
    service.register(contributor);
    TestHealthContributors.awaitHealthContributor(service, contributor.getName());
    health = service.getEndpoint().getHealth();
    Assert.assertEquals(Status.DOWN, health.getStatus());
}
Also used : FailingContributor(io.pravega.shared.health.TestHealthContributors.FailingContributor) HealthyContributor(io.pravega.shared.health.TestHealthContributors.HealthyContributor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 7 with HealthyContributor

use of io.pravega.shared.health.TestHealthContributors.HealthyContributor in project pravega by pravega.

the class HealthContributorTests method testDynamicContributor.

/**
 * Verifies that if the {@link Health} of the child {@link HealthContributor} changes, it properly
 * determines the overall health before and after the change.
 */
@Test
public void testDynamicContributor() {
    @Cleanup HealthContributor root = new HealthyContributor();
    root.register(new HealthyContributor("first"));
    Assert.assertEquals("Expecting healthy status.", Status.UP, root.getHealthSnapshot().getStatus());
    // Add a failing contributor to the root, which uses the 'UNANIMOUS' aggregation rule.
    HealthContributor failing = new FailingContributor();
    root.register(failing);
    Assert.assertEquals("Expecting failing status.", Status.DOWN, root.getHealthSnapshot().getStatus());
    // Remove the failing contributor and now expect it is healthy again.
    failing.close();
    Assert.assertEquals("Expecting healthy status.", Status.UP, root.getHealthSnapshot().getStatus());
}
Also used : FailingContributor(io.pravega.shared.health.TestHealthContributors.FailingContributor) HealthyContributor(io.pravega.shared.health.TestHealthContributors.HealthyContributor) HealthContributor(io.pravega.shared.health.HealthContributor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 8 with HealthyContributor

use of io.pravega.shared.health.TestHealthContributors.HealthyContributor in project pravega by pravega.

the class HealthContributorTests method testChildHealths.

/**
 * Tests that children {@link HealthContributor} can be properly registered to another contributor and the {@link Health}
 * of the individual children is properly reflected in the overall health of the top most contributor.
 */
@Test
public void testChildHealths() {
    @Cleanup HealthContributor contributor = new HealthyContributor();
    @Cleanup HealthContributor first = new HealthyContributor("first");
    @Cleanup HealthContributor second = new FailingContributor("second");
    contributor.register(first, second);
    Health health = contributor.getHealthSnapshot();
    Assert.assertEquals("Expected 'contributor' to report an unhealthy status.", Status.DOWN, health.getStatus());
    Assert.assertEquals("Expected to see two children registered to 'contributor'.", 2, health.getChildren().size());
}
Also used : FailingContributor(io.pravega.shared.health.TestHealthContributors.FailingContributor) Health(io.pravega.shared.health.Health) HealthyContributor(io.pravega.shared.health.TestHealthContributors.HealthyContributor) HealthContributor(io.pravega.shared.health.HealthContributor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 9 with HealthyContributor

use of io.pravega.shared.health.TestHealthContributors.HealthyContributor in project pravega by pravega.

the class HealthContributorTests method testClosedContributor.

/**
 * Verifies that a closed {@link HealthContributor} can no longer be acted upon.
 */
@Test
public void testClosedContributor() {
    @Cleanup HealthContributor root = new HealthyContributor();
    HealthContributor contributor = new HealthyContributor();
    contributor.close();
    AssertExtensions.assertThrows("Expected an exception requesting the health of a closed contributor.", () -> contributor.getHealthSnapshot(), ex -> ex instanceof ObjectClosedException);
    AssertExtensions.assertThrows("Expected an exception adding a child to a closed contributor.", () -> contributor.register(new HealthyContributor("")), ex -> ex instanceof ObjectClosedException);
    HealthContributor parent = new HealthyContributor("parent");
    root.register(parent);
    @Cleanup HealthContributor child = new FailingContributor("child");
    parent.register(child);
    parent.close();
    Assert.assertEquals("Expecting child contributor to be unreachable after closing parent", 0, root.getHealthSnapshot().getChildren().size());
    Assert.assertEquals("Expecting default Status (UP) from empty HealthContributor.", Status.UP, root.getHealthSnapshot().getStatus());
}
Also used : FailingContributor(io.pravega.shared.health.TestHealthContributors.FailingContributor) ObjectClosedException(io.pravega.common.ObjectClosedException) HealthyContributor(io.pravega.shared.health.TestHealthContributors.HealthyContributor) HealthContributor(io.pravega.shared.health.HealthContributor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 10 with HealthyContributor

use of io.pravega.shared.health.TestHealthContributors.HealthyContributor in project pravega by pravega.

the class HealthManagerTests method testLivenessEndpoints.

/**
 * Test that both the {@link HealthServiceManager} and a {@link HealthContributor} can be queried for its liveness information.
 */
@Test
public void testLivenessEndpoints() throws Exception {
    @Cleanup HealthyContributor contributor = new HealthyContributor("contributor");
    service.register(contributor);
    awaitHealthContributor(service, contributor.getName());
    Assert.assertEquals("The HealthServiceManager should produce an 'alive' result.", true, service.getEndpoint().isAlive());
    Assert.assertEquals("The HealthContributor with id should produce an 'alive' result.", true, service.getEndpoint().isAlive(contributor.getName()));
}
Also used : HealthyContributor(io.pravega.shared.health.TestHealthContributors.HealthyContributor) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Aggregations

HealthyContributor (io.pravega.shared.health.TestHealthContributors.HealthyContributor)10 Cleanup (lombok.Cleanup)10 Test (org.junit.Test)10 FailingContributor (io.pravega.shared.health.TestHealthContributors.FailingContributor)4 HealthContributor (io.pravega.shared.health.HealthContributor)3 Health (io.pravega.shared.health.Health)2 ObjectClosedException (io.pravega.common.ObjectClosedException)1