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 2019/08/06 00:25:42 UTC

[lucene-solr] branch branch_8x updated: Fix incorrect assertions in RulesTest.doIntegrationTest

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

hossman pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new e8ff976  Fix incorrect assertions in RulesTest.doIntegrationTest
e8ff976 is described below

commit e8ff97669dc028ac382089219d3c6fdfaf9ae256
Author: Chris Hostetter <ho...@apache.org>
AuthorDate: Mon Aug 5 17:08:28 2019 -0700

    Fix incorrect assertions in RulesTest.doIntegrationTest
    
    my previous commit added waitForState calls to doIntegrationTest that forgot to take into account initial repFactor when createShard was called
    
    as a result, the test could only pass if wather was called after a initial leader went live, before other replicas became live
    
    this commit fixes this mistake, and hardens the assertions about the location of those replicas given the rule in use
    
    also adds new expecation that trying to add additional replicas that would violate rule will cause request ot fail
    
    (cherry picked from commit 9e250f7219a358e158229551e7c2a9eac2d7aea6)
---
 .../test/org/apache/solr/cloud/rule/RulesTest.java | 27 +++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/solr/core/src/test/org/apache/solr/cloud/rule/RulesTest.java b/solr/core/src/test/org/apache/solr/cloud/rule/RulesTest.java
index 61dba0a..afe6acd 100644
--- a/solr/core/src/test/org/apache/solr/cloud/rule/RulesTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/rule/RulesTest.java
@@ -19,8 +19,11 @@ package org.apache.solr.cloud.rule;
 import java.lang.invoke.MethodHandles;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Paths;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.solr.client.solrj.SolrClient;
@@ -74,6 +77,10 @@ public class RulesTest extends SolrCloudTestCase {
 
   @Test
   public void doIntegrationTest() throws Exception {
+    assertEquals("Sanity Check: someone changed the cluster; " +
+                 "test logic requires specific number of jetty nodes",
+                 5, cluster.getJettySolrRunners().size());
+    
     final long minGB = (random().nextBoolean() ? 1 : 0);
     assumeTrue("doIntegrationTest needs minGB="+minGB+" usable disk space",
         ImplicitSnitch.getUsableSpaceInGB(Paths.get("/")) > minGB);
@@ -107,6 +114,7 @@ public class RulesTest extends SolrCloudTestCase {
                    if (null == collection || 2 != collection.getSlices().size()) {
                      return false;
                    }
+                   final Set<String> replicaNodes = new HashSet<>();
                    for (Slice slice : collection.getSlices()) {
                      // short circut if our slice isn't active
                      if (Slice.State.ACTIVE != slice.getState()) {
@@ -119,20 +127,33 @@ public class RulesTest extends SolrCloudTestCase {
                        if (2 != liveReplicas.size()) {
                          return false;
                        }
+                       replicaNodes.addAll(liveReplicas.stream().map
+                                           (Replica::getNodeName).collect(Collectors.toList()));
                      } else if (slice.getName().equals("shard2")) {
-                       // for shard2, we should have 1 fully live replicas
+                       // for shard2, we should have 3 fully live replicas
                        final List<Replica> liveReplicas = slice.getReplicas
                          ((r) -> r.isActive(liveNodes));
-                       if (1 != liveReplicas.size()) {
+                       if (3 != liveReplicas.size()) {
                          return false;
                        }
+                       replicaNodes.addAll(liveReplicas.stream().map
+                                           (Replica::getNodeName).collect(Collectors.toList()));
                      } else {
                        // WTF?
                        return false;
                      }
                    }
-                   return true;
+                   // now sanity check that the rules were *obeyed* and
+                   // each replica is on a unique node
+                   return 5 == replicaNodes.size();
                  });
+
+    // adding an additional replica should fail since our rule says at most one replica
+    // per node, and we know every node already has one replica
+    expectedException.expect(HttpSolrClient.RemoteSolrException.class);
+    expectedException.expectMessage(containsString("current number of eligible live nodes 0"));
+    CollectionAdminRequest.addReplicaToShard(rulesColl, "shard2").process(cluster.getSolrClient());
+    
   }
 
   @Test