tests: don't start up default collection if numSlices<=0

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1423729 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2012-12-19 01:00:58 +00:00
parent 6086c66b64
commit 2b800b3c0e
3 changed files with 104 additions and 15 deletions

View File

@ -111,7 +111,9 @@ public class ChaosMonkeySafeLeaderTest extends AbstractFullDistribZkTestBase {
// try and wait for any replications and what not to finish...
waitForThingsToLevelOut(Integer.MAX_VALUE);//Math.round((runLength / 1000.0f / 3.0f)));
Thread.sleep(2000);
waitForThingsToLevelOut(Integer.MAX_VALUE); //Math.round((runLength / 1000.0f / 3.0f)));
checkShardConsistency(true, true);

View File

@ -0,0 +1,67 @@
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 org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.params.ShardParams;
import org.apache.solr.common.util.StrUtils;
import org.junit.BeforeClass;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ShardRoutingCustomTest extends AbstractFullDistribZkTestBase {
@BeforeClass
public static void beforeShardHashingTest() throws Exception {
useFactory(null);
}
public ShardRoutingCustomTest() {
schemaString = "schema15.xml"; // we need a string id
sliceCount = 0;
}
@Override
public void doTest() throws Exception {
boolean testFinished = false;
try {
doCustomSharding();
testFinished = true;
} finally {
if (!testFinished) {
printLayoutOnTearDown = true;
}
}
}
private void doCustomSharding() throws Exception {
printLayout();
}
}

View File

@ -97,6 +97,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
String invalidField = "ignore_exception__invalid_field_not_in_schema";
protected int sliceCount;
protected CloudSolrServer controlClientCloud; // cloud version of the control client
protected volatile CloudSolrServer cloudClient;
protected List<CloudJettyRunner> cloudJettys = new ArrayList<CloudJettyRunner>();
@ -173,7 +174,11 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
public void setUp() throws Exception {
super.setUp();
// ignoreException(".*");
if (sliceCount > 0) {
System.setProperty("numShards", Integer.toString(sliceCount));
} else {
System.clearProperty("numShards");
}
}
@BeforeClass
@ -230,7 +235,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
System.setProperty("collection", "control_collection");
String numShards = System.getProperty(ZkStateReader.NUM_SHARDS_PROP);
// we want hashes by default, so set to 1 shard as opposed to leaving unset
// we want hashes by default for the control, so set to 1 shard as opposed to leaving unset
// System.clearProperty(ZkStateReader.NUM_SHARDS_PROP);
System.setProperty(ZkStateReader.NUM_SHARDS_PROP, "1");
@ -247,27 +252,39 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
controlClient = createNewSolrServer(controlJetty.getLocalPort());
if (sliceCount <= 0) {
// for now, just create the cloud client for the control if we don't create the normal cloud client.
// this can change if more tests need it.
controlClientCloud = createCloudClient("control_collection");
controlClientCloud.connect();
waitForCollection(controlClientCloud.getZkStateReader(), "control_collection", 0);
// NOTE: we are skipping creation of the chaos monkey by returning here
return;
}
initCloud();
createJettys(numServers, true);
waitForCollection(cloudClient.getZkStateReader(), DEFAULT_COLLECTION, sliceCount);
}
protected void waitForCollection(ZkStateReader reader, String collection, int slices) throws Exception {
// wait until shards have started registering...
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
int cnt = 30;
while (!zkStateReader.getClusterState().getCollections()
.contains(DEFAULT_COLLECTION)) {
while (!reader.getClusterState().getCollections().contains(collection)) {
if (cnt == 0) {
throw new RuntimeException(
"timeout waiting for collection1 in cluster state");
throw new RuntimeException("timeout waiting for collection in cluster state: collection=" + collection);
}
cnt--;
Thread.sleep(500);
}
cnt = 30;
while (zkStateReader.getClusterState().getSlices(DEFAULT_COLLECTION).size() != sliceCount) {
while (reader.getClusterState().getSlices(collection).size() < slices) {
if (cnt == 0) {
throw new RuntimeException(
"timeout waiting for collection shards to come up");
throw new RuntimeException("timeout waiting for collection shards to come up: collection="+collection + "nSlices="+slices);
}
cnt--;
Thread.sleep(500);
@ -1242,6 +1259,9 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
if (cloudClient != null) {
cloudClient.shutdown();
}
if (controlClientCloud != null) {
controlClientCloud.shutdown();
}
super.tearDown();
System.clearProperty("zkHost");