Search in sources :

Example 6 with JsonConfigurator

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

the class LookupListeningAnnouncerConfigTest method testSimpleInjection.

@Test
public void testSimpleInjection() {
    final String lookupTier = "some_tier";
    final JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
    properties.put(propertyBase + ".lookupTier", lookupTier);
    final JsonConfigProvider<LookupListeningAnnouncerConfig> configProvider = JsonConfigProvider.of(propertyBase, LookupListeningAnnouncerConfig.class);
    configProvider.inject(properties, configurator);
    final LookupListeningAnnouncerConfig config = configProvider.get().get();
    Assert.assertEquals(lookupTier, config.getLookupTier());
}
Also used : JsonConfigurator(io.druid.guice.JsonConfigurator) Test(org.junit.Test)

Example 7 with JsonConfigurator

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

the class LookupListeningAnnouncerConfigTest method testFailsInjection.

@Test(expected = IllegalArgumentException.class)
public void testFailsInjection() {
    final String lookupTier = "some_tier";
    final JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
    properties.put(propertyBase + ".lookupTier", lookupTier);
    properties.put(propertyBase + ".lookupTierIsDatasource", "true");
    final JsonConfigProvider<LookupListeningAnnouncerConfig> configProvider = JsonConfigProvider.of(propertyBase, LookupListeningAnnouncerConfig.class);
    configProvider.inject(properties, configurator);
    final LookupListeningAnnouncerConfig config = configProvider.get().get();
    Assert.assertEquals(lookupTier, config.getLookupTier());
}
Also used : JsonConfigurator(io.druid.guice.JsonConfigurator) Test(org.junit.Test)

Example 8 with JsonConfigurator

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

the class LookupListeningAnnouncerConfigTest method testDatasourceInjection.

@Test
public void testDatasourceInjection() {
    final JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
    properties.put(propertyBase + ".lookupTierIsDatasource", "true");
    final JsonConfigProvider<LookupListeningAnnouncerConfig> configProvider = JsonConfigProvider.of(propertyBase, LookupListeningAnnouncerConfig.class);
    configProvider.inject(properties, configurator);
    final LookupListeningAnnouncerConfig config = configProvider.get().get();
    Assert.assertEquals("some_datasource", config.getLookupTier());
}
Also used : JsonConfigurator(io.druid.guice.JsonConfigurator) Test(org.junit.Test)

Example 9 with JsonConfigurator

use of io.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.<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());
}
Also used : Module(com.google.inject.Module) Properties(java.util.Properties) Inject(com.google.inject.Inject) Test(org.junit.Test) Random(java.util.Random) Names(com.google.inject.name.Names) UUID(java.util.UUID) Field(java.lang.reflect.Field) Ints(com.google.common.primitives.Ints) GuiceInjectors(io.druid.guice.GuiceInjectors) ManageLifecycle(io.druid.guice.ManageLifecycle) Lifecycle(io.druid.java.util.common.lifecycle.Lifecycle) Injector(com.google.inject.Injector) Initialization(io.druid.initialization.Initialization) JsonConfigurator(io.druid.guice.JsonConfigurator) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ForkJoinPool(java.util.concurrent.ForkJoinPool) JsonConfigProvider(io.druid.guice.JsonConfigProvider) Map(java.util.Map) Assert(org.junit.Assert) Method(java.lang.reflect.Method) Before(org.junit.Before) Injector(com.google.inject.Injector) JsonConfigurator(io.druid.guice.JsonConfigurator) Properties(java.util.Properties) Test(org.junit.Test)

Example 10 with JsonConfigurator

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

the class ZkPathsConfigTest method testOverrideBaseOnlyConfig.

@Test
public void testOverrideBaseOnlyConfig() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
    JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
    JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(configPrefix, ZkPathsConfig.class);
    testProperties.clear();
    String base = UUID.randomUUID().toString();
    testProperties.put(String.format("%s.base", configPrefix), base);
    zkPathsConfig.inject(testProperties, configurator);
    propertyValues.clear();
    propertyValues.put(String.format("%s.base", configPrefix), base);
    propertyValues.put(String.format("%s.propertiesPath", configPrefix), ZKPaths.makePath(base, "properties"));
    propertyValues.put(String.format("%s.announcementsPath", configPrefix), ZKPaths.makePath(base, "announcements"));
    propertyValues.put(String.format("%s.servedSegmentsPath", configPrefix), ZKPaths.makePath(base, "servedSegments"));
    propertyValues.put(String.format("%s.liveSegmentsPath", configPrefix), ZKPaths.makePath(base, "segments"));
    propertyValues.put(String.format("%s.coordinatorPath", configPrefix), ZKPaths.makePath(base, "coordinator"));
    propertyValues.put(String.format("%s.loadQueuePath", configPrefix), ZKPaths.makePath(base, "loadQueue"));
    propertyValues.put(String.format("%s.connectorPath", configPrefix), ZKPaths.makePath(base, "connector"));
    ZkPathsConfig zkPathsConfigObj = zkPathsConfig.get().get();
    validateEntries(zkPathsConfigObj);
    Assert.assertEquals(propertyValues.size(), assertions);
    ObjectMapper jsonMapper = injector.getProvider(Key.get(ObjectMapper.class, Json.class)).get();
    String jsonVersion = jsonMapper.writeValueAsString(zkPathsConfigObj);
    ZkPathsConfig zkPathsConfigObjDeSer = jsonMapper.readValue(jsonVersion, ZkPathsConfig.class);
    Assert.assertEquals(zkPathsConfigObj, zkPathsConfigObjDeSer);
}
Also used : ZkPathsConfig(io.druid.server.initialization.ZkPathsConfig) JsonConfigurator(io.druid.guice.JsonConfigurator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

JsonConfigurator (io.druid.guice.JsonConfigurator)13 Test (org.junit.Test)13 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 Module (com.google.inject.Module)3 Names (com.google.inject.name.Names)3 GuiceInjectors (io.druid.guice.GuiceInjectors)3 JsonConfigProvider (io.druid.guice.JsonConfigProvider)3 ManageLifecycle (io.druid.guice.ManageLifecycle)3 Initialization (io.druid.initialization.Initialization)3 Lifecycle (io.druid.java.util.common.lifecycle.Lifecycle)3 Field (java.lang.reflect.Field)3 Method (java.lang.reflect.Method)3 Map (java.util.Map)3 Properties (java.util.Properties)3 Random (java.util.Random)3 UUID (java.util.UUID)3