Search in sources :

Example 11 with JsonConfigurator

use of org.apache.druid.guice.JsonConfigurator in project druid by druid-io.

the class CaffeineCacheProviderWithConfig method testFromProperties.

@Test
public void testFromProperties() {
    final String keyPrefix = "cache.config.prefix";
    final Properties properties = new Properties();
    properties.put(keyPrefix + ".expireAfter", "10");
    properties.put(keyPrefix + ".sizeInBytes", "100");
    properties.put(keyPrefix + ".cacheExecutorFactory", "single_thread");
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(binder -> {
        binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test");
        binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
        binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1);
        JsonConfigProvider.bind(binder, keyPrefix, CaffeineCacheConfig.class);
    }));
    final JsonConfigurator configurator = injector.getInstance(JsonConfigurator.class);
    final JsonConfigProvider<CaffeineCacheConfig> caffeineCacheConfigJsonConfigProvider = JsonConfigProvider.of(keyPrefix, CaffeineCacheConfig.class);
    caffeineCacheConfigJsonConfigProvider.inject(properties, configurator);
    final CaffeineCacheConfig config = caffeineCacheConfigJsonConfigProvider.get().get();
    Assert.assertEquals(10, config.getExpireAfter());
    Assert.assertEquals(100, config.getSizeInBytes());
    Assert.assertNotNull(config.createExecutor());
}
Also used : Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) Properties(java.util.Properties) JsonConfigProvider(org.apache.druid.guice.JsonConfigProvider) Inject(com.google.inject.Inject) StringUtils(org.apache.druid.java.util.common.StringUtils) Test(org.junit.Test) Random(java.util.Random) Names(com.google.inject.name.Names) UUID(java.util.UUID) Ints(com.google.common.primitives.Ints) GuiceInjectors(org.apache.druid.guice.GuiceInjectors) ArrayList(java.util.ArrayList) Injector(com.google.inject.Injector) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ForkJoinPool(java.util.concurrent.ForkJoinPool) Initialization(org.apache.druid.initialization.Initialization) Map(java.util.Map) ManageLifecycle(org.apache.druid.guice.ManageLifecycle) Assert(org.junit.Assert) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) Collections(java.util.Collections) Before(org.junit.Before) Injector(com.google.inject.Injector) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) Properties(java.util.Properties) Test(org.junit.Test)

Example 12 with JsonConfigurator

use of org.apache.druid.guice.JsonConfigurator in project druid by druid-io.

the class CaffeineCacheProviderWithConfig method testDefaultFromProperties.

@Test
public void testDefaultFromProperties() {
    final String keyPrefix = "cache.config.prefix";
    final Properties properties = new Properties();
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(binder -> {
        binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test");
        binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
        binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1);
        JsonConfigProvider.bind(binder, keyPrefix, CaffeineCacheConfig.class);
    }));
    final JsonConfigurator configurator = injector.getInstance(JsonConfigurator.class);
    final JsonConfigProvider<CaffeineCacheConfig> caffeineCacheConfigJsonConfigProvider = JsonConfigProvider.of(keyPrefix, CaffeineCacheConfig.class);
    caffeineCacheConfigJsonConfigProvider.inject(properties, configurator);
    final CaffeineCacheConfig config = caffeineCacheConfigJsonConfigProvider.get().get();
    Assert.assertEquals(-1, config.getExpireAfter());
    Assert.assertEquals(-1L, config.getSizeInBytes());
    Assert.assertEquals(ForkJoinPool.commonPool(), config.createExecutor());
}
Also used : Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) Properties(java.util.Properties) JsonConfigProvider(org.apache.druid.guice.JsonConfigProvider) Inject(com.google.inject.Inject) StringUtils(org.apache.druid.java.util.common.StringUtils) Test(org.junit.Test) Random(java.util.Random) Names(com.google.inject.name.Names) UUID(java.util.UUID) Ints(com.google.common.primitives.Ints) GuiceInjectors(org.apache.druid.guice.GuiceInjectors) ArrayList(java.util.ArrayList) Injector(com.google.inject.Injector) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ForkJoinPool(java.util.concurrent.ForkJoinPool) Initialization(org.apache.druid.initialization.Initialization) Map(java.util.Map) ManageLifecycle(org.apache.druid.guice.ManageLifecycle) Assert(org.junit.Assert) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) Collections(java.util.Collections) Before(org.junit.Before) Injector(com.google.inject.Injector) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) Properties(java.util.Properties) Test(org.junit.Test)

Example 13 with JsonConfigurator

use of org.apache.druid.guice.JsonConfigurator in project druid by druid-io.

the class CaffeineCacheProviderWithConfig method testMixedCaseFromProperties.

@Test
public void testMixedCaseFromProperties() {
    final String keyPrefix = "cache.config.prefix";
    final Properties properties = new Properties();
    properties.put(keyPrefix + ".expireAfter", "10");
    properties.put(keyPrefix + ".sizeInBytes", "100");
    properties.put(keyPrefix + ".cacheExecutorFactory", "CoMmON_FjP");
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(binder -> {
        binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test");
        binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
        binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1);
        JsonConfigProvider.bind(binder, keyPrefix, CaffeineCacheConfig.class);
    }));
    final JsonConfigurator configurator = injector.getInstance(JsonConfigurator.class);
    final JsonConfigProvider<CaffeineCacheConfig> caffeineCacheConfigJsonConfigProvider = JsonConfigProvider.of(keyPrefix, CaffeineCacheConfig.class);
    caffeineCacheConfigJsonConfigProvider.inject(properties, configurator);
    final CaffeineCacheConfig config = caffeineCacheConfigJsonConfigProvider.get().get();
    Assert.assertEquals(10, config.getExpireAfter());
    Assert.assertEquals(100, config.getSizeInBytes());
    Assert.assertEquals(ForkJoinPool.commonPool(), config.createExecutor());
}
Also used : Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) Properties(java.util.Properties) JsonConfigProvider(org.apache.druid.guice.JsonConfigProvider) Inject(com.google.inject.Inject) StringUtils(org.apache.druid.java.util.common.StringUtils) Test(org.junit.Test) Random(java.util.Random) Names(com.google.inject.name.Names) UUID(java.util.UUID) Ints(com.google.common.primitives.Ints) GuiceInjectors(org.apache.druid.guice.GuiceInjectors) ArrayList(java.util.ArrayList) Injector(com.google.inject.Injector) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ForkJoinPool(java.util.concurrent.ForkJoinPool) Initialization(org.apache.druid.initialization.Initialization) Map(java.util.Map) ManageLifecycle(org.apache.druid.guice.ManageLifecycle) Assert(org.junit.Assert) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) Collections(java.util.Collections) Before(org.junit.Before) Injector(com.google.inject.Injector) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with JsonConfigurator

use of org.apache.druid.guice.JsonConfigurator in project druid by druid-io.

the class FilteredRequestLoggerTest method testStartStop.

@Test
public void testStartStop() throws Exception {
    final Properties properties = new Properties();
    properties.setProperty("log.type", "filtered");
    properties.setProperty("log.queryTimeThresholdMs", "100");
    properties.setProperty("log.delegate.type", "test");
    final JsonConfigurator configurator = new JsonConfigurator(mapper, Validation.buildDefaultValidatorFactory().getValidator());
    final FilteredRequestLoggerProvider provider = (FilteredRequestLoggerProvider) configurator.configurate(properties, "log", RequestLoggerProvider.class);
    final FilteredRequestLoggerProvider.FilteredRequestLogger logger = ((FilteredRequestLoggerProvider.FilteredRequestLogger) provider.get());
    final TestRequestLogger delegate = (TestRequestLogger) logger.getDelegate();
    Assert.assertFalse(delegate.isStarted());
    logger.start();
    Assert.assertTrue(delegate.isStarted());
    logger.stop();
    Assert.assertFalse(delegate.isStarted());
}
Also used : JsonConfigurator(org.apache.druid.guice.JsonConfigurator) Properties(java.util.Properties) Test(org.junit.Test)

Example 15 with JsonConfigurator

use of org.apache.druid.guice.JsonConfigurator in project druid by druid-io.

the class RequestLoggerProviderTest method testLoggerPropertiesWithNoType.

@Test
public void testLoggerPropertiesWithNoType() {
    final Properties properties = new Properties();
    properties.setProperty("dummy", "unrelated");
    properties.setProperty("log.foo", "bar");
    final JsonConfigurator configurator = new JsonConfigurator(mapper, Validation.buildDefaultValidatorFactory().getValidator());
    expectedException.expect(ProvisionException.class);
    expectedException.expectMessage("missing type id property 'type'");
    configurator.configurate(properties, "log", RequestLoggerProvider.class, NoopRequestLoggerProvider.class);
}
Also used : JsonConfigurator(org.apache.druid.guice.JsonConfigurator) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

JsonConfigurator (org.apache.druid.guice.JsonConfigurator)19 Test (org.junit.Test)19 Properties (java.util.Properties)9 Injector (com.google.inject.Injector)7 ImmutableList (com.google.common.collect.ImmutableList)3 Lists (com.google.common.collect.Lists)3 Ints (com.google.common.primitives.Ints)3 Inject (com.google.inject.Inject)3 Names (com.google.inject.name.Names)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Map (java.util.Map)3 Random (java.util.Random)3 UUID (java.util.UUID)3 ForkJoinPool (java.util.concurrent.ForkJoinPool)3 GuiceInjectors (org.apache.druid.guice.GuiceInjectors)3 JsonConfigProvider (org.apache.druid.guice.JsonConfigProvider)3 ManageLifecycle (org.apache.druid.guice.ManageLifecycle)3 Initialization (org.apache.druid.initialization.Initialization)3 StringUtils (org.apache.druid.java.util.common.StringUtils)3