use of io.bootique.jdbc.DataSourceFactory 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.jdbc.DataSourceFactory 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.jdbc.DataSourceFactory in project bootique-jdbc by bootique.
the class TomcatInstrumentedJdbcModuleIT method testMetrics.
@Test
public void testMetrics() {
BQRuntime runtime = TEST_FACTORY.app("-c", "classpath:io/bootique/jdbc/instrumented/dummy-ds.yml").autoLoadModules().createRuntime();
DataSourceFactory factory = runtime.getInstance(DataSourceFactory.class);
DataSource dataSource = factory.forName("DerbyDatabaseIT");
assertNotNull(dataSource);
MetricRegistry metricRegistry = runtime.getInstance(MetricRegistry.class);
assertNotEquals(metricRegistry.getGauges().size(), 0);
}
use of io.bootique.jdbc.DataSourceFactory in project bootique-jdbc by bootique.
the class ManagedDataSourceFactoryProxyIT method testFactory_MultiLevel.
@Test
public void testFactory_MultiLevel() {
BQRuntime runtime = testFactory.app("-c", "classpath:io/bootique/jdbc/factory-type.yml").autoLoadModules().module(b -> JdbcModule.extend(b).addFactoryType(ManagedDataSourceFactoryX1.class).addFactoryType(ManagedDataSourceFactoryX2.class).addFactoryType(ManagedDataSourceFactoryX3.class).addFactoryType(ManagedDataSourceFactoryX4.class)).createRuntime();
ConfigurationFactory configFactory = runtime.getInstance(ConfigurationFactory.class);
Map<String, ManagedDataSourceFactory> configs = configFactory.config(new TypeRef<Map<String, ManagedDataSourceFactory>>() {
}, configPrefix);
assertTrue(configs.get("ds1") instanceof ManagedDataSourceFactoryX4);
assertTrue(configs.get("ds2") instanceof ManagedDataSourceFactoryX1);
DataSourceFactory factory = runtime.getInstance(DataSourceFactory.class);
DataSource ds1 = factory.forName("ds1");
assertNotNull(ds1);
DataSource ds2 = factory.forName("ds2");
assertNotNull(ds2);
}
use of io.bootique.jdbc.DataSourceFactory in project bootique-jdbc by bootique.
the class ManagedDataSourceFactoryProxyIT method testFactories_Hierarchical.
@Test
public void testFactories_Hierarchical() {
BQRuntime runtime = testFactory.app("-c", "classpath:io/bootique/jdbc/factories-type.yml").autoLoadModules().module(b -> JdbcModule.extend(b).addFactoryType(ManagedDataSourceFactoryX1.class).addFactoryType(ManagedDataSourceFactoryX2.class).addFactoryType(ManagedDataSourceFactoryX3.class).addFactoryType(ManagedDataSourceFactoryX33.class).addFactoryType(ManagedDataSourceFactoryY1.class).addFactoryType(ManagedDataSourceFactoryY2.class)).createRuntime();
ConfigurationFactory configFactory = runtime.getInstance(ConfigurationFactory.class);
Map<String, ManagedDataSourceFactory> configs = configFactory.config(new TypeRef<Map<String, ManagedDataSourceFactory>>() {
}, configPrefix);
assertTrue(configs.get("ds1") instanceof ManagedDataSourceFactoryX33);
assertTrue(configs.get("ds2") instanceof ManagedDataSourceFactoryY2);
DataSourceFactory factory = runtime.getInstance(DataSourceFactory.class);
DataSource ds1 = factory.forName("ds1");
assertNotNull(ds1);
DataSource ds2 = factory.forName("ds2");
assertNotNull(ds2);
}
Aggregations