randomize ports on specific transport and disco tests
This commit is contained in:
parent
28a4ac01e4
commit
c30fa15ddf
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue