You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2017/10/11 22:32:09 UTC

lucene-solr:master: SOLR-11456: Fix HealthCheckHandlerTest's bogus asserts and timing/order related flakiness

Repository: lucene-solr
Updated Branches:
  refs/heads/master 5e69a465e -> 8c39b37c5


SOLR-11456: Fix HealthCheckHandlerTest's bogus asserts and timing/order related flakiness


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/8c39b37c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/8c39b37c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/8c39b37c

Branch: refs/heads/master
Commit: 8c39b37c5ac7baa384fe9362924ce714edcb6f57
Parents: 5e69a46
Author: Chris Hostetter <ho...@apache.org>
Authored: Wed Oct 11 15:30:32 2017 -0700
Committer: Chris Hostetter <ho...@apache.org>
Committed: Wed Oct 11 15:30:32 2017 -0700

----------------------------------------------------------------------
 .../solr/cloud/HealthCheckHandlerTest.java      | 58 ++++++++++++++------
 1 file changed, 40 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8c39b37c/solr/core/src/test/org/apache/solr/cloud/HealthCheckHandlerTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/HealthCheckHandlerTest.java b/solr/core/src/test/org/apache/solr/cloud/HealthCheckHandlerTest.java
index 3baa181..975009c 100644
--- a/solr/core/src/test/org/apache/solr/cloud/HealthCheckHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/HealthCheckHandlerTest.java
@@ -18,7 +18,6 @@
 package org.apache.solr.cloud;
 
 import java.io.IOException;
-import java.util.Set;
 
 import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.SolrResponse;
@@ -31,7 +30,7 @@ import org.apache.solr.client.solrj.response.HealthCheckResponse;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.zookeeper.KeeperException;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -46,33 +45,55 @@ public class HealthCheckHandlerTest extends SolrCloudTestCase {
   }
 
   @Test
-  public void testHealthCheckHandler() throws IOException, SolrServerException, InterruptedException, KeeperException {
+  public void testHealthCheckHandler() throws Exception {
     SolrRequest req = new GenericSolrRequest(SolrRequest.METHOD.GET, HEALTH_CHECK_HANDLER_PATH, new ModifiableSolrParams());
+
+    // positive check that our only existing "healthy" node works with cloud client
+    // NOTE: this is using GenericSolrRequest, not HealthCheckRequest which is why it passes
+    // as compared with testHealthCheckHandlerWithCloudClient
+    // (Not sure if that's actaully a good thing -- but it's how the existing test worked)
+    assertEquals(CommonParams.OK,
+                 req.process(cluster.getSolrClient()).getResponse().get(CommonParams.STATUS));
+    
+    // positive check that our exiting "healthy" node works with direct http client
     try (HttpSolrClient httpSolrClient = getHttpSolrClient(cluster.getJettySolrRunner(0).getBaseUrl().toString())) {
-      SolrResponse response = req.process(cluster.getSolrClient());
+      SolrResponse response = req.process(httpSolrClient);
       assertEquals(CommonParams.OK, response.getResponse().get(CommonParams.STATUS));
+    }
 
-      JettySolrRunner jetty = cluster.getJettySolrRunner(0);
-      cluster.expireZkSession(jetty);
-      Set<String> live_nodes = cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes();
+    // add a new node for the purpose of negative testing
+    JettySolrRunner newJetty = cluster.startJettySolrRunner();
+    try (HttpSolrClient httpSolrClient = getHttpSolrClient(newJetty.getBaseUrl().toString())) {
+    
+      // postive check that our (new) "healthy" node works with direct http client
+      assertEquals(CommonParams.OK, req.process(httpSolrClient).getResponse().get(CommonParams.STATUS));
+                  
+      // now "break" our (new) node
+      newJetty.getCoreContainer().getZkController().getZkClient().close();
+      
+      // negative check of our (new) "broken" node that we deliberately put into an unhealth state
+      HttpSolrClient.RemoteSolrException e = expectThrows(HttpSolrClient.RemoteSolrException.class, () ->
+                                                          {
+                                                            req.process(httpSolrClient);
+                                                          });
+      assertTrue(e.getMessage(), e.getMessage().contains("Host Unavailable"));
+      assertEquals(SolrException.ErrorCode.SERVICE_UNAVAILABLE.code, e.code());
+    } finally {
+      newJetty.stop();
+    }
 
-      int counter = 0;
-      while (live_nodes.size() == 1 && counter++ < 100) {
-        Thread.sleep(100);
-        live_nodes = cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes();
-      }
+    // (redundent) positive check that our (previously) exiting "healthy" node (still) works
+    // after getting negative results from our broken node
+    try (HttpSolrClient httpSolrClient = getHttpSolrClient(cluster.getJettySolrRunner(0).getBaseUrl().toString())) {
 
-      try {
-        req.process(httpSolrClient);
-      } catch (HttpSolrClient.RemoteSolrException e) {
-        assertTrue(e.getMessage(), e.getMessage().contains("Host Unavailable"));
-        assertEquals(SolrException.ErrorCode.SERVICE_UNAVAILABLE.code, e.code());
-      }
+      assertEquals(CommonParams.OK, req.process(httpSolrClient).getResponse().get(CommonParams.STATUS));
     }
+    
   }
 
   @Test
   public void testHealthCheckHandlerSolrJ() throws IOException, SolrServerException {
+    // positive check of a HealthCheckRequest using http client
     HealthCheckRequest req = new HealthCheckRequest();
     try (HttpSolrClient httpSolrClient = getHttpSolrClient(cluster.getJettySolrRunner(0).getBaseUrl().toString())) {
       HealthCheckResponse rsp = req.process(httpSolrClient);
@@ -82,6 +103,7 @@ public class HealthCheckHandlerTest extends SolrCloudTestCase {
 
   @Test (expected = AssertionError.class)
   public void testHealthCheckHandlerWithCloudClient() throws IOException, SolrServerException {
+    // negative check of a HealthCheckRequest using cloud solr client
     HealthCheckRequest req = new HealthCheckRequest();
     req.process(cluster.getSolrClient());
   }