lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romseyg...@apache.org
Subject svn commit: r1655263 [2/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/...
Date Wed, 28 Jan 2015 11:55:58 GMT
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SolrCLI.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SolrCLI.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SolrCLI.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SolrCLI.java Wed Jan 28 11:55:57 2015
@@ -113,10 +113,8 @@ public class SolrCLI {
       
       log.debug("Connecting to Solr cluster: " + zkHost);
       int exitStatus = 0;
-      CloudSolrClient cloudSolrClient = null;
-      try {
-        cloudSolrClient = new CloudSolrClient(zkHost);
-        
+      try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) {
+
         String collection = cli.getOptionValue("collection");
         if (collection != null)
           cloudSolrClient.setDefaultCollection(collection);
@@ -132,12 +130,6 @@ public class SolrCLI {
         } else {
           throw exc;
         }
-      } finally {
-        if (cloudSolrClient != null) {
-          try {
-            cloudSolrClient.shutdown();
-          } catch (Exception ignore) {}
-        }
       }
       
       return exitStatus;
@@ -973,12 +965,13 @@ public class SolrCLI {
             replicaStatus = ZkStateReader.DOWN;
           } else {
             // query this replica directly to get doc count and assess health
-            HttpSolrClient solr = new HttpSolrClient(coreUrl);
-            String solrUrl = solr.getBaseURL();
             q = new SolrQuery("*:*");
             q.setRows(0);
             q.set("distrib", "false");
-            try {
+            try (HttpSolrClient solr = new HttpSolrClient(coreUrl)) {
+
+              String solrUrl = solr.getBaseURL();
+
               qr = solr.query(q);
               numDocs = qr.getResults().getNumFound();
 
@@ -993,15 +986,13 @@ public class SolrCLI {
               // if we get here, we can trust the state
               replicaStatus = replicaCoreProps.getState();
             } catch (Exception exc) {
-              log.error("ERROR: " + exc + " when trying to reach: " + solrUrl);
+              log.error("ERROR: " + exc + " when trying to reach: " + coreUrl);
 
               if (checkCommunicationError(exc)) {
                 replicaStatus = "down";
               } else {
                 replicaStatus = "error: "+exc;
               }
-            } finally {
-              solr.shutdown();
             }
           }
 
@@ -1161,9 +1152,8 @@ public class SolrCLI {
       }
 
       int toolExitStatus = 0;
-      CloudSolrClient cloudSolrServer = null;
-      try {
-        cloudSolrServer = new CloudSolrClient(zkHost);
+
+      try (CloudSolrClient cloudSolrServer = new CloudSolrClient(zkHost)) {
         System.out.println("Connecting to ZooKeeper at " + zkHost);
         cloudSolrServer.connect();
         toolExitStatus = runCloudTool(cloudSolrServer, cli);
@@ -1176,12 +1166,6 @@ public class SolrCLI {
         } else {
           throw exc;
         }
-      } finally {
-        if (cloudSolrServer != null) {
-          try {
-            cloudSolrServer.shutdown();
-          } catch (Exception ignore) {}
-        }
       }
 
       return toolExitStatus;
@@ -1600,12 +1584,10 @@ public class SolrCLI {
       String zkHost = getZkHost(cli);
 
       int toolExitStatus = 0;
-      CloudSolrClient cloudSolrServer = null;
-      try {
-        cloudSolrServer = new CloudSolrClient(zkHost);
+      try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) {
         System.out.println("Connecting to ZooKeeper at " + zkHost);
-        cloudSolrServer.connect();
-        toolExitStatus = deleteCollection(cloudSolrServer, cli);
+        cloudSolrClient.connect();
+        toolExitStatus = deleteCollection(cloudSolrClient, cli);
       } catch (Exception exc) {
         // since this is a CLI, spare the user the stacktrace
         String excMsg = exc.getMessage();
@@ -1615,12 +1597,6 @@ public class SolrCLI {
         } else {
           throw exc;
         }
-      } finally {
-        if (cloudSolrServer != null) {
-          try {
-            cloudSolrServer.shutdown();
-          } catch (Exception ignore) {}
-        }
       }
 
       return toolExitStatus;

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/TestTolerantSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/TestTolerantSearch.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/TestTolerantSearch.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/TestTolerantSearch.java Wed Jan 28 11:55:57 2015
@@ -69,17 +69,13 @@ public class TestTolerantSearch extends
     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("subject", "batman");
@@ -103,8 +99,8 @@ public class TestTolerantSearch extends
   
   @AfterClass
   public static void destroyThings() throws Exception {
-    collection1.shutdown();
-    collection2.shutdown();
+    collection1.close();
+    collection2.close();
     collection1 = null;
     collection2 = null;
     jetty.stop();

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java Wed Jan 28 11:55:57 2015
@@ -17,10 +17,6 @@ package org.apache.solr.cloud;
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.lucene.util.LuceneTestCase.Slow;
 import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.SolrQuery;
@@ -43,6 +39,10 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.junit.Test;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * Test sync phase that occurs when Leader goes down and a new Leader is
  * elected.
@@ -134,61 +134,55 @@ public class AliasIntegrationTest extend
     query.set("collection", "testalias");
     JettySolrRunner jetty = jettys.get(random().nextInt(jettys.size()));
     int port = jetty.getLocalPort();
-    HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias");
-    res = client.query(query);
-    assertEquals(3, res.getResults().getNumFound());
-    client.shutdown();
-    client = null;
-    
+    try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) {
+      res = client.query(query);
+      assertEquals(3, res.getResults().getNumFound());
+    }
+
     // now without collections param
     query = new SolrQuery("*:*");
     jetty = jettys.get(random().nextInt(jettys.size()));
     port = jetty.getLocalPort();
-    client = new HttpSolrClient(buildUrl(port) + "/testalias");
-    res = client.query(query);
-    assertEquals(3, res.getResults().getNumFound());
-    client.shutdown();
-    client = null;
-    
+    try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) {
+      res = client.query(query);
+      assertEquals(3, res.getResults().getNumFound());
+    }
     // create alias, collection2 first because it's not on every node
     createAlias("testalias", "collection2,collection1");
     
     // search with new cloud client
-    CloudSolrClient cloudSolrClient = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean());
-    cloudSolrClient.setParallelUpdates(random().nextBoolean());
-    query = new SolrQuery("*:*");
-    query.set("collection", "testalias");
-    res = cloudSolrClient.query(query);
-    assertEquals(5, res.getResults().getNumFound());
-    
-    // Try with setDefaultCollection
-    query = new SolrQuery("*:*");
-    cloudSolrClient.setDefaultCollection("testalias");
-    res = cloudSolrClient.query(query);
-    cloudSolrClient.shutdown();
-    assertEquals(5, res.getResults().getNumFound());
-    
+    try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean())) {
+      cloudSolrClient.setParallelUpdates(random().nextBoolean());
+      query = new SolrQuery("*:*");
+      query.set("collection", "testalias");
+      res = cloudSolrClient.query(query);
+      assertEquals(5, res.getResults().getNumFound());
+
+      // Try with setDefaultCollection
+      query = new SolrQuery("*:*");
+      cloudSolrClient.setDefaultCollection("testalias");
+      res = cloudSolrClient.query(query);
+      assertEquals(5, res.getResults().getNumFound());
+    }
+
     // search for alias with random non cloud client
     query = new SolrQuery("*:*");
     query.set("collection", "testalias");
     jetty = jettys.get(random().nextInt(jettys.size()));
     port = jetty.getLocalPort();
-    client = new HttpSolrClient(buildUrl(port) + "/testalias");
-    res = client.query(query);
-    assertEquals(5, res.getResults().getNumFound());
-    client.shutdown();
-    client = null;
-    
+    try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) {
+      res = client.query(query);
+      assertEquals(5, res.getResults().getNumFound());
+    }
     // now without collections param
     query = new SolrQuery("*:*");
     jetty = jettys.get(random().nextInt(jettys.size()));
     port = jetty.getLocalPort();
-    client = new HttpSolrClient(buildUrl(port) + "/testalias");
-    res = client.query(query);
-    assertEquals(5, res.getResults().getNumFound());
-    client.shutdown();
-    client = null;
-    
+    try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) {
+      res = client.query(query);
+      assertEquals(5, res.getResults().getNumFound());
+    }
+
     // update alias
     createAlias("testalias", "collection2");
     //checkForAlias("testalias", "collection2");
@@ -211,31 +205,23 @@ public class AliasIntegrationTest extend
     // try a std client
     // search 1 and 2, but have no collections param
     query = new SolrQuery("*:*");
-    client = new HttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias");
-    try {
+    try (HttpSolrClient client = new HttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias")) {
       res = client.query(query);
       assertEquals(5, res.getResults().getNumFound());
-    } finally {
-      client.shutdown();
-      client = null;
     }
-    
+
     createAlias("testalias", "collection2");
     
     // a second alias
     createAlias("testalias2", "collection2");
-    
-    client = new HttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias");
-    try {
+
+    try (HttpSolrClient client = new HttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias")) {
       SolrInputDocument doc8 = getDoc(id, 11, i1, -600, tlong, 600, t1,
           "humpty dumpy4 sat on a walls");
       client.add(doc8);
       client.commit();
       res = client.query(query);
       assertEquals(3, res.getResults().getNumFound());
-    } finally {
-      client.shutdown();
-      client = null;
     }
     
     createAlias("testalias", "collection2,collection1");
@@ -261,9 +247,8 @@ public class AliasIntegrationTest extend
 
   private void createAlias(String alias, String collections)
       throws SolrServerException, IOException {
-    SolrClient client = createNewSolrClient("",
-        getBaseUrl((HttpSolrClient) clients.get(0)));
-    try {
+
+    try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
       if (random().nextBoolean()) {
         ModifiableSolrParams params = new ModifiableSolrParams();
         params.set("collections", collections);
@@ -278,28 +263,25 @@ public class AliasIntegrationTest extend
         request.setAliasedCollections(collections);
         request.process(client);
       }
-    } finally {
-      client.shutdown();
     }
   }
   
   private void deleteAlias(String alias) throws SolrServerException,
       IOException {
-    SolrClient client = createNewSolrClient("",
-        getBaseUrl((HttpSolrClient) 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");
-      client.request(request);
-    } else {
-      DeleteAlias request = new DeleteAlias();
-      request.setAliasName(alias);
-      request.process(client);
+    try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) 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");
+        client.request(request);
+      } else {
+        DeleteAlias request = new DeleteAlias();
+        request.setAliasName(alias);
+        request.process(client);
+      }
     }
-    client.shutdown();
   }
   
   protected void indexDoc(List<CloudJettyRunner> skipServers, Object... fields) throws IOException,

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/AsyncMigrateRouteKeyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/AsyncMigrateRouteKeyTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/AsyncMigrateRouteKeyTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/AsyncMigrateRouteKeyTest.java Wed Jan 28 11:55:57 2015
@@ -112,14 +112,9 @@ public class AsyncMigrateRouteKeyTest ex
         .getBaseURL();
     baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
 
-    HttpSolrClient baseServer = null;
-
-    try {
-      baseServer = new HttpSolrClient(baseUrl);
+    try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) {
       baseServer.setConnectionTimeout(15000);
       return baseServer.request(request);
-    } finally {
-      baseServer.shutdown();
     }
   }
 }

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java Wed Jan 28 11:55:57 2015
@@ -148,11 +148,9 @@ public class BasicDistributedZk2Test ext
     
   }
   
-  private void testNodeWithoutCollectionForwarding() throws Exception,
-      SolrServerException, IOException {
-    try {
-      final String baseUrl = getBaseUrl((HttpSolrClient) clients.get(0));
-      HttpSolrClient client = new HttpSolrClient(baseUrl);
+  private void testNodeWithoutCollectionForwarding() throws Exception {
+    final String baseUrl = getBaseUrl((HttpSolrClient) clients.get(0));
+    try (HttpSolrClient client = new HttpSolrClient(baseUrl)) {
       client.setConnectionTimeout(30000);
       Create createCmd = new Create();
       createCmd.setRoles("none");
@@ -161,7 +159,6 @@ public class BasicDistributedZk2Test ext
       createCmd.setNumShards(1);
       createCmd.setDataDir(getDataDir(createTempDir(ONE_NODE_COLLECTION).toFile().getAbsolutePath()));
       client.request(createCmd);
-      client.shutdown();
     } catch (Exception e) {
       e.printStackTrace();
       fail(e.getMessage());
@@ -174,8 +171,8 @@ public class BasicDistributedZk2Test ext
     
     int docs = 2;
     for (SolrClient client : clients) {
-      final String baseUrl = getBaseUrl((HttpSolrClient) client);
-      addAndQueryDocs(baseUrl, docs);
+      final String clientUrl = getBaseUrl((HttpSolrClient) client);
+      addAndQueryDocs(clientUrl, docs);
       docs += 2;
     }
   }
@@ -183,36 +180,39 @@ public class BasicDistributedZk2Test ext
   // 2 docs added every call
   private void addAndQueryDocs(final String baseUrl, int docs)
       throws Exception {
-    HttpSolrClient qclient = new HttpSolrClient(baseUrl + "/onenodecollection" + "core");
-    
-    // it might take a moment for the proxy node to see us in their cloud state
-    waitForNon403or404or503(qclient);
-    
-    // add a doc
-    SolrInputDocument doc = new SolrInputDocument();
-    doc.addField("id", docs);
-    qclient.add(doc);
-    qclient.commit();
-    
+
     SolrQuery query = new SolrQuery("*:*");
-    QueryResponse results = qclient.query(query);
-    assertEquals(docs - 1, results.getResults().getNumFound());
-    qclient.shutdown();
-    
-    qclient = new HttpSolrClient(baseUrl + "/onenodecollection");
-    results = qclient.query(query);
-    assertEquals(docs - 1, results.getResults().getNumFound());
-    
-    doc = new SolrInputDocument();
-    doc.addField("id", docs + 1);
-    qclient.add(doc);
-    qclient.commit();
+
+    try (HttpSolrClient qclient = new HttpSolrClient(baseUrl + "/onenodecollection" + "core")) {
+
+      // it might take a moment for the proxy node to see us in their cloud state
+      waitForNon403or404or503(qclient);
+
+      // add a doc
+      SolrInputDocument doc = new SolrInputDocument();
+      doc.addField("id", docs);
+      qclient.add(doc);
+      qclient.commit();
+
+
+      QueryResponse results = qclient.query(query);
+      assertEquals(docs - 1, results.getResults().getNumFound());
+    }
     
-    query = new SolrQuery("*:*");
-    query.set("rows", 0);
-    results = qclient.query(query);
-    assertEquals(docs, results.getResults().getNumFound());
-    qclient.shutdown();
+    try (HttpSolrClient qclient = new HttpSolrClient(baseUrl + "/onenodecollection")) {
+      QueryResponse results = qclient.query(query);
+      assertEquals(docs - 1, results.getResults().getNumFound());
+
+      SolrInputDocument doc = new SolrInputDocument();
+      doc.addField("id", docs + 1);
+      qclient.add(doc);
+      qclient.commit();
+
+      query = new SolrQuery("*:*");
+      query.set("rows", 0);
+      results = qclient.query(query);
+      assertEquals(docs, results.getResults().getNumFound());
+    }
   }
   
   private long testUpdateAndDelete() throws Exception {

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java Wed Jan 28 11:55:57 2015
@@ -18,6 +18,7 @@ package org.apache.solr.cloud;
  */
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.LuceneTestCase.Slow;
 import org.apache.solr.JSONTestUtil;
 import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
@@ -378,14 +379,11 @@ public class BasicDistributedZkTest exte
     createCmd.setSchemaName("nonexistent_schema.xml");
     
     String url = getBaseUrl(clients.get(0));
-    final HttpSolrClient client = new HttpSolrClient(url);
-    try {
+    try (final HttpSolrClient client = new HttpSolrClient(url)) {
       client.request(createCmd);
       fail("Expected SolrCore create to fail");
     } catch (Exception e) {
       
-    } finally {
-      client.shutdown();
     }
     
     long timeout = System.currentTimeMillis() + 15000;
@@ -506,20 +504,20 @@ public class BasicDistributedZkTest exte
   private void testStopAndStartCoresInOneInstance() throws Exception {
     SolrClient client = clients.get(0);
     String url3 = getBaseUrl(client);
-    final HttpSolrClient httpSolrClient = new HttpSolrClient(url3);
-    httpSolrClient.setConnectionTimeout(15000);
-    httpSolrClient.setSoTimeout(60000);
-    ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
-        5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
-        new DefaultSolrThreadFactory("testExecutor"));
-    int cnt = 3;
-    
-    // create the cores
-    createCores(httpSolrClient, executor, "multiunload2", 1, cnt);
-    
-    executor.shutdown();
-    executor.awaitTermination(120, TimeUnit.SECONDS);
-    httpSolrClient.shutdown();
+    try (final HttpSolrClient httpSolrClient = new HttpSolrClient(url3)) {
+      httpSolrClient.setConnectionTimeout(15000);
+      httpSolrClient.setSoTimeout(60000);
+      ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
+          5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
+          new DefaultSolrThreadFactory("testExecutor"));
+      int cnt = 3;
+
+      // create the cores
+      createCores(httpSolrClient, executor, "multiunload2", 1, cnt);
+
+      executor.shutdown();
+      executor.awaitTermination(120, TimeUnit.SECONDS);
+    }
     
     ChaosMonkey.stop(cloudJettys.get(0).jetty);
     printLayout();
@@ -603,9 +601,9 @@ public class BasicDistributedZkTest exte
           ((HttpSolrClient) clients.get(clientIndex)).getBaseURL().length()
               - DEFAULT_COLLECTION.length() - 1);
       
-      SolrClient aClient = createNewSolrClient("", baseUrl);
-      res.setResponse(aClient.request(request));
-      aClient.shutdown();
+      try (SolrClient aClient = createNewSolrClient("", baseUrl)) {
+        res.setResponse(aClient.request(request));
+      }
     } else {
       res.setResponse(client.request(request));
     }
@@ -728,21 +726,20 @@ public class BasicDistributedZkTest exte
 
   private Long getNumCommits(HttpSolrClient sourceClient) throws
       SolrServerException, IOException {
-    HttpSolrClient client = new HttpSolrClient(sourceClient.getBaseURL());
-    client.setConnectionTimeout(15000);
-    client.setSoTimeout(60000);
-    ModifiableSolrParams params = new ModifiableSolrParams();
-    params.set("qt", "/admin/mbeans?key=updateHandler&stats=true");
-    // use generic request to avoid extra processing of queries
-    QueryRequest req = new QueryRequest(params);
-    NamedList<Object> resp = client.request(req);
-    NamedList mbeans = (NamedList) resp.get("solr-mbeans");
-    NamedList uhandlerCat = (NamedList) mbeans.get("UPDATEHANDLER");
-    NamedList uhandler = (NamedList) uhandlerCat.get("updateHandler");
-    NamedList stats = (NamedList) uhandler.get("stats");
-    Long commits = (Long) stats.get("commits");
-    client.shutdown();
-    return commits;
+    try (HttpSolrClient client = new HttpSolrClient(sourceClient.getBaseURL())) {
+      client.setConnectionTimeout(15000);
+      client.setSoTimeout(60000);
+      ModifiableSolrParams params = new ModifiableSolrParams();
+      params.set("qt", "/admin/mbeans?key=updateHandler&stats=true");
+      // use generic request to avoid extra processing of queries
+      QueryRequest req = new QueryRequest(params);
+      NamedList<Object> resp = client.request(req);
+      NamedList mbeans = (NamedList) resp.get("solr-mbeans");
+      NamedList uhandlerCat = (NamedList) mbeans.get("UPDATEHANDLER");
+      NamedList uhandler = (NamedList) uhandlerCat.get("updateHandler");
+      NamedList stats = (NamedList) uhandler.get("stats");
+      return (Long) stats.get("commits");
+    }
   }
 
   private void testANewCollectionInOneInstanceWithManualShardAssignement() throws Exception {
@@ -820,32 +817,30 @@ public class BasicDistributedZkTest exte
     ZkCoreNodeProps props = new ZkCoreNodeProps(getCommonCloudSolrClient().getZkStateReader().getClusterState().getLeader(oneInstanceCollection2, "slice1"));
     
     // now test that unloading a core gets us a new leader
-    HttpSolrClient unloadClient = new HttpSolrClient(baseUrl);
-    unloadClient.setConnectionTimeout(15000);
-    unloadClient.setSoTimeout(60000);
-    Unload unloadCmd = new Unload(true);
-    unloadCmd.setCoreName(props.getCoreName());
-    
-    String leader = props.getCoreUrl();
-    
-    unloadClient.request(unloadCmd);
-    unloadClient.shutdown();
-    
-    int tries = 50;
-    while (leader.equals(zkStateReader.getLeaderUrl(oneInstanceCollection2, "slice1", 10000))) {
-      Thread.sleep(100);
-      if (tries-- == 0) {
-        fail("Leader never changed");
+    try (HttpSolrClient unloadClient = new HttpSolrClient(baseUrl)) {
+      unloadClient.setConnectionTimeout(15000);
+      unloadClient.setSoTimeout(60000);
+      Unload unloadCmd = new Unload(true);
+      unloadCmd.setCoreName(props.getCoreName());
+
+      String leader = props.getCoreUrl();
+
+      unloadClient.request(unloadCmd);
+
+      int tries = 50;
+      while (leader.equals(zkStateReader.getLeaderUrl(oneInstanceCollection2, "slice1", 10000))) {
+        Thread.sleep(100);
+        if (tries-- == 0) {
+          fail("Leader never changed");
+        }
       }
     }
 
-    for (SolrClient aClient : collectionClients) {
-      aClient.shutdown();
-    }
+    IOUtils.close(collectionClients);
 
   }
 
-  private void testSearchByCollectionName() throws SolrServerException {
+  private void testSearchByCollectionName() throws SolrServerException, IOException {
     log.info("### STARTING testSearchByCollectionName");
     SolrClient client = clients.get(0);
     final String baseUrl = ((HttpSolrClient) client).getBaseURL().substring(
@@ -855,11 +850,11 @@ public class BasicDistributedZkTest exte
     
     // the cores each have different names, but if we add the collection name to the url
     // we should get mapped to the right core
-    SolrClient client1 = createNewSolrClient(oneInstanceCollection, baseUrl);
-    SolrQuery query = new SolrQuery("*:*");
-    long oneDocs = client1.query(query).getResults().getNumFound();
-    assertEquals(3, oneDocs);
-    client1.shutdown();
+    try (SolrClient client1 = createNewSolrClient(oneInstanceCollection, baseUrl)) {
+      SolrQuery query = new SolrQuery("*:*");
+      long oneDocs = client1.query(query).getResults().getNumFound();
+      assertEquals(3, oneDocs);
+    }
   }
   
   private void testUpdateByCollectionName() throws SolrServerException, IOException {
@@ -873,9 +868,9 @@ public class BasicDistributedZkTest exte
     // the cores each have different names, but if we add the collection name to the url
     // we should get mapped to the right core
     // test hitting an update url
-    SolrClient client1 = createNewSolrClient(oneInstanceCollection, baseUrl);
-    client1.commit();
-    client1.shutdown();
+    try (SolrClient client1 = createNewSolrClient(oneInstanceCollection, baseUrl)) {
+      client1.commit();
+    }
   }
 
   private void testANewCollectionInOneInstance() throws Exception {
@@ -929,9 +924,8 @@ public class BasicDistributedZkTest exte
 //    System.out.println("All Docs:" + allDocs);
     
     assertEquals(3, allDocs);
-    for(SolrClient newCollectionClient:collectionClients) {
-      newCollectionClient.shutdown();
-    }
+    IOUtils.close(collectionClients);
+
   }
 
   private void createCollection(String collection,
@@ -945,9 +939,7 @@ public class BasicDistributedZkTest exte
     Callable call = new Callable() {
       @Override
       public Object call() {
-        HttpSolrClient client = null;
-        try {
-          client = new HttpSolrClient(baseUrl);
+        try (HttpSolrClient client = new HttpSolrClient(baseUrl)) {
           client.setConnectionTimeout(15000);
           Create createCmd = new Create();
           createCmd.setRoles("none");
@@ -970,10 +962,6 @@ public class BasicDistributedZkTest exte
         } catch (Exception e) {
           e.printStackTrace();
           //fail
-        } finally {
-          if (client != null) {
-            client.shutdown();
-          }
         }
         return null;
       }
@@ -1082,9 +1070,8 @@ public class BasicDistributedZkTest exte
       Callable call = new Callable() {
         @Override
         public Object call() {
-          HttpSolrClient client = null;
-          try {
-            client = new HttpSolrClient(baseUrl);
+
+          try (HttpSolrClient client = new HttpSolrClient(baseUrl)) {
             client.setConnectionTimeout(15000);
             client.setSoTimeout(60000);
             Create createCmd = new Create();
@@ -1094,10 +1081,6 @@ public class BasicDistributedZkTest exte
           } catch (Exception e) {
             e.printStackTrace();
             //fails
-          } finally {
-            if (client != null) {
-              client.shutdown();
-            }
           }
           return null;
         }
@@ -1160,13 +1143,11 @@ public class BasicDistributedZkTest exte
   public void distribTearDown() throws Exception {
     super.distribTearDown();
     if (commondCloudSolrClient != null) {
-      commondCloudSolrClient.shutdown();
+      commondCloudSolrClient.close();
     }
     if (otherCollectionClients != null) {
       for (List<SolrClient> clientList : otherCollectionClients.values()) {
-        for (SolrClient client : clientList) {
-          client.shutdown();
-        }
+        IOUtils.close(clientList);
       }
     }
     otherCollectionClients = null;

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java Wed Jan 28 11:55:57 2015
@@ -250,13 +250,11 @@ public class ChaosMonkeyNothingIsSafeTes
         zkServer.run();
       }
       
-      CloudSolrClient client = createCloudClient("collection1");
-      try {
+
+      try (CloudSolrClient client = createCloudClient("collection1")) {
           createCollection(null, "testcollection",
               1, 1, 1, client, null, "conf1");
 
-      } finally {
-        client.shutdown();
       }
       List<Integer> numShardsNumReplicas = new ArrayList<>(2);
       numShardsNumReplicas.add(1);

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeySafeLeaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeySafeLeaderTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeySafeLeaderTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeySafeLeaderTest.java Wed Jan 28 11:55:57 2015
@@ -17,10 +17,6 @@ package org.apache.solr.cloud;
  * limitations under the License.
  */
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
 import org.apache.lucene.util.LuceneTestCase.Slow;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.SolrServerException;
@@ -32,6 +28,10 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
 @Slow
 public class ChaosMonkeySafeLeaderTest extends AbstractFullDistribZkTestBase {
   
@@ -168,14 +168,10 @@ public class ChaosMonkeySafeLeaderTest e
       zkServer = new ZkTestServer(zkServer.getZkDir(), zkServer.getPort());
       zkServer.run();
     }
-    
-    CloudSolrClient client = createCloudClient("collection1");
-    try {
-        createCollection(null, "testcollection",
-            1, 1, 1, client, null, "conf1");
 
-    } finally {
-      client.shutdown();
+    try (CloudSolrClient client = createCloudClient("collection1")) {
+        createCollection(null, "testcollection", 1, 1, 1, client, null, "conf1");
+
     }
     List<Integer> numShardsNumReplicas = new ArrayList<>(2);
     numShardsNumReplicas.add(1);

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIAsyncDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIAsyncDistributedZkTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIAsyncDistributedZkTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIAsyncDistributedZkTest.java Wed Jan 28 11:55:57 2015
@@ -57,8 +57,7 @@ public class CollectionsAPIAsyncDistribu
   @Test
   @ShardsFixed(num = 1)
   public void testSolrJAPICalls() throws Exception {
-    SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)));
-    try {
+    try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
       Create createCollectionRequest = new Create();
       createCollectionRequest.setCollectionName("testasynccollectioncreation");
       createCollectionRequest.setNumShards(1);
@@ -100,8 +99,6 @@ public class CollectionsAPIAsyncDistribu
       state = getRequestStateAfterCompletion("1004", MAX_TIMEOUT_SECONDS * 2, client);
   
       assertEquals("Shard split did not complete. Last recorded state: " + state, "completed", state);
-    } finally {
-      client.shutdown();
     }
 
     if (DEBUG) {

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java Wed Jan 28 11:55:57 2015
@@ -278,20 +278,12 @@ public class CollectionsAPIDistributedZk
     String baseUrl = getBaseUrl((HttpSolrClient) clients.get(0));
     // now try to remove a collection when a couple of its nodes are down
     if (secondConfigSet) {
-      SolrClient client = createNewSolrClient("", baseUrl);
-      try {
-        createCollection(null, "halfdeletedcollection2", 3, 3, 6, client, null,
-            "conf2");
-      } finally {
-        client.shutdown();
+      try (SolrClient client = createNewSolrClient("", baseUrl)) {
+        createCollection(null, "halfdeletedcollection2", 3, 3, 6, client, null, "conf2");
       }
     } else {
-      SolrClient client = createNewSolrClient("", baseUrl);
-      try {
-        createCollection(null, "halfdeletedcollection2", 3, 3, 6,
-          client, null);
-      } finally {
-        client.shutdown();
+      try (SolrClient client = createNewSolrClient("", baseUrl)) {
+        createCollection(null, "halfdeletedcollection2", 3, 3, 6, client, null);
       }
     }
     
@@ -333,11 +325,8 @@ public class CollectionsAPIDistributedZk
 
   private NamedList<Object> makeRequest(String baseUrl, SolrRequest request)
       throws SolrServerException, IOException {
-    SolrClient client = createNewSolrClient("", baseUrl);
-    try {
+    try (SolrClient client = createNewSolrClient("", baseUrl)) {
       return client.request(request);
-    } finally {
-      client.shutdown();
     }
   }
 
@@ -632,7 +621,7 @@ public class CollectionsAPIDistributedZk
               numShards, replicationFactor, maxShardsPerNode, client, null);
         }
       } finally {
-        if (client != null) client.shutdown();
+        if (client != null) client.close();
       }
     }
     
@@ -644,11 +633,10 @@ public class CollectionsAPIDistributedZk
       
       String url = getUrlFromZk(collection);
 
-      HttpSolrClient collectionClient = new HttpSolrClient(url);
-      
-      // poll for a second - it can take a moment before we are ready to serve
-      waitForNon403or404or503(collectionClient);
-      collectionClient.shutdown();
+      try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
+        // poll for a second - it can take a moment before we are ready to serve
+        waitForNon403or404or503(collectionClient);
+      }
     }
     
     // sometimes we restart one of the jetty nodes
@@ -664,11 +652,10 @@ public class CollectionsAPIDistributedZk
         
         String url = getUrlFromZk(collection);
         
-        HttpSolrClient collectionClient = new HttpSolrClient(url);
-        
-        // poll for a second - it can take a moment before we are ready to serve
-        waitForNon403or404or503(collectionClient);
-        collectionClient.shutdown();
+        try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
+          // poll for a second - it can take a moment before we are ready to serve
+          waitForNon403or404or503(collectionClient);
+        }
       }
     }
 
@@ -711,29 +698,27 @@ public class CollectionsAPIDistributedZk
     
     String url = getUrlFromZk(collectionName);
 
-    HttpSolrClient collectionClient = new HttpSolrClient(url);
-    
-    
-    // lets try and use the solrj client to index 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");
+    try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
 
-    collectionClient.add(doc1);
-    
-    collectionClient.add(doc2);
+      // lets try and use the solrj client to index 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();
+
+      assertEquals(3, collectionClient.query(new SolrQuery("*:*")).getResults().getNumFound());
+    }
 
-    collectionClient.add(doc3);
-    
-    collectionClient.commit();
-    
-    assertEquals(3, collectionClient.query(new SolrQuery("*:*")).getResults().getNumFound());
-    collectionClient.shutdown();
-    collectionClient = null;
-    
     // lets try a collection reload
     
     // get core open times
@@ -810,13 +795,11 @@ public class CollectionsAPIDistributedZk
     
     url = getUrlFromZk(collectionName);
     
-    collectionClient = new HttpSolrClient(url);
-    
-    // poll for a second - it can take a moment before we are ready to serve
-    waitForNon403or404or503(collectionClient);
-    collectionClient.shutdown();
-    collectionClient = null;
-    
+    try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
+      // poll for a second - it can take a moment before we are ready to serve
+      waitForNon403or404or503(collectionClient);
+    }
+
     for (int j = 0; j < cnt; j++) {
       waitForRecoveriesToFinish(collectionName, zkStateReader, false);
     }
@@ -827,8 +810,7 @@ public class CollectionsAPIDistributedZk
     int replicationFactor = 2;
     int maxShardsPerNode = 1;
     collectionInfos = new HashMap<>();
-    CloudSolrClient client = createCloudClient("awholynewcollection_" + cnt);
-    try {
+    try (CloudSolrClient client = createCloudClient("awholynewcollection_" + cnt)) {
       exp = false;
       try {
         createCollection(collectionInfos, "awholynewcollection_" + cnt,
@@ -837,8 +819,6 @@ public class CollectionsAPIDistributedZk
         exp = true;
       }
       assertTrue("expected exception", exp);
-    } finally {
-      client.shutdown();
     }
 
     
@@ -860,19 +840,17 @@ public class CollectionsAPIDistributedZk
     numShards = createNodeList.size() * maxShardsPerNode;
     replicationFactor = 1;
     collectionInfos = new HashMap<>();
-    client = createCloudClient("awholynewcollection_" + (cnt+1));
-    try {
+
+    try (SolrClient client = createCloudClient("awholynewcollection_" + (cnt+1))) {
       CollectionAdminResponse res = createCollection(collectionInfos, "awholynewcollection_" + (cnt+1), numShards, replicationFactor, maxShardsPerNode, client, StrUtils.join(createNodeList, ','), "conf1");
       assertTrue(res.isSuccess());
-    } finally {
-      client.shutdown();
     }
     checkForCollection(collectionInfos.keySet().iterator().next(), collectionInfos.entrySet().iterator().next().getValue(), createNodeList);
     
     checkNoTwoShardsUseTheSameIndexDir();
     if(disableLegacy) {
       setClusterProp(client1, ZkStateReader.LEGACY_CLOUD, null);
-      client1.shutdown();
+      client1.close();
     }
   }
   
@@ -895,17 +873,9 @@ public class CollectionsAPIDistributedZk
           int replicationFactor = TestUtil.nextInt(random(), 0, 3) + 1;
           int maxShardsPerNode = (((numShards * 2 * replicationFactor) / getCommonCloudSolrClient()
               .getZkStateReader().getClusterState().getLiveNodes().size())) + 1;
-          
-          CloudSolrClient client = null;
-          try {
-            if (i == 0) {
-              client = createCloudClient(null);
-            } else if (i == 1) {
-              client = createCloudClient(collectionName);
-            } else  {
-              client = createCloudClient(null);
-            }
-            
+
+          try (CloudSolrClient client = createCloudClient(i == 1 ? collectionName : null)) {
+
             createCollection(collectionInfos, collectionName,
                 numShards, replicationFactor, maxShardsPerNode, client, null,
                 "conf1");
@@ -917,8 +887,6 @@ public class CollectionsAPIDistributedZk
           } catch (SolrServerException | IOException e) {
             e.printStackTrace();
             throw new RuntimeException(e);
-          } finally {
-            if (client != null) client.shutdown();
           }
         }
       }
@@ -1004,12 +972,9 @@ public class CollectionsAPIDistributedZk
         while (shardIt.hasNext()) {
           Entry<String,Replica> shardEntry = shardIt.next();
           ZkCoreNodeProps coreProps = new ZkCoreNodeProps(shardEntry.getValue());
-          HttpSolrClient server = new HttpSolrClient(coreProps.getBaseUrl());
           CoreAdminResponse mcr;
-          try {
+          try (HttpSolrClient server = new HttpSolrClient(coreProps.getBaseUrl())) {
             mcr = CoreAdminRequest.getStatus(coreProps.getCoreName(), server);
-          } finally {
-            server.shutdown();
           }
           long before = mcr.getStartTime(coreProps.getCoreName()).getTime();
           urlToTime.put(coreProps.getCoreUrl(), before);
@@ -1120,8 +1085,7 @@ public class CollectionsAPIDistributedZk
 
   private void addReplicaTest() throws Exception {
     String collectionName = "addReplicaColl";
-    CloudSolrClient client = createCloudClient(null);
-    try {
+    try (CloudSolrClient client = createCloudClient(null)) {
       createCollection(collectionName, client, 2, 2);
       String newReplicaName = Assign.assignNode(collectionName, client.getZkStateReader().getClusterState());
       ArrayList<String> nodeList = new ArrayList<>(client.getZkStateReader().getClusterState().getLiveNodes());
@@ -1163,9 +1127,6 @@ public class CollectionsAPIDistributedZk
 
       assertNotNull(newReplica);
 
-
-    } finally {
-      client.shutdown();
     }
 
   }
@@ -1207,12 +1168,10 @@ public class CollectionsAPIDistributedZk
   }
 
   private void clusterPropTest() throws Exception {
-    CloudSolrClient client = createCloudClient(null);
-
-    assertTrue("cluster property not set", setClusterProp(client, ZkStateReader.LEGACY_CLOUD, "false"));
-    assertTrue("cluster property not unset ", setClusterProp(client, ZkStateReader.LEGACY_CLOUD, null));
-
-    client.shutdown();
+    try (CloudSolrClient client = createCloudClient(null)) {
+      assertTrue("cluster property not set", setClusterProp(client, ZkStateReader.LEGACY_CLOUD, "false"));
+      assertTrue("cluster property not unset ", setClusterProp(client, ZkStateReader.LEGACY_CLOUD, null));
+    }
   }
 
   public static boolean setClusterProp(CloudSolrClient client, String name , String val) throws SolrServerException, IOException, InterruptedException {

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java Wed Jan 28 11:55:57 2015
@@ -257,9 +257,8 @@ public class CollectionsAPISolrJTests ex
 
     Replica replica1 = testCollection.getReplica("core_node1");
 
-    HttpSolrClient solrServer = new HttpSolrClient(replica1.getStr("base_url"));
-    try {
-      CoreAdminResponse status = CoreAdminRequest.getStatus(replica1.getStr("core"), solrServer);
+    try (HttpSolrClient client = new HttpSolrClient(replica1.getStr("base_url"))) {
+      CoreAdminResponse status = CoreAdminRequest.getStatus(replica1.getStr("core"), client);
       NamedList<Object> coreStatus = status.getCoreStatus(replica1.getStr("core"));
       String dataDirStr = (String) coreStatus.get("dataDir");
       String instanceDirStr = (String) coreStatus.get("instanceDir");
@@ -267,9 +266,6 @@ public class CollectionsAPISolrJTests ex
           new File(instanceDirStr).getAbsolutePath(), instanceDir.getAbsolutePath());
       assertEquals("Data dir does not match param given in property.dataDir syntax",
           new File(dataDirStr).getAbsolutePath(), dataDir.getAbsolutePath());
-
-    } finally {
-      solrServer.shutdown();
     }
 
     CollectionAdminRequest.Delete deleteCollectionRequest = new CollectionAdminRequest.Delete();

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java Wed Jan 28 11:55:57 2015
@@ -17,27 +17,6 @@ package org.apache.solr.cloud;
  * limitations under the License.
  */
 
-import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;
-import static org.apache.solr.cloud.OverseerCollectionProcessor.ROUTER;
-import static org.apache.solr.cloud.OverseerCollectionProcessor.SHARDS_PROP;
-import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
-import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
-import static org.apache.solr.common.params.ShardParams._ROUTE_;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.CompletionService;
-import java.util.concurrent.ExecutorCompletionService;
-import java.util.concurrent.Future;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
 import org.apache.lucene.util.LuceneTestCase.Slow;
 import org.apache.lucene.util.TestUtil;
 import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
@@ -63,6 +42,27 @@ import org.apache.solr.util.DefaultSolrT
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.CompletionService;
+import java.util.concurrent.ExecutorCompletionService;
+import java.util.concurrent.Future;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.ROUTER;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.SHARDS_PROP;
+import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
+import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
+import static org.apache.solr.common.params.ShardParams._ROUTE_;
+
 /**
  * Tests the Custom Sharding API.
  */
@@ -183,7 +183,7 @@ public class CustomCollectionTest extend
 
         createCollection(collectionInfos, COLL_PREFIX + i,props,client);
       } finally {
-        if (client != null) client.shutdown();
+        if (client != null) client.close();
       }
     }
 
@@ -195,11 +195,10 @@ public class CustomCollectionTest extend
 
       String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collection);
 
-      HttpSolrClient collectionClient = new HttpSolrClient(url);
-
-      // poll for a second - it can take a moment before we are ready to serve
-      waitForNon403or404or503(collectionClient);
-      collectionClient.shutdown();
+      try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
+        // poll for a second - it can take a moment before we are ready to serve
+        waitForNon403or404or503(collectionClient);
+      }
     }
     ZkStateReader zkStateReader = getCommonCloudSolrClient().getZkStateReader();
     for (int j = 0; j < cnt; j++) {
@@ -224,8 +223,7 @@ public class CustomCollectionTest extend
     String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
 
     String shard_fld = "shard_s";
-    HttpSolrClient collectionClient = new HttpSolrClient(url);
-    try {
+    try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
 
       // lets try and use the solrj client to index a couple documents
   
@@ -272,9 +270,9 @@ public class CustomCollectionTest extend
       params.set("shard", "x");
       SolrRequest request = new QueryRequest(params);
       request.setPath("/admin/collections");
-      SolrClient server = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)));
-      server.request(request);
-      server.shutdown();
+      try (SolrClient server = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
+        server.request(request);
+      }
       waitForCollection(zkStateReader,collectionName,4);
       //wait for all the replicas to become active
       int attempts = 0;
@@ -300,11 +298,8 @@ public class CustomCollectionTest extend
       replicationFactor = TestUtil.nextInt(random(), 0, 3) + 2;
       int maxShardsPerNode = (((numShards * replicationFactor) / getCommonCloudSolrClient()
           .getZkStateReader().getClusterState().getLiveNodes().size())) + 1;
-  
-  
-      CloudSolrClient client = null;
-      try {
-        client = createCloudClient(null);
+
+      try (CloudSolrClient client = createCloudClient(null)) {
         Map<String, Object> props = ZkNodeProps.makeMap(
             "router.name", ImplicitDocRouter.NAME,
             REPLICATION_FACTOR, replicationFactor,
@@ -314,8 +309,6 @@ public class CustomCollectionTest extend
   
         collectionName = COLL_PREFIX + "withShardField";
         createCollection(collectionInfos, collectionName,props,client);
-      } finally {
-        if (client != null) client.shutdown();
       }
   
       List<Integer> list = collectionInfos.get(collectionName);
@@ -323,20 +316,14 @@ public class CustomCollectionTest extend
   
   
       url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
-    } finally {
-      collectionClient.shutdown();
     }
-    collectionClient = new HttpSolrClient(url);
-    try {
-      // poll for a second - it can take a moment before we are ready to serve
+
+    try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
+         // poll for a second - it can take a moment before we are ready to serve
       waitForNon403or404or503(collectionClient);
-    } finally {
-      collectionClient.shutdown();
     }
 
-
-      collectionClient = new HttpSolrClient(url);
-      try {
+    try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
       // lets try and use the solrj client to index a couple documents
   
       collectionClient.add(getDoc(id, 6, i1, -600, tlong, 600, t1,
@@ -354,8 +341,6 @@ public class CustomCollectionTest extend
       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());
-    } finally {
-      collectionClient.shutdown();
     }
   }
 
@@ -367,10 +352,8 @@ public class CustomCollectionTest extend
         .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,
@@ -378,8 +361,6 @@ public class CustomCollectionTest extend
           "router.field", shard_fld);
 
       createCollection(collectionInfos, collectionName,props,client);
-    } finally {
-      if (client != null) client.shutdown();
     }
 
     List<Integer> list = collectionInfos.get(collectionName);
@@ -388,18 +369,13 @@ public class CustomCollectionTest extend
 
     String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
 
-    HttpSolrClient collectionClient = new HttpSolrClient(url);
-    try {
+    try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
       // poll for a second - it can take a moment before we are ready to serve
       waitForNon403or404or503(collectionClient);
-      collectionClient.shutdown();
-    } finally {
-      collectionClient.shutdown();
     }
 
 
-    collectionClient = new HttpSolrClient(url);
-    try {
+    try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
       // lets try and use the solrj client to index a couple documents
   
       collectionClient.add(getDoc(id, 6, i1, -600, tlong, 600, t1,
@@ -423,17 +399,13 @@ public class CustomCollectionTest extend
       collectionClient.add (getDoc( id,100,shard_fld, "b!doc1"));
       collectionClient.commit();
       assertEquals(1, collectionClient.query(new SolrQuery("*:*").setParam(_ROUTE_, "b!")).getResults().getNumFound());
-    } finally {
-      collectionClient.shutdown();
     }
   }
 
   private void testCreateShardRepFactor() throws Exception  {
     String collectionName = "testCreateShardRepFactor";
     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, 1,
           MAX_SHARDS_PER_NODE, 5,
@@ -442,8 +414,6 @@ public class CustomCollectionTest extend
           "router.name", "implicit");
 
       createCollection(collectionInfos, collectionName, props, client);
-    } finally {
-      if (client != null) client.shutdown();
     }
     ZkStateReader zkStateReader = getCommonCloudSolrClient().getZkStateReader();
     waitForRecoveriesToFinish(collectionName, zkStateReader, false);
@@ -454,9 +424,10 @@ public class CustomCollectionTest extend
     params.set("shard", "x");
     SolrRequest request = new QueryRequest(params);
     request.setPath("/admin/collections");
-    SolrClient server = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)));
-    server.request(request);
-    server.shutdown();
+
+    try (SolrClient server = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
+      server.request(request);
+    }
 
     waitForRecoveriesToFinish(collectionName, zkStateReader, false);
 

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java Wed Jan 28 11:55:57 2015
@@ -42,109 +42,107 @@ public class DeleteInactiveReplicaTest e
 
   @Test
   public void deleteInactiveReplicaTest() throws Exception {
-    CloudSolrClient client = createCloudClient(null);
+    try (CloudSolrClient client = createCloudClient(null)) {
 
-    String collectionName = "delDeadColl";
+      String collectionName = "delDeadColl";
 
-    setClusterProp(client, ZkStateReader.LEGACY_CLOUD, "false");
-    
-    createCollection(collectionName, client);
-    
-    waitForRecoveriesToFinish(collectionName, false);
-
-    Thread.sleep(3000);
-
-    boolean stopped = false;
-    JettySolrRunner stoppedJetty = null;
-    StringBuilder sb = new StringBuilder();
-    Replica replica1 = null;
-    Slice shard1 = null;
-    long timeout = System.currentTimeMillis() + 3000;
-    DocCollection testcoll = null;
-    while(!stopped && System.currentTimeMillis()<timeout ) {
-      testcoll = client.getZkStateReader().getClusterState().getCollection(collectionName);
-      for (JettySolrRunner jetty : jettys)
-        sb.append(jetty.getBaseUrl()).append(",");
-
-      for (Slice slice : testcoll.getActiveSlices()) {
-        for (Replica replica : slice.getReplicas())
-          for (JettySolrRunner jetty : jettys) {
-            URL baseUrl = null;
-            try {
-              baseUrl = jetty.getBaseUrl();
-            } catch (Exception e) {
-              continue;
-            }
-            if (baseUrl.toString().startsWith(
-                replica.getStr(ZkStateReader.BASE_URL_PROP))) {
-              stoppedJetty = jetty;
-              ChaosMonkey.stop(jetty);
-              replica1 = replica;
-              shard1 = slice;
-              stopped = true;
-              break;
+      setClusterProp(client, ZkStateReader.LEGACY_CLOUD, "false");
+
+      createCollection(collectionName, client);
+
+      waitForRecoveriesToFinish(collectionName, false);
+
+      Thread.sleep(3000);
+
+      boolean stopped = false;
+      JettySolrRunner stoppedJetty = null;
+      StringBuilder sb = new StringBuilder();
+      Replica replica1 = null;
+      Slice shard1 = null;
+      long timeout = System.currentTimeMillis() + 3000;
+      DocCollection testcoll = null;
+      while (!stopped && System.currentTimeMillis() < timeout) {
+        testcoll = client.getZkStateReader().getClusterState().getCollection(collectionName);
+        for (JettySolrRunner jetty : jettys)
+          sb.append(jetty.getBaseUrl()).append(",");
+
+        for (Slice slice : testcoll.getActiveSlices()) {
+          for (Replica replica : slice.getReplicas())
+            for (JettySolrRunner jetty : jettys) {
+              URL baseUrl = null;
+              try {
+                baseUrl = jetty.getBaseUrl();
+              } catch (Exception e) {
+                continue;
+              }
+              if (baseUrl.toString().startsWith(
+                  replica.getStr(ZkStateReader.BASE_URL_PROP))) {
+                stoppedJetty = jetty;
+                ChaosMonkey.stop(jetty);
+                replica1 = replica;
+                shard1 = slice;
+                stopped = true;
+                break;
+              }
             }
-          }
+        }
+        Thread.sleep(100);
       }
-      Thread.sleep(100);
-    }
 
 
-    if (!stopped) {
-      fail("Could not find jetty to stop in collection " + testcoll
-          + " jettys: " + sb);
-    }
-    
-    long endAt = System.currentTimeMillis() + 3000;
-    boolean success = false;
-    while (System.currentTimeMillis() < endAt) {
-      testcoll = client.getZkStateReader()
-          .getClusterState().getCollection(collectionName);
-      if (!"active".equals(testcoll.getSlice(shard1.getName())
-          .getReplica(replica1.getName()).getStr(Slice.STATE))) {
-        success = true;
+      if (!stopped) {
+        fail("Could not find jetty to stop in collection " + testcoll
+            + " jettys: " + sb);
       }
-      if (success) break;
-      Thread.sleep(100);
-    }
 
-    log.info("removed_replicas {}/{} ", shard1.getName(), replica1.getName());
-    removeAndWaitForReplicaGone(collectionName, client, replica1,
-        shard1.getName());
-    ChaosMonkey.start(stoppedJetty);
-    log.info("restarted jetty");
-
-    Map m = makeMap("qt", "/admin/cores", "action", "status");
-
-    SolrClient queryClient = new HttpSolrClient(replica1.getStr(ZkStateReader.BASE_URL_PROP));
-    NamedList<Object> resp = queryClient.request(new QueryRequest(new MapSolrParams(m)));
-    assertNull("The core is up and running again",
-        ((NamedList) resp.get("status")).get(replica1.getStr("core")));
-    queryClient.shutdown();
-    queryClient = null;
-
-
-    Exception exp = null;
-
-    try {
-
-      m = makeMap(
-          "action", CoreAdminParams.CoreAdminAction.CREATE.toString(),
-          ZkStateReader.COLLECTION_PROP, collectionName,
-          ZkStateReader.SHARD_ID_PROP, "shard2",
-          CoreAdminParams.NAME, "testcore");
-
-      QueryRequest request = new QueryRequest(new MapSolrParams(m));
-      request.setPath("/admin/cores");
-      NamedList<Object> rsp = client.request(request);
-    } catch (Exception e) {
-      exp = e;
-      log.info("error_expected",e);
-    }
-    assertNotNull( "Exception expected", exp);
-    setClusterProp(client,ZkStateReader.LEGACY_CLOUD,null);
-    client.shutdown();
+      long endAt = System.currentTimeMillis() + 3000;
+      boolean success = false;
+      while (System.currentTimeMillis() < endAt) {
+        testcoll = client.getZkStateReader()
+            .getClusterState().getCollection(collectionName);
+        if (!"active".equals(testcoll.getSlice(shard1.getName())
+            .getReplica(replica1.getName()).getStr(Slice.STATE))) {
+          success = true;
+        }
+        if (success) break;
+        Thread.sleep(100);
+      }
 
+      log.info("removed_replicas {}/{} ", shard1.getName(), replica1.getName());
+      removeAndWaitForReplicaGone(collectionName, client, replica1,
+          shard1.getName());
+      ChaosMonkey.start(stoppedJetty);
+      log.info("restarted jetty");
+
+      Map m = makeMap("qt", "/admin/cores", "action", "status");
+
+      try (SolrClient queryClient = new HttpSolrClient(replica1.getStr(ZkStateReader.BASE_URL_PROP))) {
+        NamedList<Object> resp = queryClient.request(new QueryRequest(new MapSolrParams(m)));
+        assertNull("The core is up and running again",
+            ((NamedList) resp.get("status")).get(replica1.getStr("core")));
+      }
+
+      Exception exp = null;
+
+      try {
+
+        m = makeMap(
+            "action", CoreAdminParams.CoreAdminAction.CREATE.toString(),
+            ZkStateReader.COLLECTION_PROP, collectionName,
+            ZkStateReader.SHARD_ID_PROP, "shard2",
+            CoreAdminParams.NAME, "testcore");
+
+        QueryRequest request = new QueryRequest(new MapSolrParams(m));
+        request.setPath("/admin/cores");
+        NamedList<Object> rsp = client.request(request);
+      } catch (Exception e) {
+        exp = e;
+        log.info("error_expected", e);
+      }
+      assertNotNull("Exception expected", exp);
+      setClusterProp(client, ZkStateReader.LEGACY_CLOUD, null);
+
+    }
 
   }
 }

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteLastCustomShardedReplicaTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteLastCustomShardedReplicaTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteLastCustomShardedReplicaTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteLastCustomShardedReplicaTest.java Wed Jan 28 11:55:57 2015
@@ -63,7 +63,7 @@ public class DeleteLastCustomShardedRepl
   @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/DeleteReplicaTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java Wed Jan 28 11:55:57 2015
@@ -66,7 +66,7 @@ public class DeleteReplicaTest extends A
   @Override
   public void distribTearDown() throws Exception {
     super.distribTearDown();
-    client.shutdown();
+    client.close();
   }
 
   protected String getSolrXml() {
@@ -82,8 +82,7 @@ public class DeleteReplicaTest extends A
   @ShardsFixed(num = 4)
   public void deleteLiveReplicaTest() throws Exception {
     String collectionName = "delLiveColl";
-    CloudSolrClient client = createCloudClient(null);
-    try {
+    try (CloudSolrClient client = createCloudClient(null)) {
       createCollection(collectionName, client);
       
       waitForRecoveriesToFinish(collectionName, false);
@@ -111,14 +110,11 @@ public class DeleteReplicaTest extends A
 
       if (replica1 == null) fail("no active replicas found");
 
-      HttpSolrClient replica1Client = new HttpSolrClient(replica1.getStr("base_url"));
       String dataDir = null;
-      try {
+      try (HttpSolrClient replica1Client = new HttpSolrClient(replica1.getStr("base_url"))) {
         CoreAdminResponse status = CoreAdminRequest.getStatus(replica1.getStr("core"), replica1Client);
         NamedList<Object> coreStatus = status.getCoreStatus(replica1.getStr("core"));
         dataDir = (String) coreStatus.get("dataDir");
-      } finally {
-        replica1Client.shutdown();
       }
       try {
         // Should not be able to delete a replica that is up if onlyIfDown=true.
@@ -135,8 +131,6 @@ public class DeleteReplicaTest extends A
 
       removeAndWaitForReplicaGone(collectionName, client, replica1, shard1.getName());
       assertFalse("dataDir for " + replica1.getName() + " should have been deleted by deleteReplica API", new File(dataDir).exists());
-    } finally {
-      client.shutdown();
     }
   }
 

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java Wed Jan 28 11:55:57 2015
@@ -128,13 +128,10 @@ public class DeleteShardTest extends Abs
         .getBaseURL();
     baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
 
-    HttpSolrClient baseServer = new HttpSolrClient(baseUrl);
-    try {
+    try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) {
       baseServer.setConnectionTimeout(15000);
       baseServer.setSoTimeout(60000);
       baseServer.request(request);
-    } finally {
-      baseServer.shutdown();
     }
   }
 

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DistribCursorPagingTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DistribCursorPagingTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DistribCursorPagingTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/DistribCursorPagingTest.java Wed Jan 28 11:55:57 2015
@@ -16,22 +16,24 @@
  */
 package org.apache.solr.cloud;
 
+import com.carrotsearch.randomizedtesting.annotations.Seed;
 import org.apache.lucene.util.LuceneTestCase.Slow;
-import org.apache.lucene.util.TestUtil;
 import org.apache.lucene.util.SentinelIntSet;
+import org.apache.lucene.util.TestUtil;
 import org.apache.solr.CursorPagingTest;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.request.LukeRequest;
 import org.apache.solr.client.solrj.response.QueryResponse;
-import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.common.SolrDocument;
 import org.apache.solr.common.SolrDocumentList;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.GroupParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.search.CursorMark;
 import static org.apache.solr.common.params.CursorMarkParams.CURSOR_MARK_PARAM;
 import static org.apache.solr.common.params.CursorMarkParams.CURSOR_MARK_NEXT;
 import static org.apache.solr.common.params.CursorMarkParams.CURSOR_MARK_START;
@@ -42,9 +44,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
-import java.util.List;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 
 /**

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ExternalCollectionsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ExternalCollectionsTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ExternalCollectionsTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/ExternalCollectionsTest.java Wed Jan 28 11:55:57 2015
@@ -24,8 +24,6 @@ import org.apache.solr.common.cloud.DocC
 import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.params.CollectionParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.handler.BlobHandler;
-import org.apache.solr.handler.TestBlobHandler;
 import org.apache.zookeeper.data.Stat;
 import org.junit.Test;
 
@@ -43,7 +41,7 @@ public class ExternalCollectionsTest ext
   @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/FullSolrCloudDistribCmdsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java Wed Jan 28 11:55:57 2015
@@ -430,12 +430,11 @@ public class FullSolrCloudDistribCmdsTes
   }
   
   private long testConcurrentIndexing(long docId) throws Exception {
-    ConcurrentUpdateSolrClient concurrentClient = new ConcurrentUpdateSolrClient(
-        ((HttpSolrClient) clients.get(0)).getBaseURL(), 10, 2);
     QueryResponse results = query(cloudClient);
     long beforeCount = results.getResults().getNumFound();
     int cnt = TEST_NIGHTLY ? 2933 : 313;
-    try {
+    try (ConcurrentUpdateSolrClient concurrentClient = new ConcurrentUpdateSolrClient(
+        ((HttpSolrClient) clients.get(0)).getBaseURL(), 10, 2)) {
       concurrentClient.setConnectionTimeout(120000);
       for (int i = 0; i < cnt; i++) {
         index_specific(concurrentClient, id, docId++, "text_t", "some text so that it not's negligent work to parse this doc, even though it's still a pretty short doc");
@@ -446,8 +445,6 @@ public class FullSolrCloudDistribCmdsTes
 
       checkShardConsistency();
       assertDocCounts(VERBOSE);
-    } finally {
-      concurrentClient.shutdown();
     }
     results = query(cloudClient);
     assertEquals(beforeCount + cnt, results.getResults().getNumFound());

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java Wed Jan 28 11:55:57 2015
@@ -362,23 +362,17 @@ public class HttpPartitionTest extends A
     log.info("Sending doc 2 to old leader "+leader.getName());
     try {
       leaderSolr.add(doc);
-      leaderSolr.shutdown();
+      leaderSolr.close();
 
       // if the add worked, then the doc must exist on the new leader
-      HttpSolrClient newLeaderSolr = getHttpSolrClient(currentLeader, testCollectionName);
-      try {
+      try (HttpSolrClient newLeaderSolr = getHttpSolrClient(currentLeader, testCollectionName)) {
         assertDocExists(newLeaderSolr, testCollectionName, "2");
-      } finally {
-        newLeaderSolr.shutdown();
       }
 
     } catch (SolrException exc) {
       // this is ok provided the doc doesn't exist on the current leader
-      leaderSolr = getHttpSolrClient(currentLeader, testCollectionName);
-      try {
-        leaderSolr.add(doc); // this should work
-      } finally {
-        leaderSolr.shutdown();
+      try (HttpSolrClient client = getHttpSolrClient(currentLeader, testCollectionName)) {
+        client.add(doc); // this should work
       }
     }
 
@@ -425,12 +419,12 @@ public class HttpPartitionTest extends A
   protected void assertDocsExistInAllReplicas(List<Replica> notLeaders,
       String testCollectionName, int firstDocId, int lastDocId)
       throws Exception {
-    Replica leader = 
+    Replica leader =
         cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, "shard1", 10000);
     HttpSolrClient leaderSolr = getHttpSolrClient(leader, testCollectionName);
     List<HttpSolrClient> replicas =
         new ArrayList<HttpSolrClient>(notLeaders.size());
-    
+
     for (Replica r : notLeaders) {
       replicas.add(getHttpSolrClient(r, testCollectionName));
     }
@@ -444,10 +438,10 @@ public class HttpPartitionTest extends A
       }
     } finally {
       if (leaderSolr != null) {
-        leaderSolr.shutdown();
+        leaderSolr.close();
       }
       for (HttpSolrClient replicaSolr : replicas) {
-        replicaSolr.shutdown();
+        replicaSolr.close();
       }
     }
   }

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/LeaderFailoverAfterPartitionTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/LeaderFailoverAfterPartitionTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/LeaderFailoverAfterPartitionTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/LeaderFailoverAfterPartitionTest.java Wed Jan 28 11:55:57 2015
@@ -17,11 +17,6 @@ package org.apache.solr.cloud;
  * limitations under the License.
  */
 
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
 import org.apache.lucene.util.LuceneTestCase.Slow;
 import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
 import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@@ -30,6 +25,11 @@ import org.apache.solr.client.solrj.requ
 import org.apache.solr.common.cloud.Replica;
 import org.junit.Test;
 
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
 /**
  * Tests leader-initiated recovery scenarios after a leader node fails
  * and one of the replicas is out-of-sync.
@@ -113,17 +113,12 @@ public class LeaderFailoverAfterPartitio
     // doc should be on leader and 1 replica
     sendDoc(5);
     
-    HttpSolrClient server = getHttpSolrClient(leader, testCollectionName);
-    try {
+    try (HttpSolrClient server = getHttpSolrClient(leader, testCollectionName)) {
       assertDocExists(server, testCollectionName, "5");
-    } finally {
-      server.shutdown();
     }
-    try {
-      server = getHttpSolrClient(notLeaders.get(1), testCollectionName);
+
+    try (HttpSolrClient server = getHttpSolrClient(notLeaders.get(1), testCollectionName)) {
       assertDocExists(server, testCollectionName, "5");
-    } finally {
-      server.shutdown();
     }
   
     Thread.sleep(sleepMsBeforeHealPartition);

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/LeaderInitiatedRecoveryOnCommitTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/LeaderInitiatedRecoveryOnCommitTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/LeaderInitiatedRecoveryOnCommitTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/LeaderInitiatedRecoveryOnCommitTest.java Wed Jan 28 11:55:57 2015
@@ -83,11 +83,8 @@ public class LeaderInitiatedRecoveryOnCo
 
     // let's find the leader of shard2 and ask him to commit
     Replica shard2Leader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, "shard2");
-    HttpSolrClient server = new HttpSolrClient(ZkCoreNodeProps.getCoreUrl(shard2Leader.getStr("base_url"), shard2Leader.getStr("core")));
-    try {
+    try (HttpSolrClient server = new HttpSolrClient(ZkCoreNodeProps.getCoreUrl(shard2Leader.getStr("base_url"), shard2Leader.getStr("core")))) {
       server.commit();
-    } finally {
-      server.shutdown();
     }
 
     Thread.sleep(sleepMsBeforeHealPartition);
@@ -129,9 +126,9 @@ public class LeaderInitiatedRecoveryOnCo
     leaderProxy.close();
 
     Replica replica = notLeaders.get(0);
-    HttpSolrClient client = new HttpSolrClient(ZkCoreNodeProps.getCoreUrl(replica.getStr("base_url"), replica.getStr("core")));
-    client.commit();
-    client.shutdown();
+    try (HttpSolrClient client = new HttpSolrClient(ZkCoreNodeProps.getCoreUrl(replica.getStr("base_url"), replica.getStr("core")))) {
+      client.commit();
+    }
 
     Thread.sleep(sleepMsBeforeHealPartition);
 

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java?rev=1655263&r1=1655262&r2=1655263&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java Wed Jan 28 11:55:57 2015
@@ -119,26 +119,23 @@ public class MigrateRouteKeyTest extends
         .getBaseURL();
     baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
 
-    HttpSolrClient baseClient = new HttpSolrClient(baseUrl);
-    baseClient.setConnectionTimeout(15000);
-    baseClient.setSoTimeout(60000 * 5);
-    baseClient.request(request);
-    baseClient.shutdown();
+    try (HttpSolrClient baseClient = new HttpSolrClient(baseUrl)) {
+      baseClient.setConnectionTimeout(15000);
+      baseClient.setSoTimeout(60000 * 5);
+      baseClient.request(request);
+    }
   }
 
   private void createCollection(String targetCollection) throws Exception {
     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, 1,
           MAX_SHARDS_PER_NODE, 5,
           NUM_SLICES, 1);
 
       createCollection(collectionInfos, targetCollection, props, client);
-    } finally {
-      if (client != null) client.shutdown();
     }
 
     List<Integer> list = collectionInfos.get(targetCollection);
@@ -176,42 +173,42 @@ public class MigrateRouteKeyTest extends
     indexer.start();
 
     String url = CustomCollectionTest.getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), targetCollection);
-    HttpSolrClient collectionClient = new HttpSolrClient(url);
 
-    SolrQuery solrQuery = new SolrQuery("*:*");
-    assertEquals("DocCount on target collection does not match", 0, collectionClient.query(solrQuery).getResults().getNumFound());
+    try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
 
-    invokeMigrateApi(AbstractDistribZkTestBase.DEFAULT_COLLECTION, splitKey + "/" + BIT_SEP + "!", targetCollection);
-    long finishTime = System.currentTimeMillis();
+      SolrQuery solrQuery = new SolrQuery("*:*");
+      assertEquals("DocCount on target collection does not match", 0, collectionClient.query(solrQuery).getResults().getNumFound());
 
-    indexer.join();
-    splitKeyCount[0] += indexer.getSplitKeyCount();
-
-    try {
-      cloudClient.deleteById("a/" + BIT_SEP + "!104");
-      splitKeyCount[0]--;
-    } catch (Exception e) {
-      log.warn("Error deleting document a/" + BIT_SEP + "!104", e);
-    }
-    cloudClient.commit();
-    collectionClient.commit();
+      invokeMigrateApi(AbstractDistribZkTestBase.DEFAULT_COLLECTION, splitKey + "/" + BIT_SEP + "!", targetCollection);
+      long finishTime = System.currentTimeMillis();
 
-    solrQuery = new SolrQuery("*:*").setRows(1000);
-    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;
-
-    getCommonCloudSolrClient().getZkStateReader().updateClusterState(true);
-    ClusterState state = getCommonCloudSolrClient().getZkStateReader().getClusterState();
-    Slice slice = state.getSlice(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD2);
-    assertNotNull("Routing rule map is null", slice.getRoutingRules());
-    assertFalse("Routing rule map is empty", slice.getRoutingRules().isEmpty());
-    assertNotNull("No routing rule exists for route key: " + splitKey, slice.getRoutingRules().get(splitKey + "!"));
+      indexer.join();
+      splitKeyCount[0] += indexer.getSplitKeyCount();
+
+      try {
+        cloudClient.deleteById("a/" + BIT_SEP + "!104");
+        splitKeyCount[0]--;
+      } catch (Exception e) {
+        log.warn("Error deleting document a/" + BIT_SEP + "!104", e);
+      }
+      cloudClient.commit();
+      collectionClient.commit();
+
+      solrQuery = new SolrQuery("*:*").setRows(1000);
+      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());
+
+      getCommonCloudSolrClient().getZkStateReader().updateClusterState(true);
+      ClusterState state = getCommonCloudSolrClient().getZkStateReader().getClusterState();
+      Slice slice = state.getSlice(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD2);
+      assertNotNull("Routing rule map is null", slice.getRoutingRules());
+      assertFalse("Routing rule map is empty", slice.getRoutingRules().isEmpty());
+      assertNotNull("No routing rule exists for route key: " + splitKey, slice.getRoutingRules().get(splitKey + "!"));
 
-    boolean ruleRemoved = waitForRuleToExpire(splitKey, finishTime);
-    assertTrue("Routing rule was not expired", ruleRemoved);
+      boolean ruleRemoved = waitForRuleToExpire(splitKey, finishTime);
+      assertTrue("Routing rule was not expired", ruleRemoved);
+    }
   }
 
   static class Indexer extends Thread {



Mime
View raw message