Search in sources :

Example 6 with NodeRole

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"))));
}
Also used : NodeRole(org.apache.druid.discovery.NodeRole) Injector(com.google.inject.Injector) DruidNode(org.apache.druid.server.DruidNode) Module(com.fasterxml.jackson.databind.Module) Test(org.junit.Test)

Example 7 with NodeRole

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"))));
}
Also used : Module(com.fasterxml.jackson.databind.Module) MethodSorters(org.junit.runners.MethodSorters) Arrays(java.util.Arrays) Self(org.apache.druid.guice.annotations.Self) URL(java.net.URL) Inject(com.google.inject.Inject) Key(com.google.inject.Key) Collections2(com.google.common.collect.Collections2) HashSet(java.util.HashSet) URLClassLoader(java.net.URLClassLoader) ImmutableList(com.google.common.collect.ImmutableList) Binder(com.google.inject.Binder) ExtensionsConfig(org.apache.druid.guice.ExtensionsConfig) Nullable(javax.annotation.Nullable) LinkedHashSet(java.util.LinkedHashSet) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) JsonConfigProvider(org.apache.druid.guice.JsonConfigProvider) LoadScope(org.apache.druid.guice.annotations.LoadScope) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigurationException(com.google.inject.ConfigurationException) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) Test(org.junit.Test) IOException(java.io.IOException) Names(com.google.inject.name.Names) Multibinder(com.google.inject.multibindings.Multibinder) Sets(com.google.common.collect.Sets) GuiceInjectors(org.apache.druid.guice.GuiceInjectors) File(java.io.File) Injector(com.google.inject.Injector) List(java.util.List) Rule(org.junit.Rule) DruidNode(org.apache.druid.server.DruidNode) NodeRole(org.apache.druid.discovery.NodeRole) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) Comparator(java.util.Comparator) TemporaryFolder(org.junit.rules.TemporaryFolder) NodeRole(org.apache.druid.discovery.NodeRole) Multibinder(com.google.inject.multibindings.Multibinder) Injector(com.google.inject.Injector) DruidNode(org.apache.druid.server.DruidNode) Self(org.apache.druid.guice.annotations.Self) Module(com.fasterxml.jackson.databind.Module) Test(org.junit.Test)

Aggregations

NodeRole (org.apache.druid.discovery.NodeRole)7 Module (com.fasterxml.jackson.databind.Module)5 Injector (com.google.inject.Injector)5 DruidNode (org.apache.druid.server.DruidNode)5 Test (org.junit.Test)5 URL (java.net.URL)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Function (com.google.common.base.Function)3 Collections2 (com.google.common.collect.Collections2)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Sets (com.google.common.collect.Sets)3 Binder (com.google.inject.Binder)3 ConfigurationException (com.google.inject.ConfigurationException)3 Inject (com.google.inject.Inject)3 Key (com.google.inject.Key)3 Multibinder (com.google.inject.multibindings.Multibinder)3 Names (com.google.inject.name.Names)3 File (java.io.File)3 IOException (java.io.IOException)3