use host address instead of host name in tests to not do host lookup

This commit is contained in:
Shay Banon 2013-07-24 17:22:18 +02:00
parent ed473e272d
commit a3c3d4073b
1 changed files with 4 additions and 5 deletions

View File

@ -18,13 +18,12 @@
*/ */
package org.elasticsearch.test.integration.rest.helper; package org.elasticsearch.test.integration.rest.helper;
import com.google.common.base.Charsets;
import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.transport.TransportAddress;
import com.google.common.base.Charsets;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -32,8 +31,8 @@ import java.net.HttpURLConnection;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Map;
import java.util.List; import java.util.List;
import java.util.Map;
public class HttpClient { public class HttpClient {
@ -42,7 +41,7 @@ public class HttpClient {
public HttpClient(TransportAddress transportAddress) { public HttpClient(TransportAddress transportAddress) {
InetSocketAddress address = ((InetSocketTransportAddress) transportAddress).address(); InetSocketAddress address = ((InetSocketTransportAddress) transportAddress).address();
try { try {
baseUrl = new URL("http", address.getHostName(), address.getPort(), "/"); baseUrl = new URL("http", address.getAddress().getHostAddress(), address.getPort(), "/");
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
throw new ElasticSearchException("", e); throw new ElasticSearchException("", e);
} }
@ -81,7 +80,7 @@ public class HttpClient {
urlConnection = (HttpURLConnection) url.openConnection(); urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod(method); urlConnection.setRequestMethod(method);
if (headers != null) { if (headers != null) {
for (Map.Entry<String,String> headerEntry : headers.entrySet()) { for (Map.Entry<String, String> headerEntry : headers.entrySet()) {
urlConnection.setRequestProperty(headerEntry.getKey(), headerEntry.getValue()); urlConnection.setRequestProperty(headerEntry.getKey(), headerEntry.getValue());
} }
} }