Search in sources :

Example 1 with ServiceDataSourceModule

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);
}
Also used : ServiceContext(keywhiz.test.ServiceContext) ContextModule(keywhiz.inject.ContextModule) ServiceDataSourceModule(keywhiz.ServiceDataSourceModule) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Test(org.junit.Test)

Example 2 with ServiceDataSourceModule

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);
}
Also used : ServiceContext(keywhiz.test.ServiceContext) Injector(com.google.inject.Injector) ContextModule(keywhiz.inject.ContextModule) ServiceDataSourceModule(keywhiz.ServiceDataSourceModule) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Test(org.junit.Test)

Aggregations

ManagedDataSource (io.dropwizard.db.ManagedDataSource)2 ServiceDataSourceModule (keywhiz.ServiceDataSourceModule)2 ContextModule (keywhiz.inject.ContextModule)2 ServiceContext (keywhiz.test.ServiceContext)2 Test (org.junit.Test)2 Injector (com.google.inject.Injector)1