You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2016/06/30 16:57:21 UTC

lucene-solr:branch_6x: SOLR-8787: TestAuthenticationFramework should not extend TestMiniSolrCloudCluster (cherry picked from commit 6528dac)

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 1ce09b482 -> c7d82e7b3


SOLR-8787: TestAuthenticationFramework should not extend TestMiniSolrCloudCluster
(cherry picked from commit 6528dac)


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

Branch: refs/heads/branch_6x
Commit: c7d82e7b38676acffdb867514ebc3344c0b5faa9
Parents: 1ce09b4
Author: Shalin Shekhar Mangar <sh...@apache.org>
Authored: Thu Jun 30 19:50:17 2016 +0530
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Thu Jun 30 22:27:37 2016 +0530

----------------------------------------------------------------------
 solr/CHANGES.txt                                |   2 +
 .../solr/cloud/TestAuthenticationFramework.java | 151 ++++++++++++++++---
 2 files changed, 135 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c7d82e7b/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 7e230ab..f384b2e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -92,6 +92,8 @@ Other Changes
 * SOLR-9076: Update to Hadoop 2.7.2
   (Mark Miller, Gregory Chanan)
 
+* SOLR-8787: TestAuthenticationFramework should not extend TestMiniSolrCloudCluster. (Trey Cahill via shalin)
+
 ==================  6.1.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c7d82e7b/solr/core/src/test/org/apache/solr/cloud/TestAuthenticationFramework.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestAuthenticationFramework.java b/solr/core/src/test/org/apache/solr/cloud/TestAuthenticationFramework.java
index b9c7264..339ad75 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestAuthenticationFramework.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestAuthenticationFramework.java
@@ -16,27 +16,46 @@
  */
 package org.apache.solr.cloud;
 
+import java.io.File;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import javax.servlet.FilterChain;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.util.Map;
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.protocol.HttpContext;
+import org.apache.lucene.index.TieredMergePolicy;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.embedded.JettyConfig;
+import org.apache.solr.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
 import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.response.RequestStatusState;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.index.TieredMergePolicyFactory;
 import org.apache.solr.security.AuthenticationPlugin;
 import org.apache.solr.security.HttpClientInterceptorPlugin;
 import org.apache.solr.util.RevertDefaultThreadHandlerRule;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
@@ -45,20 +64,19 @@ import org.junit.rules.TestRule;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+
 /**
  * Test of the MiniSolrCloudCluster functionality with authentication enabled.
  */
 @LuceneTestCase.Slow
 @SuppressSysoutChecks(bugUrl = "Solr logs to JUL")
-public class TestAuthenticationFramework extends TestMiniSolrCloudCluster {
+public class TestAuthenticationFramework extends LuceneTestCase {
   
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-  
-  public TestAuthenticationFramework () {
-    NUM_SERVERS = 5;
-    NUM_SHARDS = 2;
-    REPLICATION_FACTOR = 2;
-  }
+  private int NUM_SERVERS = 5;
+  private int NUM_SHARDS = 2;
+  private int REPLICATION_FACTOR = 2;
   
   static String requestUsername = MockAuthenticationPlugin.expectedUsername;
   static String requestPassword = MockAuthenticationPlugin.expectedPassword;
@@ -72,7 +90,7 @@ public class TestAuthenticationFramework extends TestMiniSolrCloudCluster {
       new SystemPropertiesRestoreRule()).around(
       new RevertDefaultThreadHandlerRule());
 
-  @Override
+  @Before
   public void setUp() throws Exception {
     setupAuthenticationPlugin();
     super.setUp();
@@ -82,21 +100,22 @@ public class TestAuthenticationFramework extends TestMiniSolrCloudCluster {
     System.setProperty("authenticationPlugin", "org.apache.solr.cloud.TestAuthenticationFramework$MockAuthenticationPlugin");
     MockAuthenticationPlugin.expectedUsername = null;
     MockAuthenticationPlugin.expectedPassword = null;
-
   }
   
   @Test
   public void testBasics() throws Exception {
 
+    MiniSolrCloudCluster miniCluster = createMiniSolrCloudCluster();
+
     // Should pass
-    testCollectionCreateSearchDelete();
+    collectionCreateSearchDelete(miniCluster);
 
     MockAuthenticationPlugin.expectedUsername = "solr";
     MockAuthenticationPlugin.expectedPassword = "s0lrRocks";
     
     // Should fail with 401
     try {
-      testCollectionCreateSearchDelete();
+      collectionCreateSearchDelete(miniCluster);
       fail("Should've returned a 401 error");
     } catch (Exception ex) {
       if (!ex.getMessage().contains("Error 401")) {
@@ -106,18 +125,113 @@ public class TestAuthenticationFramework extends TestMiniSolrCloudCluster {
       MockAuthenticationPlugin.expectedUsername = null;
       MockAuthenticationPlugin.expectedPassword = null;
     }
+
+    miniCluster.shutdown();
   }
 
-  @Override
+  @After
   public void tearDown() throws Exception {
     System.clearProperty("authenticationPlugin");
     super.tearDown();
   }
-  
+
+  private MiniSolrCloudCluster createMiniSolrCloudCluster() throws Exception {
+    JettyConfig.Builder jettyConfig = JettyConfig.builder();
+    jettyConfig.waitForLoadingCoresToFinish(null);
+    return new MiniSolrCloudCluster(NUM_SERVERS, createTempDir(), jettyConfig.build());
+  }
+
+  private void createCollection(MiniSolrCloudCluster miniCluster, String collectionName, String asyncId)
+      throws Exception {
+    String configName = "solrCloudCollectionConfig";
+    File configDir = new File(SolrTestCaseJ4.TEST_HOME() + File.separator + "collection1" + File.separator + "conf");
+    miniCluster.uploadConfigDir(configDir, configName);
+
+    final boolean persistIndex = random().nextBoolean();
+    Map<String, String>  collectionProperties = new HashMap<>();
+
+    collectionProperties.putIfAbsent(CoreDescriptor.CORE_CONFIG, "solrconfig-tlog.xml");
+    collectionProperties.putIfAbsent("solr.tests.maxBufferedDocs", "100000");
+    collectionProperties.putIfAbsent("solr.tests.ramBufferSizeMB", "100");
+    // use non-test classes so RandomizedRunner isn't necessary
+    if (random().nextBoolean()) {
+      collectionProperties.putIfAbsent(SolrTestCaseJ4.SYSTEM_PROPERTY_SOLR_TESTS_MERGEPOLICY, TieredMergePolicy.class.getName());
+      collectionProperties.putIfAbsent(SolrTestCaseJ4.SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICY, "true");
+      collectionProperties.putIfAbsent(SolrTestCaseJ4.SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICYFACTORY, "false");
+    } else {
+      collectionProperties.putIfAbsent(SolrTestCaseJ4.SYSTEM_PROPERTY_SOLR_TESTS_MERGEPOLICYFACTORY, TieredMergePolicyFactory.class.getName());
+      collectionProperties.putIfAbsent(SolrTestCaseJ4.SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICYFACTORY, "true");
+      collectionProperties.putIfAbsent(SolrTestCaseJ4.SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICY, "false");
+    }
+    collectionProperties.putIfAbsent("solr.tests.mergeScheduler", "org.apache.lucene.index.ConcurrentMergeScheduler");
+    collectionProperties.putIfAbsent("solr.directoryFactory", (persistIndex ? "solr.StandardDirectoryFactory" : "solr.RAMDirectoryFactory"));
+
+    miniCluster.createCollection(collectionName, NUM_SHARDS, REPLICATION_FACTOR, configName, null, asyncId, collectionProperties);
+  }
+
+  public void collectionCreateSearchDelete(MiniSolrCloudCluster miniCluster) throws Exception {
+
+    final String collectionName = "testcollection";
+
+    final CloudSolrClient cloudSolrClient = miniCluster.getSolrClient();
+
+    assertNotNull(miniCluster.getZkServer());
+    List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
+    assertEquals(NUM_SERVERS, jettys.size());
+    for (JettySolrRunner jetty : jettys) {
+      assertTrue(jetty.isRunning());
+    }
+
+    // create collection
+    log.info("#### Creating a collection");
+    final String asyncId = (random().nextBoolean() ? null : "asyncId("+collectionName+".create)="+random().nextInt());
+    createCollection(miniCluster, collectionName, asyncId);
+    if (asyncId != null) {
+      final RequestStatusState state = AbstractFullDistribZkTestBase.getRequestStateAfterCompletion(asyncId, 330,
+          cloudSolrClient);
+      assertSame("did not see async createCollection completion", RequestStatusState.COMPLETED, state);
+    }
+
+    ZkStateReader zkStateReader = miniCluster.getSolrClient().getZkStateReader();
+    AbstractDistribZkTestBase.waitForRecoveriesToFinish(collectionName, zkStateReader, true, true, 330);
+
+    // modify/query collection
+    log.info("#### updating a querying collection");
+    cloudSolrClient.setDefaultCollection(collectionName);
+    SolrInputDocument doc = new SolrInputDocument();
+    doc.setField("id", "1");
+    cloudSolrClient.add(doc);
+    cloudSolrClient.commit();
+    SolrQuery query = new SolrQuery();
+    query.setQuery("*:*");
+    QueryResponse rsp = cloudSolrClient.query(query);
+    assertEquals(1, rsp.getResults().getNumFound());
+
+    // delete the collection we created earlier
+    miniCluster.deleteCollection(collectionName);
+    AbstractDistribZkTestBase.waitForCollectionToDisappear(collectionName, zkStateReader, true, true, 330);
+
+    // create it again
+    String asyncId2 = (random().nextBoolean() ? null : "asyncId("+collectionName+".create)="+random().nextInt());
+    createCollection(miniCluster, collectionName, asyncId2);
+    if (asyncId2 != null) {
+      final RequestStatusState state = AbstractFullDistribZkTestBase.getRequestStateAfterCompletion(asyncId2, 330,
+          cloudSolrClient);
+      assertSame("did not see async createCollection completion", RequestStatusState.COMPLETED, state);
+    }
+    AbstractDistribZkTestBase.waitForRecoveriesToFinish(collectionName, zkStateReader, true, true, 330);
+
+    // check that there's no left-over state
+    assertEquals(0, cloudSolrClient.query(new SolrQuery("*:*")).getResults().getNumFound());
+    cloudSolrClient.add(doc);
+    cloudSolrClient.commit();
+    assertEquals(1, cloudSolrClient.query(new SolrQuery("*:*")).getResults().getNumFound());
+  }
+
   public static class MockAuthenticationPlugin extends AuthenticationPlugin implements HttpClientInterceptorPlugin {
     public static String expectedUsername;
     public static String expectedPassword;
-
+    private HttpRequestInterceptor interceptor;
     @Override
     public void init(Map<String,Object> pluginConfig) {}
 
@@ -161,5 +275,6 @@ public class TestAuthenticationFramework extends TestMiniSolrCloudCluster {
         });
       }
     }
+    
   }
 }