[TEST] Prevent usage of System Properties in the InternalTestCluster

All settings should be passes as settings and the enviroment should not
influence the test cluster settings. The settings we care about ie.
`es.node.mode` and `es.logger.level` should be passed via settings.
This allows tests to override these settings if they for instance need
`network` transport to operate at all.

Closes #6663
This commit is contained in:
Simon Willnauer 2014-07-01 15:41:02 +02:00
parent c9b7bec3cc
commit fd1d02fd07
7 changed files with 59 additions and 15 deletions

View File

@ -184,14 +184,14 @@ To run backwards compatibiilty tests untar or unzip a release and run the tests
with the following command: with the following command:
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
mvn test -Dtests.bwc=true -Dtests.bwc.version=x.y.z -Dtests.bwc.path=/path/to/elasticsearch -Des.node.mode=network mvn test -Dtests.bwc=true -Dtests.bwc.version=x.y.z -Dtests.bwc.path=/path/to/elasticsearch
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
If the elasticsearch release is placed under `./backwards/elasticsearch-x.y.z` the path If the elasticsearch release is placed under `./backwards/elasticsearch-x.y.z` the path
can be omitted: can be omitted:
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
mvn test -Dtests.bwc=true -Dtests.bwc.version=x.y.z -Des.node.mode=network mvn test -Dtests.bwc=true -Dtests.bwc.version=x.y.z
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
To setup the bwc test environment execute the following steps (provided you are To setup the bwc test environment execute the following steps (provided you are

View File

@ -403,14 +403,4 @@ public abstract class AbstractRandomizedTest extends RandomizedTest {
public String getTestName() { public String getTestName() {
return threadAndTestNameRule.testMethodName; return threadAndTestNameRule.testMethodName;
} }
static {
String nodeLocal = System.getProperty("es.node.mode", System.getProperty("es.node.local", ""));
if (Strings.isEmpty(nodeLocal)) {
// we default to local mode to speed up tests running in IDEs etc.
// compared to a mvn default value this will also work if executed from an IDE.
System.setProperty("es.node.mode", "local");
}
}
} }

View File

@ -110,6 +110,7 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti
return ImmutableSettings.builder() return ImmutableSettings.builder()
.put(TransportModule.TRANSPORT_TYPE_KEY, NettyTransportModule.class) // run same transport / disco as external .put(TransportModule.TRANSPORT_TYPE_KEY, NettyTransportModule.class) // run same transport / disco as external
.put(DiscoveryModule.DISCOVERY_TYPE_KEY, ZenDiscoveryModule.class) .put(DiscoveryModule.DISCOVERY_TYPE_KEY, ZenDiscoveryModule.class)
.put("node.mode", "network") // we need network mode for this
.put("gateway.type", "local") // we require local gateway to mimic upgrades of nodes .put("gateway.type", "local") // we require local gateway to mimic upgrades of nodes
.put("discovery.type", "zen") // zen is needed since we start external nodes .put("discovery.type", "zen") // zen is needed since we start external nodes
.put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, TransportService.class.getName()) .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, TransportService.class.getName())

View File

@ -90,6 +90,7 @@ final class ExternalNode implements Closeable {
case "path.home": case "path.home":
case "node.mode": case "node.mode":
case "gateway.type": case "gateway.type":
case "config.ignore_system_properties":
continue; continue;
default: default:
params.add("-Des." + entry.getKey() + "=" + entry.getValue()); params.add("-Des." + entry.getKey() + "=" + entry.getValue());

View File

@ -51,7 +51,9 @@ public final class ExternalTestCluster extends TestCluster {
private final int numBenchNodes; private final int numBenchNodes;
public ExternalTestCluster(TransportAddress... transportAddresses) { public ExternalTestCluster(TransportAddress... transportAddresses) {
this.client = new TransportClient(ImmutableSettings.settingsBuilder().put("client.transport.ignore_cluster_name", true)) this.client = new TransportClient(ImmutableSettings.settingsBuilder()
.put("client.transport.ignore_cluster_name", true)
.put("node.mode", "network")) // we require network here!
.addTransportAddresses(transportAddresses); .addTransportAddresses(transportAddresses);
NodesInfoResponse nodeInfos = this.client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get(); NodesInfoResponse nodeInfos = this.client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get();

View File

@ -44,6 +44,7 @@ import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
@ -141,6 +142,8 @@ public final class InternalTestCluster extends TestCluster {
static final boolean DEFAULT_ENABLE_RANDOM_BENCH_NODES = true; static final boolean DEFAULT_ENABLE_RANDOM_BENCH_NODES = true;
private static final String NODE_MODE = nodeMode();
/* sorted map to make traverse order reproducible, concurrent since we do checks on it not within a sync block */ /* sorted map to make traverse order reproducible, concurrent since we do checks on it not within a sync block */
private final NavigableMap<String, NodeAndClient> nodes = new TreeMap<>(); private final NavigableMap<String, NodeAndClient> nodes = new TreeMap<>();
@ -235,13 +238,40 @@ public final class InternalTestCluster extends TestCluster {
builder.put("path.data", dataPath.toString()); builder.put("path.data", dataPath.toString());
} }
} }
builder.put("config.ignore_system_properties", true);
builder.put("node.mode", NODE_MODE);
builder.put("script.disable_dynamic", false); builder.put("script.disable_dynamic", false);
builder.put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false); builder.put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false);
if (Strings.hasLength(System.getProperty("es.logger.level"))) {
builder.put("logger.level", System.getProperty("es.logger.level"));
}
if (Strings.hasLength(System.getProperty("es.logger.prefix"))) {
builder.put("logger.prefix", System.getProperty("es.logger.level"));
}
defaultSettings = builder.build(); defaultSettings = builder.build();
executor = EsExecutors.newCached(1, TimeUnit.MINUTES, EsExecutors.daemonThreadFactory("test_" + clusterName)); executor = EsExecutors.newCached(1, TimeUnit.MINUTES, EsExecutors.daemonThreadFactory("test_" + clusterName));
this.hasFilterCache = random.nextBoolean(); this.hasFilterCache = random.nextBoolean();
} }
private static String nodeMode() {
Builder builder = ImmutableSettings.builder();
if (Strings.isEmpty(System.getProperty("es.node.mode"))&& Strings.isEmpty(System.getProperty("es.node.local"))) {
return "local"; // default if nothing is specified
}
if (Strings.hasLength(System.getProperty("es.node.mode"))) {
builder.put("node.mode", System.getProperty("es.node.mode"));
}
if (Strings.hasLength(System.getProperty("es.node.local"))) {
builder.put("node.local", System.getProperty("es.node.local"));
}
if (DiscoveryNode.localNode(builder.build())) {
return "local";
} else {
return "network";
}
}
public String getClusterName() { public String getClusterName() {
return clusterName; return clusterName;
} }
@ -734,10 +764,18 @@ public final class InternalTestCluster extends TestCluster {
@Override @Override
public Client client(Node node, String clusterName, Random random) { public Client client(Node node, String clusterName, Random random) {
TransportAddress addr = ((InternalNode) node).injector().getInstance(TransportService.class).boundAddress().publishAddress(); TransportAddress addr = ((InternalNode) node).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().put("client.transport.nodes_sampler_interval", "1s") Settings nodeSettings = node.settings();
Builder builder = settingsBuilder().put("client.transport.nodes_sampler_interval", "1s")
.put("name", TRANSPORT_CLIENT_PREFIX + node.settings().get("name")) .put("name", TRANSPORT_CLIENT_PREFIX + node.settings().get("name"))
.put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) .put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false)
.put(ClusterName.SETTING, clusterName).put("client.transport.sniff", sniff).build()); .put(ClusterName.SETTING, clusterName).put("client.transport.sniff", sniff);
builder.put("node.mode", nodeSettings.get("node.mode", NODE_MODE));
builder.put("node.local", nodeSettings.get("node.local", ""));
builder.put("logger.prefix", nodeSettings.get("logger.prefix", ""));
builder.put("logger.level", nodeSettings.get("logger.level", "INFO"));
builder.put("config.ignore_system_properties", true);
TransportClient client = new TransportClient(builder.build());
client.addTransportAddress(addr); client.addTransportAddress(addr);
return client; return client;
} }

View File

@ -20,6 +20,7 @@
package org.elasticsearch.tribe; package org.elasticsearch.tribe;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterState;
@ -40,6 +41,7 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
@ -92,12 +94,22 @@ public class TribeTests extends ElasticsearchIntegrationTest {
} }
private void setupTribeNode(Settings settings) { private void setupTribeNode(Settings settings) {
ImmutableMap<String,String> asMap = internalCluster().getDefaultSettings().getAsMap();
ImmutableSettings.Builder tribe1Defaults = ImmutableSettings.builder();
ImmutableSettings.Builder tribe2Defaults = ImmutableSettings.builder();
for (Map.Entry<String, String> entry : asMap.entrySet()) {
tribe1Defaults.put("tribe.t1." + entry.getKey(), entry.getValue());
tribe2Defaults.put("tribe.t2." + entry.getKey(), entry.getValue());
}
Settings merged = ImmutableSettings.builder() Settings merged = ImmutableSettings.builder()
.put("tribe.t1.cluster.name", internalCluster().getClusterName()) .put("tribe.t1.cluster.name", internalCluster().getClusterName())
.put("tribe.t2.cluster.name", cluster2.getClusterName()) .put("tribe.t2.cluster.name", cluster2.getClusterName())
.put("tribe.blocks.write", false) .put("tribe.blocks.write", false)
.put("tribe.blocks.read", false) .put("tribe.blocks.read", false)
.put(settings) .put(settings)
.put(tribe1Defaults.build())
.put(tribe2Defaults.build())
.put(internalCluster().getDefaultSettings())
.build(); .build();
tribeNode = NodeBuilder.nodeBuilder() tribeNode = NodeBuilder.nodeBuilder()