risdenk commented on code in PR #522:
URL: https://github.com/apache/solr/pull/522#discussion_r997605900


##########
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:
   Zookeeper is now on 3.8.0 so this should be possible.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to