Don't leak clients from ExternalTestCluster

When the ExternalTestCluster can't fully build it was leaking a client.
These clients created several threads each, causing "fun" thread starvation
issues.
This commit is contained in:
Nik Everett 2015-11-13 16:57:47 -05:00
parent a846a257c5
commit 1870820208
1 changed files with 24 additions and 17 deletions

View File

@ -81,26 +81,33 @@ public final class ExternalTestCluster extends TestCluster {
for (Class<? extends Plugin> pluginClass : pluginClasses) { for (Class<? extends Plugin> pluginClass : pluginClasses) {
transportClientBuilder.addPlugin(pluginClass); transportClientBuilder.addPlugin(pluginClass);
} }
this.client = transportClientBuilder.build().addTransportAddresses(transportAddresses); TransportClient client = transportClientBuilder.build();
NodesInfoResponse nodeInfos = this.client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get(); try {
httpAddresses = new InetSocketAddress[nodeInfos.getNodes().length]; client.addTransportAddresses(transportAddresses);
this.clusterName = nodeInfos.getClusterName().value(); NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get();
int dataNodes = 0; httpAddresses = new InetSocketAddress[nodeInfos.getNodes().length];
int masterAndDataNodes = 0; this.clusterName = nodeInfos.getClusterName().value();
for (int i = 0; i < nodeInfos.getNodes().length; i++) { int dataNodes = 0;
NodeInfo nodeInfo = nodeInfos.getNodes()[i]; int masterAndDataNodes = 0;
httpAddresses[i] = ((InetSocketTransportAddress) nodeInfo.getHttp().address().publishAddress()).address(); for (int i = 0; i < nodeInfos.getNodes().length; i++) {
if (DiscoveryNode.dataNode(nodeInfo.getSettings())) { NodeInfo nodeInfo = nodeInfos.getNodes()[i];
dataNodes++; httpAddresses[i] = ((InetSocketTransportAddress) nodeInfo.getHttp().address().publishAddress()).address();
masterAndDataNodes++; if (DiscoveryNode.dataNode(nodeInfo.getSettings())) {
} else if (DiscoveryNode.masterNode(nodeInfo.getSettings())) { dataNodes++;
masterAndDataNodes++; masterAndDataNodes++;
} else if (DiscoveryNode.masterNode(nodeInfo.getSettings())) {
masterAndDataNodes++;
}
} }
this.numDataNodes = dataNodes;
this.numMasterAndDataNodes = masterAndDataNodes;
this.client = client;
logger.info("Setup ExternalTestCluster [{}] made of [{}] nodes", nodeInfos.getClusterName().value(), size());
} catch (Exception e) {
client.close();
throw e;
} }
this.numDataNodes = dataNodes;
this.numMasterAndDataNodes = masterAndDataNodes;
logger.info("Setup ExternalTestCluster [{}] made of [{}] nodes", nodeInfos.getClusterName().value(), size());
} }
@Override @Override