Apache Solr open-source search software
SOLR-14958: Refactor zkHost config logic to make testing easier and reduce risk of incorrect value being used
Chris Hostetter37a61635e1c3
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex a379b1e5d11..98e2a87d81a 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -212,6 +212,8 @@ Other Changes* SOLR-14995: Update Jetty to 9.4.34 (Mike Drob)+* SOLR-14958: Refactor zkHost config logic to make testing easier and reduce risk of incorrect value being used (hossman)+================== 8.7.0 ==================Consult the lucene/CHANGES.txt file for additional, low level, changes in this release.diff --git a/solr/core/src/java/org/apache/solr/core/CloudConfig.java b/solr/core/src/java/org/apache/solr/core/CloudConfig.javaindex df608336d07..c8efbbb0461 100644--- a/solr/core/src/java/org/apache/solr/core/CloudConfig.java+++ b/solr/core/src/java/org/apache/solr/core/CloudConfig.java@@ -137,7 +137,7 @@ public class CloudConfig {private static final int DEFAULT_CREATE_COLLECTION_ACTIVE_WAIT = 45; // 45 secondsprivate static final boolean DEFAULT_CREATE_COLLECTION_CHECK_LEADER_ACTIVE = false;- private String zkHost = System.getProperty("zkHost");+ private String zkHost;private int zkClientTimeout = Integer.getInteger("zkClientTimeout", DEFAULT_ZK_CLIENT_TIMEOUT);private final int hostPort;private final String hostName;diff --git a/solr/core/src/java/org/apache/solr/core/NodeConfig.java b/solr/core/src/java/org/apache/solr/core/NodeConfig.javaindex ef8fddbe4be..46f180764a2 100644--- a/solr/core/src/java/org/apache/solr/core/NodeConfig.java+++ b/solr/core/src/java/org/apache/solr/core/NodeConfig.java@@ -87,6 +87,7 @@ public class NodeConfig {// Track if this config was loaded from zookeeper so that we can skip validating the zookeeper connection later// If it becomes necessary to track multiple potential sources in the future, replace this with an Enumprivate final boolean fromZookeeper;+ private final String defaultZkHost;private NodeConfig(String nodeName, Path coreRootDirectory, Path solrDataHome, Integer booleanQueryMaxClauseCount,Path configSetBaseDirectory, String sharedLibDirectory,@@ -98,7 +99,7 @@ public class NodeConfig {Path solrHome, SolrResourceLoader loader,Properties solrProperties, PluginInfo[] backupRepositoryPlugins,MetricsConfig metricsConfig, PluginInfo transientCacheConfig, PluginInfo tracerConfig,- boolean fromZookeeper, Set<Path> allowPaths) {+ boolean fromZookeeper, String defaultZkHost, Set<Path> allowPaths) {// all Path params here are absolute and normalized.this.nodeName = nodeName;this.coreRootDirectory = coreRootDirectory;@@ -128,6 +129,7 @@ public class NodeConfig {this.transientCacheConfig = transientCacheConfig;this.tracerConfig = tracerConfig;this.fromZookeeper = fromZookeeper;+ this.defaultZkHost = defaultZkHost;this.allowPaths = allowPaths;if (this.cloudConfig != null && this.getCoreLoadThreadCount(false) < 2) {@@ -263,9 +265,33 @@ public class NodeConfig {return tracerConfig;}+ /**+ * True if this node config was loaded from zookeeper+ * @see #getDefaultZkHost+ */public boolean isFromZookeeper() {return fromZookeeper;}++ /**+ * This method returns the default "zkHost" value for this node -- either read from the system properties,+ * or from the "extra" properties configured explicitly on the SolrDispatchFilter; or null if not specified.+ *+ * This is the value that would have been used when attempting locate the solr.xml in ZooKeeper (regardless of wether+ * the file was actaully loaded from ZK or from local disk)+ *+ * (This value should only be used for "accounting" purposes to track where the node config came from if+ * it <em>was</em> loaded from zk -- ie: to check if the chroot has already been applied.+ * It may be different from the "zkHost" <em>configured</em> in the "cloud" section of the solr.xml,+ * which should be used for all zk connections made by this node to participate in the cluster)+ *+ * @see #isFromZookeeper+ * @see #getCloudConfig()+ * @see CloudConfig#getZkHost()+ */+ public String getDefaultZkHost() {+ return defaultZkHost;+ }/*** Extra file paths that will be allowed for core creation, in addition to@@ -303,6 +329,7 @@ public class NodeConfig {private PluginInfo transientCacheConfig;private PluginInfo tracerConfig;private boolean fromZookeeper = false;+ private String defaultZkHost;private Set<Path> allowPaths = Collections.emptySet();private final Path solrHome;@@ -467,6 +494,11 @@ public class NodeConfig {this.fromZookeeper = fromZookeeper;return this;}++ public NodeConfigBuilder setDefaultZkHost(String defaultZkHost) {+ this.defaultZkHost = defaultZkHost;+ return this;+ }public NodeConfigBuilder setAllowPaths(Set<Path> paths) {this.allowPaths = paths;@@ -483,7 +515,7 @@ public class NodeConfig {updateShardHandlerConfig, coreAdminHandlerClass, collectionsAdminHandlerClass, healthCheckHandlerClass, infoHandlerClass, configSetsHandlerClass,logWatcherConfig, cloudConfig, coreLoadThreads, replayUpdatesThreads, transientCacheSize, useSchemaCache, managementPath,solrHome, loader, solrProperties,- backupRepositoryPlugins, metricsConfig, transientCacheConfig, tracerConfig, fromZookeeper, allowPaths);+ backupRepositoryPlugins, metricsConfig, transientCacheConfig, tracerConfig, fromZookeeper, defaultZkHost, allowPaths);}public NodeConfigBuilder setSolrResourceLoader(SolrResourceLoader resourceLoader) {diff --git a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.javaindex 69522951faf..d68d16b0b5e 100644--- a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java+++ b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java@@ -40,6 +40,7 @@ import java.util.stream.Collectors;import com.google.common.base.Strings;import org.apache.commons.io.IOUtils;+import org.apache.commons.lang3.StringUtils;import org.apache.solr.client.solrj.impl.HttpClientUtil;import org.apache.solr.common.SolrException;import org.apache.solr.common.util.DOMUtil;@@ -67,22 +68,61 @@ public class SolrXmlConfig {// TODO should these from* methods return a NodeConfigBuilder so that the caller (a test) can make further// manipulations like add properties and set the CorePropertiesLocator and "async" mode?+ public final static String ZK_HOST = "zkHost";public final static String SOLR_XML_FILE = "solr.xml";public final static String SOLR_DATA_HOME = "solr.data.home";private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());+ /**+ * Given some node Properties, checks if non-null and a 'zkHost' is alread included. If so, the Properties are+ * returned as is. If not, then the returned value will be a new Properties, wrapping the original Properties,+ * with the 'zkHost' value set based on the value of the corispond System property (if set)+ *+ * In theory we only need this logic once, ideally in SolrDispatchFilter, but we put it here to re-use+ * redundently because of how much surface area our API has for various tests to poke at us.+ */+ public static Properties wrapAndSetZkHostFromSysPropIfNeeded(final Properties props) {+ if (null != props && ! StringUtils.isEmpty(props.getProperty(ZK_HOST))) {+ // nothing to do...+ return props;+ }+ // we always wrap if we might set a property -- never mutate the original props+ final Properties results = (null == props ? new Properties() : new Properties(props));+ final String sysprop = System.getProperty(ZK_HOST);+ if (! StringUtils.isEmpty(sysprop)) {+ results.setProperty(ZK_HOST, sysprop);+ }+ return results;+ }++public static NodeConfig fromConfig(Path solrHome, XmlConfigFile config, boolean fromZookeeper) {checkForIllegalConfig(config);+ // sanity check: if our config came from zookeeper, then there *MUST* be Node Properties that tell us+ // what zkHost was used to read it (either via webapp context attribute, or that SolrDispatchFilter+ // filled in for us from system properties)+ assert ( (! fromZookeeper) || (null != config.getSubstituteProperties()+ && null != config.getSubstituteProperties().getProperty(ZK_HOST)));++ // Regardless of where/how we this XmlConfigFile was loaded from, if it contains a zkHost property,+ // we're going to use that as our "default" and only *directly* check the system property if it's not specified.+ //+ // (checking the sys prop here is really just for tests that by-pass SolrDispatchFilter. In non-test situations,+ // SolrDispatchFilter will check the system property if needed in order to try and load solr.xml from ZK, and+ // should have put the sys prop value in the node properties for us)+ final String defaultZkHost+ = wrapAndSetZkHostFromSysPropIfNeeded(config.getSubstituteProperties()).getProperty(ZK_HOST);+CloudConfig cloudConfig = null;UpdateShardHandlerConfig deprecatedUpdateConfig = null;if (config.getNodeList("solr/solrcloud", false).getLength() > 0) {NamedList<Object> cloudSection = readNodeListAsNamedList(config, "solr/solrcloud/*[@name]", "<solrcloud>");deprecatedUpdateConfig = loadUpdateConfig(cloudSection, false);- cloudConfig = fillSolrCloudSection(cloudSection);+ cloudConfig = fillSolrCloudSection(cloudSection, config, defaultZkHost);}NamedList<Object> entries = readNodeListAsNamedList(config, "solr/*[@name]", "<solr>");@@ -115,6 +155,7 @@ public class SolrXmlConfig {configBuilder.setBackupRepositoryPlugins(getBackupRepositoryPluginInfos(config));configBuilder.setMetricsConfig(getMetricsConfig(config));configBuilder.setFromZookeeper(fromZookeeper);+ configBuilder.setDefaultZkHost(defaultZkHost);return fillSolrSection(configBuilder, entries);}@@ -391,14 +432,16 @@ public class SolrXmlConfig {throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, section + " section missing required entry '" + key + "'");}- private static CloudConfig fillSolrCloudSection(NamedList<Object> nl) {+ private static CloudConfig fillSolrCloudSection(NamedList<Object> nl, XmlConfigFile config, String defaultZkHost) {String hostName = required("solrcloud", "host", removeValue(nl, "host"));int hostPort = parseInt("hostPort", required("solrcloud", "hostPort", removeValue(nl, "hostPort")));String hostContext = required("solrcloud", "hostContext", removeValue(nl, "hostContext"));CloudConfig.CloudConfigBuilder builder = new CloudConfig.CloudConfigBuilder(hostName, hostPort, hostContext);-+ // set the defaultZkHost until/unless it's overridden in the "cloud section" (below)...+ builder.setZkHost(defaultZkHost);+for (Map.Entry<String, Object> entry : nl) {String name = entry.getKey();if (entry.getValue() == null)diff --git a/solr/core/src/java/org/apache/solr/core/ZkContainer.java b/solr/core/src/java/org/apache/solr/core/ZkContainer.javaindex eb7c850c0da..91f760d9cea 100644--- a/solr/core/src/java/org/apache/solr/core/ZkContainer.java+++ b/solr/core/src/java/org/apache/solr/core/ZkContainer.java@@ -118,7 +118,8 @@ public class ZkContainer {boolean boostrapConf = Boolean.getBoolean("bootstrap_conf");// We may have already loaded NodeConfig from zookeeper with same connect string, so no need to recheck chroot- boolean alreadyUsedChroot = cc.getConfig().isFromZookeeper() && zookeeperHost.equals(System.getProperty("zkHost"));+ boolean alreadyUsedChroot = (cc.getConfig().isFromZookeeper()+ && zookeeperHost.equals(cc.getConfig().getDefaultZkHost()));if(!alreadyUsedChroot && !ZkController.checkChrootPath(zookeeperHost, (confDir!=null) || boostrapConf || zkRunOnly)) {throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,"A chroot was specified in ZkHost but the znode doesn't exist. " + zookeeperHost);diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.javaindex 95afda4b82c..e29b0166563 100644--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java@@ -115,6 +115,7 @@ public class SolrDispatchFilter extends BaseSolrFilter {private SolrMetricManager metricManager;private String registryName;private volatile boolean closeOnDestroy = true;+ private Properties extraProperties;private RateLimitManager rateLimitManager;@@ -146,78 +147,77 @@ public class SolrDispatchFilter extends BaseSolrFilter {public static final String SOLR_LOG_LEVEL = "solr.log.level";@Override- public void init(FilterConfig config) throws ServletException- {+ public void init(FilterConfig config) throws ServletException {SSLConfigurationsFactory.current().init();if (log.isTraceEnabled()) {log.trace("SolrDispatchFilter.init(): {}", this.getClass().getClassLoader());}CoreContainer coresInit = null;- try{-- StartupLoggingUtils.checkLogDir();- if (log.isInfoEnabled()) {- log.info("Using logger factory {}", StartupLoggingUtils.getLoggerImplStr());- }- logWelcomeBanner();- String muteConsole = System.getProperty(SOLR_LOG_MUTECONSOLE);- if (muteConsole != null && !Arrays.asList("false","0","off","no").contains(muteConsole.toLowerCase(Locale.ROOT))) {- StartupLoggingUtils.muteConsole();- }- String logLevel = System.getProperty(SOLR_LOG_LEVEL);- if (logLevel != null) {- log.info("Log level override, property solr.log.level={}", logLevel);- StartupLoggingUtils.changeLogLevel(logLevel);- }-- String exclude = config.getInitParameter("excludePatterns");- if(exclude != null) {- String[] excludeArray = exclude.split(",");- excludePatterns = new ArrayList<>();- for (String element : excludeArray) {- excludePatterns.add(Pattern.compile(element));- }- }try {- Properties extraProperties = (Properties) config.getServletContext().getAttribute(PROPERTIES_ATTRIBUTE);- if (extraProperties == null)- extraProperties = new Properties();-+ // "extra" properties must be init'ed first so we know things like "do we have a zkHost"+ // wrap as defaults (if set) so we can modify w/o polluting the Properties provided by our caller+ this.extraProperties = SolrXmlConfig.wrapAndSetZkHostFromSysPropIfNeeded+ ((Properties) config.getServletContext().getAttribute(PROPERTIES_ATTRIBUTE));++ StartupLoggingUtils.checkLogDir();+ if (log.isInfoEnabled()) {+ log.info("Using logger factory {}", StartupLoggingUtils.getLoggerImplStr());+ }++ logWelcomeBanner();++ String muteConsole = System.getProperty(SOLR_LOG_MUTECONSOLE);+ if (muteConsole != null && !Arrays.asList("false","0","off","no").contains(muteConsole.toLowerCase(Locale.ROOT))) {+ StartupLoggingUtils.muteConsole();+ }+ String logLevel = System.getProperty(SOLR_LOG_LEVEL);+ if (logLevel != null) {+ log.info("Log level override, property solr.log.level={}", logLevel);+ StartupLoggingUtils.changeLogLevel(logLevel);+ }++ String exclude = config.getInitParameter("excludePatterns");+ if(exclude != null) {+ String[] excludeArray = exclude.split(",");+ excludePatterns = new ArrayList<>();+ for (String element : excludeArray) {+ excludePatterns.add(Pattern.compile(element));+ }+ }+String solrHome = (String) config.getServletContext().getAttribute(SOLRHOME_ATTRIBUTE);final Path solrHomePath = solrHome == null ? SolrPaths.locateSolrHome() : Paths.get(solrHome);coresInit = createCoreContainer(solrHomePath, extraProperties);this.httpClient = coresInit.getUpdateShardHandler().getDefaultHttpClient();setupJvmMetrics(coresInit);-+SolrZkClient zkClient = null;ZkController zkController = coresInit.getZkController();-+if (zkController != null) {zkClient = zkController.getZkClient();}-+RateLimitManager.Builder builder = new RateLimitManager.Builder(zkClient);-+this.rateLimitManager = builder.build();-+if (zkController != null) {zkController.zkStateReader.registerClusterPropertiesListener(this.rateLimitManager);}-+if (log.isDebugEnabled()) {log.debug("user.dir={}", System.getProperty("user.dir"));}- }- catch( Throwable t ) {+ } catch( Throwable t ) {// catch this so our filter still workslog.error( "Could not start Solr. Check solr/home property and the logs");SolrCore.log( t );if (t instanceof Error) {throw (Error) t;}- }-- }finally{++ } finally{log.trace("SolrDispatchFilter.init() done");this.cores = coresInit; // crucially final assignmentinit.countDown();@@ -279,18 +279,23 @@ public class SolrDispatchFilter extends BaseSolrFilter {return System.getProperty("jetty.port");}- /* We are in cloud mode if Java option zkRun exists OR zkHost exists and is non-empty */+ /**+ * We are in cloud mode if Java option zkRun exists OR zkHost exists and is non-empty+ * @see SolrXmlConfig#wrapAndSetZkHostFromSysPropIfNeeded+ * @see #extraProperties+ * @see #init+ */private boolean isCloudMode() {- return ((System.getProperty("zkHost") != null && !StringUtils.isEmpty(System.getProperty("zkHost")))- || System.getProperty("zkRun") != null);+ assert null != extraProperties; // we should never be called w/o this being initialized+ return (null != extraProperties.getProperty(SolrXmlConfig.ZK_HOST)) || (null != System.getProperty("zkRun"));}/*** Override this to change CoreContainer initialization* @return a CoreContainer to hold this server's cores*/- protected CoreContainer createCoreContainer(Path solrHome, Properties extraProperties) {- NodeConfig nodeConfig = loadNodeConfig(solrHome, extraProperties);+ protected CoreContainer createCoreContainer(Path solrHome, Properties nodeProps) {+ NodeConfig nodeConfig = loadNodeConfig(solrHome, nodeProps);final CoreContainer coreContainer = new CoreContainer(nodeConfig, true);coreContainer.load();return coreContainer;@@ -305,8 +310,8 @@ public class SolrDispatchFilter extends BaseSolrFilter {if (!StringUtils.isEmpty(System.getProperty("solr.solrxml.location"))) {log.warn("Solr property solr.solrxml.location is no longer supported. Will automatically load solr.xml from ZooKeeper if it exists");}-- String zkHost = System.getProperty("zkHost");+ nodeProperties = SolrXmlConfig.wrapAndSetZkHostFromSysPropIfNeeded(nodeProperties);+ String zkHost = nodeProperties.getProperty(SolrXmlConfig.ZK_HOST);if (!StringUtils.isEmpty(zkHost)) {int startUpZkTimeOut = Integer.getInteger("waitForZk", 30);startUpZkTimeOut *= 1000;diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.javaindex 8e1f286d6ce..57d9a93826b 100644--- a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java+++ b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java@@ -29,6 +29,7 @@ import java.util.Collections;import java.util.List;import java.util.Objects;import java.util.Optional;+import java.util.Properties;import java.util.Random;import java.util.Set;import java.util.SortedMap;@@ -296,10 +297,7 @@ public class MiniSolrCloudCluster {zkClient.makePath("/solr/security.json", securityJson.get().getBytes(Charset.defaultCharset()), true);}}-- // tell solr to look in zookeeper for solr.xml- System.setProperty("zkHost", zkServer.getZkAddress());-+List<Callable<JettySolrRunner>> startups = new ArrayList<>(numServers);for (int i = 0; i < numServers; ++i) {startups.add(() -> startJettySolrRunner(newNodeName(), jettyConfig.context, jettyConfig));@@ -467,12 +465,16 @@ public class MiniSolrCloudCluster {* @return a JettySolrRunner*/public JettySolrRunner startJettySolrRunner(String name, String hostContext, JettyConfig config) throws Exception {+ // tell solr node to look in zookeeper for solr.xml+ final Properties nodeProps = new Properties();+ nodeProps.setProperty("zkHost", zkServer.getZkAddress());+Path runnerPath = createInstancePath(name);String context = getHostContextSuitableForServletContext(hostContext);JettyConfig newConfig = JettyConfig.builder(config).setContext(context).build();JettySolrRunner jetty = !trackJettyMetrics- ? new JettySolrRunner(runnerPath.toString(), newConfig)- :new JettySolrRunnerWithMetrics(runnerPath.toString(), newConfig);+ ? new JettySolrRunner(runnerPath.toString(), nodeProps, newConfig)+ : new JettySolrRunnerWithMetrics(runnerPath.toString(), nodeProps, newConfig);jetty.start();jettys.add(jetty);return jetty;@@ -627,12 +629,8 @@ public class MiniSolrCloudCluster {throw shutdownError;}} finally {- try {- if (!externalZkServer) {- zkServer.shutdown();- }- } finally {- System.clearProperty("zkHost");+ if (!externalZkServer) {+ zkServer.shutdown();}}}@@ -826,8 +824,8 @@ public class MiniSolrCloudCluster {/** @lucene.experimental */public static final class JettySolrRunnerWithMetrics extends JettySolrRunner {- public JettySolrRunnerWithMetrics(String solrHome, JettyConfig config) {- super(solrHome, config);+ public JettySolrRunnerWithMetrics(String solrHome, Properties nodeProps, JettyConfig config) {+ super(solrHome, nodeProps, config);}private volatile MetricRegistry metricRegistry;diff --git a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.javaindex 7657c3f8dd1..a2f81770c12 100644--- a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java+++ b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java@@ -174,13 +174,14 @@ public class TestHarness extends BaseTestHarness {}public static NodeConfig buildTestNodeConfig(Path solrHome) {- CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder(System.getProperty("host"),- Integer.getInteger("hostPort", 8983),- System.getProperty("hostContext", ""))- .setZkClientTimeout(Integer.getInteger("zkClientTimeout", 30000))- .build();- if (System.getProperty("zkHost") == null)- cloudConfig = null;+ CloudConfig cloudConfig = (null == System.getProperty("zkHost"))+ ? null+ : new CloudConfig.CloudConfigBuilder(System.getProperty("host"),+ Integer.getInteger("hostPort", 8983),+ System.getProperty("hostContext", ""))+ .setZkClientTimeout(Integer.getInteger("zkClientTimeout", 30000))+ .setZkHost(System.getProperty("zkHost"))+ .build();UpdateShardHandlerConfig updateShardHandlerConfig = new UpdateShardHandlerConfig(HttpClientUtil.DEFAULT_MAXCONNECTIONS,HttpClientUtil.DEFAULT_MAXCONNECTIONSPERHOST,diff --git a/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.java b/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.javaindex 2bbf33f2d4f..37a2bfbb310 100644--- a/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.java+++ b/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.java@@ -18,7 +18,9 @@package org.apache.solr.cloud;import java.io.IOException;+import java.nio.file.Path;import java.util.concurrent.atomic.AtomicInteger;+import java.util.Properties;import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;import org.apache.lucene.util.LuceneTestCase;@@ -97,4 +99,76 @@ public class MiniSolrCloudClusterTest extends SolrTestCaseJ4 {cluster.shutdown();}+ public void testMultipleClustersDiffZk() throws Exception {+ final MiniSolrCloudCluster x = new MiniSolrCloudCluster(1, createTempDir(), JettyConfig.builder().build());+ try {+ final MiniSolrCloudCluster y = new MiniSolrCloudCluster(1, createTempDir(), JettyConfig.builder().build());+ try {++ // sanity check we're not talking to ourselves+ assertNotSame(x.getZkServer(), y.getZkServer());+ assertNotEquals(x.getZkServer().getZkAddress(), y.getZkServer().getZkAddress());++ // baseline check+ assertEquals(1, x.getJettySolrRunners().size());+ assertZkHost("x", x.getZkServer().getZkAddress(), x.getJettySolrRunners().get(0));++ assertEquals(1, y.getJettySolrRunners().size());+ assertZkHost("y", y.getZkServer().getZkAddress(), y.getJettySolrRunners().get(0));++ // adding nodes should be isolated+ final JettySolrRunner j2x = x.startJettySolrRunner();+ assertZkHost("x2", x.getZkServer().getZkAddress(), j2x);+ assertEquals(2, x.getJettySolrRunners().size());+ assertEquals(1, y.getJettySolrRunners().size());++ final JettySolrRunner j2y = y.startJettySolrRunner();+ assertZkHost("y2", y.getZkServer().getZkAddress(), j2y);+ assertEquals(2, x.getJettySolrRunners().size());+ assertEquals(2, y.getJettySolrRunners().size());+ } finally {+ y.shutdown();+ }+ } finally {+ x.shutdown();+ }+ }++ public void testJettyUsingSysProp() throws Exception {+ try {+ // this cluster will use a sysprop to communicate zkHost to it's nodes -- not node props in the servlet context+ final MiniSolrCloudCluster x = new MiniSolrCloudCluster(1, createTempDir(), JettyConfig.builder().build()) {+ @Override+ public JettySolrRunner startJettySolrRunner(String name, String hostContext, JettyConfig config) throws Exception {+ System.setProperty("zkHost", getZkServer().getZkAddress());++ final Properties nodeProps = new Properties();+ nodeProps.setProperty("test-from-sysprop", "yup");++ Path runnerPath = createTempDir(name);+ JettyConfig newConfig = JettyConfig.builder(config).setContext("/blarfh").build();+ JettySolrRunner jetty = new JettySolrRunner(runnerPath.toString(), nodeProps, newConfig);+ return super.startJettySolrRunner(jetty);+ }+ };+ try {+ // baseline check+ assertEquals(1, x.getJettySolrRunners().size());+ assertZkHost("x", x.getZkServer().getZkAddress(), x.getJettySolrRunners().get(0));++ // verify MiniSolrCloudCluster's impl didn't change out from under us making test useless+ assertEquals("yup", x.getJettySolrRunners().get(0).getNodeProperties().getProperty("test-from-sysprop"));+ assertNull(x.getJettySolrRunners().get(0).getNodeProperties().getProperty("zkHost"));++ } finally {+ x.shutdown();+ }+ }finally {+ System.clearProperty("zkHost");+ }+ }++ private static void assertZkHost(final String msg, final String zkHost, final JettySolrRunner node) {+ assertEquals(zkHost, node.getCoreContainer().getNodeConfig().getCloudConfig().getZkHost());+ }}