Test: make httpClient() helper not rely on internalCluster (which may be read only)

This commit is contained in:
Ryan Ernst 2015-04-06 23:25:53 -07:00
parent eed7c8af6d
commit 9c209e46be
1 changed files with 7 additions and 1 deletions

View File

@ -1947,7 +1947,13 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
}
protected HttpRequestBuilder httpClient() {
return new HttpRequestBuilder(HttpClients.createDefault()).httpTransport(internalCluster().getDataNodeInstance(HttpServerTransport.class));
final NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
final NodeInfo[] nodes = nodeInfos.getNodes();
assertTrue(nodes.length > 0);
TransportAddress publishAddress = randomFrom(nodes).getHttp().address().publishAddress();
assertEquals(1, publishAddress.uniqueAddressTypeId());
InetSocketAddress address = ((InetSocketTransportAddress) publishAddress).address();
return new HttpRequestBuilder(HttpClients.createDefault()).host(address.getHostName()).port(address.getPort());
}
/**