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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations