[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
This commit is contained in:
javanna 2015-02-03 16:45:27 +01:00 committed by Luca Cavanna
parent 8540a863aa
commit ebb7ecb00e
1 changed files with 3 additions and 8 deletions

View File

@ -21,10 +21,10 @@ package org.elasticsearch.test.rest.client;
import com.carrotsearch.randomizedtesting.RandomizedTest; import com.carrotsearch.randomizedtesting.RandomizedTest;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; 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.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.client.support.Headers; import org.elasticsearch.client.support.Headers;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
@ -49,7 +49,6 @@ import java.util.concurrent.TimeUnit;
public class RestClient implements Closeable { public class RestClient implements Closeable {
private static final ESLogger logger = Loggers.getLogger(RestClient.class); 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 RestSpec restSpec;
private final CloseableHttpClient httpClient; private final CloseableHttpClient httpClient;
@ -222,7 +221,7 @@ public class RestClient implements Closeable {
} }
protected CloseableHttpClient createHttpClient() { protected CloseableHttpClient createHttpClient() {
return HttpClients.createMinimal(connectionPool); return HttpClients.createMinimal(new PoolingHttpClientConnectionManager(15, TimeUnit.SECONDS));
} }
public InetSocketAddress[] httpAddresses() { public InetSocketAddress[] httpAddresses() {
@ -233,10 +232,6 @@ public class RestClient implements Closeable {
* Closes the REST client and the underlying http client * Closes the REST client and the underlying http client
*/ */
public void close() { public void close() {
try { IOUtils.closeWhileHandlingException(httpClient);
httpClient.close();
} catch(IOException e) {
logger.error(e.getMessage(), e);
}
} }
} }