use of io.dropwizard.db.ManagedDataSource in project keywhiz by square.
the class ServiceDataSourceModule method dataSource.
@Provides
@Singleton
ManagedDataSource dataSource(Environment environment, KeywhizConfig config) {
DataSourceFactory dataSourceFactory = config.getDataSourceFactory();
ManagedDataSource dataSource = dataSourceFactory.build(environment.metrics(), "db-writable");
environment.lifecycle().manage(dataSource);
environment.healthChecks().register("db-read-write-health", new JooqHealthCheck(dataSource, LOG_ONLY));
return dataSource;
}
use of io.dropwizard.db.ManagedDataSource in project keywhiz by square.
the class ServiceDataSourceModuleTest method dataSourcesAreSingletons.
@Test
public void dataSourcesAreSingletons() {
class Holder {
@Inject
ManagedDataSource readWrite;
@Inject
@Readonly
ManagedDataSource readonly;
}
Holder holder1 = new Holder();
Holder holder2 = new Holder();
ServiceContext context = ServiceContext.create();
Injector injector = Guice.createInjector(new ContextModule(context.getConfig(), context.getEnvironment()), new ServiceDataSourceModule());
injector.injectMembers(holder1);
injector.injectMembers(holder2);
assertSame(holder1.readWrite, holder2.readWrite);
assertSame(holder1.readonly, holder2.readonly);
}
Aggregations