You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ho...@apache.org on 2022/09/23 21:17:57 UTC

[solr] branch branch_9x updated: Fix leaky threads in testCoreAdminRequestStatus

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

houston 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 6a0f1d0c953 Fix leaky threads in testCoreAdminRequestStatus
6a0f1d0c953 is described below

commit 6a0f1d0c95317c53c3e59790bf25106b9cde9676
Author: Houston Putman <ho...@apache.org>
AuthorDate: Fri Sep 23 17:12:48 2022 -0400

    Fix leaky threads in testCoreAdminRequestStatus
    
    The logic of the test was moved into a try/catch
    
    (cherry picked from commit 3aaffa86809604a3a4d4d0e0c79e819d7167fd5e)
---
 .../handler/admin/CoreAdminRequestStatusTest.java  | 102 +++++++++++----------
 1 file changed, 52 insertions(+), 50 deletions(-)

diff --git a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminRequestStatusTest.java b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminRequestStatusTest.java
index d210be05bcf..59b7fac53d4 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminRequestStatusTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminRequestStatusTest.java
@@ -44,68 +44,70 @@ public class CoreAdminRequestStatusTest extends SolrTestCaseJ4 {
 
     final CoreAdminHandler admin = new CoreAdminHandler(cores);
 
-    Path instDir;
-    try (SolrCore template = cores.getCore("collection1")) {
-      assertNotNull(template);
-      instDir = template.getCoreDescriptor().getInstanceDir();
-    }
+    try {
+      Path instDir;
+      try (SolrCore template = cores.getCore("collection1")) {
+        assertNotNull(template);
+        instDir = template.getCoreDescriptor().getInstanceDir();
+      }
+
+      assertTrue("instDir doesn't exist: " + instDir, Files.exists(instDir));
+      final File instPropFile = new File(workDir, "instProp");
+      FileUtils.copyDirectory(instDir.toFile(), instPropFile);
 
-    assertTrue("instDir doesn't exist: " + instDir, Files.exists(instDir));
-    final File instPropFile = new File(workDir, "instProp");
-    FileUtils.copyDirectory(instDir.toFile(), instPropFile);
+      // create a new core (using CoreAdminHandler) w/ properties
+
+      SolrQueryResponse resp = new SolrQueryResponse();
+      admin.handleRequestBody(
+          req(
+              CoreAdminParams.ACTION,
+              CoreAdminParams.CoreAdminAction.CREATE.toString(),
+              CoreAdminParams.INSTANCE_DIR,
+              instPropFile.getAbsolutePath(),
+              CoreAdminParams.NAME,
+              "dummycore",
+              CommonAdminParams.ASYNC,
+              "42"),
+          resp);
+      assertNull("Exception on create", resp.getException());
 
-    // create a new core (using CoreAdminHandler) w/ properties
+      int maxRetries = 10;
 
-    SolrQueryResponse resp = new SolrQueryResponse();
-    admin.handleRequestBody(
-        req(
-            CoreAdminParams.ACTION,
-            CoreAdminParams.CoreAdminAction.CREATE.toString(),
-            CoreAdminParams.INSTANCE_DIR,
-            instPropFile.getAbsolutePath(),
-            CoreAdminParams.NAME,
-            "dummycore",
-            CommonAdminParams.ASYNC,
-            "42"),
-        resp);
-    assertNull("Exception on create", resp.getException());
+      while (maxRetries-- > 0) {
+        resp = new SolrQueryResponse();
+        admin.handleRequestBody(
+            req(
+                CoreAdminParams.ACTION,
+                CoreAdminParams.CoreAdminAction.REQUESTSTATUS.toString(),
+                CoreAdminParams.REQUESTID,
+                "42"),
+            resp);
+        if (resp.getValues().get("STATUS") != null
+            && resp.getValues().get("STATUS").equals("completed")) break;
+        Thread.sleep(1000);
+      }
 
-    int maxRetries = 10;
+      assertEquals(
+          "The status of request was expected to be completed",
+          "completed",
+          resp.getValues().get("STATUS"));
 
-    while (maxRetries-- > 0) {
       resp = new SolrQueryResponse();
       admin.handleRequestBody(
           req(
               CoreAdminParams.ACTION,
               CoreAdminParams.CoreAdminAction.REQUESTSTATUS.toString(),
               CoreAdminParams.REQUESTID,
-              "42"),
+              "9999999"),
           resp);
-      if (resp.getValues().get("STATUS") != null
-          && resp.getValues().get("STATUS").equals("completed")) break;
-      Thread.sleep(1000);
-    }
-
-    assertEquals(
-        "The status of request was expected to be completed",
-        "completed",
-        resp.getValues().get("STATUS"));
 
-    resp = new SolrQueryResponse();
-    admin.handleRequestBody(
-        req(
-            CoreAdminParams.ACTION,
-            CoreAdminParams.CoreAdminAction.REQUESTSTATUS.toString(),
-            CoreAdminParams.REQUESTID,
-            "9999999"),
-        resp);
-
-    assertEquals(
-        "Was expecting it to be invalid but found a task with the id.",
-        "notfound",
-        resp.getValues().get("STATUS"));
-
-    admin.shutdown();
-    admin.close();
+      assertEquals(
+          "Was expecting it to be invalid but found a task with the id.",
+          "notfound",
+          resp.getValues().get("STATUS"));
+    } finally {
+      admin.shutdown();
+      admin.close();
+    }
   }
 }