Tests: Improve netty test behaviour

Based on some test failures, this commit fixes two minor things

* Bind ports only on so called ephemeral ports to prevent try to
  bind to ports where elasticsearch already runs on
* Remove @Network annotation as it was used in a wrong scope
This commit is contained in:
Alexander Reelsen 2014-11-13 15:42:52 +01:00
parent f56976c2b3
commit 9956e7721d
2 changed files with 6 additions and 18 deletions

View File

@ -24,7 +24,6 @@ import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.elasticsearch.test.junit.annotations.Network;
import org.elasticsearch.transport.TransportModule;
import org.junit.Test;
@ -35,10 +34,7 @@ import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
import static org.hamcrest.Matchers.is;
/**
*
*/
@ClusterScope(scope = Scope.SUITE, numDataNodes = 1, enableRandomBenchNodes = false)
@ClusterScope(scope = Scope.SUITE, numDataNodes = 1, enableRandomBenchNodes = false, numClientNodes = 0)
public class NettyTransportMultiPortIntegrationTests extends ElasticsearchIntegrationTest {
private static int randomPort = -1;
@ -47,7 +43,7 @@ public class NettyTransportMultiPortIntegrationTests extends ElasticsearchIntegr
@Override
protected Settings nodeSettings(int nodeOrdinal) {
if (randomPort == -1) {
randomPort = randomIntBetween(1025, 65000);
randomPort = randomIntBetween(49152, 65525);
randomPortRange = String.format(Locale.ROOT, "%s-%s", randomPort, randomPort+10);
}
return settingsBuilder()
@ -61,14 +57,13 @@ public class NettyTransportMultiPortIntegrationTests extends ElasticsearchIntegr
}
@Test
@Network
public void testThatTransportClientCanConnect() throws Exception {
Settings settings = settingsBuilder()
.put("cluster.name", internalCluster().getClusterName())
.put(TransportModule.TRANSPORT_TYPE_KEY, NettyTransport.class.getName())
.build();
try (TransportClient transportClient = new TransportClient(settings)) {
transportClient.addTransportAddress(new InetSocketTransportAddress("localhost", randomPort));
try (TransportClient transportClient = new TransportClient(settings, false)) {
transportClient.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", randomPort));
ClusterHealthResponse response = transportClient.admin().cluster().prepareHealth().get();
assertThat(response.getStatus(), is(ClusterHealthStatus.GREEN));
}

View File

@ -31,7 +31,6 @@ import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.test.cache.recycler.MockBigArrays;
import org.elasticsearch.test.junit.annotations.Network;
import org.elasticsearch.threadpool.ThreadPool;
import org.junit.After;
import org.junit.Test;
@ -47,9 +46,6 @@ import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
import static org.hamcrest.Matchers.is;
/**
*
*/
@ClusterScope(scope = Scope.TEST, numDataNodes = 1)
public class NettyTransportMultiPortTests extends ElasticsearchTestCase {
@ -135,7 +131,6 @@ public class NettyTransportMultiPortTests extends ElasticsearchTestCase {
}
@Test
@Network
public void testThatBindingOnDifferentHostsWorks() throws Exception {
int[] ports = getRandomPorts(2);
InetAddress firstNonLoopbackAddress = NetworkUtils.getFirstNonLoopbackAddress(NetworkUtils.StackType.IPv4);
@ -155,15 +150,13 @@ public class NettyTransportMultiPortTests extends ElasticsearchTestCase {
assertConnectionRefused(ports[1]);
}
// TODO, make sure one can check more settings and that they are applied correctly
private int[] getRandomPorts(int numberOfPorts) {
IntOpenHashSet ports = new IntOpenHashSet();
for (int i = 0; i < numberOfPorts; i++) {
int port = randomIntBetween(1025, 65000);
int port = randomIntBetween(49152, 65535);
while (ports.contains(port)) {
port = randomIntBetween(1025, 65000);
port = randomIntBetween(49152, 65535);
}
ports.add(port);
}