use of com.google.inject.multibindings.Multibinder in project druid by druid-io.
the class InitializationTest method testCreateInjectorWithNodeRoleFilterUsingInject_moduleLoaded.
@Test
public void testCreateInjectorWithNodeRoleFilterUsingInject_moduleLoaded() {
final Set<NodeRole> nodeRoles = ImmutableSet.of(new NodeRole("role1"), new NodeRole("druid"));
final DruidNode expected = new DruidNode("test-inject", null, false, null, null, true, false);
Injector startupInjector = GuiceInjectors.makeStartupInjectorWithModules(ImmutableList.of(binder -> {
Multibinder<NodeRole> selfBinder = Multibinder.newSetBinder(binder, NodeRole.class, Self.class);
nodeRoles.forEach(nodeRole -> selfBinder.addBinding().toInstance(nodeRole));
}));
Injector injector = Initialization.makeInjectorWithModules(nodeRoles, startupInjector, ImmutableList.of((com.google.inject.Module) binder -> JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), expected), new NodeRolesInjectTestModule()));
Assert.assertNotNull(injector);
Assert.assertEquals(expected, injector.getInstance(Key.get(DruidNode.class, Self.class)));
Assert.assertEquals("I am Druid", injector.getInstance(Key.get(String.class, Names.named("emperor"))));
}
use of com.google.inject.multibindings.Multibinder in project druid by druid-io.
the class InitializationTest method testCreateInjectorWithNodeRoleFilterUsingInject_moduleNotLoaded.
@Test
public void testCreateInjectorWithNodeRoleFilterUsingInject_moduleNotLoaded() {
final Set<NodeRole> nodeRoles = ImmutableSet.of(new NodeRole("role1"), new NodeRole("role2"));
final DruidNode expected = new DruidNode("test-inject", null, false, null, null, true, false);
Injector startupInjector = GuiceInjectors.makeStartupInjectorWithModules(ImmutableList.of(binder -> {
Multibinder<NodeRole> selfBinder = Multibinder.newSetBinder(binder, NodeRole.class, Self.class);
nodeRoles.forEach(nodeRole -> selfBinder.addBinding().toInstance(nodeRole));
}));
Injector injector = Initialization.makeInjectorWithModules(nodeRoles, startupInjector, ImmutableList.of((com.google.inject.Module) binder -> JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), expected), new NodeRolesInjectTestModule()));
Assert.assertNotNull(injector);
Assert.assertEquals(expected, injector.getInstance(Key.get(DruidNode.class, Self.class)));
Assert.assertThrows("Guice configuration errors", ConfigurationException.class, () -> injector.getInstance(Key.get(String.class, Names.named("emperor"))));
}
Aggregations