You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by an...@apache.org on 2015/04/25 14:44:13 UTC

svn commit: r1676024 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/core/ solr/core/src/test/org/apache/solr/cloud/ solr/test-framework/ solr/test-framework/src/java/org/apache/solr/cloud/

Author: andyetitmoves
Date: Sat Apr 25 12:44:12 2015
New Revision: 1676024

URL: http://svn.apache.org/r1676024
Log:
SOLR-7081: TestMiniSolrCloudCluster.testBasics tidies up after itself, adds collection create/delete/create test case.

TestMiniSolrCloudCluster.testBasics now re-creates the server it removed for test purposes,
thus restoring the original NUM_SERVERS count. TestMiniSolrCloudCluster.testBasics now also deletes
the collection it created for test purposes (this revision adds MiniSolrCloudCluster.deleteCollection
and AbstractDistribZkTestBase.waitForCollectionToDisappear methods).

Sometimes TestMiniSolrCloudCluster.testBasics runs its create-collection/search-collection/delete-collection
logic twice, thus creating a create/delete/create-collection test case.

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java
    lucene/dev/branches/branch_5x/solr/test-framework/   (props changed)
    lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
    lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java

Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1676024&r1=1676023&r2=1676024&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Sat Apr 25 12:44:12 2015
@@ -163,6 +163,9 @@ Other Changes
 * SOLR-7421: RecoveryAfterSoftCommitTest fails frequently on Jenkins due to full index
   replication taking longer than 30 seconds. (Timothy Potter, shalin)
 
+* SOLR-7081: Add new test case to test if create/delete/re-create collections work.
+  (Christine Poerschke via Ramkumar Aiyengar)
+
 * SOLR-7467: Upgrade t-digest to 3.1 (hossman)
 
 * SOLR-7471: Stop requiring docValues for interval faceting (Tomás Fernández Löbbe)

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java?rev=1676024&r1=1676023&r2=1676024&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java Sat Apr 25 12:44:12 2015
@@ -74,6 +74,12 @@ public class TestMiniSolrCloudCluster ex
 
   @Test
   public void testBasics() throws Exception {
+    testCollectionCreateSearchDelete();
+    // sometimes run a second test e.g. to test collection create-delete-create scenario
+    if (random().nextBoolean()) testCollectionCreateSearchDelete();
+  }
+    
+  private void testCollectionCreateSearchDelete() throws Exception {
 
     File solrXml = new File(SolrTestCaseJ4.TEST_HOME(), "solr-no-core.xml");
     MiniSolrCloudCluster miniCluster = new MiniSolrCloudCluster(NUM_SERVERS, null, createTempDir().toFile(), solrXml, null, null);
@@ -114,8 +120,8 @@ public class TestMiniSolrCloudCluster ex
       miniCluster.createCollection(collectionName, NUM_SHARDS, REPLICATION_FACTOR, configName, collectionProperties);
 
       try (SolrZkClient zkClient = new SolrZkClient
-          (miniCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, 45000, null)) {
-        ZkStateReader zkStateReader = new ZkStateReader(zkClient);
+          (miniCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, 45000, null);
+          ZkStateReader zkStateReader = new ZkStateReader(zkClient)) {
         AbstractDistribZkTestBase.waitForRecoveriesToFinish(collectionName, zkStateReader, true, true, 330);
 
         // modify/query collection
@@ -155,6 +161,17 @@ public class TestMiniSolrCloudCluster ex
             assertEquals(NUM_SERVERS - 1, miniCluster.getJettySolrRunners().size());
           }
         }
+
+        // now restore the original state so that this function could be called multiple times
+        
+        // re-create a server (to restore original NUM_SERVERS count)
+        startedServer = miniCluster.startJettySolrRunner(null, null, null);
+        assertTrue(startedServer.isRunning());
+        assertEquals(NUM_SERVERS, miniCluster.getJettySolrRunners().size());
+
+        // delete the collection we created earlier
+        miniCluster.deleteCollection(collectionName);
+        AbstractDistribZkTestBase.waitForCollectionToDisappear(collectionName, zkStateReader, true, true, 330);
       }
     }
     finally {

Modified: lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java?rev=1676024&r1=1676023&r2=1676024&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java (original)
+++ lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java Sat Apr 25 12:44:12 2015
@@ -184,6 +184,37 @@ public abstract class AbstractDistribZkT
     log.info("Recoveries finished - collection: " + collection);
   }
 
+  public static void waitForCollectionToDisappear(String collection,
+      ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout, int timeoutSeconds)
+      throws Exception {
+    log.info("Wait for collection to disappear - collection: " + collection + " failOnTimeout:" + failOnTimeout + " timeout (sec):" + timeoutSeconds);
+    boolean cont = true;
+    int cnt = 0;
+    
+    while (cont) {
+      if (verbose) System.out.println("-");
+      zkStateReader.updateClusterState(true);
+      ClusterState clusterState = zkStateReader.getClusterState();
+      if (!clusterState.hasCollection(collection)) break;
+      if (cnt == timeoutSeconds) {
+        if (verbose) System.out.println("Gave up waiting for "+collection+" to disappear..");
+        if (failOnTimeout) {
+          Diagnostics.logThreadDumps("Gave up waiting for "+collection+" to disappear.  THREAD DUMP:");
+          zkStateReader.getZkClient().printLayoutToStdOut();
+          fail("The collection ("+collection+") is still present - waited for " + timeoutSeconds + " seconds");
+          // won't get here
+          return;
+        }
+        cont = false;
+      } else {
+        Thread.sleep(1000);
+      }
+      cnt++;
+    }
+
+    log.info("Collection has disappeared - collection: " + collection);
+  }
+  
   protected void assertAllActive(String collection,ZkStateReader zkStateReader)
       throws KeeperException, InterruptedException {
 

Modified: lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java?rev=1676024&r1=1676023&r2=1676024&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java (original)
+++ lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java Sat Apr 25 12:44:12 2015
@@ -284,7 +284,7 @@ public class MiniSolrCloudCluster {
   
   public NamedList<Object> createCollection(String name, int numShards, int replicationFactor, 
       String configName, Map<String, String> collectionProperties) throws SolrServerException, IOException {
-    ModifiableSolrParams params = new ModifiableSolrParams();
+    final ModifiableSolrParams params = new ModifiableSolrParams();
     params.set(CoreAdminParams.ACTION, CollectionAction.CREATE.name());
     params.set(CoreAdminParams.NAME, name);
     params.set("numShards", numShards);
@@ -296,7 +296,20 @@ public class MiniSolrCloudCluster {
       }
     }
     
-    QueryRequest request = new QueryRequest(params);
+    return makeCollectionsRequest(params);
+  }
+
+  public NamedList<Object> deleteCollection(String name) throws SolrServerException, IOException {
+    final ModifiableSolrParams params = new ModifiableSolrParams();
+    params.set(CoreAdminParams.ACTION, CollectionAction.DELETE.name());
+    params.set(CoreAdminParams.NAME, name);
+
+    return makeCollectionsRequest(params);
+  }
+
+  private NamedList<Object> makeCollectionsRequest(final ModifiableSolrParams params) throws SolrServerException, IOException {
+    
+    final QueryRequest request = new QueryRequest(params);
     request.setPath("/admin/collections");
     
     return solrClient.request(request);