randomize ports on specific transport and disco tests

This commit is contained in:
Shay Banon 2013-07-28 14:45:52 +02:00
parent 28a4ac01e4
commit c30fa15ddf
4 changed files with 25 additions and 6 deletions

View File

@ -33,6 +33,7 @@ import org.elasticsearch.discovery.zen.DiscoveryNodesProvider;
import org.elasticsearch.discovery.zen.ping.ZenPing; import org.elasticsearch.discovery.zen.ping.ZenPing;
import org.elasticsearch.discovery.zen.ping.multicast.MulticastZenPing; import org.elasticsearch.discovery.zen.ping.multicast.MulticastZenPing;
import org.elasticsearch.node.service.NodeService; import org.elasticsearch.node.service.NodeService;
import org.elasticsearch.test.integration.ElasticsearchTestCase;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import org.elasticsearch.transport.local.LocalTransport; import org.elasticsearch.transport.local.LocalTransport;
@ -42,17 +43,25 @@ import java.net.DatagramPacket;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MulticastSocket; import java.net.MulticastSocket;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; 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 @Test
public void testSimplePings() { public void testSimplePings() {
Settings settings = ImmutableSettings.EMPTY; Settings settings = ImmutableSettings.EMPTY;
settings = buildRandomMulticast(settings);
ThreadPool threadPool = new ThreadPool(); ThreadPool threadPool = new ThreadPool();
ClusterName clusterName = new ClusterName("test"); ClusterName clusterName = new ClusterName("test");
final TransportService transportServiceA = new TransportService(new LocalTransport(settings, threadPool, Version.CURRENT), threadPool).start(); final TransportService transportServiceA = new TransportService(new LocalTransport(settings, threadPool, Version.CURRENT), threadPool).start();
@ -105,6 +114,8 @@ public class MulticastZenPingTests {
@Test @Test
public void testExternalPing() throws Exception { public void testExternalPing() throws Exception {
Settings settings = ImmutableSettings.EMPTY; Settings settings = ImmutableSettings.EMPTY;
settings = buildRandomMulticast(settings);
ThreadPool threadPool = new ThreadPool(); ThreadPool threadPool = new ThreadPool();
ClusterName clusterName = new ClusterName("test"); ClusterName clusterName = new ClusterName("test");
final TransportService transportServiceA = new TransportService(new LocalTransport(settings, threadPool, Version.CURRENT), threadPool).start(); final TransportService transportServiceA = new TransportService(new LocalTransport(settings, threadPool, Version.CURRENT), threadPool).start();

View File

@ -32,22 +32,26 @@ import org.elasticsearch.discovery.zen.DiscoveryNodesProvider;
import org.elasticsearch.discovery.zen.ping.ZenPing; import org.elasticsearch.discovery.zen.ping.ZenPing;
import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing;
import org.elasticsearch.node.service.NodeService; import org.elasticsearch.node.service.NodeService;
import org.elasticsearch.test.integration.ElasticsearchTestCase;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import org.elasticsearch.transport.netty.NettyTransport; import org.elasticsearch.transport.netty.NettyTransport;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
/** /**
* *
*/ */
public class UnicastZenPingTests { public class UnicastZenPingTests extends ElasticsearchTestCase {
@Test @Test
public void testSimplePings() { public void testSimplePings() {
Settings settings = ImmutableSettings.EMPTY; 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(); ThreadPool threadPool = new ThreadPool();
ClusterName clusterName = new ClusterName("test"); ClusterName clusterName = new ClusterName("test");
NetworkService networkService = new NetworkService(settings); NetworkService networkService = new NetworkService(settings);

View File

@ -27,6 +27,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.test.integration.ElasticsearchTestCase;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.*; import org.elasticsearch.transport.*;
import org.junit.After; import org.junit.After;
@ -38,13 +39,12 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.elasticsearch.transport.TransportRequestOptions.options; import static org.elasticsearch.transport.TransportRequestOptions.options;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
/** /**
* *
*/ */
public abstract class AbstractSimpleTransportTests { public abstract class AbstractSimpleTransportTests extends ElasticsearchTestCase {
protected ThreadPool threadPool; protected ThreadPool threadPool;

View File

@ -22,6 +22,7 @@ package org.elasticsearch.test.unit.transport.netty;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.network.NetworkService;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.test.unit.transport.AbstractSimpleTransportTests; import org.elasticsearch.test.unit.transport.AbstractSimpleTransportTests;
@ -34,6 +35,9 @@ public class SimpleNettyTransportTests extends AbstractSimpleTransportTests {
@Override @Override
protected TransportService build(Settings settings, Version version) { 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(); return new TransportService(settings, new NettyTransport(settings, threadPool, new NetworkService(settings), version), threadPool).start();
} }