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

houston 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 c57345b  SOLR-15870: Fix TestCollectionAPI HTTP error
c57345b is described below

commit c57345b1293ba1a623a53415e4adc93104d99e9c
Author: Houston Putman <[email protected]>
AuthorDate: Mon Feb 28 10:52:20 2022 -0500

    SOLR-15870: Fix TestCollectionAPI HTTP error
    
    The error occured because the test was using a single client
    to issue Admin commands before and after a server was restarted.
    The HTTP Client caches connections, and didn't evict the expired
    connection to the server after it restarted. SolrJ does not attempt to
    retry Admin calls, therefore the test failed whenever the stale
    connection was used.
---
 .../cloud/api/collections/TestCollectionAPI.java   | 33 ++++++++++++----------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git 
a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java
 
b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java
index 32598ee..c9b8294 100644
--- 
a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java
+++ 
b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java
@@ -366,21 +366,24 @@ public class TestCollectionAPI extends 
ReplicaPropertiesBase {
 
       // bring them up again
       jetty.start();
-      SolrCloudManager cloudManager = new SolrClientCloudManager(null, client);
-      zkStateReader.waitForLiveNodes(30, TimeUnit.SECONDS, (o, n) -> n != null 
&& n.contains(nodeName));
-      CloudUtil.waitForState(cloudManager, COLLECTION_NAME, 30, 
TimeUnit.SECONDS, (liveNodes, coll) ->
-        coll != null &&
-            coll.getReplicas().stream()
-                .allMatch(r -> r.getState().equals(Replica.State.ACTIVE)));
-      rsp = request.process(client).getResponse();
-      collection = (Map<String, Object>) Utils.getObjectByPath(rsp, false, 
"cluster/collections/" + COLLECTION_NAME);
-      assertEquals("collection health", "GREEN", collection.get("health"));
-      shardStatus = (Map<String, Object>) collection.get("shards");
-      assertEquals(2, shardStatus.size());
-      health = (String) Utils.getObjectByPath(shardStatus, false, 
"shard1/health");
-      assertEquals("shard1 health", "GREEN", health);
-      health = (String) Utils.getObjectByPath(shardStatus, false, 
"shard2/health");
-      assertEquals("shard2 health", "GREEN", health);
+      // Need to start a new client, in case the http connections in the old 
client are still cached to the restarted server.
+      // If this is the case, it will throw an HTTP Exception, and we don't 
retry Admin requests.
+      try (CloudSolrClient newClient = createCloudClient(null)) {
+        newClient.getZkStateReader().waitForLiveNodes(30, TimeUnit.SECONDS, 
(o, n) -> n != null && n.contains(nodeName));
+        newClient.getZkStateReader().waitForState(COLLECTION_NAME, 30, 
TimeUnit.SECONDS, (liveNodes, coll) ->
+            coll != null &&
+                coll.getReplicas().stream()
+                    .allMatch(r -> r.getState().equals(Replica.State.ACTIVE)));
+        rsp = request.process(newClient).getResponse();
+        collection = (Map<String, Object>) Utils.getObjectByPath(rsp, false, 
"cluster/collections/" + COLLECTION_NAME);
+        assertEquals("collection health", "GREEN", collection.get("health"));
+        shardStatus = (Map<String, Object>) collection.get("shards");
+        assertEquals(2, shardStatus.size());
+        health = (String) Utils.getObjectByPath(shardStatus, false, 
"shard1/health");
+        assertEquals("shard1 health", "GREEN", health);
+        health = (String) Utils.getObjectByPath(shardStatus, false, 
"shard2/health");
+        assertEquals("shard2 health", "GREEN", health);
+      }
     }
   }
 

Reply via email to