This is an automated email from the ASF dual-hosted git repository.
hossman pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new a4084e899e4 SOLR-17478: Fix (test only) bug in ZkTestServer
a4084e899e4 is described below
commit a4084e899e447a57c4050ce8db9a3aa91588cd02
Author: Chris Hostetter <[email protected]>
AuthorDate: Thu Nov 21 16:15:09 2024 -0700
SOLR-17478: Fix (test only) bug in ZkTestServer
---
.../src/java/org/apache/solr/SolrTestCaseJ4.java | 3 --
.../java/org/apache/solr/cloud/ZkTestServer.java | 42 ++++++++++++++++++++--
2 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index 03388397050..d7d67f05ef1 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -17,7 +17,6 @@
package org.apache.solr;
import static java.util.Objects.requireNonNull;
-import static org.apache.solr.cloud.SolrZkServer.ZK_WHITELIST_PROPERTY;
import static org.apache.solr.common.cloud.ZkStateReader.HTTPS;
import static org.apache.solr.common.cloud.ZkStateReader.URL_SCHEME;
import static
org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM;
@@ -292,7 +291,6 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
System.setProperty("solr.filterCache.async",
String.valueOf(random().nextBoolean()));
System.setProperty("solr.http.disableCookies", Boolean.toString(rarely()));
- System.setProperty(ZK_WHITELIST_PROPERTY, "*");
startTrackingSearchers();
ignoreException("ignore_exception");
newRandomConfig();
@@ -340,7 +338,6 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
System.clearProperty(URL_SCHEME);
System.clearProperty("solr.cloud.wait-for-updates-with-stale-state-pause");
System.clearProperty("solr.zkclienttmeout");
- System.clearProperty(ZK_WHITELIST_PROPERTY);
HttpClientUtil.resetHttpClientBuilder();
Http2SolrClient.resetSslContextFactory();
diff --git
a/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java
b/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java
index 2041760c0d4..b18f255e8bf 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java
@@ -16,6 +16,9 @@
*/
package org.apache.solr.cloud;
+import static org.apache.solr.cloud.SolrZkServer.ZK_WHITELIST_PROPERTY;
+import static org.junit.Assert.assertTrue;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -57,6 +60,7 @@ import org.apache.zookeeper.server.ServerCnxnFactory;
import org.apache.zookeeper.server.ServerConfig;
import org.apache.zookeeper.server.ZKDatabase;
import org.apache.zookeeper.server.ZooKeeperServer;
+import org.apache.zookeeper.server.command.FourLetterCommands;
import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
import org.apache.zookeeper.test.ClientBase;
@@ -380,7 +384,9 @@ public class ZkTestServer {
try {
int port = cnxnFactory.getLocalPort();
if (port > 0) {
- ClientBase.waitForServerDown(getZkHost(), 30000);
+ assertTrue(
+ "ZK Server did not go down when expected",
+ ClientBase.waitForServerDown(getZkHost(), 30000));
}
} catch (NullPointerException ignored) {
// server never successfully started
@@ -534,6 +540,8 @@ public class ZkTestServer {
public void run(boolean solrFormat) throws InterruptedException, IOException
{
log.info("STARTING ZK TEST SERVER");
+ ensureStatCommandWhitelisted();
+
AtomicReference<Throwable> zooError = new AtomicReference<>();
try {
if (zooThread != null) {
@@ -596,7 +604,8 @@ public class ZkTestServer {
}
log.info("start zk server on port: {}", port);
- ClientBase.waitForServerUp(getZkHost(), 30000);
+ assertTrue(
+ "ZK Server did not go up when expected",
ClientBase.waitForServerUp(getZkHost(), 30000));
init(solrFormat);
} catch (Exception e) {
@@ -852,4 +861,33 @@ public class ZkTestServer {
public SolrZkClient getZkClient() {
return chRootClient;
}
+
+ /** Ensure the {@link ClientBase} helper methods we want to use will work. */
+ private static void ensureStatCommandWhitelisted() {
+ // Use this instead of hardcoding "stat" so we get compile error if ZK
removes the command
+ final String stat =
FourLetterCommands.getCommandString(FourLetterCommands.statCmd);
+ if (!FourLetterCommands.isEnabled(stat)) {
+ final String original = System.getProperty(ZK_WHITELIST_PROPERTY);
+ try {
+ log.error(
+ "ZkTestServer requires the 'stat' command, temporarily
manipulating your whitelist");
+ System.setProperty(ZK_WHITELIST_PROPERTY, "*");
+ FourLetterCommands.resetWhiteList();
+ // This call to isEnabled should force ZK to "re-read" the system
property in it's static
+ // vrs
+ assertTrue(
+ "Temporary manipulation of ZK Whitelist didn't work?",
+ FourLetterCommands.isEnabled(stat));
+ } finally {
+ if (null == original) {
+ System.clearProperty(ZK_WHITELIST_PROPERTY);
+ } else {
+ System.setProperty(ZK_WHITELIST_PROPERTY, original);
+ }
+ }
+ assertTrue(
+ "Temporary manipulation of ZK Whitelist didn't survive re-setting
original value, ZK 4LW init logic has broken this class",
+ FourLetterCommands.isEnabled(stat));
+ }
+ }
}