use of io.bootique.BQRuntime in project bootique-jdbc by bootique.
the class HikariCPInstrumentedModuleIT method testMetrics_TurnedOn.
@Test
public void testMetrics_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);
DataSource ds = factory.forName("derby1");
assertNotNull(ds);
assertTrue(ds instanceof HikariDataSource);
HikariDataSource hikariDS = (HikariDataSource) ds;
String poolName = hikariDS.getPoolName();
MetricRegistry metricRegistry = runtime.getInstance(MetricRegistry.class);
assertEquals(metricRegistry.getTimers().size(), 1);
assertEquals(metricRegistry.getTimers().firstKey(), MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_WAIT));
assertEquals(metricRegistry.getGauges().size(), 4);
assertEquals(metricRegistry.getGauges().keySet(), new HashSet<String>() {
{
add(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_TOTAL_CONNECTIONS));
add(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_IDLE_CONNECTIONS));
add(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_ACTIVE_CONNECTIONS));
add(MetricRegistry.name(poolName, METRIC_CATEGORY, METRIC_NAME_PENDING_CONNECTIONS));
}
});
}
use of io.bootique.BQRuntime 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);
}
use of io.bootique.BQRuntime in project bootique-jdbc by bootique.
the class HikariCPDerbyIT method testDerbyDataSource.
@Test
public void testDerbyDataSource() throws SQLException {
BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPDerbyIT.yml").autoLoadModules().createRuntime();
DataSource ds4 = runtime.getInstance(DataSourceFactory.class).forName("derby4");
assertNotNull(ds4);
assertTrue(ds4 instanceof HikariDataSource);
HikariDataSource hikariDS = (HikariDataSource) ds4;
assertEquals("org.apache.derby.jdbc.EmbeddedDataSource", hikariDS.getDataSourceClassName());
HikariPool pool = (HikariPool) hikariDS.getHikariPoolMXBean();
assertTrue(pool.getUnwrappedDataSource().getClass().isAssignableFrom(EmbeddedDataSource.class));
try (Connection c = hikariDS.getConnection()) {
assertEquals("jdbc:derby:target/derby4", c.getMetaData().getURL());
}
}
use of io.bootique.BQRuntime in project bootique-jdbc by bootique.
the class HikariCPDerbyIT method testDerbyDataSource_ConnectionAttributes.
@Test
public void testDerbyDataSource_ConnectionAttributes() throws SQLException {
BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPDerbyIT_connAttrs.yml").autoLoadModules().createRuntime();
DataSource ds6 = runtime.getInstance(DataSourceFactory.class).forName("derby6");
assertNotNull(ds6);
HikariDataSource hikariDS = (HikariDataSource) ds6;
try (Connection c = hikariDS.getConnection()) {
assertEquals("jdbc:derby:", c.getMetaData().getURL());
}
}
use of io.bootique.BQRuntime in project bootique-jdbc by bootique.
the class HikariCPModuleIT method testDataSource_FullConfig.
@Test
public void testDataSource_FullConfig() throws SQLException {
BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPModuleIT_full.yml").autoLoadModules().createRuntime();
DataSource ds = runtime.getInstance(DataSourceFactory.class).forName("ds1");
assertNotNull(ds);
assertTrue(ds instanceof HikariDataSource);
HikariDataSource hikariDS = (HikariDataSource) ds;
assertEquals(250, hikariDS.getConnectionTimeout());
assertEquals(250, hikariDS.getValidationTimeout());
assertEquals(20000, hikariDS.getIdleTimeout());
assertEquals(20000, hikariDS.getLeakDetectionThreshold());
assertEquals(50000, hikariDS.getMaxLifetime());
assertEquals(3, hikariDS.getMaximumPoolSize());
assertEquals(1, hikariDS.getMinimumIdle());
assertEquals("x", hikariDS.getUsername());
assertEquals("x", hikariDS.getPassword());
assertEquals(100, hikariDS.getInitializationFailTimeout());
assertEquals("test-catalog", hikariDS.getCatalog());
assertEquals("org.apache.derby.jdbc.EmbeddedDataSource", hikariDS.getDataSourceClassName());
assertEquals("jdbc:derby:;", hikariDS.getJdbcUrl());
assertEquals("test-pool", hikariDS.getPoolName());
assertEquals("TRANSACTION_SERIALIZABLE", hikariDS.getTransactionIsolation());
assertTrue(hikariDS.isAutoCommit());
assertFalse(hikariDS.isReadOnly());
assertFalse(hikariDS.isIsolateInternalQueries());
assertFalse(hikariDS.isRegisterMbeans());
assertFalse(hikariDS.isAllowPoolSuspension());
try (Connection c = hikariDS.getConnection()) {
assertEquals("jdbc:derby:target/ds1", c.getMetaData().getURL());
}
}
Aggregations