From 1109c1275b84a5e490556d6fb687b1216870f358 Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Wed, 19 Mar 2014 18:25:00 +0000 Subject: [PATCH] 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 --- solr/CHANGES.txt | 3 + .../TestContentStreamDataSource.java | 2 + .../hadoop/MorphlineGoLiveMiniMRTest.java | 1 + .../solr/AbstractSolrMorphlineTestBase.java | 1 + .../solr/cloud/AliasIntegrationTest.java | 33 ++++++---- .../CollectionsAPIDistributedZkTest.java | 6 ++ .../solr/cloud/CustomCollectionTest.java | 12 ++-- .../solr/cloud/DeleteInactiveReplicaTest.java | 8 ++- .../apache/solr/cloud/DeleteShardTest.java | 1 + .../solr/cloud/MigrateRouteKeyTest.java | 2 + .../org/apache/solr/cloud/ShardSplitTest.java | 3 + .../org/apache/solr/cloud/SyncSliceTest.java | 2 + .../solr/cloud/UnloadDistributedZkTest.java | 27 ++++++++ .../solr/core/OpenCloseCoreStressTest.java | 9 +++ .../solr/handler/TestReplicationHandler.java | 32 +++++++-- .../client/solrj/LargeVolumeTestBase.java | 4 ++ .../solrj/MultiCoreExampleTestBase.java | 65 +++++++++++++++---- .../solr/client/solrj/SolrExampleTests.java | 8 +++ .../solrj/embedded/MultiCoreEmbeddedTest.java | 24 ++----- .../embedded/MultiCoreExampleJettyTest.java | 30 +-------- .../response/NoOpResponseParserTest.java | 1 + .../org/apache/solr/SolrJettyTestBase.java | 1 + .../cloud/AbstractFullDistribZkTestBase.java | 5 +- 23 files changed, 194 insertions(+), 86 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 8d79e7e9388..67856201cf7 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -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 diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java index 665471a2667..a209fa8e374 100644 --- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java +++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java @@ -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); diff --git a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineGoLiveMiniMRTest.java b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineGoLiveMiniMRTest.java index c0db9d69854..ae6bd25b704 100644 --- a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineGoLiveMiniMRTest.java +++ b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineGoLiveMiniMRTest.java @@ -658,6 +658,7 @@ public class MorphlineGoLiveMiniMRTest extends AbstractFullDistribZkTestBase { + new ZkCoreNodeProps(replica).getCoreUrl(), found, count); } found = count; + client.shutdown(); } } } diff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java index de8a9f004dc..f9dd687602c 100644 --- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java +++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java @@ -125,6 +125,7 @@ public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 { @After public void tearDown() throws Exception { collector = null; + solrServer.shutdown(); solrServer = null; super.tearDown(); } diff --git a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java index a090aef983c..9a083a09ea2 100644 --- a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java @@ -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 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 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 skipServers, Object... fields) throws IOException, diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java index c6d1cf57596..398e7bd67d6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java @@ -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); diff --git a/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java b/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java index de318aa8521..4fa5f5f03b2 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java @@ -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 { diff --git a/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java b/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java index 8968b21048d..324c8cf4217 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java @@ -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 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 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; diff --git a/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java b/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java index a55bd6cd6f6..22bccfd1d22 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java @@ -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, diff --git a/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java b/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java index 71908c49091..52891e3aee7 100644 --- a/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java @@ -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(); diff --git a/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java b/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java index be4a6755f20..3c493bbf80c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java @@ -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 ranges, int[] docCounts, String id, int n) throws Exception { diff --git a/solr/core/src/test/org/apache/solr/cloud/SyncSliceTest.java b/solr/core/src/test/org/apache/solr/cloud/SyncSliceTest.java index adfceeaaded..04f98894ef5 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SyncSliceTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SyncSliceTest.java @@ -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); diff --git a/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java index 21372b02a17..dd18110b062 100644 --- a/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java @@ -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(); } diff --git a/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java b/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java index 73171e1fb2d..97c8bf6c975 100644 --- a/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java +++ b/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java @@ -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 diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java index 43e73842b68..6c87ee3e44a 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java +++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java @@ -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--; diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java index 287f00a2847..b191f413d61 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java @@ -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(); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java index 2d18e85d4b6..56fec2821ce 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java @@ -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 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 response = getSolrCore("corefoo").query(new SolrQuery().setRequestHandler("/admin/system")).getResponse(); NamedList coreInfo = (NamedList) response.get("core"); String indexDir = (String) ((NamedList) coreInfo.get("directory")).get("index"); - response = getSolrCore("core0").query(new SolrQuery().setRequestHandler("/admin/system")).getResponse(); coreInfo = (NamedList) response.get("core"); String dataDir = (String) ((NamedList) coreInfo.get("directory")).get("data"); - - System.out.println( (String) ((NamedList) coreInfo.get("directory")).get("dirimpl")); - // test delete index on core CoreAdminRequest.unloadCore("corefoo", true, coreadmin); File dir = new File(indexDir); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java index 1c68f18d296..71ece60372c 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java @@ -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 diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreEmbeddedTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreEmbeddedTest.java index 56048f9932f..e57ab9af5cb 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreEmbeddedTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreEmbeddedTest.java @@ -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(); } } diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java index 09567c3807c..dca452cd4f1 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java @@ -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... diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/response/NoOpResponseParserTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/response/NoOpResponseParserTest.java index acc2d14b523..490d2f0870f 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/response/NoOpResponseParserTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/response/NoOpResponseParserTest.java @@ -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 { diff --git a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java index 1852af7bfdd..c40ac7a81c2 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java @@ -79,6 +79,7 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4 jetty.stop(); jetty = null; } + if (server != null) server.shutdown(); server = null; } diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java index e525926271c..6fbd5c41d8a 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java @@ -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)); }