Specify a unique cluster name for all Integration tests

This commit is contained in:
Igor Motov 2011-06-16 23:03:29 -04:00 committed by kimchy
parent 5540fbf7ab
commit ae5b963e97
13 changed files with 66 additions and 15 deletions

View File

@ -22,6 +22,7 @@ package org.elasticsearch.test.integration;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkUtils;
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.node.Node; import org.elasticsearch.node.Node;
@ -41,7 +42,10 @@ public abstract class AbstractNodesTests {
private Map<String, Client> clients = newHashMap(); private Map<String, Client> clients = newHashMap();
private Settings defaultSettings = ImmutableSettings.Builder.EMPTY_SETTINGS; private Settings defaultSettings = ImmutableSettings
.settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
.build();
public void putDefaultSettings(Settings.Builder settings) { public void putDefaultSettings(Settings.Builder settings) {
putDefaultSettings(settings.build()); putDefaultSettings(settings.build());

View File

@ -21,6 +21,8 @@ package org.elasticsearch.test.integration.client.transport;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.node.internal.InternalNode; import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.search.basic.TransportTwoNodesSearchTests; import org.elasticsearch.test.integration.search.basic.TransportTwoNodesSearchTests;
@ -33,7 +35,10 @@ public class ClientTransportTwoNodesSearchTests extends TransportTwoNodesSearchT
@Override protected Client getClient() { @Override protected Client getClient() {
TransportAddress server1Address = ((InternalNode) node("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress(); TransportAddress server1Address = ((InternalNode) node("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(); TransportClient client = new TransportClient(ImmutableSettings
.settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
.build());
client.addTransportAddress(server1Address); client.addTransportAddress(server1Address);
return client; return client;
} }

View File

@ -20,6 +20,7 @@
package org.elasticsearch.test.integration.client.transport; package org.elasticsearch.test.integration.client.transport;
import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.test.integration.AbstractNodesTests; import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterMethod;
@ -44,7 +45,10 @@ public class DiscoveryTransportClientTests extends AbstractNodesTests {
public void testWithDiscovery() throws Exception { public void testWithDiscovery() throws Exception {
startNode("server1"); startNode("server1");
client = new TransportClient(ImmutableSettings.settingsBuilder().put("discovery.enabled", true).build()); client = new TransportClient(ImmutableSettings.settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
.put("discovery.enabled", true)
.build());
// wait a bit so nodes will be discovered // wait a bit so nodes will be discovered
Thread.sleep(1000); Thread.sleep(1000);
client.admin().indices().create(createIndexRequest("test")).actionGet(); client.admin().indices().create(createIndexRequest("test")).actionGet();

View File

@ -21,6 +21,7 @@ package org.elasticsearch.test.integration.client.transport;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.node.internal.InternalNode; import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.document.DocumentActionsTests; import org.elasticsearch.test.integration.document.DocumentActionsTests;
@ -35,14 +36,18 @@ public class TransportClientDocumentActionsTests extends DocumentActionsTests {
@Override protected Client getClient1() { @Override protected Client getClient1() {
TransportAddress server1Address = ((InternalNode) node("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress(); TransportAddress server1Address = ((InternalNode) node("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().put("client.transport.sniff", false).build()); TransportClient client = new TransportClient(settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
.put("client.transport.sniff", false).build());
client.addTransportAddress(server1Address); client.addTransportAddress(server1Address);
return client; return client;
} }
@Override protected Client getClient2() { @Override protected Client getClient2() {
TransportAddress server2Address = ((InternalNode) node("server2")).injector().getInstance(TransportService.class).boundAddress().publishAddress(); TransportAddress server2Address = ((InternalNode) node("server2")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().put("client.transport.sniff", false).build()); TransportClient client = new TransportClient(settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
.put("client.transport.sniff", false).build());
client.addTransportAddress(server2Address); client.addTransportAddress(server2Address);
return client; return client;
} }

View File

@ -21,6 +21,7 @@ package org.elasticsearch.test.integration.client.transport;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.node.internal.InternalNode; import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.document.MoreLikeThisActionTests; import org.elasticsearch.test.integration.document.MoreLikeThisActionTests;
@ -35,14 +36,18 @@ public class TransportClientMoreLikeThisActionTests extends MoreLikeThisActionTe
@Override protected Client getClient1() { @Override protected Client getClient1() {
TransportAddress server1Address = ((InternalNode) node("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress(); TransportAddress server1Address = ((InternalNode) node("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().put("discovery.enabled", false).build()); TransportClient client = new TransportClient(settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
.put("discovery.enabled", false).build());
client.addTransportAddress(server1Address); client.addTransportAddress(server1Address);
return client; return client;
} }
@Override protected Client getClient2() { @Override protected Client getClient2() {
TransportAddress server1Address = ((InternalNode) node("server2")).injector().getInstance(TransportService.class).boundAddress().publishAddress(); TransportAddress server1Address = ((InternalNode) node("server2")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().put("discovery.enabled", false).build()); TransportClient client = new TransportClient(settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
.put("discovery.enabled", false).build());
client.addTransportAddress(server1Address); client.addTransportAddress(server1Address);
return client; return client;
} }

View File

@ -21,6 +21,7 @@ package org.elasticsearch.test.integration.client.transport;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.node.internal.InternalNode; import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.document.DocumentActionsTests; import org.elasticsearch.test.integration.document.DocumentActionsTests;
@ -35,14 +36,18 @@ public class TransportClientSniffDocumentActionsTests extends DocumentActionsTes
@Override protected Client getClient1() { @Override protected Client getClient1() {
TransportAddress server1Address = ((InternalNode) node("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress(); TransportAddress server1Address = ((InternalNode) node("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().put("client.transport.sniff", true).build()); TransportClient client = new TransportClient(settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
.put("client.transport.sniff", true).build());
client.addTransportAddress(server1Address); client.addTransportAddress(server1Address);
return client; return client;
} }
@Override protected Client getClient2() { @Override protected Client getClient2() {
TransportAddress server2Address = ((InternalNode) node("server2")).injector().getInstance(TransportService.class).boundAddress().publishAddress(); TransportAddress server2Address = ((InternalNode) node("server2")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().put("client.transport.sniff", true).build()); TransportClient client = new TransportClient(settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
.put("client.transport.sniff", true).build());
client.addTransportAddress(server2Address); client.addTransportAddress(server2Address);
return client; return client;
} }

View File

@ -28,6 +28,7 @@ import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Requests; import org.elasticsearch.client.Requests;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.gateway.Gateway; import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.indices.IndexAlreadyExistsException; import org.elasticsearch.indices.IndexAlreadyExistsException;
@ -63,6 +64,7 @@ public class HdfsGatewayTests {
private Node buildNode() { private Node buildNode() {
Settings settings = settingsBuilder() Settings settings = settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
.put("gateway.type", "hdfs") .put("gateway.type", "hdfs")
.put("gateway.hdfs.uri", "file:///") .put("gateway.hdfs.uri", "file:///")
// .put("gateway.hdfs.uri", "hdfs://training-vm.local:8022") // .put("gateway.hdfs.uri", "hdfs://training-vm.local:8022")

View File

@ -24,6 +24,7 @@ import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder; import org.elasticsearch.node.NodeBuilder;
@ -55,7 +56,10 @@ public class GroovyScriptSearchTests {
private Client client; private Client client;
@BeforeMethod public void createNodes() throws Exception { @BeforeMethod public void createNodes() throws Exception {
node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder().put("gateway.type", "none").put("number_of_shards", 1)).node(); node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress())
.put("gateway.type", "none")
.put("number_of_shards", 1)).node();
client = node.client(); client = node.client();
} }

View File

@ -24,6 +24,7 @@ import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder; import org.elasticsearch.node.NodeBuilder;
@ -55,7 +56,10 @@ public class JavaScriptScriptSearchTests {
private Client client; private Client client;
@BeforeMethod public void createNodes() throws Exception { @BeforeMethod public void createNodes() throws Exception {
node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder().put("gateway.type", "none").put("number_of_shards", 1)).node(); node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress())
.put("gateway.type", "none")
.put("number_of_shards", 1)).node();
client = node.client(); client = node.client();
} }

View File

@ -24,6 +24,7 @@ import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder; import org.elasticsearch.node.NodeBuilder;
@ -56,7 +57,10 @@ public class PythonScriptSearchTests {
private Client client; private Client client;
@BeforeMethod public void createNodes() throws Exception { @BeforeMethod public void createNodes() throws Exception {
node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder().put("gateway.type", "none").put("number_of_shards", 1)).node(); node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress())
.put("gateway.type", "none")
.put("number_of_shards", 1)).node();
client = node.client(); client = node.client();
} }

View File

@ -24,6 +24,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.count.CountResponse; import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterMethod;
@ -51,7 +52,9 @@ public class SimpleAttachmentIntegrationTests {
private Node node; private Node node;
@BeforeClass public void setupServer() { @BeforeClass public void setupServer() {
node = nodeBuilder().local(true).settings(settingsBuilder().put("gateway.type", "none")).node(); node = nodeBuilder().local(true).settings(settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress())
.put("gateway.type", "none")).node();
} }
@AfterClass public void closeServer() { @AfterClass public void closeServer() {

View File

@ -21,6 +21,7 @@ package org.elasticsearch.memcached.test;
import net.spy.memcached.MemcachedClient; import net.spy.memcached.MemcachedClient;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterMethod;
@ -48,7 +49,9 @@ public abstract class AbstractMemcachedActionsTests {
@BeforeMethod @BeforeMethod
public void setup() throws IOException { public void setup() throws IOException {
node = nodeBuilder().settings(settingsBuilder().put("gateway.type", "none")).node(); node = nodeBuilder().settings(settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress())
.put("gateway.type", "none")).node();
memcachedClient = createMemcachedClient(); memcachedClient = createMemcachedClient();
} }

View File

@ -24,6 +24,7 @@ import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport; import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException; import org.apache.thrift.transport.TTransportException;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
@ -57,7 +58,9 @@ public class SimpleThriftTests {
private Rest.Client client; private Rest.Client client;
@BeforeMethod public void setup() throws IOException, TTransportException { @BeforeMethod public void setup() throws IOException, TTransportException {
node = nodeBuilder().settings(settingsBuilder().put("gateway.type", "none")).node(); node = nodeBuilder().settings(settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress())
.put("gateway.type", "none")).node();
transport = new TSocket("localhost", 9500); transport = new TSocket("localhost", 9500);
TProtocol protocol = new TBinaryProtocol(transport); TProtocol protocol = new TBinaryProtocol(transport);
client = new Rest.Client(protocol); client = new Rest.Client(protocol);