From fbf2c3f9f7ba641206f65842f2de7b4e8d9b8926 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 16 Sep 2014 10:08:25 +0200 Subject: [PATCH] [TEST] Use node names for transport clients an close them in tests --- .../NodesStatsBasicBackwardsCompat.java | 7 +++++-- .../TransportClientHeadersTests.java | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/elasticsearch/bwcompat/NodesStatsBasicBackwardsCompat.java b/src/test/java/org/elasticsearch/bwcompat/NodesStatsBasicBackwardsCompat.java index a28fafdeebb..26ad27cb065 100644 --- a/src/test/java/org/elasticsearch/bwcompat/NodesStatsBasicBackwardsCompat.java +++ b/src/test/java/org/elasticsearch/bwcompat/NodesStatsBasicBackwardsCompat.java @@ -43,14 +43,15 @@ public class NodesStatsBasicBackwardsCompat extends ElasticsearchBackwardsCompat NodesInfoResponse nodesInfo = client().admin().cluster().prepareNodesInfo().execute().actionGet(); Settings settings = ImmutableSettings.settingsBuilder() - .put("client.transport.ignore_cluster_name", true).build(); + .put("client.transport.ignore_cluster_name", true) + .put("node.name", "transport_client_" + getTestName()).build(); // We explicitly connect to each node with a custom TransportClient for (NodeInfo n : nodesInfo.getNodes()) { TransportClient tc = new TransportClient(settings).addTransportAddress(n.getNode().address()); - // Just verify that the NS can be sent and serialized/deserialized between nodes with basic indices NodesStatsResponse ns = tc.admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet(); + tc.close(); } } @@ -61,6 +62,7 @@ public class NodesStatsBasicBackwardsCompat extends ElasticsearchBackwardsCompat NodesInfoResponse nodesInfo = client().admin().cluster().prepareNodesInfo().execute().actionGet(); Settings settings = ImmutableSettings.settingsBuilder() + .put("node.name", "transport_client_" + getTestName()) .put("client.transport.ignore_cluster_name", true).build(); // We explicitly connect to each node with a custom TransportClient @@ -82,6 +84,7 @@ public class NodesStatsBasicBackwardsCompat extends ElasticsearchBackwardsCompat } } NodesStatsResponse ns = nsBuilder.execute().actionGet(); + tc.close(); } } diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java index 608a6493b0c..515880c8115 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.client.transport; +import org.apache.lucene.util.IOUtils; import org.elasticsearch.Version; import org.elasticsearch.action.GenericAction; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; @@ -58,6 +59,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { protected Client buildClient(Settings headersSettings, GenericAction[] testedActions) { TransportClient client = new TransportClient(ImmutableSettings.builder() .put("client.transport.sniff", false) + .put("node.name", "transport_client_" + this.getTestName()) .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, InternalTransportService.class.getName()) .put(HEADER_SETTINGS) .build()); @@ -71,21 +73,26 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { TransportClient client = new TransportClient(ImmutableSettings.builder() .put("client.transport.sniff", true) .put("cluster.name", "cluster1") + .put("node.name", "transport_client_" + this.getTestName() + "_1") .put("client.transport.nodes_sampler_interval", "1s") .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, InternalTransportService.class.getName()) .put(HEADER_SETTINGS) .build()); + try { + client.addTransportAddress(address); - client.addTransportAddress(address); + InternalTransportService service = (InternalTransportService) client.injector.getInstance(TransportService.class); - InternalTransportService service = (InternalTransportService) client.injector.getInstance(TransportService.class); + if (!service.clusterStateLatch.await(5, TimeUnit.SECONDS)) { + fail("takes way too long to get the cluster state"); + } - if (!service.clusterStateLatch.await(5, TimeUnit.SECONDS)) { - fail("takes way too long to get the cluster state"); + assertThat(client.connectedNodes().size(), is(1)); + assertThat(client.connectedNodes().get(0).getAddress(), is((TransportAddress) address)); + } finally { + client.close(); } - assertThat(client.connectedNodes().size(), is(1)); - assertThat(client.connectedNodes().get(0).getAddress(), is((TransportAddress) address)); } public static class InternalTransportService extends TransportService {