SOLR-7599: More clean up of duplicate methods, renamed some methods and variable names

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1682258 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2015-05-28 14:58:47 +00:00
parent c4acf28dd1
commit c6afa72f07
7 changed files with 34 additions and 64 deletions

View File

@ -1104,21 +1104,6 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
}
}
volatile CloudSolrClient commondCloudSolrClient;
protected CloudSolrClient getCommonCloudSolrClient() {
if (commondCloudSolrClient == null) {
synchronized(this) {
commondCloudSolrClient = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean());
commondCloudSolrClient.setParallelUpdates(random().nextBoolean());
commondCloudSolrClient.setDefaultCollection(DEFAULT_COLLECTION);
commondCloudSolrClient.getLbClient().setConnectionTimeout(15000);
commondCloudSolrClient.getLbClient().setSoTimeout(30000);
commondCloudSolrClient.connect();
}
}
return commondCloudSolrClient;
}
@Override
protected QueryResponse queryServer(ModifiableSolrParams params) throws SolrServerException, IOException {
@ -1135,9 +1120,6 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
@Override
public void distribTearDown() throws Exception {
super.distribTearDown();
if (commondCloudSolrClient != null) {
commondCloudSolrClient.close();
}
if (otherCollectionClients != null) {
for (List<SolrClient> clientList : otherCollectionClients.values()) {
IOUtils.close(clientList);

View File

@ -83,7 +83,7 @@ public class CollectionStateFormat2Test extends AbstractFullDistribZkTestBase {
client.request(request);
checkForMissingCollection(collectionName);
assertCollectionNotExists(collectionName, 45);
assertFalse("collection state should not exist externally", cloudClient.getZkStateReader().getZkClient().exists(ZkStateReader.getCollectionPath(collectionName), true));
}

View File

@ -208,7 +208,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
}
checkForMissingCollection(collectionName);
assertCollectionNotExists(collectionName, 45);
assertFalse(cloudClient.getZkStateReader().getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true));
@ -236,8 +236,8 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
request.setPath("/admin/collections");
makeRequest(baseUrl, request);
checkForMissingCollection(collectionName);
assertCollectionNotExists(collectionName, 45);
// now creating that collection should work
params = new ModifiableSolrParams();
@ -734,7 +734,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
makeRequest(baseUrl, request);
// ensure its out of the state
checkForMissingCollection(collectionName);
assertCollectionNotExists(collectionName, 45);
//collectionNameList.remove(collectionName);

View File

@ -72,7 +72,6 @@ import static org.apache.solr.common.params.ShardParams._ROUTE_;
@SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
private static final String DEFAULT_COLLECTION = "collection1";
private static final boolean DEBUG = false;
protected String getSolrXml() {

View File

@ -153,7 +153,7 @@ public class MigrateRouteKeyTest extends BasicDistributedZkTest {
Indexer indexer = new Indexer(cloudClient, splitKey, 1, 30);
indexer.start();
String url = CustomCollectionTest.getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), targetCollection);
String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), targetCollection);
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {

View File

@ -241,7 +241,7 @@ public class ShardSplitTest extends BasicDistributedZkTest {
waitForRecoveriesToFinish(false);
String url = CustomCollectionTest.getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
@ -315,7 +315,7 @@ public class ShardSplitTest extends BasicDistributedZkTest {
waitForRecoveriesToFinish(false);
String url = CustomCollectionTest.getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {

View File

@ -16,10 +16,6 @@ package org.apache.solr.cloud;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static org.apache.solr.cloud.OverseerCollectionProcessor.CREATE_NODE_SET;
import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;
import static org.apache.solr.cloud.OverseerCollectionProcessor.SHARDS_PROP;
import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
import java.io.File;
import java.io.IOException;
@ -83,6 +79,11 @@ import org.noggit.JSONWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.solr.cloud.OverseerCollectionProcessor.CREATE_NODE_SET;
import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;
import static org.apache.solr.cloud.OverseerCollectionProcessor.SHARDS_PROP;
import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
/**
* TODO: we should still test this works as a custom update chain as well as
* what we test now - the default update chain
@ -250,10 +251,8 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
CloudSolrClient client = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean());
client.setParallelUpdates(random().nextBoolean());
if (defaultCollection != null) client.setDefaultCollection(defaultCollection);
client.getLbClient().getHttpClient().getParams()
.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);
client.getLbClient().getHttpClient().getParams()
.setParameter(CoreConnectionPNames.SO_TIMEOUT, 60000);
client.getLbClient().setConnectionTimeout(30000);
client.getLbClient().setSoTimeout(60000);
return client;
}
@ -304,7 +303,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
initCloud();
createJettys(numServers).size();
createJettys(numServers);
int cnt = getTotalReplicas(DEFAULT_COLLECTION);
if (cnt > 0) {
@ -1507,8 +1506,8 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
if (VERBOSE || printLayoutOnTearDown) {
super.printLayout();
}
if (commondCloudSolrClient != null) {
commondCloudSolrClient.close();
if (commonCloudSolrClient != null) {
commonCloudSolrClient.close();
}
if (controlClient != null) {
controlClient.close();
@ -1733,20 +1732,24 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
}
private CloudSolrClient commondCloudSolrClient;
private CloudSolrClient commonCloudSolrClient;
protected CloudSolrClient getCommonCloudSolrClient() {
synchronized (this) {
if (commondCloudSolrClient == null) {
commondCloudSolrClient = new CloudSolrClient(zkServer.getZkAddress(),
random().nextBoolean());
commondCloudSolrClient.getLbClient().setConnectionTimeout(30000);
commondCloudSolrClient.setParallelUpdates(random().nextBoolean());
commondCloudSolrClient.setDefaultCollection(DEFAULT_COLLECTION);
commondCloudSolrClient.connect();
if (commonCloudSolrClient == null) {
boolean updatesToLeaders = random().nextBoolean();
boolean parallelUpdates = random().nextBoolean();
commonCloudSolrClient = new CloudSolrClient(zkServer.getZkAddress(),
updatesToLeaders);
commonCloudSolrClient.getLbClient().setConnectionTimeout(5000);
commonCloudSolrClient.getLbClient().setSoTimeout(120000);
commonCloudSolrClient.setParallelUpdates(parallelUpdates);
commonCloudSolrClient.setDefaultCollection(DEFAULT_COLLECTION);
commonCloudSolrClient.connect();
log.info("Created commonCloudSolrClient with updatesToLeaders={} and parallelUpdates={}", updatesToLeaders, parallelUpdates);
}
}
return commondCloudSolrClient;
return commonCloudSolrClient;
}
public static String getUrlFromZk(ClusterState clusterState, String collection) {
@ -1797,25 +1800,11 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
fail("Could not find the new collection - " + exp.code() + " : " + collectionClient.getBaseURL());
}
protected void checkForMissingCollection(String collectionName)
throws Exception {
// check for a collection - we poll the state
long timeoutAt = System.currentTimeMillis() + 45000;
boolean found = true;
while (System.currentTimeMillis() < timeoutAt) {
getCommonCloudSolrClient().getZkStateReader().updateClusterState(true);
ClusterState clusterState = getCommonCloudSolrClient().getZkStateReader().getClusterState();
if (!clusterState.hasCollection(collectionName)) {
found = false;
break;
}
Thread.sleep(100);
}
if (found) {
fail("Found collection that should be gone " + collectionName);
}
protected void assertCollectionNotExists(String collectionName, int timeoutSeconds) throws Exception {
waitForCollectionToDisappear(collectionName, getCommonCloudSolrClient().getZkStateReader(), false, true, timeoutSeconds);
}
protected NamedList<Object> invokeCollectionApi(String... args) throws SolrServerException, IOException {
ModifiableSolrParams params = new ModifiableSolrParams();
SolrRequest request = new QueryRequest(params);