use of io.bootique.jdbc.DataSourceFactory in project bootique-jdbc by bootique.
the class ManagedDataSourceFactoryProxyIT method testFactory_MultilevelNoType.
@Test
public void testFactory_MultilevelNoType() {
BQRuntime runtime = testFactory.app("-c", "classpath:io/bootique/jdbc/factory-notype.yml").autoLoadModules().module(b -> JdbcModule.extend(b).addFactoryType(ManagedDataSourceFactoryX1.class).addFactoryType(ManagedDataSourceFactoryX2.class).addFactoryType(ManagedDataSourceFactoryX3.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 ManagedDataSourceFactoryProxy);
assertTrue(configs.get("ds2") instanceof ManagedDataSourceFactoryProxy);
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 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);
}
use of io.bootique.jdbc.DataSourceFactory 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);
}
use of io.bootique.jdbc.DataSourceFactory in project bootique-jdbc by bootique.
the class ManagedDataSourceFactoryProxyIT method testFactory_Hierarchical.
@Test
public void testFactory_Hierarchical() {
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(ManagedDataSourceFactoryX33.class).addFactoryType(ManagedDataSourceFactoryX4.class).addFactoryType(ManagedDataSourceFactoryX44.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);
}
Aggregations