You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2015/01/01 21:48:30 UTC
svn commit: r1648938 - in /lucene/dev/branches/branch_5x: ./ solr/
solr/core/ solr/core/src/java/org/apache/solr/core/
solr/core/src/test/org/apache/solr/cloud/
solr/core/src/test/org/apache/solr/core/ solr/test-framework/
solr/test-framework/src/java/...
Author: erick
Date: Thu Jan 1 20:48:29 2015
New Revision: 1648938
URL: http://svn.apache.org/r1648938
Log:
SOLR-6483, Refactor some methods in MiniSolrCloudCluster tests
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/java/org/apache/solr/core/RequestParams.java (props changed)
lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java
lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/core/BlobStoreTestRequestHandlerV2.java (props changed)
lucene/dev/branches/branch_5x/solr/test-framework/ (props changed)
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=1648938&r1=1648937&r2=1648938&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Thu Jan 1 20:48:29 2015
@@ -547,6 +547,9 @@ Other Changes
* SOLR-6895: SolrServer classes are renamed to *SolrClient. The existing
classes still exist, but are deprecated. (Alan Woodward, Erik Hatcher)
+* SOLR-6483: Refactor some methods in MiniSolrCloudCluster tests (Steve Davids via
+ Erick Erickson)
+
================== 4.10.3 ==================
Bug Fixes
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=1648938&r1=1648937&r2=1648938&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 Thu Jan 1 20:48:29 2015
@@ -32,10 +32,7 @@ import org.apache.solr.common.cloud.Repl
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkStateReader;
-import org.apache.solr.common.params.CollectionParams.CollectionAction;
-import org.apache.solr.common.params.CoreAdminParams;
-import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.util.RevertDefaultThreadHandlerRule;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -88,14 +85,6 @@ public class TestMiniSolrCloudCluster ex
miniCluster.shutdown();
}
miniCluster = null;
- System.clearProperty("solr.tests.mergePolicy");
- System.clearProperty("solr.tests.maxBufferedDocs");
- System.clearProperty("solr.tests.maxIndexingThreads");
- System.clearProperty("solr.tests.ramBufferSizeMB");
- System.clearProperty("solr.tests.mergeScheduler");
- System.clearProperty("solr.directoryFactory");
- System.clearProperty("solr.solrxml.location");
- System.clearProperty("zkHost");
}
@Test
@@ -117,28 +106,33 @@ public class TestMiniSolrCloudCluster ex
assertTrue(startedServer.isRunning());
assertEquals(NUM_SERVERS, miniCluster.getJettySolrRunners().size());
- CloudSolrClient cloudSolrClient = null;
- SolrZkClient zkClient = null;
- try {
- cloudSolrClient = new CloudSolrClient(miniCluster.getZkServer().getZkAddress(), true);
- cloudSolrClient.connect();
- zkClient = new SolrZkClient(miniCluster.getZkServer().getZkAddress(),
- AbstractZkTestCase.TIMEOUT, 45000, null);
-
- // create collection
- String collectionName = "testSolrCloudCollection";
- String configName = "solrCloudCollectionConfig";
- System.setProperty("solr.tests.mergePolicy", "org.apache.lucene.index.TieredMergePolicy");
- uploadConfigToZk(SolrTestCaseJ4.TEST_HOME() + File.separator + "collection1" + File.separator + "conf", configName);
- createCollection(cloudSolrClient, collectionName, NUM_SHARDS, REPLICATION_FACTOR, configName);
-
+ // create collection
+ String collectionName = "testSolrCloudCollection";
+ String configName = "solrCloudCollectionConfig";
+ File configDir = new File(SolrTestCaseJ4.TEST_HOME() + File.separator + "collection1" + File.separator + "conf");
+ miniCluster.uploadConfigDir(configDir, configName);
+
+ Map<String, String> collectionProperties = new HashMap<>();
+ collectionProperties.put(CoreDescriptor.CORE_CONFIG, "solrconfig-tlog.xml");
+ collectionProperties.put("solr.tests.maxBufferedDocs", "100000");
+ collectionProperties.put("solr.tests.maxIndexingThreads", "-1");
+ collectionProperties.put("solr.tests.ramBufferSizeMB", "100");
+ // use non-test classes so RandomizedRunner isn't necessary
+ collectionProperties.put("solr.tests.mergePolicy", "org.apache.lucene.index.TieredMergePolicy");
+ collectionProperties.put("solr.tests.mergeScheduler", "org.apache.lucene.index.ConcurrentMergeScheduler");
+ collectionProperties.put("solr.directoryFactory", "solr.RAMDirectoryFactory");
+ 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);
+ waitForRecoveriesToFinish(collectionName, zkStateReader, true, true, 330);
+
// modify/query collection
+ CloudSolrClient cloudSolrClient = miniCluster.getSolrClient();
cloudSolrClient.setDefaultCollection(collectionName);
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "1");
-
- ZkStateReader zkStateReader = new ZkStateReader(zkClient);
- waitForRecoveriesToFinish(collectionName, zkStateReader, true, true, 330);
cloudSolrClient.add(doc);
cloudSolrClient.commit();
SolrQuery query = new SolrQuery();
@@ -171,64 +165,9 @@ public class TestMiniSolrCloudCluster ex
assertEquals(NUM_SERVERS - 1, miniCluster.getJettySolrRunners().size());
}
}
- } finally {
- if (cloudSolrClient != null) {
- cloudSolrClient.shutdown();
- }
- if (zkClient != null) {
- zkClient.close();
- }
}
}
- protected void uploadConfigToZk(String configDir, String configName) throws Exception {
- // override settings in the solrconfig include
- System.setProperty("solr.tests.maxBufferedDocs", "100000");
- System.setProperty("solr.tests.maxIndexingThreads", "-1");
- System.setProperty("solr.tests.ramBufferSizeMB", "100");
- // use non-test classes so RandomizedRunner isn't necessary
- System.setProperty("solr.tests.mergeScheduler", "org.apache.lucene.index.ConcurrentMergeScheduler");
- System.setProperty("solr.directoryFactory", "solr.RAMDirectoryFactory");
-
- SolrZkClient zkClient = null;
- try {
- zkClient = new SolrZkClient(miniCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, 45000, null);
- uploadConfigFileToZk(zkClient, configName, "solrconfig.xml", new File(configDir, "solrconfig-tlog.xml"));
- uploadConfigFileToZk(zkClient, configName, "schema.xml", new File(configDir, "schema.xml"));
- uploadConfigFileToZk(zkClient, configName, "solrconfig.snippet.randomindexconfig.xml",
- new File(configDir, "solrconfig.snippet.randomindexconfig.xml"));
- uploadConfigFileToZk(zkClient, configName, "currency.xml", new File(configDir, "currency.xml"));
- uploadConfigFileToZk(zkClient, configName, "mapping-ISOLatin1Accent.txt",
- new File(configDir, "mapping-ISOLatin1Accent.txt"));
- uploadConfigFileToZk(zkClient, configName, "old_synonyms.txt", new File(configDir, "old_synonyms.txt"));
- uploadConfigFileToZk(zkClient, configName, "open-exchange-rates.json",
- new File(configDir, "open-exchange-rates.json"));
- uploadConfigFileToZk(zkClient, configName, "protwords.txt", new File(configDir, "protwords.txt"));
- uploadConfigFileToZk(zkClient, configName, "stopwords.txt", new File(configDir, "stopwords.txt"));
- uploadConfigFileToZk(zkClient, configName, "synonyms.txt", new File(configDir, "synonyms.txt"));
- } finally {
- if (zkClient != null) zkClient.close();
- }
- }
-
- protected void uploadConfigFileToZk(SolrZkClient zkClient, String configName, String nameInZk, File file)
- throws Exception {
- zkClient.makePath(ZkController.CONFIGS_ZKNODE + "/" + configName + "/" + nameInZk, file, false, true);
- }
-
- protected NamedList<Object> createCollection(CloudSolrClient client, String name, int numShards,
- int replicationFactor, String configName) throws Exception {
- ModifiableSolrParams modParams = new ModifiableSolrParams();
- modParams.set(CoreAdminParams.ACTION, CollectionAction.CREATE.name());
- modParams.set("name", name);
- modParams.set("numShards", numShards);
- modParams.set("replicationFactor", replicationFactor);
- modParams.set("collection.configName", configName);
- QueryRequest request = new QueryRequest(modParams);
- request.setPath("/admin/collections");
- return client.request(request);
- }
-
protected void waitForRecoveriesToFinish(String collection,
ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout, int timeoutSeconds)
throws Exception {
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=1648938&r1=1648937&r2=1648938&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 Thu Jan 1 20:48:29 2015
@@ -18,17 +18,23 @@ package org.apache.solr.cloud;
*/
import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
+import java.io.IOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.SortedMap;
-import org.apache.commons.io.IOUtils;
+import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
+import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.common.cloud.SolrZkClient;
-import org.apache.zookeeper.CreateMode;
+import org.apache.solr.common.params.CollectionParams.CollectionAction;
+import org.apache.solr.common.params.CoreAdminParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.zookeeper.KeeperException;
import org.eclipse.jetty.servlet.ServletHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,6 +46,7 @@ public class MiniSolrCloudCluster {
private ZkTestServer zkServer;
private List<JettySolrRunner> jettys;
private File testDir;
+ private CloudSolrClient solrClient;
/**
* "Mini" SolrCloud cluster to be used for testing
@@ -59,18 +66,10 @@ public class MiniSolrCloudCluster {
+ "zookeeper/server1/data";
zkServer = new ZkTestServer(zkDir);
zkServer.run();
-
- SolrZkClient zkClient = null;
- InputStream is = null;
- try {
- zkClient = new SolrZkClient(zkServer.getZkHost(),
- AbstractZkTestCase.TIMEOUT, 45000, null);
- zkClient.makePath("/solr", false, true);
- is = new FileInputStream(solrXml);
- zkClient.create("/solr/solr.xml", IOUtils.toByteArray(is), CreateMode.PERSISTENT, true);
- } finally {
- IOUtils.closeQuietly(is);
- if (zkClient != null) zkClient.close();
+
+ try(SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(),
+ AbstractZkTestCase.TIMEOUT, 45000, null)) {
+ zkClient.makePath("/solr/solr.xml", solrXml, false, true);
}
// tell solr to look in zookeeper for solr.xml
@@ -81,6 +80,8 @@ public class MiniSolrCloudCluster {
for (int i = 0; i < numServers; ++i) {
startJettySolrRunner(hostContext, extraServlets, extraRequestFilters);
}
+
+ solrClient = buildSolrClient();
}
/**
@@ -126,12 +127,40 @@ public class MiniSolrCloudCluster {
jettys.remove(index);
return jetty;
}
+
+ public void uploadConfigDir(File configDir, String configName) throws IOException, KeeperException, InterruptedException {
+ try(SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(),
+ AbstractZkTestCase.TIMEOUT, 45000, null)) {
+ ZkController.uploadConfigDir(zkClient, configDir, configName);
+ }
+ }
+
+ public NamedList<Object> createCollection(String name, int numShards, int replicationFactor,
+ String configName, Map<String, String> collectionProperties) throws SolrServerException, IOException {
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ params.set(CoreAdminParams.ACTION, CollectionAction.CREATE.name());
+ params.set(CoreAdminParams.NAME, name);
+ params.set("numShards", numShards);
+ params.set("replicationFactor", replicationFactor);
+ params.set("collection.configName", configName);
+ if(collectionProperties != null) {
+ for(Map.Entry<String, String> property : collectionProperties.entrySet()){
+ params.set(CoreAdminParams.PROPERTY_PREFIX + property.getKey(), property.getValue());
+ }
+ }
+
+ QueryRequest request = new QueryRequest(params);
+ request.setPath("/admin/collections");
+
+ return solrClient.request(request);
+ }
/**
* Shut down the cluster, including all Solr nodes and ZooKeeper
*/
public void shutdown() throws Exception {
try {
+ solrClient.shutdown();
for (int i = jettys.size() - 1; i >= 0; --i) {
stopJettySolrRunner(i);
}
@@ -144,6 +173,14 @@ public class MiniSolrCloudCluster {
}
}
}
+
+ public CloudSolrClient getSolrClient() {
+ return solrClient;
+ }
+
+ protected CloudSolrClient buildSolrClient() {
+ return new CloudSolrClient(getZkServer().getZkAddress());
+ }
private static String getHostContextSuitableForServletContext(String ctx) {
if (ctx == null || "".equals(ctx)) ctx = "/solr";
@@ -151,4 +188,4 @@ public class MiniSolrCloudCluster {
if (!ctx.startsWith("/")) ctx = "/" + ctx;
return ctx;
}
-}
\ No newline at end of file
+}