Search in sources :

Example 1 with HealthCheckOutcome

use of io.bootique.metrics.health.HealthCheckOutcome in project bootique-jdbc by bootique.

the class HikariCPInstrumentedModuleIT method testHealthChecks_HealthNoParam_ChecksTurnedOff.

@Test
public void testHealthChecks_HealthNoParam_ChecksTurnedOff() {
    BQRuntime runtime = TEST_FACTORY.app("-c", "classpath:io/bootique/jdbc/instrumented/hikaricp/dummy-ds.yml").autoLoadModules().createRuntime();
    DataSourceFactory factory = runtime.getInstance(DataSourceFactory.class);
    String dataSourceName = "DerbyDatabaseIT";
    HikariDataSource dataSource = (HikariDataSource) factory.forName(dataSourceName);
    assertNotNull(dataSource);
    HealthCheckRegistry registry = runtime.getInstance(HealthCheckRegistry.class);
    /**
     * embedded health check {@link io.bootique.jdbc.instrumented.healthcheck.DataSourceHealthCheck}
     */
    assertTrue(registry.containsHealthCheck(DataSourceHealthCheck.healthCheckName(dataSourceName)));
    Map<String, HealthCheckOutcome> results = registry.runHealthChecks();
    assertEquals(results.size(), 1);
}
Also used : DataSourceFactory(io.bootique.jdbc.DataSourceFactory) HikariDataSource(com.zaxxer.hikari.HikariDataSource) HealthCheckOutcome(io.bootique.metrics.health.HealthCheckOutcome) BQRuntime(io.bootique.BQRuntime) HealthCheckRegistry(io.bootique.metrics.health.HealthCheckRegistry) Test(org.junit.Test)

Example 2 with HealthCheckOutcome

use of io.bootique.metrics.health.HealthCheckOutcome in project bootique-jdbc by bootique.

the class HikariCPInstrumentedModuleIT method testHealthChecksMultipleDs.

@Test
public void testHealthChecksMultipleDs() throws SQLException {
    BQRuntime runtime = TEST_FACTORY.app("-c", "classpath:io/bootique/jdbc/instrumented/hikaricp/hikaricp-ds2-health.yml").autoLoadModules().createRuntime();
    DataSourceFactory factory = runtime.getInstance(DataSourceFactory.class);
    String derby2 = "derby2", derby3 = "derby3";
    HikariDataSource ds2 = (HikariDataSource) factory.forName(derby2);
    assertNotNull(ds2);
    HikariDataSource ds3 = (HikariDataSource) factory.forName(derby3);
    assertNotNull(ds3);
    HealthCheckRegistry registry = runtime.getInstance(HealthCheckRegistry.class);
    assertTrue(registry.containsHealthCheck(ConnectivityCheck.healthCheckName(derby2)));
    assertTrue(registry.containsHealthCheck(Connection99PercentCheck.healthCheckName(derby2)));
    /**
     * embedded health check {@link io.bootique.jdbc.instrumented.healthcheck.DataSourceHealthCheck}
     */
    assertTrue(registry.containsHealthCheck(DataSourceHealthCheck.healthCheckName(derby2)));
    assertTrue(registry.containsHealthCheck(ConnectivityCheck.healthCheckName(derby3)));
    assertTrue(registry.containsHealthCheck(Connection99PercentCheck.healthCheckName(derby3)));
    /**
     * embedded health check {@link io.bootique.jdbc.instrumented.healthcheck.DataSourceHealthCheck}
     */
    assertTrue(registry.containsHealthCheck(DataSourceHealthCheck.healthCheckName(derby3)));
    Map<String, HealthCheckOutcome> results = registry.runHealthChecks();
    assertEquals(results.size(), 6);
}
Also used : DataSourceFactory(io.bootique.jdbc.DataSourceFactory) HikariDataSource(com.zaxxer.hikari.HikariDataSource) HealthCheckOutcome(io.bootique.metrics.health.HealthCheckOutcome) BQRuntime(io.bootique.BQRuntime) HealthCheckRegistry(io.bootique.metrics.health.HealthCheckRegistry) Test(org.junit.Test)

Example 3 with HealthCheckOutcome

use of io.bootique.metrics.health.HealthCheckOutcome in project bootique-jdbc by bootique.

the class HikariCPInstrumentedModuleIT method testHealthChecks_TurnedOn.

@Test
public void testHealthChecks_TurnedOn() {
    BQRuntime runtime = TEST_FACTORY.app("-c", "classpath:io/bootique/jdbc/instrumented/hikaricp/hikaricp-ds-health.yml").autoLoadModules().createRuntime();
    DataSourceFactory factory = runtime.getInstance(DataSourceFactory.class);
    String dataSourceName = "derby1";
    HikariDataSource dataSource = (HikariDataSource) factory.forName(dataSourceName);
    assertNotNull(dataSource);
    HealthCheckRegistry registry = runtime.getInstance(HealthCheckRegistry.class);
    assertTrue(registry.containsHealthCheck(ConnectivityCheck.healthCheckName(dataSourceName)));
    assertTrue(registry.containsHealthCheck(Connection99PercentCheck.healthCheckName(dataSourceName)));
    /**
     * embedded health check {@link io.bootique.jdbc.instrumented.healthcheck.DataSourceHealthCheck}
     */
    assertTrue(registry.containsHealthCheck(DataSourceHealthCheck.healthCheckName(dataSourceName)));
    Map<String, HealthCheckOutcome> results = registry.runHealthChecks();
    assertEquals(results.size(), 3);
}
Also used : DataSourceFactory(io.bootique.jdbc.DataSourceFactory) HikariDataSource(com.zaxxer.hikari.HikariDataSource) HealthCheckOutcome(io.bootique.metrics.health.HealthCheckOutcome) BQRuntime(io.bootique.BQRuntime) HealthCheckRegistry(io.bootique.metrics.health.HealthCheckRegistry) Test(org.junit.Test)

Aggregations

HikariDataSource (com.zaxxer.hikari.HikariDataSource)3 BQRuntime (io.bootique.BQRuntime)3 DataSourceFactory (io.bootique.jdbc.DataSourceFactory)3 HealthCheckOutcome (io.bootique.metrics.health.HealthCheckOutcome)3 HealthCheckRegistry (io.bootique.metrics.health.HealthCheckRegistry)3 Test (org.junit.Test)3