This is an automated email from the ASF dual-hosted git repository.

hossman pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 532bd9d1dd2 SOLR-17478: Fix (test only) bug in ZkTestServer
532bd9d1dd2 is described below

commit 532bd9d1dd28fd69dfbfbc5e1021a360579d4785
Author: Chris Hostetter <[email protected]>
AuthorDate: Thu Nov 21 16:15:09 2024 -0700

    SOLR-17478: Fix (test only) bug in ZkTestServer
    
    (cherry picked from commit a4084e899e447a57c4050ce8db9a3aa91588cd02)
---
 .../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 d0f8f9e3995..3db7c03ab5e 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.DistributedUpdateProcessor.DistribPhase;
@@ -300,7 +299,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();
@@ -378,7 +376,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 14d2a5a1f86..479507b6f5e 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;
@@ -58,6 +61,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;
@@ -381,7 +385,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
@@ -535,6 +541,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) {
@@ -597,7 +605,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) {
@@ -869,4 +878,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));
+    }
+  }
 }

Reply via email to