From 5a96141d7f3bccd1df9684dee870028da7be18d2 Mon Sep 17 00:00:00 2001 From: Anshum Gupta Date: Sun, 24 May 2015 05:28:43 +0000 Subject: [PATCH] SOLR-7468: Close the cloud client created for test in a finally block. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1681413 13f79535-47bb-0310-9956-ffa450edef68 --- .../solr/cloud/TestSolrCloudWithKerberos.java | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithKerberos.java b/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithKerberos.java index 268a6aeeff8..a6570d602d8 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithKerberos.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithKerberos.java @@ -146,30 +146,34 @@ public class TestSolrCloudWithKerberos extends AbstractFullDistribZkTestBase { @Test public void testKerberizedSolr() throws Exception { - HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); - CloudSolrClient testClient = createCloudClient("testcollection"); - - CollectionAdminRequest.Create create = new CollectionAdminRequest.Create(); - create.setCollectionName("testcollection"); - create.setConfigName("conf1"); - create.setNumShards(1); - create.setReplicationFactor(1); - create.process(testClient); - - waitForCollection(testClient.getZkStateReader(), "testcollection", 1); - CollectionAdminRequest.List list = new CollectionAdminRequest.List(); - - CollectionAdminResponse response = list.process(testClient); - assertTrue("Expected to see testcollection but it doesn't exist", - ((ArrayList) response.getResponse().get("collections")).contains("testcollection")); - - testClient.setDefaultCollection("testcollection"); - indexDoc(testClient, params("commit", "true"), getDoc("id", 1)); - //cloudClient.commit(); + CloudSolrClient testClient = null; + try { + HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); + testClient = createCloudClient("testcollection"); - QueryResponse queryResponse = testClient.query(new SolrQuery("*:*")); - assertEquals("Expected #docs and actual isn't the same", 1, queryResponse.getResults().size()); - testClient.close(); + CollectionAdminRequest.Create create = new CollectionAdminRequest.Create(); + create.setCollectionName("testcollection"); + create.setConfigName("conf1"); + create.setNumShards(1); + create.setReplicationFactor(1); + create.process(testClient); + + waitForCollection(testClient.getZkStateReader(), "testcollection", 1); + CollectionAdminRequest.List list = new CollectionAdminRequest.List(); + + CollectionAdminResponse response = list.process(testClient); + assertTrue("Expected to see testcollection but it doesn't exist", + ((ArrayList) response.getResponse().get("collections")).contains("testcollection")); + + testClient.setDefaultCollection("testcollection"); + indexDoc(testClient, params("commit", "true"), getDoc("id", 1)); + + QueryResponse queryResponse = testClient.query(new SolrQuery("*:*")); + assertEquals("Expected #docs and actual isn't the same", 1, queryResponse.getResults().size()); + } finally { + if(testClient != null) + testClient.close(); + } } @Override