Search in sources :

Example 6 with JsonConfigurator

use of org.apache.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(CONFIG_PREFIX, ZkPathsConfig.class);
    testProperties.clear();
    String base = UUID.randomUUID().toString();
    testProperties.put(StringUtils.format("%s.base", CONFIG_PREFIX), base);
    zkPathsConfig.inject(testProperties, configurator);
    propertyValues.clear();
    propertyValues.put(StringUtils.format("%s.base", CONFIG_PREFIX), base);
    propertyValues.put(StringUtils.format("%s.propertiesPath", CONFIG_PREFIX), ZKPaths.makePath(base, "properties"));
    propertyValues.put(StringUtils.format("%s.announcementsPath", CONFIG_PREFIX), ZKPaths.makePath(base, "announcements"));
    propertyValues.put(StringUtils.format("%s.servedSegmentsPath", CONFIG_PREFIX), ZKPaths.makePath(base, "servedSegments"));
    propertyValues.put(StringUtils.format("%s.liveSegmentsPath", CONFIG_PREFIX), ZKPaths.makePath(base, "segments"));
    propertyValues.put(StringUtils.format("%s.coordinatorPath", CONFIG_PREFIX), ZKPaths.makePath(base, "coordinator"));
    propertyValues.put(StringUtils.format("%s.loadQueuePath", CONFIG_PREFIX), ZKPaths.makePath(base, "loadQueue"));
    propertyValues.put(StringUtils.format("%s.connectorPath", CONFIG_PREFIX), 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(org.apache.druid.server.initialization.ZkPathsConfig) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with JsonConfigurator

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

the class IndexerZkConfigTest method testNullConfig.

@Test
public void testNullConfig() {
    propertyValues.clear();
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(SIMPLE_ZK_CONFIG_MODULE));
    JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
    JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(ZK_SERVICE_CONFIG_STRING, ZkPathsConfig.class);
    zkPathsConfig.inject(propertyValues, configurator);
    JsonConfigProvider<IndexerZkConfig> indexerZkConfig = JsonConfigProvider.of(INDEXER_PROPERTY_STRING, IndexerZkConfig.class);
    indexerZkConfig.inject(propertyValues, configurator);
    Assert.assertEquals("/druid/indexer/tasks", indexerZkConfig.get().get().getTasksPath());
}
Also used : Injector(com.google.inject.Injector) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) Test(org.junit.Test)

Example 8 with JsonConfigurator

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

the class IndexerZkConfigTest method testSimpleConfig.

@Test
public void testSimpleConfig() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(SIMPLE_ZK_CONFIG_MODULE));
    JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
    JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(ZK_SERVICE_CONFIG_STRING, ZkPathsConfig.class);
    zkPathsConfig.inject(propertyValues, configurator);
    JsonConfigProvider<IndexerZkConfig> indexerZkConfig = JsonConfigProvider.of(INDEXER_PROPERTY_STRING, IndexerZkConfig.class);
    indexerZkConfig.inject(propertyValues, configurator);
    IndexerZkConfig zkConfig = indexerZkConfig.get().get();
    ZkPathsConfig zkPathsConfig1 = zkPathsConfig.get().get();
    validateEntries(zkConfig);
    validateEntries(zkPathsConfig1);
    Assert.assertEquals(CLOBBERABLE_PROPERTIES.size(), assertions);
}
Also used : Injector(com.google.inject.Injector) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) Test(org.junit.Test)

Example 9 with JsonConfigurator

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

the class IndexerZkConfigTest method testExactConfig.

@Test
public void testExactConfig() {
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(SIMPLE_ZK_CONFIG_MODULE));
    propertyValues.setProperty(ZK_SERVICE_CONFIG_STRING + ".base", "/druid/metrics");
    JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
    JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(ZK_SERVICE_CONFIG_STRING, ZkPathsConfig.class);
    zkPathsConfig.inject(propertyValues, configurator);
    ZkPathsConfig zkPathsConfig1 = zkPathsConfig.get().get();
    IndexerZkConfig indexerZkConfig = new IndexerZkConfig(zkPathsConfig1, null, null, null, null);
    Assert.assertEquals("/druid/metrics/indexer", indexerZkConfig.getBase());
    Assert.assertEquals("/druid/metrics/indexer/announcements", indexerZkConfig.getAnnouncementsPath());
}
Also used : Injector(com.google.inject.Injector) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) Test(org.junit.Test)

Example 10 with JsonConfigurator

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

the class IndexerZkConfigTest method testIndexerBaseOverride.

@Test
public void testIndexerBaseOverride() {
    final String overrideValue = "/foo/bar/baz";
    final String indexerPropertyKey = INDEXER_PROPERTY_STRING + ".base";
    final String priorValue = System.getProperty(indexerPropertyKey);
    // Set it here so that the binding picks it up
    System.setProperty(indexerPropertyKey, overrideValue);
    final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(SIMPLE_ZK_CONFIG_MODULE));
    propertyValues.clear();
    // Have to set it here as well annoyingly enough
    propertyValues.setProperty(indexerPropertyKey, overrideValue);
    JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
    JsonConfigProvider<IndexerZkConfig> indexerPathsConfig = JsonConfigProvider.of(INDEXER_PROPERTY_STRING, IndexerZkConfig.class);
    indexerPathsConfig.inject(propertyValues, configurator);
    IndexerZkConfig indexerZkConfig = indexerPathsConfig.get().get();
    // Rewind value before we potentially fail
    if (priorValue == null) {
        System.clearProperty(indexerPropertyKey);
    } else {
        System.setProperty(indexerPropertyKey, priorValue);
    }
    Assert.assertEquals(overrideValue, indexerZkConfig.getBase());
    Assert.assertEquals(overrideValue + "/announcements", indexerZkConfig.getAnnouncementsPath());
}
Also used : Injector(com.google.inject.Injector) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) 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