lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gcha...@apache.org
Subject svn commit: r1653403 - in /lucene/dev/branches/branch_5x/solr: core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
Date Tue, 20 Jan 2015 23:21:09 GMT
Author: gchanan
Date: Tue Jan 20 23:21:09 2015
New Revision: 1653403

URL: http://svn.apache.org/r1653403
Log:
SOLR-6987: SSL support for MiniSolrCloudCluster

Added:
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java
  (with props)
Modified:
    lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java

Added: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java?rev=1653403&view=auto
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java
(added)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java
Tue Jan 20 23:21:09 2015
@@ -0,0 +1,90 @@
+package org.apache.solr.cloud;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.impl.HttpSolrClient;
+import org.apache.solr.client.solrj.request.CoreAdminRequest;
+import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Tests SSL (if test framework selects it) with MiniSolrCloudCluster.
+ * {@link TestMiniSolrCloudCluster} does not inherit from {@link SolrTestCaseJ4}
+ * so does not support SSL.
+ */
+public class TestMiniSolrCloudClusterSSL extends SolrTestCaseJ4 {
+
+  private static MiniSolrCloudCluster miniCluster;
+  private static final int NUM_SERVERS = 5;
+
+  @BeforeClass
+  public static void startup() throws Exception {
+    String testHome = SolrTestCaseJ4.TEST_HOME();
+    miniCluster = new MiniSolrCloudCluster(NUM_SERVERS, null, createTempDir().toFile(), new
File(testHome, "solr-no-core.xml"),
+      null, null, sslConfig);
+  }
+
+  @AfterClass
+  public static void shutdown() throws Exception {
+    if (miniCluster != null) {
+      miniCluster.shutdown();
+    }
+    miniCluster = null;
+  }
+
+  @Test
+  public void testMiniSolrCloudClusterSSL() throws Exception {
+    // test send request to each server
+    sendRequestToEachServer();
+
+    // shut down a server
+    JettySolrRunner stoppedServer = miniCluster.stopJettySolrRunner(0);
+    assertTrue(stoppedServer.isStopped());
+    assertEquals(NUM_SERVERS - 1, miniCluster.getJettySolrRunners().size());
+
+    // create a new server
+    JettySolrRunner startedServer = miniCluster.startJettySolrRunner(null, null, null, sslConfig);
+    assertTrue(startedServer.isRunning());
+    assertEquals(NUM_SERVERS, miniCluster.getJettySolrRunners().size());
+
+    // test send request to each server
+    sendRequestToEachServer();
+  }
+
+  private void sendRequestToEachServer() throws Exception {
+    List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
+    for (JettySolrRunner jetty : jettys) {
+      HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString());
+      try {
+        CoreAdminRequest req = new CoreAdminRequest();
+        req.setAction( CoreAdminAction.STATUS );
+        client.request(req);
+      } finally {
+        client.shutdown();
+      }
+    }
+  }
+}

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=1653403&r1=1653402&r2=1653403&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
Tue Jan 20 23:21:09 2015
@@ -27,6 +27,7 @@ import java.util.SortedMap;
 
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.embedded.SSLConfig;
 import org.apache.solr.client.solrj.impl.CloudSolrClient;
 import org.apache.solr.client.solrj.request.QueryRequest;
 import org.apache.solr.common.cloud.SolrZkClient;
@@ -60,6 +61,23 @@ public class MiniSolrCloudCluster {
   public MiniSolrCloudCluster(int numServers, String hostContext, File baseDir, File solrXml,
       SortedMap<ServletHolder, String> extraServlets,
       SortedMap<Class, String> extraRequestFilters) throws Exception {
+    this(numServers, hostContext, baseDir, solrXml, extraServlets, extraRequestFilters, null);
+  }
+
+  /**
+   * "Mini" SolrCloud cluster to be used for testing
+   * @param numServers number of Solr servers to start
+   * @param hostContext context path of Solr servers used by Jetty
+   * @param baseDir base directory that the mini cluster should be run from
+   * @param solrXml solr.xml file to be uploaded to ZooKeeper
+   * @param extraServlets Extra servlets to be started by Jetty
+   * @param extraRequestFilters extra filters to be started by Jetty
+   * @param sslConfig SSL configuration
+   */
+  public MiniSolrCloudCluster(int numServers, String hostContext, File baseDir, File solrXml,
+      SortedMap<ServletHolder, String> extraServlets,
+      SortedMap<Class, String> extraRequestFilters,
+      SSLConfig sslConfig) throws Exception {
     testDir = baseDir;
 
     String zkDir = testDir.getAbsolutePath() + File.separator
@@ -78,7 +96,11 @@ public class MiniSolrCloudCluster {
 
     jettys = new LinkedList<JettySolrRunner>();
     for (int i = 0; i < numServers; ++i) {
-      startJettySolrRunner(hostContext, extraServlets, extraRequestFilters);
+      if (sslConfig == null) {
+        startJettySolrRunner(hostContext, extraServlets, extraRequestFilters);
+      } else {
+        startJettySolrRunner(hostContext, extraServlets, extraRequestFilters, sslConfig);
+      }
     }
     
     solrClient = buildSolrClient();
@@ -108,9 +130,23 @@ public class MiniSolrCloudCluster {
   public JettySolrRunner startJettySolrRunner(String hostContext,
       SortedMap<ServletHolder, String> extraServlets,
       SortedMap<Class, String> extraRequestFilters) throws Exception {
+    return startJettySolrRunner(hostContext, extraServlets, extraRequestFilters, null);
+  }
+
+  /**
+   * Start a new Solr instance
+   * @param hostContext context path of Solr servers used by Jetty
+   * @param extraServlets Extra servlets to be started by Jetty
+   * @param extraRequestFilters extra filters to be started by Jetty
+   * @param sslConfig SSL configuration
+   * @return new Solr instance
+   */
+  public JettySolrRunner startJettySolrRunner(String hostContext,
+      SortedMap<ServletHolder, String> extraServlets,
+      SortedMap<Class, String> extraRequestFilters, SSLConfig sslConfig) throws Exception
{
     String context = getHostContextSuitableForServletContext(hostContext);
-    JettySolrRunner jetty = new JettySolrRunner(testDir.getAbsolutePath(), context, 0, null,
null,
-      true, extraServlets, null, extraRequestFilters);
+    JettySolrRunner jetty = new JettySolrRunner(testDir.getAbsolutePath(), context,
+      0, null, null, true, extraServlets, sslConfig, extraRequestFilters);
     jetty.start();
     jettys.add(jetty);
     return jetty;



Mime
View raw message