From ebb7ecb00e31126f545334fe7b8067b570c6e3ce Mon Sep 17 00:00:00 2001 From: javanna Date: Tue, 3 Feb 2015 16:45:27 +0100 Subject: [PATCH] [TEST] RestClient to use a non static pooling connection manager When closing an instance of RestClient, the connection manager gets shutdown, which makes it not usable anymore. If that is static, like it is now, no RestClient will work anymore from that moment on. Each instance of RestClient should have its own instance of connection manager --- .../elasticsearch/test/rest/client/RestClient.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/elasticsearch/test/rest/client/RestClient.java b/src/test/java/org/elasticsearch/test/rest/client/RestClient.java index 793ed3530af..5022f8b802f 100644 --- a/src/test/java/org/elasticsearch/test/rest/client/RestClient.java +++ b/src/test/java/org/elasticsearch/test/rest/client/RestClient.java @@ -21,10 +21,10 @@ package org.elasticsearch.test.rest.client; import com.carrotsearch.randomizedtesting.RandomizedTest; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.lucene.util.IOUtils; import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.ESLogger; @@ -49,7 +49,6 @@ import java.util.concurrent.TimeUnit; public class RestClient implements Closeable { private static final ESLogger logger = Loggers.getLogger(RestClient.class); - private static final HttpClientConnectionManager connectionPool = new PoolingHttpClientConnectionManager(15, TimeUnit.SECONDS); private final RestSpec restSpec; private final CloseableHttpClient httpClient; @@ -222,7 +221,7 @@ public class RestClient implements Closeable { } protected CloseableHttpClient createHttpClient() { - return HttpClients.createMinimal(connectionPool); + return HttpClients.createMinimal(new PoolingHttpClientConnectionManager(15, TimeUnit.SECONDS)); } public InetSocketAddress[] httpAddresses() { @@ -233,10 +232,6 @@ public class RestClient implements Closeable { * Closes the REST client and the underlying http client */ public void close() { - try { - httpClient.close(); - } catch(IOException e) { - logger.error(e.getMessage(), e); - } + IOUtils.closeWhileHandlingException(httpClient); } }