SOLR-5883: Many tests do not shutdown SolrServer.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1579336 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2014-03-19 18:25:00 +00:00
parent f946c7dd6a
commit 1109c1275b
23 changed files with 194 additions and 86 deletions

View File

@ -243,6 +243,9 @@ Other Changes
* SOLR-5881: Upgrade ZooKeeper to 3.4.6 (Shawn Heisey)
* SOLR-5883: Many tests do not shutdown SolrServer.
(Tomás Fernández Löbbe via Mark Miller)
================== 4.7.1 ==================
Versions of Major Components

View File

@ -79,6 +79,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
SolrDocument doc = results.get(0);
assertEquals("1", doc.getFieldValue("id"));
assertEquals("Hello C1", ((List)doc.getFieldValue("desc")).get(0));
solrServer.shutdown();
}
@Test
@ -100,6 +101,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
qres = solrServer.query(queryAll);
results = qres.getResults();
if (2 == results.getNumFound()) {
solrServer.shutdown();
return;
}
Thread.sleep(500);

View File

@ -658,6 +658,7 @@ public class MorphlineGoLiveMiniMRTest extends AbstractFullDistribZkTestBase {
+ new ZkCoreNodeProps(replica).getCoreUrl(), found, count);
}
found = count;
client.shutdown();
}
}
}

View File

@ -125,6 +125,7 @@ public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 {
@After
public void tearDown() throws Exception {
collector = null;
solrServer.shutdown();
solrServer = null;
super.tearDown();
}

View File

@ -23,6 +23,7 @@ import java.util.List;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
@ -30,13 +31,11 @@ import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.CollectionParams.CollectionAction;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@ -141,6 +140,8 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
HttpSolrServer server = new HttpSolrServer(buildUrl(port) + "/testalias");
res = server.query(query);
assertEquals(3, res.getResults().getNumFound());
server.shutdown();
server = null;
// now without collections param
query = new SolrQuery("*:*");
@ -149,6 +150,8 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
server = new HttpSolrServer(buildUrl(port) + "/testalias");
res = server.query(query);
assertEquals(3, res.getResults().getNumFound());
server.shutdown();
server = null;
// create alias, collection2 first because it's not on every node
createAlias("testalias", "collection2,collection1");
@ -177,6 +180,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
res = server.query(query);
assertEquals(5, res.getResults().getNumFound());
// now without collections param
query = new SolrQuery("*:*");
jetty = jettys.get(random().nextInt(jettys.size()));
@ -184,6 +188,8 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
server = new HttpSolrServer(buildUrl(port) + "/testalias");
res = server.query(query);
assertEquals(5, res.getResults().getNumFound());
server.shutdown();
server = null;
// update alias
createAlias("testalias", "collection2");
@ -210,6 +216,8 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
HttpSolrServer client = new HttpSolrServer(getBaseUrl((HttpSolrServer) clients.get(0)) + "/testalias");
res = client.query(query);
assertEquals(5, res.getResults().getNumFound());
client.shutdown();
client = null;
createAlias("testalias", "collection2");
@ -223,6 +231,8 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
client.commit();
res = client.query(query);
assertEquals(3, res.getResults().getNumFound());
client.shutdown();
client = null;
createAlias("testalias", "collection2,collection1");
@ -245,6 +255,8 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
private void createAlias(String alias, String collections)
throws SolrServerException, IOException {
SolrServer server = createNewSolrServer("",
getBaseUrl((HttpSolrServer) clients.get(0)));
if (random().nextBoolean()) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("collections", collections);
@ -252,29 +264,28 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
params.set("action", CollectionAction.CREATEALIAS.toString());
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> result = createNewSolrServer("",
getBaseUrl((HttpSolrServer) clients.get(0))).request(request);
server.request(request);
} else {
CollectionAdminResponse resp = CollectionAdminRequest.CreateAlias
.createAlias(alias, collections, createNewSolrServer("",
getBaseUrl((HttpSolrServer) clients.get(0))));
CollectionAdminRequest.CreateAlias.createAlias(alias, collections, server);
}
server.shutdown();
}
private void deleteAlias(String alias) throws SolrServerException,
IOException {
SolrServer server = createNewSolrServer("",
getBaseUrl((HttpSolrServer) clients.get(0)));
if (random().nextBoolean()) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("name", alias);
params.set("action", CollectionAction.DELETEALIAS.toString());
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> result = createNewSolrServer("",
getBaseUrl((HttpSolrServer) clients.get(0))).request(request);
server.request(request);
} else {
CollectionAdminResponse resp = CollectionAdminRequest.deleteAlias(alias,
createNewSolrServer("", getBaseUrl((HttpSolrServer) clients.get(0))));
CollectionAdminRequest.deleteAlias(alias,server);
}
server.shutdown();
}
protected void indexDoc(List<CloudJettyRunner> skipServers, Object... fields) throws IOException,

View File

@ -732,6 +732,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
// poll for a second - it can take a moment before we are ready to serve
waitForNon403or404or503(collectionClient);
collectionClient.shutdown();
}
// sometimes we restart one of the jetty nodes
@ -751,6 +752,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
// poll for a second - it can take a moment before we are ready to serve
waitForNon403or404or503(collectionClient);
collectionClient.shutdown();
}
}
@ -813,6 +815,8 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
collectionClient.commit();
assertEquals(3, collectionClient.query(new SolrQuery("*:*")).getResults().getNumFound());
collectionClient.shutdown();
collectionClient = null;
// lets try a collection reload
@ -894,6 +898,8 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
// poll for a second - it can take a moment before we are ready to serve
waitForNon403or404or503(collectionClient);
collectionClient.shutdown();
collectionClient = null;
for (int j = 0; j < cnt; j++) {
waitForRecoveriesToFinish(collectionName, zkStateReader, false);

View File

@ -199,6 +199,7 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
// poll for a second - it can take a moment before we are ready to serve
waitForNon403or404or503(collectionClient);
collectionClient.shutdown();
}
ZkStateReader zkStateReader = getCommonCloudSolrServer().getZkStateReader();
for (int j = 0; j < cnt; j++) {
@ -320,7 +321,8 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
url = getUrlFromZk(getCommonCloudSolrServer().getZkStateReader().getClusterState(), collectionName);
collectionClient.shutdown();
collectionClient = new HttpSolrServer(url);
// poll for a second - it can take a moment before we are ready to serve
@ -328,7 +330,7 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
collectionClient.shutdown();
collectionClient = new HttpSolrServer(url);
@ -349,8 +351,7 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
assertEquals(0, collectionClient.query(new SolrQuery("*:*").setParam(_ROUTE_,"b")).getResults().getNumFound());
//TODO debug the following case
assertEquals(3, collectionClient.query(new SolrQuery("*:*").setParam(_ROUTE_, "a")).getResults().getNumFound());
collectionClient.shutdown();
}
private void testRouteFieldForHashRouter()throws Exception{
@ -386,6 +387,7 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
// poll for a second - it can take a moment before we are ready to serve
waitForNon403or404or503(collectionClient);
collectionClient.shutdown();
collectionClient = new HttpSolrServer(url);
@ -414,7 +416,7 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
collectionClient.add (getDoc( id,100,shard_fld, "b!doc1"));
collectionClient.commit();
assertEquals(1, collectionClient.query(new SolrQuery("*:*").setParam(_ROUTE_, "b!")).getResults().getNumFound());
collectionClient.shutdown();
}
private void testCreateShardRepFactor() throws Exception {

View File

@ -23,6 +23,7 @@ import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
import java.net.URL;
import java.util.Map;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
@ -36,7 +37,6 @@ import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.util.NamedList;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
//@Ignore("Not currently valid see SOLR-5580")
public class DeleteInactiveReplicaTest extends DeleteReplicaTest{
@ -131,10 +131,12 @@ public class DeleteInactiveReplicaTest extends DeleteReplicaTest{
Map m = makeMap("qt", "/admin/cores", "action", "status");
NamedList<Object> resp = new HttpSolrServer(replica1.getStr(ZkStateReader.BASE_URL_PROP))
.request(new QueryRequest(new MapSolrParams(m)));
SolrServer server = new HttpSolrServer(replica1.getStr(ZkStateReader.BASE_URL_PROP));
NamedList<Object> resp = server.request(new QueryRequest(new MapSolrParams(m)));
assertNull("The core is up and running again",
((NamedList) resp.get("status")).get(replica1.getStr("core")));
server.shutdown();
server = null;
Exception exp = null;

View File

@ -140,6 +140,7 @@ public class DeleteShardTest extends AbstractFullDistribZkTestBase {
baseServer.setConnectionTimeout(15000);
baseServer.setSoTimeout(60000);
baseServer.request(request);
baseServer.shutdown();
}
protected void setSliceAsInactive(String slice) throws SolrServerException, IOException,

View File

@ -214,6 +214,8 @@ public class MigrateRouteKeyTest extends BasicDistributedZkTest {
QueryResponse response = collectionClient.query(solrQuery);
log.info("Response from target collection: " + response);
assertEquals("DocCount on target collection does not match", splitKeyCount[0], response.getResults().getNumFound());
collectionClient.shutdown();
collectionClient = null;
getCommonCloudSolrServer().getZkStateReader().updateClusterState(true);
ClusterState state = getCommonCloudSolrServer().getZkStateReader().getClusterState();

View File

@ -314,6 +314,7 @@ public class ShardSplitTest extends BasicDistributedZkTest {
assertEquals(docCounts[0], collectionClient.query(new SolrQuery("*:*").setParam("shards", "shard1_0")).getResults().getNumFound());
assertEquals(docCounts[1], collectionClient.query(new SolrQuery("*:*").setParam("shards", "shard1_1")).getResults().getNumFound());
collectionClient.shutdown();
}
private void splitByRouteKeyTest() throws Exception {
@ -404,6 +405,7 @@ public class ShardSplitTest extends BasicDistributedZkTest {
assertEquals("shard1_0 must have 0 docs for route key: " + splitKey, 0, collectionClient.query(solrQuery.setParam("shards", "shard1_0")).getResults().getNumFound());
assertEquals("Wrong number of docs on shard1_1 for route key: " + splitKey, splitKeyDocCount, collectionClient.query(solrQuery.setParam("shards", "shard1_1")).getResults().getNumFound());
assertEquals("shard1_2 must have 0 docs for route key: " + splitKey, 0, collectionClient.query(solrQuery.setParam("shards", "shard1_2")).getResults().getNumFound());
collectionClient.shutdown();
}
protected void checkDocCountsAndShardStates(int[] docCounts, int numReplicas) throws Exception {
@ -523,6 +525,7 @@ public class ShardSplitTest extends BasicDistributedZkTest {
baseServer.setConnectionTimeout(15000);
baseServer.setSoTimeout(60000 * 5);
baseServer.request(request);
baseServer.shutdown();
}
protected void indexAndUpdateCount(DocRouter router, List<DocRouter.Range> ranges, int[] docCounts, String id, int n) throws Exception {

View File

@ -137,6 +137,8 @@ public class SyncSliceTest extends AbstractFullDistribZkTestBase {
// we only set the connect timeout, not so timeout
baseServer.setConnectionTimeout(30000);
baseServer.request(request);
baseServer.shutdown();
baseServer = null;
waitForThingsToLevelOut(15);

View File

@ -136,6 +136,8 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
unloadCmd = new Unload(false);
unloadCmd.setCoreName("test_unload_shard_and_collection_1");
server.request(unloadCmd);
server.shutdown();
server = null;
//printLayout();
// the collection should be gone
@ -169,6 +171,8 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
String core1DataDir = dataDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection1" + "_1n";
createCmd.setDataDir(getDataDir(core1DataDir));
server.request(createCmd);
server.shutdown();
server = null;
ZkStateReader zkStateReader = getCommonCloudSolrServer().getZkStateReader();
@ -187,6 +191,8 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
String core2dataDir = dataDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection1" + "_2n";
createCmd.setDataDir(getDataDir(core2dataDir));
server.request(createCmd);
server.shutdown();
server = null;
zkStateReader.updateClusterState(true);
slices = zkStateReader.getClusterState().getCollection("unloadcollection").getSlices().size();
@ -212,6 +218,8 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
collectionClient.add(doc2);
collectionClient.add(doc3);
collectionClient.commit();
collectionClient.shutdown();
collectionClient = null;
}
// create another replica for our collection
@ -225,6 +233,9 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
String core3dataDir = dataDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection" + "_3n";
createCmd.setDataDir(getDataDir(core3dataDir));
server.request(createCmd);
server.shutdown();
server = null;
waitForRecoveriesToFinish("unloadcollection", zkStateReader, false);
@ -240,6 +251,8 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
"humpty dumpy sat on a wall");
addClient.add(doc1);
}
addClient.shutdown();
addClient = null;
// don't commit so they remain in the tran log
//collectionClient.commit();
@ -254,6 +267,8 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
ModifiableSolrParams p = (ModifiableSolrParams) unloadCmd.getParams();
collectionClient.request(unloadCmd);
collectionClient.shutdown();
collectionClient = null;
// Thread.currentThread().sleep(500);
// printLayout();
@ -279,6 +294,8 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
"humpty dumpy sat on a wall");
addClient.add(doc1);
}
addClient.shutdown();
addClient = null;
// create another replica for our collection
@ -294,6 +311,8 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
String core4dataDir = dataDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection" + "_4n";
createCmd.setDataDir(getDataDir(core4dataDir));
server.request(createCmd);
server.shutdown();
server = null;
waitForRecoveriesToFinish("unloadcollection", zkStateReader, false);
@ -307,6 +326,8 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
unloadCmd.setCoreName(leaderProps.getCoreName());
p = (ModifiableSolrParams) unloadCmd.getParams();
collectionClient.request(unloadCmd);
collectionClient.shutdown();
collectionClient = null;
tries = 50;
while (leaderProps.getCoreUrl().equals(zkStateReader.getLeaderUrl("unloadcollection", "shard1", 15000))) {
@ -332,6 +353,8 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
createCmd.setCollection("unloadcollection");
createCmd.setDataDir(getDataDir(core1DataDir));
server.request(createCmd);
server.shutdown();
server = null;
waitForRecoveriesToFinish("unloadcollection", zkStateReader, false);
@ -342,6 +365,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
SolrQuery q = new SolrQuery("*:*");
q.set("distrib", false);
long found1 = server.query(q).getResults().getNumFound();
server.shutdown();
server = new HttpSolrServer(url3 + "/unloadcollection");
server.setConnectionTimeout(15000);
server.setSoTimeout(30000);
@ -349,6 +373,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
q = new SolrQuery("*:*");
q.set("distrib", false);
long found3 = server.query(q).getResults().getNumFound();
server.shutdown();
server = new HttpSolrServer(url4 + "/unloadcollection");
server.setConnectionTimeout(15000);
server.setSoTimeout(30000);
@ -360,6 +385,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
// all 3 shards should now have the same number of docs
assertEquals(found1, found3);
assertEquals(found3, found4);
server.shutdown();
}
@ -402,6 +428,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
}
executor.shutdown();
executor.awaitTermination(120, TimeUnit.SECONDS);
server.shutdown();
}

View File

@ -32,6 +32,7 @@ import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.LuceneTestCase.BadApple;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.UpdateRequest;
@ -95,6 +96,14 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
public void tearDownServer() throws Exception {
if (jetty != null) jetty.stop();
FileUtils.deleteDirectory(solrHomeDirectory);
for(SolrServer server:indexingServers) {
server.shutdown();
}
for(SolrServer server:queryServers) {
server.shutdown();
}
indexingServers.clear();
queryServers.clear();
}
@Test

View File

@ -28,11 +28,11 @@ import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
import java.util.Date;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -52,16 +52,16 @@ import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.CachingDirectoryFactory;
@ -74,7 +74,6 @@ import org.apache.solr.util.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
/**
@ -143,6 +142,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
slave.tearDown();
masterJetty = slaveJetty = null;
master = slave = null;
masterClient.shutdown();
slaveClient.shutdown();
masterClient = slaveClient = null;
}
@ -344,6 +345,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
try {
if (repeater != null) repeater.tearDown();
} catch (Exception e) { /* :NOOP: */ }
if (repeaterClient != null) repeaterClient.shutdown();
}
}
@ -536,6 +538,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
masterJetty.stop();
masterJetty = createJetty(master);
masterClient.shutdown();
masterClient = createNewSolrServer(masterJetty.getLocalPort());
slave.setTestPort(masterJetty.getLocalPort());
@ -554,6 +557,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
assertFalse(slaveXsltDir.exists());
slaveJetty = createJetty(slave);
slaveClient.shutdown();
slaveClient = createNewSolrServer(slaveJetty.getLocalPort());
//add a doc with new field and commit on master to trigger snappull from slave.
@ -631,6 +635,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
slave.copyConfigFile(CONF_DIR + "solrconfig-slave1.xml", "solrconfig.xml");
slaveJetty.stop();
slaveJetty = createJetty(slave);
slaveClient.shutdown();
slaveClient = createNewSolrServer(slaveJetty.getLocalPort());
masterClient.deleteByQuery("*:*");
@ -778,12 +783,14 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
slave.copyConfigFile(CONF_DIR +slaveSchema, "schema.xml");
slaveJetty.stop();
slaveJetty = createJetty(slave);
slaveClient.shutdown();
slaveClient = createNewSolrServer(slaveJetty.getLocalPort());
master.copyConfigFile(CONF_DIR + "solrconfig-master3.xml",
"solrconfig.xml");
masterJetty.stop();
masterJetty = createJetty(master);
masterClient.shutdown();
masterClient = createNewSolrServer(masterJetty.getLocalPort());
masterClient.deleteByQuery("*:*");
@ -898,6 +905,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
slave.copyConfigFile(CONF_DIR + "solrconfig-slave1.xml", "solrconfig.xml");
slaveJetty.stop();
slaveJetty = createJetty(slave);
slaveClient.shutdown();
slaveClient = createNewSolrServer(slaveJetty.getLocalPort());
try {
@ -906,6 +914,9 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
repeater.copyConfigFile(CONF_DIR + "solrconfig-repeater.xml",
"solrconfig.xml");
repeaterJetty = createJetty(repeater);
if (repeaterClient != null) {
repeaterClient.shutdown();
}
repeaterClient = createNewSolrServer(repeaterJetty.getLocalPort());
for (int i = 0; i < 3; i++)
@ -1039,6 +1050,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
masterJetty.stop();
masterJetty = createJetty(master);
masterClient.shutdown();
masterClient = createNewSolrServer(masterJetty.getLocalPort());
for (int i = 0; i < nDocs; i++)
@ -1056,6 +1068,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
//start slave
slaveJetty = createJetty(slave);
slaveClient.shutdown();
slaveClient = createNewSolrServer(slaveJetty.getLocalPort());
//get docs from slave and check if number is equal to master
@ -1089,6 +1102,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
masterJetty.stop();
masterJetty = createJetty(master);
masterClient.shutdown();
masterClient = createNewSolrServer(masterJetty.getLocalPort());
for (int i = 0; i < nDocs; i++)
@ -1114,6 +1128,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
// start slave
slaveJetty = createJetty(slave);
slaveClient.shutdown();
slaveClient = createNewSolrServer(slaveJetty.getLocalPort());
// get docs from slave and check if number is equal to master
@ -1147,6 +1162,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
masterJetty.stop();
masterJetty = createJetty(master);
masterClient.shutdown();
masterClient = createNewSolrServer(masterJetty.getLocalPort());
masterClient.deleteByQuery("*:*");
@ -1164,6 +1180,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
//start slave
slaveJetty = createJetty(slave);
slaveClient.shutdown();
slaveClient = createNewSolrServer(slaveJetty.getLocalPort());
//get docs from slave and check if number is equal to master
@ -1244,6 +1261,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
masterJetty.stop();
masterJetty = createJetty(master);
masterClient.shutdown();
masterClient = createNewSolrServer(masterJetty.getLocalPort());
slave.setTestPort(masterJetty.getLocalPort());
@ -1251,6 +1269,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
slaveJetty.stop();
slaveJetty = createJetty(slave);
slaveClient.shutdown();
slaveClient = createNewSolrServer(slaveJetty.getLocalPort());
slaveClient.deleteByQuery("*:*");
@ -1304,6 +1323,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
"solrconfig.xml");
masterJetty = createJetty(master);
masterClient.shutdown();
masterClient = createNewSolrServer(masterJetty.getLocalPort());
nDocs--;

View File

@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
@ -116,6 +117,9 @@ public abstract class LargeVolumeTestBase extends SolrJettyTestBase
// a commit/optimize can fail with a too many warming searchers exception
log.info("Caught benign exception during commit: " + e.getMessage());
}
if (!(tserver instanceof EmbeddedSolrServer)) {
tserver.shutdown();
}
} catch (Exception e) {
e.printStackTrace();

View File

@ -17,6 +17,10 @@
package org.apache.solr.client.solrj;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload;
@ -26,12 +30,9 @@ import org.apache.solr.client.solrj.response.CoreAdminResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.util.ExternalPaths;
import org.junit.Test;
import java.io.File;
/**
*
@ -43,6 +44,12 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
private File dataDir2;
private File dataDir1;
private SolrServer solrCore0;
private SolrServer solrCore1;
private SolrServer solrAdmin;
private final Set<SolrServer> clients = new HashSet<>();
@Override public String getSolrHome() { return ExternalPaths.EXAMPLE_MULTICORE_HOME; }
@ -74,6 +81,14 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
System.err.println("!!!! WARNING: best effort to remove " + dataDir2.getAbsolutePath() + " FAILED !!!!!");
}
}
if(solrCore0 != null) solrCore0.shutdown();
if(solrCore1 != null) solrCore1.shutdown();
if(solrAdmin != null) solrAdmin.shutdown();
solrCore0 = solrCore1 = solrAdmin = null;
for (SolrServer client:clients) {
client.shutdown();
}
clients.clear();
}
@Override
@ -87,11 +102,40 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
{
throw new UnsupportedOperationException();
}
protected SolrServer getSolrCore0()
{
if (solrCore0 == null) {
solrCore0 = createServer( "core0" );
}
return solrCore0;
}
protected abstract SolrServer getSolrCore0();
protected abstract SolrServer getSolrCore1();
protected abstract SolrServer getSolrAdmin();
protected abstract SolrServer getSolrCore(String name);
protected SolrServer getSolrCore1()
{
if (solrCore1 == null) {
solrCore1 = createServer( "core1" );
}
return solrCore1;
}
protected SolrServer getSolrAdmin()
{
if (solrAdmin == null) {
solrAdmin = createServer( "" );
}
return solrAdmin;
}
protected SolrServer getSolrCore(String name)
{
SolrServer server = createServer(name);
clients.add(server);
return server;
}
protected abstract SolrServer createServer(String string);
@Test
public void testMultiCore() throws Exception
@ -197,25 +241,22 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
CoreAdminRequest.renameCore("coreb","corec",coreadmin);
CoreAdminRequest.renameCore("corec","cored",coreadmin);
CoreAdminRequest.renameCore("cored","corefoo",coreadmin);
try {
try {
getSolrCore("core1").query( new SolrQuery( "id:BBB" ) );
fail( "core1 should be gone" );
}
catch( Exception ex ) {}
assertEquals( 1, getSolrCore("corefoo").query( new SolrQuery( "id:BBB" ) ).getResults().size() );
NamedList<Object> response = getSolrCore("corefoo").query(new SolrQuery().setRequestHandler("/admin/system")).getResponse();
NamedList<Object> coreInfo = (NamedList<Object>) response.get("core");
String indexDir = (String) ((NamedList<Object>) coreInfo.get("directory")).get("index");
response = getSolrCore("core0").query(new SolrQuery().setRequestHandler("/admin/system")).getResponse();
coreInfo = (NamedList<Object>) response.get("core");
String dataDir = (String) ((NamedList<Object>) coreInfo.get("directory")).get("data");
System.out.println( (String) ((NamedList<Object>) coreInfo.get("directory")).get("dirimpl"));
// test delete index on core
CoreAdminRequest.unloadCore("corefoo", true, coreadmin);
File dir = new File(indexDir);

View File

@ -32,6 +32,7 @@ import com.google.common.collect.Maps;
import junit.framework.Assert;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.client.solrj.impl.BinaryResponseParser;
import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
@ -56,6 +57,7 @@ import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.params.AnalysisParams;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.FacetParams;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -215,6 +217,7 @@ abstract public class SolrExampleTests extends SolrExampleTestsBase
QueryResponse rsp = client.query(q);
assertNotNull(rsp.getResponse().get("mode"));
assertNotNull(rsp.getResponse().get("lucene"));
client.shutdown();
}
}
@ -539,6 +542,11 @@ abstract public class SolrExampleTests extends SolrExampleTestsBase
SolrDocumentList out = rsp.getResults();
assertEquals(2, out.getNumFound());
if (!(server1 instanceof EmbeddedSolrServer)) {
/* Do not shutdown in case of using EmbeddedSolrServer,
* as that would shutdown the CoreContainer */
server1.shutdown();
}
}
@Test

View File

@ -51,26 +51,12 @@ public class MultiCoreEmbeddedTest extends MultiCoreExampleTestBase {
}
@Override
protected SolrServer getSolrCore0()
{
return new EmbeddedSolrServer( cores, "core0" );
}
@Override
protected SolrServer getSolrCore1()
{
return new EmbeddedSolrServer( cores, "core1" );
}
@Override
protected SolrServer getSolrCore(String name)
{
return new EmbeddedSolrServer( cores, name );
}
@Override
protected SolrServer createServer(String string) {
return new EmbeddedSolrServer( cores, string );
}
protected SolrServer getSolrAdmin()
{
return new EmbeddedSolrServer( cores, "core0" );
return getSolrCore0();
}
}

View File

@ -22,9 +22,9 @@ import org.apache.solr.client.solrj.MultiCoreExampleTestBase;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
@ -42,7 +42,6 @@ import org.junit.Test;
public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {
JettySolrRunner jetty;
int port = 0;
static final String context = "/example";
@ -64,32 +63,7 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {
jetty.stop(); // stop the server
}
@Override
protected SolrServer getSolrCore(String name)
{
return createServer(name);
}
@Override
protected SolrServer getSolrCore0()
{
return createServer( "core0" );
}
@Override
protected SolrServer getSolrCore1()
{
return createServer( "core1" );
}
@Override
protected SolrServer getSolrAdmin()
{
return createServer( "" );
}
private SolrServer createServer( String name )
protected SolrServer createServer( String name )
{
try {
// setup the server...

View File

@ -82,6 +82,7 @@ public class NoOpResponseParserTest extends SolrJettyTestBase {
String responseString = (String) resp.get("response");
assertResponse(responseString);
server.shutdown();
}
private void assertResponse(String responseString) throws IOException {

View File

@ -79,6 +79,7 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
jetty.stop();
jetty = null;
}
if (server != null) server.shutdown();
server = null;
}

View File

@ -1619,8 +1619,9 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
CollectionAdminResponse res = new CollectionAdminResponse();
if (client == null) {
final String baseUrl = getBaseUrl((HttpSolrServer) clients.get(clientIndex));
res.setResponse(createNewSolrServer("", baseUrl).request(request));
SolrServer server = createNewSolrServer("", baseUrl);
res.setResponse(server.request(request));
server.shutdown();
} else {
res.setResponse(client.request(request));
}