use of io.druid.guice.JsonConfigProvider 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.<Module>of(binder -> {
binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test");
binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
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(-1, config.getSizeInBytes());
Assert.assertEquals(ForkJoinPool.commonPool(), config.createExecutor());
}
use of io.druid.guice.JsonConfigProvider 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.<Module>of(binder -> {
binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test");
binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
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 io.druid.guice.JsonConfigProvider 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.<Module>of(binder -> {
binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test");
binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
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());
}
Aggregations