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,9 +81,11 @@ public final class ExternalTestCluster extends TestCluster {
for (Class<? extends Plugin> pluginClass : pluginClasses) {
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 {
client.addTransportAddresses(transportAddresses);
NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get();
httpAddresses = new InetSocketAddress[nodeInfos.getNodes().length];
this.clusterName = nodeInfos.getClusterName().value();
int dataNodes = 0;
@ -100,7 +102,12 @@ public final class ExternalTestCluster extends TestCluster {
}
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;
}
}
@Override