diff --git a/src/test/java/org/elasticsearch/test/unit/discovery/zen/ping/multicast/MulticastZenPingTests.java b/src/test/java/org/elasticsearch/test/unit/discovery/zen/ping/multicast/MulticastZenPingTests.java index 5730c72ae61..f8df3bd110b 100644 --- a/src/test/java/org/elasticsearch/test/unit/discovery/zen/ping/multicast/MulticastZenPingTests.java +++ b/src/test/java/org/elasticsearch/test/unit/discovery/zen/ping/multicast/MulticastZenPingTests.java @@ -33,6 +33,7 @@ import org.elasticsearch.discovery.zen.DiscoveryNodesProvider; import org.elasticsearch.discovery.zen.ping.ZenPing; import org.elasticsearch.discovery.zen.ping.multicast.MulticastZenPing; import org.elasticsearch.node.service.NodeService; +import org.elasticsearch.test.integration.ElasticsearchTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.local.LocalTransport; @@ -42,17 +43,25 @@ import java.net.DatagramPacket; import java.net.InetAddress; import java.net.MulticastSocket; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; /** * */ -public class MulticastZenPingTests { +public class MulticastZenPingTests extends ElasticsearchTestCase { + + private Settings buildRandomMulticast(Settings settings) { + ImmutableSettings.Builder builder = ImmutableSettings.builder().put(settings); + builder.put("discovery.zen.ping.multicast.group", "224.2.3." + randomIntBetween(0, 255)); + builder.put("discovery.zen.ping.multicast.port", randomIntBetween(55000, 56000)); + return builder.build(); + } @Test public void testSimplePings() { Settings settings = ImmutableSettings.EMPTY; + settings = buildRandomMulticast(settings); + ThreadPool threadPool = new ThreadPool(); ClusterName clusterName = new ClusterName("test"); final TransportService transportServiceA = new TransportService(new LocalTransport(settings, threadPool, Version.CURRENT), threadPool).start(); @@ -105,6 +114,8 @@ public class MulticastZenPingTests { @Test public void testExternalPing() throws Exception { Settings settings = ImmutableSettings.EMPTY; + settings = buildRandomMulticast(settings); + ThreadPool threadPool = new ThreadPool(); ClusterName clusterName = new ClusterName("test"); final TransportService transportServiceA = new TransportService(new LocalTransport(settings, threadPool, Version.CURRENT), threadPool).start(); diff --git a/src/test/java/org/elasticsearch/test/unit/discovery/zen/ping/unicast/UnicastZenPingTests.java b/src/test/java/org/elasticsearch/test/unit/discovery/zen/ping/unicast/UnicastZenPingTests.java index aad5df948ed..89a1cbeb1a4 100644 --- a/src/test/java/org/elasticsearch/test/unit/discovery/zen/ping/unicast/UnicastZenPingTests.java +++ b/src/test/java/org/elasticsearch/test/unit/discovery/zen/ping/unicast/UnicastZenPingTests.java @@ -32,22 +32,26 @@ import org.elasticsearch.discovery.zen.DiscoveryNodesProvider; import org.elasticsearch.discovery.zen.ping.ZenPing; import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; import org.elasticsearch.node.service.NodeService; +import org.elasticsearch.test.integration.ElasticsearchTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.netty.NettyTransport; import org.junit.Test; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; /** * */ -public class UnicastZenPingTests { +public class UnicastZenPingTests extends ElasticsearchTestCase { @Test public void testSimplePings() { Settings settings = ImmutableSettings.EMPTY; + int startPort = 11000 + randomIntBetween(0, 1000); + int endPort = startPort + 10; + settings = ImmutableSettings.builder().put(settings).put("transport.tcp.port", startPort + "-" + endPort).build(); + ThreadPool threadPool = new ThreadPool(); ClusterName clusterName = new ClusterName("test"); NetworkService networkService = new NetworkService(settings); diff --git a/src/test/java/org/elasticsearch/test/unit/transport/AbstractSimpleTransportTests.java b/src/test/java/org/elasticsearch/test/unit/transport/AbstractSimpleTransportTests.java index 21ab9899e31..e6dfd1944b8 100644 --- a/src/test/java/org/elasticsearch/test/unit/transport/AbstractSimpleTransportTests.java +++ b/src/test/java/org/elasticsearch/test/unit/transport/AbstractSimpleTransportTests.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.test.integration.ElasticsearchTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; import org.junit.After; @@ -38,13 +39,12 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import static org.elasticsearch.transport.TransportRequestOptions.options; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; /** * */ -public abstract class AbstractSimpleTransportTests { +public abstract class AbstractSimpleTransportTests extends ElasticsearchTestCase { protected ThreadPool threadPool; diff --git a/src/test/java/org/elasticsearch/test/unit/transport/netty/SimpleNettyTransportTests.java b/src/test/java/org/elasticsearch/test/unit/transport/netty/SimpleNettyTransportTests.java index 4c44fa0e4cb..670afd363cb 100644 --- a/src/test/java/org/elasticsearch/test/unit/transport/netty/SimpleNettyTransportTests.java +++ b/src/test/java/org/elasticsearch/test/unit/transport/netty/SimpleNettyTransportTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.test.unit.transport.netty; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.network.NetworkService; +import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.test.unit.transport.AbstractSimpleTransportTests; @@ -34,6 +35,9 @@ public class SimpleNettyTransportTests extends AbstractSimpleTransportTests { @Override protected TransportService build(Settings settings, Version version) { + int startPort = 11000 + randomIntBetween(0, 255); + int endPort = startPort + 10; + settings = ImmutableSettings.builder().put(settings).put("transport.tcp.port", startPort + "-" + endPort).build(); return new TransportService(settings, new NettyTransport(settings, threadPool, new NetworkService(settings), version), threadPool).start(); }