You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by kr...@apache.org on 2023/07/07 12:43:56 UTC

[solr] branch branch_9x updated: Fix TestSolrCLIRunExample Nightly Thread Leak (#1760)

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

krisden 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 0e150a6178c Fix TestSolrCLIRunExample Nightly Thread Leak (#1760)
0e150a6178c is described below

commit 0e150a6178cc79b9f8b4b1c6d9e45bf1a6d57f37
Author: Kevin Risden <ri...@users.noreply.github.com>
AuthorDate: Fri Jul 7 08:39:18 2023 -0400

    Fix TestSolrCLIRunExample Nightly Thread Leak (#1760)
    
    Co-authored-by: Houston Putman <ho...@apache.org>
---
 .../java/org/apache/solr/cli/RunExampleTool.java   | 57 +++++++++-------------
 1 file changed, 24 insertions(+), 33 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
index 5df4f7ff196..1e83a8226db 100644
--- a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
@@ -326,10 +326,8 @@ public class RunExampleTool extends ToolBase {
             "exampledocs directory not found, skipping indexing step for the techproducts example");
       }
     } else if ("films".equals(exampleName) && !alreadyExists) {
-      SolrClient solrClient = new Http2SolrClient.Builder(solrUrl).build();
-
-      echo("Adding dense vector field type to films schema \"_default\"");
-      try {
+      try (SolrClient solrClient = new Http2SolrClient.Builder(solrUrl).build()) {
+        echo("Adding dense vector field type to films schema \"_default\"");
         SolrCLI.postJsonToSolr(
             solrClient,
             "/" + collectionName + "/schema",
@@ -342,13 +340,9 @@ public class RunExampleTool extends ToolBase {
                 + "          \"knnAlgorithm\":hnsw\n"
                 + "        }\n"
                 + "      }");
-      } catch (Exception ex) {
-        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, ex);
-      }
 
-      echo(
-          "Adding name, initial_release_date, and film_vector fields to films schema \"_default\"");
-      try {
+        echo(
+            "Adding name, initial_release_date, and film_vector fields to films schema \"_default\"");
         SolrCLI.postJsonToSolr(
             solrClient,
             "/" + collectionName + "/schema",
@@ -371,12 +365,9 @@ public class RunExampleTool extends ToolBase {
                 + "          \"stored\":true\n"
                 + "        }\n"
                 + "      }");
-      } catch (Exception ex) {
-        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, ex);
-      }
 
-      echo("Adding paramsets \"algo\" and \"algo_b\" to films configuration for relevancy tuning");
-      try {
+        echo(
+            "Adding paramsets \"algo\" and \"algo_b\" to films configuration for relevancy tuning");
         SolrCLI.postJsonToSolr(
             solrClient,
             "/" + collectionName + "/config/params",
@@ -395,29 +386,29 @@ public class RunExampleTool extends ToolBase {
                 + "             }\n"
                 + "            }\n"
                 + "        }\n");
+
+        File filmsJsonFile = new File(exampleDir, "films/films.json");
+        String updateUrl = String.format(Locale.ROOT, "%s/%s/update/json", solrUrl, collectionName);
+        echo("Indexing films example docs from " + filmsJsonFile.getAbsolutePath());
+        String currentPropVal = System.getProperty("url");
+        System.setProperty("url", updateUrl);
+        SimplePostTool.main(new String[] {filmsJsonFile.getAbsolutePath()});
+        if (currentPropVal != null) {
+          System.setProperty("url", currentPropVal); // reset
+        } else {
+          System.clearProperty("url");
+        }
       } catch (Exception ex) {
         throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, ex);
       }
 
-      File filmsJsonFile = new File(exampleDir, "films/films.json");
-      String updateUrl = String.format(Locale.ROOT, "%s/%s/update/json", solrUrl, collectionName);
-      echo("Indexing films example docs from " + filmsJsonFile.getAbsolutePath());
-      String currentPropVal = System.getProperty("url");
-      System.setProperty("url", updateUrl);
-      SimplePostTool.main(new String[] {filmsJsonFile.getAbsolutePath()});
-      if (currentPropVal != null) {
-        System.setProperty("url", currentPropVal); // reset
-      } else {
-        System.clearProperty("url");
-      }
+      echo(
+          "\nSolr "
+              + exampleName
+              + " example launched successfully. Direct your Web browser to "
+              + solrUrl
+              + " to visit the Solr Admin UI");
     }
-
-    echo(
-        "\nSolr "
-            + exampleName
-            + " example launched successfully. Direct your Web browser to "
-            + solrUrl
-            + " to visit the Solr Admin UI");
   }
 
   protected void runCloudExample(CommandLine cli) throws Exception {