lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cpoersc...@apache.org
Subject svn commit: r1719908 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java
Date Mon, 14 Dec 2015 13:35:30 GMT
Author: cpoerschke
Date: Mon Dec 14 13:35:30 2015
New Revision: 1719908

URL: http://svn.apache.org/viewvc?rev=1719908&view=rev
Log:
SOLR-8352: randomise unload order in UnloadDistributedZkTest.testUnloadShardAndCollection

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1719908&r1=1719907&r2=1719908&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Dec 14 13:35:30 2015
@@ -310,6 +310,8 @@ Other Changes
 
 * SOLR-8404: tweak SolrQueryResponse.getToLogAsString, add TestSolrQueryResponse.testToLog
(Christine Poerschke)
 
+* SOLR-8352: randomise unload order in UnloadDistributedZkTest.testUnloadShardAndCollection
(Christine Poerschke)
+
 ==================  5.4.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java?rev=1719908&r1=1719907&r2=1719908&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java
Mon Dec 14 13:35:30 2015
@@ -26,6 +26,8 @@ import org.apache.solr.client.solrj.impl
 import org.apache.solr.client.solrj.request.CoreAdminRequest.Create;
 import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload;
 import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.cloud.Replica;
+import org.apache.solr.common.cloud.Slice;
 import org.apache.solr.common.cloud.ZkCoreNodeProps;
 import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.params.ModifiableSolrParams;
@@ -38,6 +40,7 @@ import org.junit.Test;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Collection;
 import java.util.Random;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.ThreadPoolExecutor;
@@ -72,15 +75,51 @@ public class UnloadDistributedZkTest ext
     }
   }
 
+  private void checkCoreNamePresenceAndSliceCount(String collectionName, String coreName,
+      boolean shouldBePresent, int expectedSliceCount) throws Exception {
+    final TimeOut timeout = new TimeOut(45, TimeUnit.SECONDS);
+    Boolean isPresent = null; // null meaning "don't know"
+    while (null == isPresent || shouldBePresent != isPresent.booleanValue()) {
+      final Collection<Slice> slices = getCommonCloudSolrClient().getZkStateReader().getClusterState().getSlices(collectionName);
+      if (timeout.hasTimedOut()) {
+        printLayout();
+        fail("checkCoreNamePresenceAndSliceCount failed:"
+            +" collection="+collectionName+" CoreName="+coreName
+            +" shouldBePresent="+shouldBePresent+" isPresent="+isPresent
+            +" expectedSliceCount="+expectedSliceCount+" actualSliceCount="+slices.size());
+      }
+      if (expectedSliceCount == (slices == null ? 0 : slices.size())) {
+        isPresent = false;
+        if (slices != null) {
+          for (Slice slice : slices) {
+            for (Replica replica : slice.getReplicas()) {
+              if (coreName.equals(replica.get("core"))) {
+                isPresent = true;
+              }
+            }
+          }
+        }
+      }
+      Thread.sleep(1000);
+    }
+  }
+
   private void testUnloadShardAndCollection() throws Exception{
+
+    final int numShards = 2;
+
+    final String collection = "test_unload_shard_and_collection";
+
+    final String coreName1 = collection+"_1";
+    final String coreName2 = collection+"_2";
+
     // create one leader and one replica
     Create createCmd = new Create();
-    createCmd.setCoreName("test_unload_shard_and_collection_1");
-    String collection = "test_unload_shard_and_collection";
+    createCmd.setCoreName(coreName1);
     createCmd.setCollection(collection);
     String coreDataDir = createTempDir().toFile().getAbsolutePath();
     createCmd.setDataDir(getDataDir(coreDataDir));
-    createCmd.setNumShards(2);
+    createCmd.setNumShards(numShards);
     
     SolrClient client = clients.get(0);
     String url1 = getBaseUrl(client);
@@ -91,8 +130,7 @@ public class UnloadDistributedZkTest ext
       adminClient.request(createCmd);
 
       createCmd = new Create();
-      createCmd.setCoreName("test_unload_shard_and_collection_2");
-      collection = "test_unload_shard_and_collection";
+      createCmd.setCoreName(coreName2);
       createCmd.setCollection(collection);
       coreDataDir = createTempDir().toFile().getAbsolutePath();
       createCmd.setDataDir(getDataDir(coreDataDir));
@@ -102,28 +140,23 @@ public class UnloadDistributedZkTest ext
       // does not mean they are active and up yet :*
       waitForRecoveriesToFinish(collection, false);
 
+      final boolean unloadInOrder = random().nextBoolean();
+      final String unloadCmdCoreName1 = (unloadInOrder ? coreName1 : coreName2);
+      final String unloadCmdCoreName2 = (unloadInOrder ? coreName2 : coreName1);
+
       // now unload one of the two
       Unload unloadCmd = new Unload(false);
-      unloadCmd.setCoreName("test_unload_shard_and_collection_2");
+      unloadCmd.setCoreName(unloadCmdCoreName1);
       adminClient.request(unloadCmd);
 
       // there should be only one shard
-      int slices = getCommonCloudSolrClient().getZkStateReader().getClusterState().getSlices(collection).size();
-      final TimeOut timeout = new TimeOut(45, TimeUnit.SECONDS);
-      while (slices != 1) {
-        if (timeout.hasTimedOut()) {
-          printLayout();
-          fail("Expected to find only one slice in " + collection);
-        }
-
-        Thread.sleep(1000);
-        slices = getCommonCloudSolrClient().getZkStateReader().getClusterState().getSlices(collection).size();
-      }
+      checkCoreNamePresenceAndSliceCount(collection, unloadCmdCoreName1, false /* shouldBePresent
*/, numShards-1 /* expectedSliceCount */);
 
       // now unload one of the other
       unloadCmd = new Unload(false);
-      unloadCmd.setCoreName("test_unload_shard_and_collection_1");
+      unloadCmd.setCoreName(unloadCmdCoreName2);
       adminClient.request(unloadCmd);
+      checkCoreNamePresenceAndSliceCount(collection, unloadCmdCoreName2, false /* shouldBePresent
*/, numShards-2 /* expectedSliceCount */);
     }
 
     //printLayout();



Mime
View raw message