Apache Solr open-source search software
Fix TestSolrCLIRunExample Nightly Thread Leak (#1760)
Kevin Risdenfc852b34e909
diff --git a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.javaindex 2056451a0ab..22552c2a62a 100644--- a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java+++ b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java@@ -334,10 +334,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",@@ -350,13 +348,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",@@ -379,12 +373,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",@@ -403,29 +394,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 {