Search in sources :

Example 26 with BQRuntime

use of io.bootique.BQRuntime 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)

Example 27 with BQRuntime

use of io.bootique.BQRuntime in project bootique-jdbc by bootique.

the class HikariCPInstrumentedModuleProviderTest method testModuleDeclaresDependencies.

@Test
public void testModuleDeclaresDependencies() {
    final BQRuntime bqRuntime = testFactory.app().module(new HikariCPInstrumentedModuleProvider()).createRuntime();
    BQRuntimeChecker.testModulesLoaded(bqRuntime, InstrumentedJdbcModule.class, MetricsModule.class, JdbcModule.class);
}
Also used : BQRuntime(io.bootique.BQRuntime) Test(org.junit.Test)

Example 28 with BQRuntime

use of io.bootique.BQRuntime in project bootique-jdbc by bootique.

the class HikariCPDerbyIT method testDerbyDriver_ConnectionAttributes.

@Test
public void testDerbyDriver_ConnectionAttributes() throws SQLException {
    BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPDerbyIT_connAttrs.yml").autoLoadModules().createRuntime();
    DataSource ds7 = runtime.getInstance(DataSourceFactory.class).forName("derby7");
    assertNotNull(ds7);
    HikariDataSource hikariDS = (HikariDataSource) ds7;
    try (Connection c = hikariDS.getConnection()) {
        assertEquals("jdbc:derby:target/derby7", c.getMetaData().getURL());
    }
}
Also used : DataSourceFactory(io.bootique.jdbc.DataSourceFactory) HikariDataSource(com.zaxxer.hikari.HikariDataSource) BQRuntime(io.bootique.BQRuntime) Connection(java.sql.Connection) DriverDataSource(com.zaxxer.hikari.util.DriverDataSource) EmbeddedDataSource(org.apache.derby.jdbc.EmbeddedDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 29 with BQRuntime

use of io.bootique.BQRuntime in project bootique-jdbc by bootique.

the class HikariCPDerbyIT method testDerbyDriverDataSource.

@Test
public void testDerbyDriverDataSource() throws SQLException {
    BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPDerbyIT.yml").autoLoadModules().createRuntime();
    DataSource ds5 = runtime.getInstance(DataSourceFactory.class).forName("derby5");
    assertNotNull(ds5);
    assertTrue(ds5 instanceof HikariDataSource);
    HikariDataSource hikariDS = (HikariDataSource) ds5;
    assertEquals("org.apache.derby.jdbc.EmbeddedDriver", hikariDS.getDriverClassName());
    HikariPool pool = (HikariPool) hikariDS.getHikariPoolMXBean();
    assertTrue(pool.getUnwrappedDataSource() instanceof DriverDataSource);
    try (Connection c = hikariDS.getConnection()) {
        assertEquals("jdbc:derby:", c.getMetaData().getURL());
    }
}
Also used : DataSourceFactory(io.bootique.jdbc.DataSourceFactory) HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariPool(com.zaxxer.hikari.pool.HikariPool) DriverDataSource(com.zaxxer.hikari.util.DriverDataSource) BQRuntime(io.bootique.BQRuntime) Connection(java.sql.Connection) DriverDataSource(com.zaxxer.hikari.util.DriverDataSource) EmbeddedDataSource(org.apache.derby.jdbc.EmbeddedDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 30 with BQRuntime

use of io.bootique.BQRuntime in project bootique-jdbc by bootique.

the class HikariCPModuleIT method testDataSource_TypeAutoDetected.

@Test
public void testDataSource_TypeAutoDetected() {
    BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPModuleIT_notype.yml").autoLoadModules().createRuntime();
    DataSource ds = runtime.getInstance(DataSourceFactory.class).forName("derby3");
    assertNotNull(ds);
    assertTrue(ds instanceof HikariDataSource);
    HikariDataSource hikariDS = (HikariDataSource) ds;
    assertEquals("jdbc:derby:target/derby3;create=true", hikariDS.getJdbcUrl());
}
Also used : DataSourceFactory(io.bootique.jdbc.DataSourceFactory) HikariDataSource(com.zaxxer.hikari.HikariDataSource) BQRuntime(io.bootique.BQRuntime) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Aggregations

BQRuntime (io.bootique.BQRuntime)45 Test (org.junit.Test)39 DataSource (javax.sql.DataSource)23 DataSourceFactory (io.bootique.jdbc.DataSourceFactory)22 HikariDataSource (com.zaxxer.hikari.HikariDataSource)12 ProvisionException (com.google.inject.ProvisionException)10 BootiqueException (io.bootique.BootiqueException)10 BQTestFactory (io.bootique.test.junit.BQTestFactory)10 JsonTypeName (com.fasterxml.jackson.annotation.JsonTypeName)9 Injector (com.google.inject.Injector)9 Map (java.util.Map)9 Optional (java.util.Optional)9 Assert.assertNotNull (org.junit.Assert.assertNotNull)9 Assert.assertTrue (org.junit.Assert.assertTrue)9 Assert.fail (org.junit.Assert.fail)9 Rule (org.junit.Rule)9 Mockito.mock (org.mockito.Mockito.mock)9 JdbcModule (io.bootique.jdbc.JdbcModule)8 Connection (java.sql.Connection)7 ConfigurationFactory (io.bootique.config.ConfigurationFactory)6