use of org.apache.druid.discovery.NodeRole in project druid by druid-io.
the class InitializationTest method testCreateInjectorWithNodeRoleFilterUsingAnnotation_moduleLoaded.
@Test
public void testCreateInjectorWithNodeRoleFilterUsingAnnotation_moduleLoaded() {
final DruidNode expected = new DruidNode("test-inject", null, false, null, null, true, false);
Injector startupInjector = GuiceInjectors.makeStartupInjector();
Injector injector = Initialization.makeInjectorWithModules(ImmutableSet.of(new NodeRole("role1"), new NodeRole("druid")), startupInjector, ImmutableList.of((com.google.inject.Module) binder -> JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), expected), new LoadOnAnnotationTestModule()));
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 org.apache.druid.discovery.NodeRole 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