use of keywhiz.ServiceDataSourceModule in project keywhiz by square.
the class ServiceDataSourceModuleTest method injectsDataSources.
@Test
public void injectsDataSources() {
class Holder {
@Inject
ManagedDataSource readWrite;
@Inject
@Readonly
ManagedDataSource readonly;
}
Holder holder = new Holder();
ServiceContext context = ServiceContext.create();
Guice.createInjector(new ContextModule(context.getConfig(), context.getEnvironment()), new ServiceDataSourceModule()).injectMembers(holder);
assertNotNull(holder.readWrite);
assertNotNull(holder.readonly);
}
use of keywhiz.ServiceDataSourceModule 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