Search in sources :

Example 1 with DruidNode

use of io.druid.server.DruidNode in project druid by druid-io.

the class CacheMonitorTest method testOptionalInject.

@Test
public void testOptionalInject() throws Exception {
    Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {

        @Override
        public void configure(Binder binder) {
            JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null));
        }
    }));
    CacheMonitor monitor = injector.getInstance(CacheMonitor.class);
    Assert.assertNull(monitor.cache);
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) DruidNode(io.druid.server.DruidNode) Self(io.druid.guice.annotations.Self) Module(com.google.inject.Module) Test(org.junit.Test)

Example 2 with DruidNode

use of io.druid.server.DruidNode in project druid by druid-io.

the class BaseJettyTest method setup.

@Before
public void setup() throws Exception {
    setProperties();
    Injector injector = setupInjector();
    final DruidNode node = injector.getInstance(Key.get(DruidNode.class, Self.class));
    port = node.getPort();
    lifecycle = injector.getInstance(Lifecycle.class);
    lifecycle.start();
    ClientHolder holder = injector.getInstance(ClientHolder.class);
    server = injector.getInstance(Server.class);
    client = holder.getClient();
}
Also used : Server(org.eclipse.jetty.server.Server) Injector(com.google.inject.Injector) Lifecycle(io.druid.java.util.common.lifecycle.Lifecycle) DruidNode(io.druid.server.DruidNode) Self(io.druid.guice.annotations.Self) Before(org.junit.Before)

Example 3 with DruidNode

use of io.druid.server.DruidNode in project druid by druid-io.

the class JettyQosTest method setupInjector.

@Override
protected Injector setupInjector() {
    return Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(new Module() {

        @Override
        public void configure(Binder binder) {
            JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test", "localhost", null));
            binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class);
            Jerseys.addResource(binder, SlowResource.class);
            Jerseys.addResource(binder, ExceptionResource.class);
            Jerseys.addResource(binder, DefaultResource.class);
            JettyBindings.addQosFilter(binder, "/slow/*", 2);
            final ServerConfig serverConfig = new ObjectMapper().convertValue(ImmutableMap.of("numThreads", "10"), ServerConfig.class);
            binder.bind(ServerConfig.class).toInstance(serverConfig);
            LifecycleModule.register(binder, Server.class);
        }
    }));
}
Also used : Binder(com.google.inject.Binder) DruidNode(io.druid.server.DruidNode) Self(io.druid.guice.annotations.Self) Module(com.google.inject.Module) LifecycleModule(io.druid.guice.LifecycleModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with DruidNode

use of io.druid.server.DruidNode in project druid by druid-io.

the class JettyTest method setupInjector.

@Override
protected Injector setupInjector() {
    return Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(new Module() {

        @Override
        public void configure(Binder binder) {
            JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test", "localhost", null));
            binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class);
            Multibinder<ServletFilterHolder> multibinder = Multibinder.newSetBinder(binder, ServletFilterHolder.class);
            multibinder.addBinding().toInstance(new ServletFilterHolder() {

                @Override
                public String getPath() {
                    return "/*";
                }

                @Override
                public Map<String, String> getInitParameters() {
                    return null;
                }

                @Override
                public Class<? extends Filter> getFilterClass() {
                    return DummyAuthFilter.class;
                }

                @Override
                public Filter getFilter() {
                    return null;
                }

                @Override
                public EnumSet<DispatcherType> getDispatcherType() {
                    return null;
                }
            });
            Jerseys.addResource(binder, SlowResource.class);
            Jerseys.addResource(binder, ExceptionResource.class);
            Jerseys.addResource(binder, DefaultResource.class);
            LifecycleModule.register(binder, Server.class);
        }
    }));
}
Also used : EnumSet(java.util.EnumSet) Self(io.druid.guice.annotations.Self) ServletFilterHolder(io.druid.server.initialization.jetty.ServletFilterHolder) Binder(com.google.inject.Binder) Filter(javax.servlet.Filter) DruidNode(io.druid.server.DruidNode) Module(com.google.inject.Module) LifecycleModule(io.druid.guice.LifecycleModule) Map(java.util.Map)

Example 5 with DruidNode

use of io.druid.server.DruidNode in project druid by druid-io.

the class MetricsModuleTest method testSimpleInjectionWithValues.

@Test
public void testSimpleInjectionWithValues() {
    final String dataSource = "some datasource";
    final String taskId = "some task";
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {

        @Override
        public void configure(Binder binder) {
            JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null));
            binder.bind(Key.get(String.class, Names.named(DataSourceTaskIdHolder.DATA_SOURCE_BINDING))).toInstance(dataSource);
            binder.bind(Key.get(String.class, Names.named(DataSourceTaskIdHolder.TASK_ID_BINDING))).toInstance(taskId);
        }
    }));
    final DataSourceTaskIdHolder dimensionIdHolder = new DataSourceTaskIdHolder();
    injector.injectMembers(dimensionIdHolder);
    Assert.assertEquals(dataSource, dimensionIdHolder.getDataSource());
    Assert.assertEquals(taskId, dimensionIdHolder.getTaskId());
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) DruidNode(io.druid.server.DruidNode) Self(io.druid.guice.annotations.Self) Module(com.google.inject.Module) Test(org.junit.Test)

Aggregations

DruidNode (io.druid.server.DruidNode)19 Self (io.druid.guice.annotations.Self)13 Binder (com.google.inject.Binder)12 Injector (com.google.inject.Injector)11 Module (com.google.inject.Module)11 Test (org.junit.Test)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)4 Before (org.junit.Before)4 Properties (java.util.Properties)3 ServiceEmitter (com.metamx.emitter.service.ServiceEmitter)2 NoopServiceAnnouncer (io.druid.curator.discovery.NoopServiceAnnouncer)2 LifecycleModule (io.druid.guice.LifecycleModule)2 Json (io.druid.guice.annotations.Json)2 ZkPathsConfig (io.druid.server.initialization.ZkPathsConfig)2 NamespaceExtractionModule (io.druid.server.lookup.namespace.NamespaceExtractionModule)2 NoopServiceEmitter (io.druid.server.metrics.NoopServiceEmitter)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Server (org.eclipse.jetty.server.Server)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1