mirror of https://github.com/apache/druid.git
Change IndexerZkConfig to use @JacksonInject instead of just straight @Inject
* Updated IndexerZkConfig to use no setters, and take all arguments from constructor instead * Also added more unit tests
This commit is contained in:
parent
8ea237d6a1
commit
67757b6aea
|
@ -19,9 +19,9 @@
|
|||
|
||||
package io.druid.server.initialization;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JacksonInject;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.inject.Inject;
|
||||
import org.apache.curator.utils.ZKPaths;
|
||||
|
||||
/**
|
||||
|
@ -29,19 +29,41 @@ import org.apache.curator.utils.ZKPaths;
|
|||
*/
|
||||
public class IndexerZkConfig
|
||||
{
|
||||
@Inject
|
||||
@JsonIgnore
|
||||
private ZkPathsConfig zkPathsConfig = new ZkPathsConfig();
|
||||
@JsonCreator
|
||||
public IndexerZkConfig(
|
||||
@JacksonInject ZkPathsConfig zkPathsConfig,
|
||||
@JsonProperty("base") String base,
|
||||
@JsonProperty("announcementsPath") String announcementsPath,
|
||||
@JsonProperty("tasksPath") String tasksPath,
|
||||
@JsonProperty("status") String status,
|
||||
@JsonProperty("leaderLatchPath") String leaderLatchPath
|
||||
)
|
||||
{
|
||||
this.zkPathsConfig = zkPathsConfig;
|
||||
this.base = base;
|
||||
this.announcementsPath = announcementsPath;
|
||||
this.tasksPath = tasksPath;
|
||||
this.status = status;
|
||||
this.leaderLatchPath = leaderLatchPath;
|
||||
}
|
||||
|
||||
@JacksonInject
|
||||
private final ZkPathsConfig zkPathsConfig;
|
||||
|
||||
@JsonProperty
|
||||
private String base;
|
||||
private final String base;
|
||||
|
||||
@JsonProperty
|
||||
private String announcementsPath;
|
||||
private final String announcementsPath;
|
||||
|
||||
@JsonProperty
|
||||
private String tasksPath;
|
||||
private final String tasksPath;
|
||||
|
||||
@JsonProperty
|
||||
private String status;
|
||||
private final String status;
|
||||
|
||||
@JsonProperty
|
||||
private String leaderLatchPath;
|
||||
private final String leaderLatchPath;
|
||||
|
||||
private String defaultIndexerPath(final String subPath)
|
||||
{
|
||||
|
@ -77,11 +99,4 @@ public class IndexerZkConfig
|
|||
{
|
||||
return zkPathsConfig;
|
||||
}
|
||||
|
||||
// Setter required for easy debugging
|
||||
public IndexerZkConfig setZkPathsConfig(ZkPathsConfig zkPathsConfig)
|
||||
{
|
||||
this.zkPathsConfig = zkPathsConfig;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -396,14 +396,14 @@ public class RemoteTaskRunnerTest
|
|||
remoteTaskRunner = new RemoteTaskRunner(
|
||||
jsonMapper,
|
||||
config,
|
||||
new IndexerZkConfig().setZkPathsConfig(new ZkPathsConfig()
|
||||
new IndexerZkConfig(new ZkPathsConfig()
|
||||
{
|
||||
@Override
|
||||
public String getBase()
|
||||
{
|
||||
return basePath;
|
||||
}
|
||||
}),
|
||||
},null,null,null,null,null),
|
||||
cf,
|
||||
new SimplePathChildrenCacheFactory.Builder().build(),
|
||||
null,
|
||||
|
|
|
@ -140,7 +140,7 @@ public class WorkerTaskMonitorTest
|
|||
|
||||
workerCuratorCoordinator = new WorkerCuratorCoordinator(
|
||||
jsonMapper,
|
||||
new IndexerZkConfig().setZkPathsConfig(
|
||||
new IndexerZkConfig(
|
||||
new ZkPathsConfig()
|
||||
{
|
||||
@Override
|
||||
|
@ -148,7 +148,7 @@ public class WorkerTaskMonitorTest
|
|||
{
|
||||
return basePath;
|
||||
}
|
||||
}),
|
||||
},null,null,null,null,null),
|
||||
new TestRemoteTaskRunnerConfig(),
|
||||
cf,
|
||||
worker
|
||||
|
|
|
@ -77,14 +77,14 @@ public class WorkerResourceTest
|
|||
|
||||
curatorCoordinator = new WorkerCuratorCoordinator(
|
||||
jsonMapper,
|
||||
new IndexerZkConfig().setZkPathsConfig(new ZkPathsConfig()
|
||||
new IndexerZkConfig(new ZkPathsConfig()
|
||||
{
|
||||
@Override
|
||||
public String getBase()
|
||||
{
|
||||
return basePath;
|
||||
}
|
||||
}),
|
||||
},null,null,null,null,null),
|
||||
new RemoteTaskRunnerConfig(),
|
||||
cf,
|
||||
worker
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.junit.AfterClass;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
@ -42,7 +43,9 @@ import java.lang.reflect.Method;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -52,7 +55,7 @@ public class IndexerZkConfigTest
|
|||
{
|
||||
private static final String indexerPropertyString = "test.druid.zk.paths.indexer";
|
||||
private static final String zkServiceConfigString = "test.druid.zk.paths";
|
||||
private static final Collection<String> clobberableProperties = new ArrayList<>();
|
||||
private static final Collection<String> clobberableProperties = new HashSet<>();
|
||||
|
||||
private static final Module simpleZkConfigModule = new Module()
|
||||
{
|
||||
|
@ -65,13 +68,11 @@ public class IndexerZkConfigTest
|
|||
JsonConfigProvider.bind(binder, indexerPropertyString, IndexerZkConfig.class);
|
||||
JsonConfigProvider.bind(
|
||||
binder, zkServiceConfigString,
|
||||
CuratorConfig.class
|
||||
ZkPathsConfig.class
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
private static final Map<String, String> priorValues = new HashMap<>();
|
||||
|
||||
@BeforeClass
|
||||
public static void setup()
|
||||
{
|
||||
|
@ -85,22 +86,9 @@ public class IndexerZkConfigTest
|
|||
clobberableProperties.add(String.format("%s.%s", zkServiceConfigString, field.getName()));
|
||||
}
|
||||
}
|
||||
for (String clobberableProperty : clobberableProperties) {
|
||||
priorValues.put(clobberableProperty, System.getProperty(clobberableProperty));
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup()
|
||||
{
|
||||
for (Map.Entry<String, String> entry : priorValues.entrySet()) {
|
||||
if (null != entry.getKey() && null != entry.getValue()) {
|
||||
System.setProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> propertyValues = new HashMap<>();
|
||||
private Properties propertyValues = new Properties();
|
||||
private int assertions = 0;
|
||||
|
||||
@Before
|
||||
|
@ -109,7 +97,6 @@ public class IndexerZkConfigTest
|
|||
for (String property : clobberableProperties) {
|
||||
propertyValues.put(property, UUID.randomUUID().toString());
|
||||
}
|
||||
System.getProperties().putAll(propertyValues);
|
||||
assertions = 0;
|
||||
}
|
||||
|
||||
|
@ -150,6 +137,28 @@ public class IndexerZkConfigTest
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullConfig(){
|
||||
propertyValues.clear();
|
||||
|
||||
final Injector injector = Initialization.makeInjectorWithModules(
|
||||
GuiceInjectors.makeStartupInjector(),
|
||||
ImmutableList.<Module>of(simpleZkConfigModule)
|
||||
);
|
||||
JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
|
||||
|
||||
JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(zkServiceConfigString, ZkPathsConfig.class);
|
||||
zkPathsConfig.inject(propertyValues, configurator);
|
||||
|
||||
JsonConfigProvider<IndexerZkConfig> indexerZkConfig = JsonConfigProvider.of(
|
||||
indexerPropertyString,
|
||||
IndexerZkConfig.class
|
||||
);
|
||||
indexerZkConfig.inject(propertyValues, configurator);
|
||||
|
||||
Assert.assertEquals("/druid/indexer/leaderLatchPath", indexerZkConfig.get().get().getLeaderLatchPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleConfig() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException
|
||||
{
|
||||
|
@ -160,16 +169,46 @@ public class IndexerZkConfigTest
|
|||
JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
|
||||
|
||||
JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(zkServiceConfigString, ZkPathsConfig.class);
|
||||
zkPathsConfig.inject(System.getProperties(), configurator);
|
||||
zkPathsConfig.inject(propertyValues, configurator);
|
||||
|
||||
JsonConfigProvider<IndexerZkConfig> indexerZkConfig = JsonConfigProvider.of(
|
||||
indexerPropertyString,
|
||||
IndexerZkConfig.class
|
||||
);
|
||||
indexerZkConfig.inject(System.getProperties(), configurator);
|
||||
indexerZkConfig.inject(propertyValues, configurator);
|
||||
|
||||
validateEntries(indexerZkConfig.get().get());
|
||||
validateEntries(zkPathsConfig.get().get());
|
||||
|
||||
IndexerZkConfig zkConfig = indexerZkConfig.get().get();
|
||||
ZkPathsConfig zkPathsConfig1 = zkPathsConfig.get().get();
|
||||
|
||||
validateEntries(zkConfig);
|
||||
validateEntries(zkPathsConfig1);
|
||||
Assert.assertEquals(clobberableProperties.size(), assertions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExactConfig(){
|
||||
final Injector injector = Initialization.makeInjectorWithModules(
|
||||
GuiceInjectors.makeStartupInjector(),
|
||||
ImmutableList.<Module>of(simpleZkConfigModule)
|
||||
);
|
||||
propertyValues.setProperty(zkServiceConfigString + ".base", "/druid/metrics");
|
||||
|
||||
|
||||
JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
|
||||
|
||||
JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(
|
||||
zkServiceConfigString,
|
||||
ZkPathsConfig.class
|
||||
);
|
||||
|
||||
zkPathsConfig.inject(propertyValues, configurator);
|
||||
|
||||
ZkPathsConfig zkPathsConfig1 = zkPathsConfig.get().get();
|
||||
|
||||
IndexerZkConfig indexerZkConfig = new IndexerZkConfig(zkPathsConfig1,null,null,null,null,null);
|
||||
|
||||
Assert.assertEquals("indexer", indexerZkConfig.getBase());
|
||||
Assert.assertEquals("/druid/metrics/indexer/announcements", indexerZkConfig.getAnnouncementsPath());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue