introduced NodeSettingsSource in the test infrastructure os tests with scopes TEST & SUITE without an explicit numNodes definitions will fall back on the nodeSettings(int) callback
This commit is contained in:
parent
1d7e20b712
commit
4aa315974b
|
@ -20,8 +20,6 @@ package org.elasticsearch.test;
|
|||
|
||||
import com.carrotsearch.randomizedtesting.SeedUtils;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.Iterators;
|
||||
import org.apache.lucene.util.AbstractRandomizedTest.IntegrationTests;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
|
@ -595,12 +593,24 @@ public abstract class AbstractIntegrationTest extends ElasticSearchTestCase {
|
|||
|
||||
protected TestCluster buildTestCluster(Scope scope) {
|
||||
long currentClusterSeed = randomLong();
|
||||
Builder<Integer, Settings> ordinalMap = ImmutableMap.builder();
|
||||
int numNodes = getNumNodes();
|
||||
for (int i = 0; i < numNodes; i++) {
|
||||
ordinalMap.put(i, nodeSettings(i));
|
||||
NodeSettingsSource nodeSettingsSource;
|
||||
if (numNodes > 0) {
|
||||
NodeSettingsSource.Immutable.Builder nodesSettings = NodeSettingsSource.Immutable.builder();
|
||||
for (int i = 0; i < numNodes; i++) {
|
||||
nodesSettings.set(i, nodeSettings(i));
|
||||
}
|
||||
nodeSettingsSource = nodesSettings.build();
|
||||
} else {
|
||||
nodeSettingsSource = new NodeSettingsSource() {
|
||||
@Override
|
||||
public Settings settings(int nodeOrdinal) {
|
||||
return nodeSettings(nodeOrdinal);
|
||||
}
|
||||
};
|
||||
}
|
||||
return new TestCluster(currentClusterSeed, getNumNodes(), TestCluster.clusterName(scope.name(), ElasticSearchTestCase.CHILD_VM_ID, currentClusterSeed), ordinalMap.build());
|
||||
|
||||
return new TestCluster(currentClusterSeed, numNodes, TestCluster.clusterName(scope.name(), ElasticSearchTestCase.CHILD_VM_ID, currentClusterSeed), nodeSettingsSource);
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Licensed to ElasticSearch and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. ElasticSearch licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class NodeSettingsSource {
|
||||
|
||||
public static final NodeSettingsSource EMPTY = new NodeSettingsSource() {
|
||||
@Override
|
||||
public Settings settings(int nodeOrdinal) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return the settings for the node represented by the given ordinal, or {@code null} if there are not settings defined (in which
|
||||
* case a random settings will be generated for the node)
|
||||
*/
|
||||
public abstract Settings settings(int nodeOrdinal);
|
||||
|
||||
public static class Immutable extends NodeSettingsSource {
|
||||
|
||||
private final Map<Integer, Settings> settingsPerNode;
|
||||
|
||||
private Immutable(Map<Integer, Settings> settingsPerNode) {
|
||||
this.settingsPerNode = settingsPerNode;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Settings settings(int nodeOrdinal) {
|
||||
return settingsPerNode.get(nodeOrdinal);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private final ImmutableMap.Builder<Integer, Settings> settingsPerNode = ImmutableMap.builder();
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder set(int ordinal, Settings settings) {
|
||||
settingsPerNode.put(ordinal, settings);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Immutable build() {
|
||||
return new Immutable(settingsPerNode.build());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -94,14 +94,13 @@ public class TestCluster implements Closeable, Iterable<Client> {
|
|||
|
||||
private double transportClientRatio = 0.0;
|
||||
|
||||
private final Map<Integer, Settings> perNodeSettingsMap;
|
||||
private static final Map<Integer, Settings> EMPTY = Collections.emptyMap();
|
||||
private final NodeSettingsSource nodeSettingsSource;
|
||||
|
||||
public TestCluster(long clusterSeed, String clusterName) {
|
||||
this(clusterSeed, -1, clusterName, EMPTY);
|
||||
this(clusterSeed, -1, clusterName, NodeSettingsSource.EMPTY);
|
||||
}
|
||||
|
||||
public TestCluster(long clusterSeed, int numNodes, String clusterName, Map<Integer, Settings> perNodeSettings) {
|
||||
public TestCluster(long clusterSeed, int numNodes, String clusterName, NodeSettingsSource nodeSettingsSource) {
|
||||
this.clusterName = clusterName;
|
||||
Random random = new Random(clusterSeed);
|
||||
numSharedNodes = numNodes == -1 ? 2 + random.nextInt(4) : numNodes; // at least 2 nodes if randomized
|
||||
|
@ -129,12 +128,12 @@ public class TestCluster implements Closeable, Iterable<Client> {
|
|||
// default to non gateway
|
||||
.put("gateway.type", "none")
|
||||
.build();
|
||||
this.perNodeSettingsMap = perNodeSettings;
|
||||
this.nodeSettingsSource = nodeSettingsSource;
|
||||
}
|
||||
|
||||
private Settings getSettings(int nodeOrdinal, Settings others) {
|
||||
Builder builder = ImmutableSettings.settingsBuilder().put(defaultSettings);
|
||||
Settings settings = perNodeSettingsMap.get(nodeOrdinal);
|
||||
Settings settings = nodeSettingsSource.settings(nodeOrdinal);
|
||||
if (settings != null) {
|
||||
builder.put(settings);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue