[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:
parent
c9b7bec3cc
commit
fd1d02fd07
|
@ -184,14 +184,14 @@ To run backwards compatibiilty tests untar or unzip a release and run the tests
|
|||
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
|
||||
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
|
||||
|
|
|
@ -403,14 +403,4 @@ public abstract class AbstractRandomizedTest extends RandomizedTest {
|
|||
public String getTestName() {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -110,6 +110,7 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti
|
|||
return ImmutableSettings.builder()
|
||||
.put(TransportModule.TRANSPORT_TYPE_KEY, NettyTransportModule.class) // run same transport / disco as external
|
||||
.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("discovery.type", "zen") // zen is needed since we start external nodes
|
||||
.put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, TransportService.class.getName())
|
||||
|
|
|
@ -90,6 +90,7 @@ final class ExternalNode implements Closeable {
|
|||
case "path.home":
|
||||
case "node.mode":
|
||||
case "gateway.type":
|
||||
case "config.ignore_system_properties":
|
||||
continue;
|
||||
default:
|
||||
params.add("-Des." + entry.getKey() + "=" + entry.getValue());
|
||||
|
|
|
@ -51,7 +51,9 @@ public final class ExternalTestCluster extends TestCluster {
|
|||
private final int numBenchNodes;
|
||||
|
||||
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);
|
||||
|
||||
NodesInfoResponse nodeInfos = this.client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get();
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
|
|||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.FileSystemUtils;
|
||||
import org.elasticsearch.common.lease.Releasables;
|
||||
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;
|
||||
|
||||
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 */
|
||||
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("config.ignore_system_properties", true);
|
||||
builder.put("node.mode", NODE_MODE);
|
||||
builder.put("script.disable_dynamic", 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();
|
||||
executor = EsExecutors.newCached(1, TimeUnit.MINUTES, EsExecutors.daemonThreadFactory("test_" + clusterName));
|
||||
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() {
|
||||
return clusterName;
|
||||
}
|
||||
|
@ -734,10 +764,18 @@ public final class InternalTestCluster extends TestCluster {
|
|||
@Override
|
||||
public Client client(Node node, String clusterName, Random random) {
|
||||
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("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);
|
||||
return client;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.tribe;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
|
@ -40,6 +41,7 @@ import org.junit.BeforeClass;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
|
@ -92,12 +94,22 @@ public class TribeTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
|
||||
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()
|
||||
.put("tribe.t1.cluster.name", internalCluster().getClusterName())
|
||||
.put("tribe.t2.cluster.name", cluster2.getClusterName())
|
||||
.put("tribe.blocks.write", false)
|
||||
.put("tribe.blocks.read", false)
|
||||
.put(settings)
|
||||
.put(tribe1Defaults.build())
|
||||
.put(tribe2Defaults.build())
|
||||
.put(internalCluster().getDefaultSettings())
|
||||
.build();
|
||||
|
||||
tribeNode = NodeBuilder.nodeBuilder()
|
||||
|
|
Loading…
Reference in New Issue