You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2015/01/28 12:55:58 UTC
svn commit: r1655263 [3/4] - in /lucene/dev/trunk/solr: ./
contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/
contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/
contrib/map-reduce/src/java/org/apache/solr/hadoop/...
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/MultiThreadedOCPTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/MultiThreadedOCPTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/MultiThreadedOCPTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/MultiThreadedOCPTest.java Wed Jan 28 11:55:57 2015
@@ -74,8 +74,7 @@ public class MultiThreadedOCPTest extend
}
private void testParallelCollectionAPICalls() throws IOException, SolrServerException {
- SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)));
- try {
+ try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
for(int i = 1 ; i <= NUM_COLLECTIONS ; i++) {
Create createCollectionRequest = new Create();
createCollectionRequest.setCollectionName("ocptest" + i);
@@ -108,14 +107,11 @@ public class MultiThreadedOCPTest extend
String state = getRequestStateAfterCompletion(i + "", REQUEST_STATUS_TIMEOUT, client);
assertTrue("Task " + i + " did not complete, final state: " + state,state.equals("completed"));
}
- } finally {
- client.shutdown();
}
}
private void testTaskExclusivity() throws IOException, SolrServerException {
- SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)));
- try {
+ try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
Create createCollectionRequest = new Create();
createCollectionRequest.setCollectionName("ocptest_shardsplit");
createCollectionRequest.setNumShards(4);
@@ -166,14 +162,11 @@ public class MultiThreadedOCPTest extend
String state = getRequestStateAfterCompletion(i + "", REQUEST_STATUS_TIMEOUT, client);
assertTrue("Task " + i + " did not complete, final state: " + state,state.equals("completed"));
}
- } finally {
- client.shutdown();
}
}
private void testDeduplicationOfSubmittedTasks() throws IOException, SolrServerException {
- SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)));
- try {
+ try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
Create createCollectionRequest = new Create();
createCollectionRequest.setCollectionName("ocptest_shardsplit2");
createCollectionRequest.setNumShards(4);
@@ -208,8 +201,6 @@ public class MultiThreadedOCPTest extend
String state = getRequestStateAfterCompletion(i + "", REQUEST_STATUS_TIMEOUT, client);
assertTrue("Task " + i + " did not complete, final state: " + state,state.equals("completed"));
}
- } finally {
- client.shutdown();
}
}
@@ -230,8 +221,7 @@ public class MultiThreadedOCPTest extend
}
};
indexThread.start();
- SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)));
- try {
+ try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
SplitShard splitShardRequest = new SplitShard();
splitShardRequest.setCollectionName("collection1");
@@ -266,8 +256,6 @@ public class MultiThreadedOCPTest extend
indexThread.join();
} catch (InterruptedException e) {
log.warn("Indexing thread interrupted.");
- } finally {
- client.shutdown();
}
}
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerRolesTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerRolesTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerRolesTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerRolesTest.java Wed Jan 28 11:55:57 2015
@@ -18,20 +18,6 @@ package org.apache.solr.cloud;
*/
-import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;
-import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
-import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
-import static org.apache.solr.cloud.OverseerCollectionProcessor.getSortedOverseerNodeNames;
-import static org.apache.solr.cloud.OverseerCollectionProcessor.getLeaderNode;
-import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrRequest;
@@ -49,6 +35,20 @@ import org.apache.zookeeper.data.Stat;
import org.junit.BeforeClass;
import org.junit.Test;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.getLeaderNode;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.getSortedOverseerNodeNames;
+import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
+import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
+import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
+
@LuceneTestCase.Slow
@SuppressSSL // See SOLR-5776
public class OverseerRolesTest extends AbstractFullDistribZkTestBase{
@@ -70,7 +70,7 @@ public class OverseerRolesTest extends
@Override
public void distribTearDown() throws Exception {
super.distribTearDown();
- client.shutdown();
+ client.close();
}
protected String getSolrXml() {
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerStatusTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerStatusTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerStatusTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerStatusTest.java Wed Jan 28 11:55:57 2015
@@ -38,6 +38,7 @@ public class OverseerStatusTest extends
@Test
public void test() throws Exception {
+
waitForThingsToLevelOut(15);
// find existing command counts because collection may be created by base test class too
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java Wed Jan 28 11:55:57 2015
@@ -67,7 +67,7 @@ public class RemoteQueryErrorTest extend
} catch(Exception ex) {
fail("Expected a SolrException to occur, instead received: " + ex.getClass());
} finally {
- solrClient.shutdown();
+ solrClient.close();
}
}
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java Wed Jan 28 11:55:57 2015
@@ -17,12 +17,6 @@ package org.apache.solr.cloud;
* limitations under the License.
*/
-import java.io.File;
-import java.net.ServerSocket;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@@ -36,6 +30,12 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.net.ServerSocket;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
//@AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/SOLR-6157")
/**
@@ -173,20 +173,16 @@ public class ReplicationFactorTest exten
@SuppressWarnings("rawtypes")
protected void sendNonDirectUpdateRequestReplica(Replica replica, UpdateRequest up, int expectedRf, String collection) throws Exception {
- HttpSolrClient solrServer = null;
- try {
- ZkCoreNodeProps zkProps = new ZkCoreNodeProps(replica);
- String url = zkProps.getBaseUrl() + "/" + collection;
- solrServer = new HttpSolrClient(url);
-
+
+ ZkCoreNodeProps zkProps = new ZkCoreNodeProps(replica);
+ String url = zkProps.getBaseUrl() + "/" + collection;
+
+ try (HttpSolrClient solrServer = new HttpSolrClient(url)) {
NamedList resp = solrServer.request(up);
NamedList hdr = (NamedList) resp.get("responseHeader");
Integer batchRf = (Integer)hdr.get(UpdateRequest.REPFACT);
assertTrue("Expected rf="+expectedRf+" for batch but got "+
batchRf+"; clusterState: "+printClusterStateInfo(), batchRf == expectedRf);
- } finally {
- if (solrServer != null)
- solrServer.shutdown();
}
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java Wed Jan 28 11:55:57 2015
@@ -73,6 +73,7 @@ public class ShardSplitTest extends Basi
@Test
public void test() throws Exception {
+
waitForThingsToLevelOut(15);
if (usually()) {
@@ -231,10 +232,8 @@ public class ShardSplitTest extends Basi
.getZkStateReader().getClusterState().getLiveNodes().size())) + 1;
HashMap<String, List<Integer>> collectionInfos = new HashMap<>();
- CloudSolrClient client = null;
String shard_fld = "shard_s";
- try {
- client = createCloudClient(null);
+ try (CloudSolrClient client = createCloudClient(null)) {
Map<String, Object> props = ZkNodeProps.makeMap(
REPLICATION_FACTOR, replicationFactor,
MAX_SHARDS_PER_NODE, maxShardsPerNode,
@@ -242,8 +241,6 @@ public class ShardSplitTest extends Basi
"router.field", shard_fld);
createCollection(collectionInfos, collectionName,props,client);
- } finally {
- if (client != null) client.shutdown();
}
List<Integer> list = collectionInfos.get(collectionName);
@@ -253,52 +250,52 @@ public class ShardSplitTest extends Basi
String url = CustomCollectionTest.getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
- HttpSolrClient collectionClient = new HttpSolrClient(url);
-
- ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
- final DocRouter router = clusterState.getCollection(collectionName).getRouter();
- Slice shard1 = clusterState.getSlice(collectionName, SHARD1);
- DocRouter.Range shard1Range = shard1.getRange() != null ? shard1.getRange() : router.fullRange();
- final List<DocRouter.Range> ranges = router.partitionRange(2, shard1Range);
- final int[] docCounts = new int[ranges.size()];
-
- for (int i = 100; i <= 200; i++) {
- String shardKey = "" + (char)('a' + (i % 26)); // See comment in ShardRoutingTest for hash distribution
+ try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
- collectionClient.add(getDoc(id, i, "n_ti", i, shard_fld, shardKey));
- int idx = getHashRangeIdx(router, ranges, shardKey);
- if (idx != -1) {
- docCounts[idx]++;
+ ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
+ final DocRouter router = clusterState.getCollection(collectionName).getRouter();
+ Slice shard1 = clusterState.getSlice(collectionName, SHARD1);
+ DocRouter.Range shard1Range = shard1.getRange() != null ? shard1.getRange() : router.fullRange();
+ final List<DocRouter.Range> ranges = router.partitionRange(2, shard1Range);
+ final int[] docCounts = new int[ranges.size()];
+
+ for (int i = 100; i <= 200; i++) {
+ String shardKey = "" + (char) ('a' + (i % 26)); // See comment in ShardRoutingTest for hash distribution
+
+ collectionClient.add(getDoc(id, i, "n_ti", i, shard_fld, shardKey));
+ int idx = getHashRangeIdx(router, ranges, shardKey);
+ if (idx != -1) {
+ docCounts[idx]++;
+ }
}
- }
- for (int i = 0; i < docCounts.length; i++) {
- int docCount = docCounts[i];
- log.info("Shard {} docCount = {}", "shard1_" + i, docCount);
- }
+ for (int i = 0; i < docCounts.length; i++) {
+ int docCount = docCounts[i];
+ log.info("Shard {} docCount = {}", "shard1_" + i, docCount);
+ }
- collectionClient.commit();
+ collectionClient.commit();
- for (int i = 0; i < 3; i++) {
- try {
- splitShard(collectionName, SHARD1, null, null);
- break;
- } catch (HttpSolrClient.RemoteSolrException e) {
- if (e.code() != 500) {
- throw e;
- }
- log.error("SPLITSHARD failed. " + (i < 2 ? " Retring split" : ""), e);
- if (i == 2) {
- fail("SPLITSHARD was not successful even after three tries");
+ for (int i = 0; i < 3; i++) {
+ try {
+ splitShard(collectionName, SHARD1, null, null);
+ break;
+ } catch (HttpSolrClient.RemoteSolrException e) {
+ if (e.code() != 500) {
+ throw e;
+ }
+ log.error("SPLITSHARD failed. " + (i < 2 ? " Retring split" : ""), e);
+ if (i == 2) {
+ fail("SPLITSHARD was not successful even after three tries");
+ }
}
}
- }
- waitForRecoveriesToFinish(collectionName, false);
+ waitForRecoveriesToFinish(collectionName, false);
- 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();
+ 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());
+ }
}
private void splitByRouteKeyTest() throws Exception {
@@ -310,17 +307,14 @@ public class ShardSplitTest extends Basi
.getZkStateReader().getClusterState().getLiveNodes().size())) + 1;
HashMap<String, List<Integer>> collectionInfos = new HashMap<>();
- CloudSolrClient client = null;
- try {
- client = createCloudClient(null);
+
+ try (CloudSolrClient client = createCloudClient(null)) {
Map<String, Object> props = ZkNodeProps.makeMap(
REPLICATION_FACTOR, replicationFactor,
MAX_SHARDS_PER_NODE, maxShardsPerNode,
NUM_SLICES, numShards);
createCollection(collectionInfos, collectionName,props,client);
- } finally {
- if (client != null) client.shutdown();
}
List<Integer> list = collectionInfos.get(collectionName);
@@ -330,66 +324,66 @@ public class ShardSplitTest extends Basi
String url = CustomCollectionTest.getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
- HttpSolrClient collectionClient = new HttpSolrClient(url);
+ try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
- String splitKey = "b!";
+ String splitKey = "b!";
- ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
- final DocRouter router = clusterState.getCollection(collectionName).getRouter();
- Slice shard1 = clusterState.getSlice(collectionName, SHARD1);
- DocRouter.Range shard1Range = shard1.getRange() != null ? shard1.getRange() : router.fullRange();
- final List<DocRouter.Range> ranges = ((CompositeIdRouter) router).partitionRangeByKey(splitKey, shard1Range);
- final int[] docCounts = new int[ranges.size()];
-
- int uniqIdentifier = (1<<12);
- int splitKeyDocCount = 0;
- for (int i = 100; i <= 200; i++) {
- String shardKey = "" + (char)('a' + (i % 26)); // See comment in ShardRoutingTest for hash distribution
-
- String idStr = shardKey + "!" + i;
- collectionClient.add(getDoc(id, idStr, "n_ti", (shardKey + "!").equals(splitKey) ? uniqIdentifier : i));
- int idx = getHashRangeIdx(router, ranges, idStr);
- if (idx != -1) {
- docCounts[idx]++;
+ ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
+ final DocRouter router = clusterState.getCollection(collectionName).getRouter();
+ Slice shard1 = clusterState.getSlice(collectionName, SHARD1);
+ DocRouter.Range shard1Range = shard1.getRange() != null ? shard1.getRange() : router.fullRange();
+ final List<DocRouter.Range> ranges = ((CompositeIdRouter) router).partitionRangeByKey(splitKey, shard1Range);
+ final int[] docCounts = new int[ranges.size()];
+
+ int uniqIdentifier = (1 << 12);
+ int splitKeyDocCount = 0;
+ for (int i = 100; i <= 200; i++) {
+ String shardKey = "" + (char) ('a' + (i % 26)); // See comment in ShardRoutingTest for hash distribution
+
+ String idStr = shardKey + "!" + i;
+ collectionClient.add(getDoc(id, idStr, "n_ti", (shardKey + "!").equals(splitKey) ? uniqIdentifier : i));
+ int idx = getHashRangeIdx(router, ranges, idStr);
+ if (idx != -1) {
+ docCounts[idx]++;
+ }
+ if (splitKey.equals(shardKey + "!"))
+ splitKeyDocCount++;
}
- if (splitKey.equals(shardKey + "!"))
- splitKeyDocCount++;
- }
- for (int i = 0; i < docCounts.length; i++) {
- int docCount = docCounts[i];
- log.info("Shard {} docCount = {}", "shard1_" + i, docCount);
- }
- log.info("Route key doc count = {}", splitKeyDocCount);
+ for (int i = 0; i < docCounts.length; i++) {
+ int docCount = docCounts[i];
+ log.info("Shard {} docCount = {}", "shard1_" + i, docCount);
+ }
+ log.info("Route key doc count = {}", splitKeyDocCount);
- collectionClient.commit();
+ collectionClient.commit();
- for (int i = 0; i < 3; i++) {
- try {
- splitShard(collectionName, null, null, splitKey);
- break;
- } catch (HttpSolrClient.RemoteSolrException e) {
- if (e.code() != 500) {
- throw e;
- }
- log.error("SPLITSHARD failed. " + (i < 2 ? " Retring split" : ""), e);
- if (i == 2) {
- fail("SPLITSHARD was not successful even after three tries");
+ for (int i = 0; i < 3; i++) {
+ try {
+ splitShard(collectionName, null, null, splitKey);
+ break;
+ } catch (HttpSolrClient.RemoteSolrException e) {
+ if (e.code() != 500) {
+ throw e;
+ }
+ log.error("SPLITSHARD failed. " + (i < 2 ? " Retring split" : ""), e);
+ if (i == 2) {
+ fail("SPLITSHARD was not successful even after three tries");
+ }
}
}
- }
- waitForRecoveriesToFinish(collectionName, false);
- SolrQuery solrQuery = new SolrQuery("*:*");
- assertEquals("DocCount on shard1_0 does not match", docCounts[0], collectionClient.query(solrQuery.setParam("shards", "shard1_0")).getResults().getNumFound());
- assertEquals("DocCount on shard1_1 does not match", docCounts[1], collectionClient.query(solrQuery.setParam("shards", "shard1_1")).getResults().getNumFound());
- assertEquals("DocCount on shard1_2 does not match", docCounts[2], collectionClient.query(solrQuery.setParam("shards", "shard1_2")).getResults().getNumFound());
-
- solrQuery = new SolrQuery("n_ti:" + uniqIdentifier);
- 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();
+ waitForRecoveriesToFinish(collectionName, false);
+ SolrQuery solrQuery = new SolrQuery("*:*");
+ assertEquals("DocCount on shard1_0 does not match", docCounts[0], collectionClient.query(solrQuery.setParam("shards", "shard1_0")).getResults().getNumFound());
+ assertEquals("DocCount on shard1_1 does not match", docCounts[1], collectionClient.query(solrQuery.setParam("shards", "shard1_1")).getResults().getNumFound());
+ assertEquals("DocCount on shard1_2 does not match", docCounts[2], collectionClient.query(solrQuery.setParam("shards", "shard1_2")).getResults().getNumFound());
+
+ solrQuery = new SolrQuery("n_ti:" + uniqIdentifier);
+ 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());
+ }
}
protected void checkDocCountsAndShardStates(int[] docCounts, int numReplicas) throws Exception {
@@ -426,23 +420,17 @@ public class ShardSplitTest extends Basi
query.set("distrib", false);
ZkCoreNodeProps shard1_0 = getLeaderUrlFromZk(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_0);
- HttpSolrClient shard1_0Client = new HttpSolrClient(shard1_0.getCoreUrl());
QueryResponse response;
- try {
+ try (HttpSolrClient shard1_0Client = new HttpSolrClient(shard1_0.getCoreUrl())) {
response = shard1_0Client.query(query);
- } finally {
- shard1_0Client.shutdown();
}
long shard10Count = response.getResults().getNumFound();
ZkCoreNodeProps shard1_1 = getLeaderUrlFromZk(
AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_1);
- HttpSolrClient shard1_1Client = new HttpSolrClient(shard1_1.getCoreUrl());
QueryResponse response2;
- try {
+ try (HttpSolrClient shard1_1Client = new HttpSolrClient(shard1_1.getCoreUrl())) {
response2 = shard1_1Client.query(query);
- } finally {
- shard1_1Client.shutdown();
}
long shard11Count = response2.getResults().getNumFound();
@@ -452,7 +440,7 @@ public class ShardSplitTest extends Basi
assertEquals("Wrong doc count on shard1_1. See SOLR-5309", docCounts[1], shard11Count);
}
- protected void checkSubShardConsistency(String shard) throws SolrServerException {
+ protected void checkSubShardConsistency(String shard) throws SolrServerException, IOException {
SolrQuery query = new SolrQuery("*:*").setRows(1000).setFields("id", "_version_");
query.set("distrib", false);
@@ -462,12 +450,9 @@ public class ShardSplitTest extends Basi
int c = 0;
for (Replica replica : slice.getReplicas()) {
String coreUrl = new ZkCoreNodeProps(replica).getCoreUrl();
- HttpSolrClient client = new HttpSolrClient(coreUrl);
QueryResponse response;
- try {
+ try (HttpSolrClient client = new HttpSolrClient(coreUrl)) {
response = client.query(query);
- } finally {
- client.shutdown();
}
numFound[c++] = response.getResults().getNumFound();
log.info("Shard: " + shard + " Replica: {} has {} docs", coreUrl, String.valueOf(response.getResults().getNumFound()));
@@ -505,13 +490,10 @@ public class ShardSplitTest extends Basi
.getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
- HttpSolrClient baseServer = new HttpSolrClient(baseUrl);
- try {
+ try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) {
baseServer.setConnectionTimeout(30000);
baseServer.setSoTimeout(60000 * 5);
baseServer.request(request);
- } finally {
- baseServer.shutdown();
}
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/SyncSliceTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/SyncSliceTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/SyncSliceTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/SyncSliceTest.java Wed Jan 28 11:55:57 2015
@@ -128,13 +128,12 @@ public class SyncSliceTest extends Abstr
.getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
- HttpSolrClient baseClient = new HttpSolrClient(baseUrl);
- // we only set the connect timeout, not so timeout
- baseClient.setConnectionTimeout(30000);
- baseClient.request(request);
- baseClient.shutdown();
- baseClient = null;
-
+ try (HttpSolrClient baseClient = new HttpSolrClient(baseUrl)) {
+ // we only set the connect timeout, not so timeout
+ baseClient.setConnectionTimeout(30000);
+ baseClient.request(request);
+ }
+
waitForThingsToLevelOut(15);
checkShardConsistency(false, true);
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java Wed Jan 28 11:55:57 2015
@@ -35,8 +35,6 @@ import org.apache.solr.common.util.Named
import org.apache.zookeeper.KeeperException;
import org.junit.Test;
-import static org.apache.solr.cloud.OverseerCollectionProcessor.SHARD_UNIQUE;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -44,6 +42,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.SHARD_UNIQUE;
+
public class TestCollectionAPI extends ReplicaPropertiesBase {
public static final String COLLECTION_NAME = "testcollection";
@@ -62,13 +62,9 @@ public class TestCollectionAPI extends R
@Test
@ShardsFixed(num = 2)
public void test() throws Exception {
- CloudSolrClient client = createCloudClient(null);
- try {
+ try (CloudSolrClient client = createCloudClient(null)) {
createCollection(null, COLLECTION_NAME, 2, 2, 2, client, null, "conf1");
createCollection(null, COLLECTION_NAME1, 1, 1, 1, client, null, "conf1");
- } finally {
- //remove collections
- client.shutdown();
}
waitForCollection(cloudClient.getZkStateReader(), COLLECTION_NAME, 2);
@@ -87,8 +83,8 @@ public class TestCollectionAPI extends R
}
private void clusterStatusWithCollectionAndShard() throws IOException, SolrServerException {
- CloudSolrClient client = createCloudClient(null);
- try {
+
+ try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
params.set("collection", COLLECTION_NAME);
@@ -109,16 +105,12 @@ public class TestCollectionAPI extends R
Map<String, Object> selectedShardStatus = (Map<String, Object>) shardStatus.get(SHARD1);
assertNotNull(selectedShardStatus);
- } finally {
- //remove collections
- client.shutdown();
}
}
private void listCollection() throws IOException, SolrServerException {
- CloudSolrClient client = createCloudClient(null);
- try {
+ try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.LIST.toString());
SolrRequest request = new QueryRequest(params);
@@ -130,17 +122,13 @@ public class TestCollectionAPI extends R
assertTrue(DEFAULT_COLLECTION + " was not found in list", collections.contains(DEFAULT_COLLECTION));
assertTrue(COLLECTION_NAME + " was not found in list", collections.contains(COLLECTION_NAME));
assertTrue(COLLECTION_NAME1 + " was not found in list", collections.contains(COLLECTION_NAME1));
- } finally {
- //remove collections
- client.shutdown();
}
-
}
private void clusterStatusNoCollection() throws Exception {
- CloudSolrClient client = createCloudClient(null);
- try {
+
+ try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
SolrRequest request = new QueryRequest(params);
@@ -157,16 +145,12 @@ public class TestCollectionAPI extends R
List<String> liveNodes = (List<String>) cluster.get("live_nodes");
assertNotNull("Live nodes should not be null", liveNodes);
assertFalse(liveNodes.isEmpty());
- } finally {
- //remove collections
- client.shutdown();
}
}
private void clusterStatusWithCollection() throws IOException, SolrServerException {
- CloudSolrClient client = createCloudClient(null);
- try {
+ try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
params.set("collection", COLLECTION_NAME);
@@ -180,15 +164,11 @@ public class TestCollectionAPI extends R
assertNotNull("Collections should not be null in cluster state", collections);
assertNotNull(collections.get(COLLECTION_NAME));
assertEquals(1, collections.size());
- } finally {
- //remove collections
- client.shutdown();
}
}
private void clusterStatusWithRouteKey() throws IOException, SolrServerException {
- CloudSolrClient client = createCloudClient(DEFAULT_COLLECTION);
- try {
+ try (CloudSolrClient client = createCloudClient(DEFAULT_COLLECTION)) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "a!123"); // goes to shard2. see ShardRoutingTest for details
client.add(doc);
@@ -213,15 +193,11 @@ public class TestCollectionAPI extends R
assertEquals(1, shardStatus.size());
Map<String, Object> selectedShardStatus = (Map<String, Object>) shardStatus.get(SHARD2);
assertNotNull(selectedShardStatus);
- } finally {
- //remove collections
- client.shutdown();
}
}
private void clusterStatusAliasTest() throws Exception {
- CloudSolrClient client = createCloudClient(null);
- try {
+ try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CREATEALIAS.toString());
params.set("name", "myalias");
@@ -251,14 +227,11 @@ public class TestCollectionAPI extends R
Map<String, Object> collection = (Map<String, Object>) collections.get(DEFAULT_COLLECTION);
List<String> collAlias = (List<String>) collection.get("aliases");
assertEquals("Aliases not found", Lists.newArrayList("myalias"), collAlias);
- } finally {
- client.shutdown();
}
}
private void clusterStatusRolesTest() throws Exception {
- CloudSolrClient client = createCloudClient(null);
- try {
+ try (CloudSolrClient client = createCloudClient(null)) {
client.connect();
Replica replica = client.getZkStateReader().getLeaderRetry(DEFAULT_COLLECTION, SHARD1);
@@ -285,14 +258,11 @@ public class TestCollectionAPI extends R
assertNotNull(overseer);
assertEquals(1, overseer.size());
assertTrue(overseer.contains(replica.getNodeName()));
- } finally {
- client.shutdown();
}
}
private void replicaPropTest() throws Exception {
- CloudSolrClient client = createCloudClient(null);
- try {
+ try (CloudSolrClient client = createCloudClient(null)) {
client.connect();
Map<String, Slice> slices = client.getZkStateReader().getClusterState().getCollection(COLLECTION_NAME).getSlicesMap();
List<String> sliceList = new ArrayList<>(slices.keySet());
@@ -568,8 +538,6 @@ public class TestCollectionAPI extends R
verifyPropertyNotPresent(client, COLLECTION_NAME, c1_s1_r1, "property.node_name");
verifyPropertyNotPresent(client, COLLECTION_NAME, c1_s1_r1, "property.base_url");
- } finally {
- client.shutdown();
}
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java Wed Jan 28 11:55:57 2015
@@ -17,19 +17,18 @@ package org.apache.solr.cloud;
* limitations under the License.
*/
-import java.io.File;
-import java.util.List;
-
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;
-
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import java.io.File;
+import java.util.List;
+
/**
* Tests SSL (if test framework selects it) with MiniSolrCloudCluster.
* {@link TestMiniSolrCloudCluster} does not inherit from {@link SolrTestCaseJ4}
@@ -77,13 +76,10 @@ public class TestMiniSolrCloudClusterSSL
private void sendRequestToEachServer() throws Exception {
List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
for (JettySolrRunner jetty : jettys) {
- HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString());
- try {
+ try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString())) {
CoreAdminRequest req = new CoreAdminRequest();
req.setAction( CoreAdminAction.STATUS );
client.request(req);
- } finally {
- client.shutdown();
}
}
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java Wed Jan 28 11:55:57 2015
@@ -51,13 +51,11 @@ public class TestRebalanceLeaders extend
Map<String, Replica> expected = new HashMap<>();
-
@Test
@ShardsFixed(num = 4)
public void test() throws Exception {
- CloudSolrClient client = createCloudClient(null);
reps = random().nextInt(9) + 1; // make sure and do at least one.
- try {
+ try (CloudSolrClient client = createCloudClient(null)) {
// Mix up a bunch of different combinations of shards and replicas in order to exercise boundary cases.
// shards, replicationfactor, maxreplicaspernode
int shards = random().nextInt(7);
@@ -65,9 +63,6 @@ public class TestRebalanceLeaders extend
int rFactor = random().nextInt(4);
if (rFactor < 2) rFactor = 2;
createCollection(null, COLLECTION_NAME, shards, rFactor, shards * rFactor + 1, client, null, "conf1");
- } finally {
- //remove collections
- client.shutdown();
}
waitForCollection(cloudClient.getZkStateReader(), COLLECTION_NAME, 2);
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestReplicaProperties.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestReplicaProperties.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestReplicaProperties.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestReplicaProperties.java Wed Jan 28 11:55:57 2015
@@ -18,11 +18,6 @@ package org.apache.solr.cloud;
*/
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
@@ -38,6 +33,11 @@ import org.apache.solr.common.util.Named
import org.apache.zookeeper.KeeperException;
import org.junit.Test;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
@Slow
public class TestReplicaProperties extends ReplicaPropertiesBase {
@@ -51,8 +51,8 @@ public class TestReplicaProperties exten
@Test
@ShardsFixed(num = 4)
public void test() throws Exception {
- CloudSolrClient client = createCloudClient(null);
- try {
+
+ try (CloudSolrClient client = createCloudClient(null)) {
// Mix up a bunch of different combinations of shards and replicas in order to exercise boundary cases.
// shards, replicationfactor, maxreplicaspernode
int shards = random().nextInt(7);
@@ -60,9 +60,6 @@ public class TestReplicaProperties exten
int rFactor = random().nextInt(4);
if (rFactor < 2) rFactor = 2;
createCollection(null, COLLECTION_NAME, shards, rFactor, shards * rFactor + 1, client, null, "conf1");
- } finally {
- //remove collections
- client.shutdown();
}
waitForCollection(cloudClient.getZkStateReader(), COLLECTION_NAME, 2);
@@ -74,8 +71,8 @@ public class TestReplicaProperties exten
}
private void listCollection() throws IOException, SolrServerException {
- CloudSolrClient client = createCloudClient(null);
- try {
+
+ try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.LIST.toString());
SolrRequest request = new QueryRequest(params);
@@ -86,16 +83,13 @@ public class TestReplicaProperties exten
assertTrue("control_collection was not found in list", collections.contains("control_collection"));
assertTrue(DEFAULT_COLLECTION + " was not found in list", collections.contains(DEFAULT_COLLECTION));
assertTrue(COLLECTION_NAME + " was not found in list", collections.contains(COLLECTION_NAME));
- } finally {
- //remove collections
- client.shutdown();
}
}
private void clusterAssignPropertyTest() throws Exception {
- CloudSolrClient client = createCloudClient(null);
- try {
+
+ try (CloudSolrClient client = createCloudClient(null)) {
client.connect();
try {
doPropertyAction(client,
@@ -192,8 +186,6 @@ public class TestReplicaProperties exten
verifyLeaderAssignment(client, COLLECTION_NAME);
- } finally {
- client.shutdown();
}
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestRequestStatusCollectionAPI.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestRequestStatusCollectionAPI.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestRequestStatusCollectionAPI.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/TestRequestStatusCollectionAPI.java Wed Jan 28 11:55:57 2015
@@ -196,10 +196,10 @@ public class TestRequestStatusCollection
.getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
- HttpSolrClient baseServer = new HttpSolrClient(baseUrl);
- baseServer.setConnectionTimeout(15000);
- NamedList<Object> resp = baseServer.request(request);
- baseServer.shutdown();
- return resp;
+ try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) {
+ baseServer.setConnectionTimeout(15000);
+ return baseServer.request(request);
+ }
+
}
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java Wed Jan 28 11:55:57 2015
@@ -29,6 +29,7 @@ import org.apache.solr.common.SolrInputD
import org.apache.solr.common.cloud.ZkCoreNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
import org.apache.solr.update.DirectUpdateHandler2;
import org.apache.solr.util.DefaultSolrThreadFactory;
import org.junit.Test;
@@ -82,51 +83,51 @@ public class UnloadDistributedZkTest ext
SolrClient client = clients.get(0);
String url1 = getBaseUrl(client);
- HttpSolrClient adminClient = new HttpSolrClient(url1);
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(60000);
- adminClient.request(createCmd);
-
- createCmd = new Create();
- createCmd.setCoreName("test_unload_shard_and_collection_2");
- collection = "test_unload_shard_and_collection";
- createCmd.setCollection(collection);
- coreDataDir = createTempDir().toFile().getAbsolutePath();
- createCmd.setDataDir(getDataDir(coreDataDir));
-
- adminClient.request(createCmd);
-
- // does not mean they are active and up yet :*
- waitForRecoveriesToFinish(collection, false);
- // now unload one of the two
- Unload unloadCmd = new Unload(false);
- unloadCmd.setCoreName("test_unload_shard_and_collection_2");
- adminClient.request(unloadCmd);
-
- // there should be only one shard
- int slices = getCommonCloudSolrClient().getZkStateReader().getClusterState().getSlices(collection).size();
- long timeoutAt = System.currentTimeMillis() + 45000;
- while (slices != 1) {
- if (System.currentTimeMillis() > timeoutAt) {
- printLayout();
- fail("Expected to find only one slice in " + collection);
+ try (HttpSolrClient adminClient = new HttpSolrClient(url1)) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(60000);
+ adminClient.request(createCmd);
+
+ createCmd = new Create();
+ createCmd.setCoreName("test_unload_shard_and_collection_2");
+ collection = "test_unload_shard_and_collection";
+ createCmd.setCollection(collection);
+ coreDataDir = createTempDir().toFile().getAbsolutePath();
+ createCmd.setDataDir(getDataDir(coreDataDir));
+
+ adminClient.request(createCmd);
+
+ // does not mean they are active and up yet :*
+ waitForRecoveriesToFinish(collection, false);
+
+ // now unload one of the two
+ Unload unloadCmd = new Unload(false);
+ unloadCmd.setCoreName("test_unload_shard_and_collection_2");
+ adminClient.request(unloadCmd);
+
+ // there should be only one shard
+ int slices = getCommonCloudSolrClient().getZkStateReader().getClusterState().getSlices(collection).size();
+ long timeoutAt = System.currentTimeMillis() + 45000;
+ while (slices != 1) {
+ if (System.currentTimeMillis() > timeoutAt) {
+ printLayout();
+ fail("Expected to find only one slice in " + collection);
+ }
+
+ Thread.sleep(1000);
+ slices = getCommonCloudSolrClient().getZkStateReader().getClusterState().getSlices(collection).size();
}
-
- Thread.sleep(1000);
- slices = getCommonCloudSolrClient().getZkStateReader().getClusterState().getSlices(collection).size();
+
+ // now unload one of the other
+ unloadCmd = new Unload(false);
+ unloadCmd.setCoreName("test_unload_shard_and_collection_1");
+ adminClient.request(unloadCmd);
}
-
- // now unload one of the other
- unloadCmd = new Unload(false);
- unloadCmd.setCoreName("test_unload_shard_and_collection_1");
- adminClient.request(unloadCmd);
- adminClient.shutdown();
- adminClient = null;
-
+
//printLayout();
// the collection should be gone
- timeoutAt = System.currentTimeMillis() + 30000;
+ long timeoutAt = System.currentTimeMillis() + 30000;
while (getCommonCloudSolrClient().getZkStateReader().getClusterState().hasCollection(collection)) {
if (System.currentTimeMillis() > timeoutAt) {
printLayout();
@@ -143,24 +144,23 @@ public class UnloadDistributedZkTest ext
*/
private void testCoreUnloadAndLeaders() throws Exception {
File tmpDir = createTempDir().toFile();
-
+
+ String core1DataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection1" + "_1n";
+
// create a new collection collection
SolrClient client = clients.get(0);
String url1 = getBaseUrl(client);
- HttpSolrClient adminClient = new HttpSolrClient(url1);
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(60000);
-
- Create createCmd = new Create();
- createCmd.setCoreName("unloadcollection1");
- createCmd.setCollection("unloadcollection");
- createCmd.setNumShards(1);
- String core1DataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection1" + "_1n";
- createCmd.setDataDir(getDataDir(core1DataDir));
- adminClient.request(createCmd);
- adminClient.shutdown();
- adminClient = null;
-
+ try (HttpSolrClient adminClient = new HttpSolrClient(url1)) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(60000);
+
+ Create createCmd = new Create();
+ createCmd.setCoreName("unloadcollection1");
+ createCmd.setCollection("unloadcollection");
+ createCmd.setNumShards(1);
+ createCmd.setDataDir(getDataDir(core1DataDir));
+ adminClient.request(createCmd);
+ }
ZkStateReader zkStateReader = getCommonCloudSolrClient().getZkStateReader();
zkStateReader.updateClusterState(true);
@@ -170,17 +170,15 @@ public class UnloadDistributedZkTest ext
client = clients.get(1);
String url2 = getBaseUrl(client);
- adminClient = new HttpSolrClient(url2);
-
- createCmd = new Create();
- createCmd.setCoreName("unloadcollection2");
- createCmd.setCollection("unloadcollection");
- String core2dataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection1" + "_2n";
- createCmd.setDataDir(getDataDir(core2dataDir));
- adminClient.request(createCmd);
- adminClient.shutdown();
- adminClient = null;
-
+ try (HttpSolrClient adminClient = new HttpSolrClient(url2)) {
+
+ Create createCmd = new Create();
+ createCmd.setCoreName("unloadcollection2");
+ createCmd.setCollection("unloadcollection");
+ String core2dataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection1" + "_2n";
+ createCmd.setDataDir(getDataDir(core2dataDir));
+ adminClient.request(createCmd);
+ }
zkStateReader.updateClusterState(true);
slices = zkStateReader.getClusterState().getCollection("unloadcollection").getSlices().size();
assertEquals(1, slices);
@@ -190,73 +188,64 @@ public class UnloadDistributedZkTest ext
ZkCoreNodeProps leaderProps = getLeaderUrlFromZk("unloadcollection", "shard1");
Random random = random();
- HttpSolrClient collectionClient;
if (random.nextBoolean()) {
- collectionClient = new HttpSolrClient(leaderProps.getCoreUrl());
- // lets try and use the solrj client to index and retrieve a couple
- // documents
- SolrInputDocument doc1 = getDoc(id, 6, i1, -600, tlong, 600, t1,
- "humpty dumpy sat on a wall");
- SolrInputDocument doc2 = getDoc(id, 7, i1, -600, tlong, 600, t1,
- "humpty dumpy3 sat on a walls");
- SolrInputDocument doc3 = getDoc(id, 8, i1, -600, tlong, 600, t1,
- "humpty dumpy2 sat on a walled");
- collectionClient.add(doc1);
- collectionClient.add(doc2);
- collectionClient.add(doc3);
- collectionClient.commit();
- collectionClient.shutdown();
- collectionClient = null;
+ try (HttpSolrClient collectionClient = new HttpSolrClient(leaderProps.getCoreUrl())) {
+ // lets try and use the solrj client to index and retrieve a couple
+ // documents
+ SolrInputDocument doc1 = getDoc(id, 6, i1, -600, tlong, 600, t1,
+ "humpty dumpy sat on a wall");
+ SolrInputDocument doc2 = getDoc(id, 7, i1, -600, tlong, 600, t1,
+ "humpty dumpy3 sat on a walls");
+ SolrInputDocument doc3 = getDoc(id, 8, i1, -600, tlong, 600, t1,
+ "humpty dumpy2 sat on a walled");
+ collectionClient.add(doc1);
+ collectionClient.add(doc2);
+ collectionClient.add(doc3);
+ collectionClient.commit();
+ }
}
// create another replica for our collection
client = clients.get(2);
String url3 = getBaseUrl(client);
- adminClient = new HttpSolrClient(url3);
-
- createCmd = new Create();
- createCmd.setCoreName("unloadcollection3");
- createCmd.setCollection("unloadcollection");
- String core3dataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection" + "_3n";
- createCmd.setDataDir(getDataDir(core3dataDir));
- adminClient.request(createCmd);
- adminClient.shutdown();
- adminClient = null;
-
+ try (HttpSolrClient adminClient = new HttpSolrClient(url3)) {
+ Create createCmd = new Create();
+ createCmd.setCoreName("unloadcollection3");
+ createCmd.setCollection("unloadcollection");
+ String core3dataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection" + "_3n";
+ createCmd.setDataDir(getDataDir(core3dataDir));
+ adminClient.request(createCmd);
+ }
waitForRecoveriesToFinish("unloadcollection", zkStateReader, false);
// so that we start with some versions when we reload...
DirectUpdateHandler2.commitOnClose = false;
- HttpSolrClient addClient = new HttpSolrClient(url3 + "/unloadcollection3");
- addClient.setConnectionTimeout(30000);
+ try (HttpSolrClient addClient = new HttpSolrClient(url3 + "/unloadcollection3")) {
+ addClient.setConnectionTimeout(30000);
- // add a few docs
- for (int x = 20; x < 100; x++) {
- SolrInputDocument doc1 = getDoc(id, x, i1, -600, tlong, 600, t1,
- "humpty dumpy sat on a wall");
- addClient.add(doc1);
+ // add a few docs
+ for (int x = 20; x < 100; x++) {
+ SolrInputDocument doc1 = getDoc(id, x, i1, -600, tlong, 600, t1,
+ "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();
// unload the leader
- collectionClient = new HttpSolrClient(leaderProps.getBaseUrl());
- collectionClient.setConnectionTimeout(15000);
- collectionClient.setSoTimeout(30000);
-
- Unload unloadCmd = new Unload(false);
- unloadCmd.setCoreName(leaderProps.getCoreName());
- ModifiableSolrParams p = (ModifiableSolrParams) unloadCmd.getParams();
-
- collectionClient.request(unloadCmd);
- collectionClient.shutdown();
- collectionClient = null;
+ try (HttpSolrClient collectionClient = new HttpSolrClient(leaderProps.getBaseUrl())) {
+ collectionClient.setConnectionTimeout(15000);
+ collectionClient.setSoTimeout(30000);
+
+ Unload unloadCmd = new Unload(false);
+ unloadCmd.setCoreName(leaderProps.getCoreName());
+ ModifiableSolrParams p = (ModifiableSolrParams) unloadCmd.getParams();
+ collectionClient.request(unloadCmd);
+ }
// Thread.currentThread().sleep(500);
// printLayout();
@@ -271,51 +260,45 @@ public class UnloadDistributedZkTest ext
// ensure there is a leader
zkStateReader.getLeaderRetry("unloadcollection", "shard1", 15000);
- addClient = new HttpSolrClient(url2 + "/unloadcollection2");
- addClient.setConnectionTimeout(30000);
- addClient.setSoTimeout(90000);
-
- // add a few docs while the leader is down
- for (int x = 101; x < 200; x++) {
- SolrInputDocument doc1 = getDoc(id, x, i1, -600, tlong, 600, t1,
- "humpty dumpy sat on a wall");
- addClient.add(doc1);
+ try (HttpSolrClient addClient = new HttpSolrClient(url2 + "/unloadcollection2")) {
+ addClient.setConnectionTimeout(30000);
+ addClient.setSoTimeout(90000);
+
+ // add a few docs while the leader is down
+ for (int x = 101; x < 200; x++) {
+ SolrInputDocument doc1 = getDoc(id, x, i1, -600, tlong, 600, t1,
+ "humpty dumpy sat on a wall");
+ addClient.add(doc1);
+ }
}
- addClient.shutdown();
- addClient = null;
-
// create another replica for our collection
client = clients.get(3);
String url4 = getBaseUrl(client);
- adminClient = new HttpSolrClient(url4);
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(30000);
-
- createCmd = new Create();
- createCmd.setCoreName("unloadcollection4");
- createCmd.setCollection("unloadcollection");
- String core4dataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection" + "_4n";
- createCmd.setDataDir(getDataDir(core4dataDir));
- adminClient.request(createCmd);
- adminClient.shutdown();
- adminClient = null;
-
+ try (HttpSolrClient adminClient = new HttpSolrClient(url4)) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(30000);
+
+ Create createCmd = new Create();
+ createCmd.setCoreName("unloadcollection4");
+ createCmd.setCollection("unloadcollection");
+ String core4dataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection" + "_4n";
+ createCmd.setDataDir(getDataDir(core4dataDir));
+ adminClient.request(createCmd);
+ }
waitForRecoveriesToFinish("unloadcollection", zkStateReader, false);
// unload the leader again
leaderProps = getLeaderUrlFromZk("unloadcollection", "shard1");
- collectionClient = new HttpSolrClient(leaderProps.getBaseUrl());
- collectionClient.setConnectionTimeout(15000);
- collectionClient.setSoTimeout(30000);
-
- unloadCmd = new Unload(false);
- unloadCmd.setCoreName(leaderProps.getCoreName());
- p = (ModifiableSolrParams) unloadCmd.getParams();
- collectionClient.request(unloadCmd);
- collectionClient.shutdown();
- collectionClient = null;
-
+ try (HttpSolrClient collectionClient = new HttpSolrClient(leaderProps.getBaseUrl())) {
+ collectionClient.setConnectionTimeout(15000);
+ collectionClient.setSoTimeout(30000);
+
+ Unload unloadCmd = new Unload(false);
+ unloadCmd.setCoreName(leaderProps.getCoreName());
+ SolrParams p = (ModifiableSolrParams) unloadCmd.getParams();
+ collectionClient.request(unloadCmd);
+ }
tries = 50;
while (leaderProps.getCoreUrl().equals(zkStateReader.getLeaderUrl("unloadcollection", "shard1", 15000))) {
Thread.sleep(100);
@@ -331,88 +314,90 @@ public class UnloadDistributedZkTest ext
DirectUpdateHandler2.commitOnClose = true;
// bring the downed leader back as replica
- adminClient = new HttpSolrClient(leaderProps.getBaseUrl());
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(30000);
-
- createCmd = new Create();
- createCmd.setCoreName(leaderProps.getCoreName());
- createCmd.setCollection("unloadcollection");
- createCmd.setDataDir(getDataDir(core1DataDir));
- adminClient.request(createCmd);
- adminClient.shutdown();
- adminClient = null;
-
+ try (HttpSolrClient adminClient = new HttpSolrClient(leaderProps.getBaseUrl())) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(30000);
+
+ Create createCmd = new Create();
+ createCmd.setCoreName(leaderProps.getCoreName());
+ createCmd.setCollection("unloadcollection");
+ createCmd.setDataDir(getDataDir(core1DataDir));
+ adminClient.request(createCmd);
+ }
waitForRecoveriesToFinish("unloadcollection", zkStateReader, false);
+
+ long found1, found3;
- adminClient = new HttpSolrClient(url2 + "/unloadcollection");
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(30000);
- adminClient.commit();
- SolrQuery q = new SolrQuery("*:*");
- q.set("distrib", false);
- long found1 = adminClient.query(q).getResults().getNumFound();
- adminClient.shutdown();
- adminClient = new HttpSolrClient(url3 + "/unloadcollection");
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(30000);
- adminClient.commit();
- q = new SolrQuery("*:*");
- q.set("distrib", false);
- long found3 = adminClient.query(q).getResults().getNumFound();
- adminClient.shutdown();
- adminClient = new HttpSolrClient(url4 + "/unloadcollection");
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(30000);
- adminClient.commit();
- q = new SolrQuery("*:*");
- q.set("distrib", false);
- long found4 = adminClient.query(q).getResults().getNumFound();
-
- // all 3 shards should now have the same number of docs
- assertEquals(found1, found3);
- assertEquals(found3, found4);
- adminClient.shutdown();
+ try (HttpSolrClient adminClient = new HttpSolrClient(url2 + "/unloadcollection")) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(30000);
+ adminClient.commit();
+ SolrQuery q = new SolrQuery("*:*");
+ q.set("distrib", false);
+ found1 = adminClient.query(q).getResults().getNumFound();
+ }
+ try (HttpSolrClient adminClient = new HttpSolrClient(url3 + "/unloadcollection")) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(30000);
+ adminClient.commit();
+ SolrQuery q = new SolrQuery("*:*");
+ q.set("distrib", false);
+ found3 = adminClient.query(q).getResults().getNumFound();
+ }
+
+ try (HttpSolrClient adminClient = new HttpSolrClient(url4 + "/unloadcollection")) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(30000);
+ adminClient.commit();
+ SolrQuery q = new SolrQuery("*:*");
+ q.set("distrib", false);
+ long found4 = adminClient.query(q).getResults().getNumFound();
+
+ // all 3 shards should now have the same number of docs
+ assertEquals(found1, found3);
+ assertEquals(found3, found4);
+ }
}
private void testUnloadLotsOfCores() throws Exception {
SolrClient client = clients.get(2);
String url3 = getBaseUrl(client);
- final HttpSolrClient adminClient = new HttpSolrClient(url3);
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(60000);
- ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
- 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
- new DefaultSolrThreadFactory("testExecutor"));
- int cnt = atLeast(3);
-
- // create the cores
- createCores(adminClient, executor, "multiunload", 2, cnt);
-
- executor.shutdown();
- executor.awaitTermination(120, TimeUnit.SECONDS);
- executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5,
- TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
- new DefaultSolrThreadFactory("testExecutor"));
- for (int j = 0; j < cnt; j++) {
- final int freezeJ = j;
- executor.execute(new Runnable() {
- @Override
- public void run() {
- Unload unloadCmd = new Unload(true);
- unloadCmd.setCoreName("multiunload" + freezeJ);
- try {
- adminClient.request(unloadCmd);
- } catch (SolrServerException | IOException e) {
- throw new RuntimeException(e);
+ try (final HttpSolrClient adminClient = new HttpSolrClient(url3)) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(60000);
+ ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
+ 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
+ new DefaultSolrThreadFactory("testExecutor"));
+ int cnt = atLeast(3);
+
+ // create the cores
+ createCores(adminClient, executor, "multiunload", 2, cnt);
+
+ executor.shutdown();
+ executor.awaitTermination(120, TimeUnit.SECONDS);
+ executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5,
+ TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
+ new DefaultSolrThreadFactory("testExecutor"));
+ for (int j = 0; j < cnt; j++) {
+ final int freezeJ = j;
+ executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ Unload unloadCmd = new Unload(true);
+ unloadCmd.setCoreName("multiunload" + freezeJ);
+ try {
+ adminClient.request(unloadCmd);
+ } catch (SolrServerException | IOException e) {
+ throw new RuntimeException(e);
+ }
}
- }
- });
- Thread.sleep(random().nextInt(50));
+ });
+ Thread.sleep(random().nextInt(50));
+ }
+ executor.shutdown();
+ executor.awaitTermination(120, TimeUnit.SECONDS);
}
- executor.shutdown();
- executor.awaitTermination(120, TimeUnit.SECONDS);
- adminClient.shutdown();
}
+
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java Wed Jan 28 11:55:57 2015
@@ -22,6 +22,7 @@ import com.carrotsearch.randomizedtestin
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.NRTCachingDirectory;
+import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase.Nightly;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrQuery;
@@ -117,10 +118,8 @@ public class HdfsWriteToMultipleCollecti
client.commit();
collectionsCount += client.query(new SolrQuery("*:*")).getResults().getNumFound();
}
-
- for (CloudSolrClient client : cloudClients) {
- client.shutdown();
- }
+
+ IOUtils.close(cloudClients);
assertEquals(addCnt, collectionsCount);
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java Wed Jan 28 11:55:57 2015
@@ -17,14 +17,8 @@
package org.apache.solr.cloud.hdfs;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Timer;
-import java.util.TimerTask;
-
+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
@@ -32,8 +26,8 @@ import org.apache.hadoop.hdfs.MiniDFSClu
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCase.Slow;
-import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.QueryRequest;
@@ -45,11 +39,16 @@ import org.apache.solr.common.util.Named
import org.apache.zookeeper.KeeperException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.junit.Test;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+
@Slow
@ThreadLeakScope(Scope.NONE) // hdfs client currently leaks thread(s)
public class StressHdfsTest extends BasicDistributedZkTest {
@@ -164,8 +163,7 @@ public class StressHdfsTest extends Basi
int i = 0;
for (SolrClient client : clients) {
- HttpSolrClient c = new HttpSolrClient(getBaseUrl(client) + "/" + DELETE_DATA_DIR_COLLECTION);
- try {
+ try (HttpSolrClient c = new HttpSolrClient(getBaseUrl(client) + "/" + DELETE_DATA_DIR_COLLECTION)) {
int docCnt = random().nextInt(1000) + 1;
for (int j = 0; j < docCnt; j++) {
c.add(getDoc("id", i++, "txt_t", "just some random text for a doc"));
@@ -183,8 +181,6 @@ public class StressHdfsTest extends Basi
NamedList<Object> coreInfo = (NamedList<Object>) response.get("core");
String dataDir = (String) ((NamedList<Object>) coreInfo.get("directory")).get("data");
dataDirs.add(dataDir);
- } finally {
- c.shutdown();
}
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java Wed Jan 28 11:55:57 2015
@@ -18,8 +18,8 @@
package org.apache.solr.core;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.IOUtils;
import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.UpdateRequest;
@@ -93,12 +93,8 @@ public class OpenCloseCoreStressTest ext
@After
public void tearDownServer() throws Exception {
if (jetty != null) jetty.stop();
- for(SolrClient client: indexingClients) {
- client.shutdown();
- }
- for(SolrClient client: queryingClients) {
- client.shutdown();
- }
+ IOUtils.close(indexingClients);
+ IOUtils.close(queryingClients);
indexingClients.clear();
queryingClients.clear();
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestBlobHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestBlobHandler.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestBlobHandler.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestBlobHandler.java Wed Jan 28 11:55:57 2015
@@ -59,8 +59,8 @@ public class TestBlobHandler extends Abs
@Test
public void doBlobHandlerTest() throws Exception {
- SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)));
- try {
+
+ try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
CollectionAdminResponse response1;
CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create();
createCollectionRequest.setCollectionName(".system");
@@ -99,8 +99,6 @@ public class TestBlobHandler extends Abs
compareInputAndOutput(baseUrl+"/.system/blob/test?wt=filestream", bytarr2);
compareInputAndOutput(baseUrl+"/.system/blob/test/1?wt=filestream", bytarr);
- } finally {
- client.shutdown();
}
}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java Wed Jan 28 11:55:57 2015
@@ -138,8 +138,8 @@ public class TestReplicationHandler exte
slave.tearDown();
masterJetty = slaveJetty = null;
master = slave = null;
- masterClient.shutdown();
- slaveClient.shutdown();
+ masterClient.close();
+ slaveClient.close();
masterClient = slaveClient = null;
}
@@ -269,15 +269,12 @@ public class TestReplicationHandler exte
params.set("qt","/admin/cores");
QueryRequest req = new QueryRequest(params);
- HttpSolrClient adminClient = adminClient(s);
- try {
+ try (HttpSolrClient adminClient = adminClient(s)) {
NamedList<Object> res = adminClient.request(req);
assertNotNull("null response from server", res);
return res;
}
- finally {
- adminClient.shutdown();
- }
+
}
private HttpSolrClient adminClient(SolrClient client) {
@@ -350,7 +347,7 @@ public class TestReplicationHandler exte
try {
if (repeater != null) repeater.tearDown();
} catch (Exception e) { /* :NOOP: */ }
- if (repeaterClient != null) repeaterClient.shutdown();
+ if (repeaterClient != null) repeaterClient.close();
}
}
@@ -500,7 +497,7 @@ public class TestReplicationHandler exte
masterJetty.stop();
masterJetty = createJetty(master);
- masterClient.shutdown();
+ masterClient.close();
masterClient = createNewSolrClient(masterJetty.getLocalPort());
slave.setTestPort(masterJetty.getLocalPort());
@@ -519,7 +516,7 @@ public class TestReplicationHandler exte
assertFalse(slaveXsltDir.exists());
slaveJetty = createJetty(slave);
- slaveClient.shutdown();
+ slaveClient.close();
slaveClient = createNewSolrClient(slaveJetty.getLocalPort());
//add a doc with new field and commit on master to trigger snappull from slave.
@@ -596,7 +593,7 @@ public class TestReplicationHandler exte
slave.copyConfigFile(CONF_DIR + "solrconfig-slave1.xml", "solrconfig.xml");
slaveJetty.stop();
slaveJetty = createJetty(slave);
- slaveClient.shutdown();
+ slaveClient.close();
slaveClient = createNewSolrClient(slaveJetty.getLocalPort());
masterClient.deleteByQuery("*:*");
@@ -732,14 +729,14 @@ public class TestReplicationHandler exte
slave.copyConfigFile(CONF_DIR +slaveSchema, "schema.xml");
slaveJetty.stop();
slaveJetty = createJetty(slave);
- slaveClient.shutdown();
+ slaveClient.close();
slaveClient = createNewSolrClient(slaveJetty.getLocalPort());
master.copyConfigFile(CONF_DIR + "solrconfig-master3.xml",
"solrconfig.xml");
masterJetty.stop();
masterJetty = createJetty(master);
- masterClient.shutdown();
+ masterClient.close();
masterClient = createNewSolrClient(masterJetty.getLocalPort());
masterClient.deleteByQuery("*:*");
@@ -854,7 +851,7 @@ public class TestReplicationHandler exte
slave.copyConfigFile(CONF_DIR + "solrconfig-slave1.xml", "solrconfig.xml");
slaveJetty.stop();
slaveJetty = createJetty(slave);
- slaveClient.shutdown();
+ slaveClient.close();
slaveClient = createNewSolrClient(slaveJetty.getLocalPort());
try {
@@ -864,7 +861,7 @@ public class TestReplicationHandler exte
"solrconfig.xml");
repeaterJetty = createJetty(repeater);
if (repeaterClient != null) {
- repeaterClient.shutdown();
+ repeaterClient.close();
}
repeaterClient = createNewSolrClient(repeaterJetty.getLocalPort());
@@ -916,7 +913,7 @@ public class TestReplicationHandler exte
repeaterJetty = null;
}
if (repeaterClient != null) {
- repeaterClient.shutdown();
+ repeaterClient.close();
}
}
@@ -1000,7 +997,7 @@ public class TestReplicationHandler exte
masterJetty.stop();
masterJetty = createJetty(master);
- masterClient.shutdown();
+ masterClient.close();
masterClient = createNewSolrClient(masterJetty.getLocalPort());
for (int i = 0; i < nDocs; i++)
@@ -1018,7 +1015,7 @@ public class TestReplicationHandler exte
//start slave
slaveJetty = createJetty(slave);
- slaveClient.shutdown();
+ slaveClient.close();
slaveClient = createNewSolrClient(slaveJetty.getLocalPort());
//get docs from slave and check if number is equal to master
@@ -1052,7 +1049,7 @@ public class TestReplicationHandler exte
masterJetty.stop();
masterJetty = createJetty(master);
- masterClient.shutdown();
+ masterClient.close();
masterClient = createNewSolrClient(masterJetty.getLocalPort());
for (int i = 0; i < nDocs; i++)
@@ -1078,7 +1075,7 @@ public class TestReplicationHandler exte
// start slave
slaveJetty = createJetty(slave);
- slaveClient.shutdown();
+ slaveClient.close();
slaveClient = createNewSolrClient(slaveJetty.getLocalPort());
// get docs from slave and check if number is equal to master
@@ -1112,7 +1109,7 @@ public class TestReplicationHandler exte
masterJetty.stop();
masterJetty = createJetty(master);
- masterClient.shutdown();
+ masterClient.close();
masterClient = createNewSolrClient(masterJetty.getLocalPort());
masterClient.deleteByQuery("*:*");
@@ -1130,7 +1127,7 @@ public class TestReplicationHandler exte
//start slave
slaveJetty = createJetty(slave);
- slaveClient.shutdown();
+ slaveClient.close();
slaveClient = createNewSolrClient(slaveJetty.getLocalPort());
//get docs from slave and check if number is equal to master
@@ -1211,7 +1208,7 @@ public class TestReplicationHandler exte
masterJetty.stop();
masterJetty = createJetty(master);
- masterClient.shutdown();
+ masterClient.close();
masterClient = createNewSolrClient(masterJetty.getLocalPort());
slave.setTestPort(masterJetty.getLocalPort());
@@ -1219,7 +1216,7 @@ public class TestReplicationHandler exte
slaveJetty.stop();
slaveJetty = createJetty(slave);
- slaveClient.shutdown();
+ slaveClient.close();
slaveClient = createNewSolrClient(slaveJetty.getLocalPort());
slaveClient.deleteByQuery("*:*");
@@ -1272,7 +1269,7 @@ public class TestReplicationHandler exte
master.copyConfigFile(CONF_DIR + "solrconfig-master-throttled.xml", "solrconfig.xml");
useFactory(null);
masterJetty = createJetty(master);
- masterClient.shutdown();
+ masterClient.close();
masterClient = createNewSolrClient(masterJetty.getLocalPort());
//index docs
@@ -1284,7 +1281,7 @@ public class TestReplicationHandler exte
//Check Index Size
String dataDir = master.getDataDir();
- masterClient.shutdown();
+ masterClient.close();
masterJetty.stop();
Directory dir = FSDirectory.open(Paths.get(dataDir, "index"));
@@ -1305,7 +1302,7 @@ public class TestReplicationHandler exte
slave.setTestPort(masterJetty.getLocalPort());
slave.copyConfigFile(CONF_DIR + "solrconfig-slave1.xml", "solrconfig.xml");
slaveJetty = createJetty(slave);
- slaveClient.shutdown();
+ slaveClient.close();
slaveClient = createNewSolrClient(slaveJetty.getLocalPort());
long startTime = System.nanoTime();
@@ -1403,8 +1400,7 @@ public class TestReplicationHandler exte
final long sleepInterval = 200;
long timeSlept = 0;
- HttpSolrClient adminClient = adminClient(client);
- try {
+ try (HttpSolrClient adminClient = adminClient(client)) {
SolrParams p = params("action", "status", "core", "collection1");
while (timeSlept < timeout) {
QueryRequest req = new QueryRequest(p);
@@ -1434,9 +1430,6 @@ public class TestReplicationHandler exte
fail("timed out waiting for collection1 startAt time to exceed: " + min);
return min; // compilation neccessity
}
- finally {
- adminClient.shutdown();
- }
}
private static String buildUrl(int port) {
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java Wed Jan 28 11:55:57 2015
@@ -108,7 +108,7 @@ public class TestReplicationHandlerBacku
@After
public void tearDown() throws Exception {
super.tearDown();
- masterClient.shutdown();
+ masterClient.close();
masterClient = null;
masterJetty.stop();
master.tearDown();
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java Wed Jan 28 11:55:57 2015
@@ -201,41 +201,31 @@ public class CoreAdminHandlerTest extend
File corex = new File(solrHomeDirectory, "corex");
FileUtils.write(new File(corex, "core.properties"), "", Charsets.UTF_8.toString());
JettySolrRunner runner = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), "/solr", 0);
- HttpSolrClient client = null;
- try {
- runner.start();
- client = new HttpSolrClient("http://localhost:" + runner.getLocalPort() + "/solr/corex");
+ runner.start();
+
+ try (HttpSolrClient client = new HttpSolrClient("http://localhost:" + runner.getLocalPort() + "/solr/corex")) {
client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "123");
client.add(doc);
client.commit();
- client.shutdown();
+ }
- client = new HttpSolrClient("http://localhost:" + runner.getLocalPort() + "/solr");
+ try (HttpSolrClient client = new HttpSolrClient("http://localhost:" + runner.getLocalPort() + "/solr")) {
client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
CoreAdminRequest.Unload req = new CoreAdminRequest.Unload(false);
req.setDeleteInstanceDir(true);
req.setCoreName("corex");
req.process(client);
- client.shutdown();
+ }
- runner.stop();
+ runner.stop();
+
+ assertFalse("Instance directory exists after core unload with deleteInstanceDir=true : " + corex,
+ corex.exists());
- assertFalse("Instance directory exists after core unload with deleteInstanceDir=true : " + corex,
- corex.exists());
- } catch (Exception e) {
- log.error("Exception testing core unload with deleteInstanceDir=true", e);
- } finally {
- if (client != null) {
- client.shutdown();
- }
- if (!runner.isStopped()) {
- runner.stop();
- }
- }
}
@Test
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java Wed Jan 28 11:55:57 2015
@@ -75,17 +75,13 @@ public class DistributedDebugComponentTe
shard2 = urlCollection2.replaceAll("https?://", "");
//create second core
- HttpSolrClient nodeClient = new HttpSolrClient(url);
- try {
+ try (HttpSolrClient nodeClient = new HttpSolrClient(url)) {
CoreAdminRequest.Create req = new CoreAdminRequest.Create();
req.setCoreName("collection2");
req.setConfigSet("collection1");
nodeClient.request(req);
}
- finally {
- nodeClient.shutdown();
- }
-
+
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "1");
doc.setField("text", "batman");
@@ -101,8 +97,8 @@ public class DistributedDebugComponentTe
@AfterClass
public static void destroyThings() throws Exception {
- collection1.shutdown();
- collection2.shutdown();
+ collection1.close();
+ collection2.close();
collection1 = null;
collection2 = null;
jetty.stop();