You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ep...@apache.org on 2025/05/29 16:51:09 UTC

(solr) branch main updated: SOLR-17772: Tests for examples failing on Windows (#3378)

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

epugh 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 e714925a32a SOLR-17772: Tests for examples failing on Windows (#3378)
e714925a32a is described below

commit e714925a32a5146f274c267cc3265aa13be51372
Author: Rahul Goswami <ra...@gmail.com>
AuthorDate: Thu May 29 12:51:02 2025 -0400

    SOLR-17772: Tests for examples failing on Windows (#3378)
    
    * tests for examples failing on Windows
    
    * simplify CLI tests
    
    * CHANGES.txt
    
    * move entry to 10.0 instead of 9.9 in CHANGES.txt
---
 solr/CHANGES.txt                                   |   3 +-
 .../org/apache/solr/cli/TestSolrCLIRunExample.java | 137 ++++++++++-----------
 2 files changed, 66 insertions(+), 74 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5b5e1247882..7cf56b84a49 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -56,7 +56,8 @@ Optimizations
 
 Bug Fixes
 ---------------------
-(No changes)
+* SOLR-17772: Tests for CLI examples were failing on Windows due to a legacy bug uncovered by fix in SOLR-7962. 
+  Additionally achieves simplification of CLI tests (Rahul Goswami via Eric Pugh)
 
 Deprecation Removals
 ----------------------
diff --git a/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java b/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java
index 90219220371..98f98456d7e 100644
--- a/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java
+++ b/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java
@@ -98,94 +98,85 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
 
     @Override
     public int execute(org.apache.commons.exec.CommandLine cmd) throws IOException {
+      String exe = cmd.getExecutable();
+      assert (exe.endsWith("solr") || exe.endsWith("solr.cmd"));
+
       // collect the commands as they are executed for analysis by the test
       commandsExecuted.add(cmd);
 
-      String exe = cmd.getExecutable();
-      if (exe.endsWith("solr")) {
-        String[] args = cmd.getArguments();
-        if ("start".equals(args[0])) {
-          if (hasFlag("--user-managed", args)) {
-            return startStandaloneSolr(args);
-          }
+      String[] args = cmd.getArguments();
+      if ("start".equals(args[0])) {
+        if (hasFlag("--user-managed", args)) {
+          return startStandaloneSolr(args);
+        }
 
-          String solrHomeDir = getArg("--solr-home", args);
-          int port = Integer.parseInt(getArg("-p", args));
-          Path solrXmlPath = Path.of(solrHomeDir).resolve("solr.xml");
-          if (!Files.exists(solrXmlPath)) {
-            String solrServerDir = getArg("--server-dir", args);
-            solrXmlPath = Path.of(solrServerDir).resolve("solr").resolve("solr.xml");
+        String solrHomeDir = getArg("--solr-home", args);
+        int port = Integer.parseInt(getArg("-p", args));
+        Path solrXmlPath = Path.of(solrHomeDir).resolve("solr.xml");
+        if (!Files.exists(solrXmlPath)) {
+          String solrServerDir = getArg("--server-dir", args);
+          solrXmlPath = Path.of(solrServerDir).resolve("solr").resolve("solr.xml");
+        }
+        String solrxml = Files.readString(solrXmlPath, Charset.defaultCharset());
+
+        JettyConfig jettyConfig = JettyConfig.builder().setPort(port).build();
+        try {
+          if (solrCloudCluster == null) {
+            Path logDir = createTempDir("solr_logs");
+            System.setProperty("solr.log.dir", logDir.toString());
+            System.setProperty("host", "localhost");
+            System.setProperty("jetty.port", String.valueOf(port));
+            solrCloudCluster = new MiniSolrCloudCluster(1, createTempDir(), solrxml, jettyConfig);
+          } else {
+            // another member of this cluster -- not supported yet, due to how
+            // MiniSolrCloudCluster works
+            throw new IllegalArgumentException(
+                "Only launching one SolrCloud node is supported by this test!");
           }
-          String solrxml = Files.readString(solrXmlPath, Charset.defaultCharset());
-
-          JettyConfig jettyConfig = JettyConfig.builder().setPort(port).build();
-          try {
-            if (solrCloudCluster == null) {
-              Path logDir = createTempDir("solr_logs");
-              System.setProperty("solr.log.dir", logDir.toString());
-              System.setProperty("host", "localhost");
-              System.setProperty("jetty.port", String.valueOf(port));
-              solrCloudCluster = new MiniSolrCloudCluster(1, createTempDir(), solrxml, jettyConfig);
-            } else {
-              // another member of this cluster -- not supported yet, due to how
-              // MiniSolrCloudCluster works
-              throw new IllegalArgumentException(
-                  "Only launching one SolrCloud node is supported by this test!");
-            }
-          } catch (Exception e) {
-            if (e instanceof RuntimeException) {
-              throw (RuntimeException) e;
-            } else {
-              throw new RuntimeException(e);
-            }
+        } catch (Exception e) {
+          if (e instanceof RuntimeException) {
+            throw (RuntimeException) e;
+          } else {
+            throw new RuntimeException(e);
           }
-        } else if ("stop".equals(args[0])) {
+        }
+      } else if ("stop".equals(args[0])) {
 
-          int port = Integer.parseInt(getArg("-p", args));
+        int port = Integer.parseInt(getArg("-p", args));
 
-          // stop the requested node
-          if (standaloneSolr != null) {
-            int localPort = standaloneSolr.getLocalPort();
-            if (port == localPort) {
-              try {
-                standaloneSolr.stop();
-                log.info("Stopped standalone Solr instance running on port {}", port);
-              } catch (Exception e) {
-                if (e instanceof RuntimeException) {
-                  throw (RuntimeException) e;
-                } else {
-                  throw new RuntimeException(e);
-                }
+        // stop the requested node
+        if (standaloneSolr != null) {
+          int localPort = standaloneSolr.getLocalPort();
+          if (port == localPort) {
+            try {
+              standaloneSolr.stop();
+              log.info("Stopped standalone Solr instance running on port {}", port);
+            } catch (Exception e) {
+              if (e instanceof RuntimeException) {
+                throw (RuntimeException) e;
+              } else {
+                throw new RuntimeException(e);
               }
-            } else {
-              throw new IllegalArgumentException("No Solr is running on port " + port);
             }
           } else {
-            if (solrCloudCluster != null) {
-              try {
-                solrCloudCluster.shutdown();
-                log.info("Stopped SolrCloud test cluster");
-              } catch (Exception e) {
-                if (e instanceof RuntimeException) {
-                  throw (RuntimeException) e;
-                } else {
-                  throw new RuntimeException(e);
-                }
+            throw new IllegalArgumentException("No Solr is running on port " + port);
+          }
+        } else {
+          if (solrCloudCluster != null) {
+            try {
+              solrCloudCluster.shutdown();
+              log.info("Stopped SolrCloud test cluster");
+            } catch (Exception e) {
+              if (e instanceof RuntimeException) {
+                throw (RuntimeException) e;
+              } else {
+                throw new RuntimeException(e);
               }
-            } else {
-              throw new IllegalArgumentException("No Solr nodes found to stop!");
             }
+          } else {
+            throw new IllegalArgumentException("No Solr nodes found to stop!");
           }
         }
-      } else {
-        String cmdLine = joinArgs(cmd.getArguments());
-        log.info("Executing command: {}", cmdLine);
-        try {
-          return super.execute(cmd);
-        } catch (Exception exc) {
-          log.error("Execute command [{}] failed due to: {}", cmdLine, exc, exc);
-          throw exc;
-        }
       }
 
       return 0;