You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2022/01/13 22:32:38 UTC

[GitHub] [solr] madrob commented on a change in pull request #522: SOLR-15415 Use Embedded ZK in Tests

madrob commented on a change in pull request #522:
URL: https://github.com/apache/solr/pull/522#discussion_r783303150



##########
File path: solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java
##########
@@ -164,13 +166,25 @@ public void randomConnectionLoss() throws KeeperException, InterruptedException
       connloss.incrementAndGet();
     }
   }
-  
+
   public static void causeConnectionLoss(JettySolrRunner jetty) {
     CoreContainer cores = jetty.getCoreContainer();
     if (cores != null) {
       monkeyLog("Will cause connection loss on " + jetty.getLocalPort());
       SolrZkClient zkClient = cores.getZkController().getZkClient();
-      zkClient.getSolrZooKeeper().closeCnxn();
+      causeConnectionLoss(zkClient.getSolrZooKeeper());
+    }
+  }
+
+  public static void causeConnectionLoss(ZooKeeper zooKeeper) {
+    if (zooKeeper instanceof TestableZooKeeper) {
+      try {
+        ((TestableZooKeeper) zooKeeper).testableConnloss();
+      } catch (IOException ignored) {
+        // best effort
+      }
+    } else {
+      // TODO?

Review comment:
       Should this have the old reflection code that we used in SolrZooKeeper?

##########
File path: solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java
##########
@@ -73,8 +74,8 @@ public boolean isLikelyExpired(long timeToExpire) {
     }
   }
 
-  public static abstract class IsClosed {
-    public abstract boolean isClosed();
+  public interface IsClosed {

Review comment:
       Public API Change.

##########
File path: solr/core/src/test-files/log4j2.xml
##########
@@ -30,6 +30,7 @@
   <Loggers>
     <!-- Use <AsyncLogger/<AsyncRoot and <Logger/<Root for asynchronous logging or synchonous logging respectively -->
     <Logger name="org.apache.zookeeper" level="WARN"/>
+    <Logger name="org.apache.zookeeper.PortAssignment" level="INFO"/>

Review comment:
       This will go away later.

##########
File path: solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java
##########
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.common.cloud;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.SocketAddress;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-import org.apache.solr.common.util.SuppressForbidden;
-import org.apache.zookeeper.ClientCnxn;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooKeeper;
-
-// we use this class to expose nasty stuff for tests
-@SuppressWarnings({"try"})
-public class SolrZooKeeper extends ZooKeeper {

Review comment:
       Public API Change.

##########
File path: solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java
##########
@@ -509,191 +438,67 @@ public void run() throws InterruptedException, IOException {
 
   public void run(boolean solrFormat) throws InterruptedException, IOException {
     log.info("STARTING ZK TEST SERVER");
-    AtomicReference<Throwable> zooError = new AtomicReference<>();
-    try {
-      if (zooThread != null) {
-        throw new IllegalStateException("ZK TEST SERVER IS ALREADY RUNNING");
-      }
-      Thread parentThread = Thread.currentThread();
-      // we don't call super.distribSetUp
-      zooThread = new Thread("ZkTestServer Run Thread") {
-
-        @Override
-        public void run() {
-          ServerConfig config = new ServerConfig() {
-
-            {
-              setClientPort(ZkTestServer.this.clientPort);
-              this.dataDir = zkDir.toFile();
-              this.dataLogDir = zkDir.toFile();
-              this.tickTime = theTickTime;
-              this.maxSessionTimeout = ZkTestServer.this.maxSessionTimeout;
-              this.minSessionTimeout = ZkTestServer.this.minSessionTimeout;
-            }
-
-            public void setClientPort(int clientPort) {
-              if (clientPortAddress != null) {
-                try {
-                  this.clientPortAddress = new InetSocketAddress(
-                      InetAddress.getByName(clientPortAddress.getHostName()), clientPort);
-                } catch (UnknownHostException e) {
-                  throw new RuntimeException(e);
-                }
-              } else {
-                this.clientPortAddress = new InetSocketAddress(clientPort);
-              }
-              log.info("client port: {}", this.clientPortAddress);
-            }
-          };
-          try {
-            zkServer.runFromConfig(config);
-          } catch (Throwable t) {
-            zooError.set(t);
-            parentThread.interrupt();
-          }
-        }
-      };
 
-      ObjectReleaseTracker.track(zooThread);
-      zooThread.start();
+    if (clientPort == 0) {
+      // Hacks to get PortAssignment to work with our test runner partitioning
+/*
+      String processCount = System.getProperty("tests.jvms", "1");
+      System.setProperty("test.junit.threads", processCount);
 
-      int cnt = 0;
-      int port = -1;
-      try {
-        port = getPort();
-      } catch (IllegalStateException ignored) {
-        // Possibly fix this API to return null instead of throwing
+      String cmdLine = System.getProperty("sun.java.command"); // worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 2'
+      System.getProperties().forEach((k,v) -> log.info("{}={}", k, v));
+      Matcher m = Pattern.compile("Executor (\\d+)").matcher(cmdLine);
+      if (m.find()) {
+        System.setProperty("zookeeper.junit.threadid", m.group(1));
       }
-      while (port < 1) {
-        Thread.sleep(100);
-        try {
-          port = getPort();
-        } catch (IllegalStateException ignored) {
-          // Possibly fix this API to return null instead of throwing
-        }
-        if (cnt == 500) {
-          throw new RuntimeException("Could not get the port for ZooKeeper server");
-        }
-        cnt++;
-      }
-      log.info("start zk server on port: {}", port);
+*/
+
+      clientPort = PortAssignment.unique();
+    }
 
-      waitForServerUp(getZkHost(), 30000);
+    Properties configuration = new Properties();
+    configuration.setProperty("clientPort", String.valueOf(clientPort));
+    configuration.setProperty("tickTime", String.valueOf(theTickTime));
+    configuration.setProperty("maxSessionTimeout", String.valueOf(maxSessionTimeout));
+    configuration.setProperty("minSessionTimeout", String.valueOf(minSessionTimeout));
+    configuration.setProperty("admin.enableServer", Boolean.FALSE.toString());
 
+    Files.createDirectories(zkDir);
+    try {
+      zkse = ZooKeeperServerEmbedded.builder()
+              .baseDir(zkDir)
+              .configuration(configuration)
+              .exitHandler(ExitHandler.LOG_ONLY)
+              .build();
+      zkse.start();

Review comment:
       This really needs ZOOKEEPER-4312.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org