Skip to content

Commit 5fbead0

Browse files
authored
Zen2: Add infrastructure for integration tests (#34365)
Adds the infrastructure to run integration tests against Zen2.
1 parent 8b9fa55 commit 5fbead0

File tree

14 files changed

+230
-69
lines changed

14 files changed

+230
-69
lines changed

server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.cluster.block.ClusterBlocks;
3131
import org.elasticsearch.cluster.coordination.FollowersChecker.FollowerCheckRequest;
3232
import org.elasticsearch.cluster.coordination.JoinHelper.InitialJoinAccumulator;
33+
import org.elasticsearch.cluster.metadata.MetaData;
3334
import org.elasticsearch.cluster.node.DiscoveryNode;
3435
import org.elasticsearch.cluster.node.DiscoveryNodes;
3536
import org.elasticsearch.cluster.routing.allocation.AllocationService;
@@ -429,8 +430,8 @@ Mode getMode() {
429430
}
430431
}
431432

432-
// package-visible for testing
433-
DiscoveryNode getLocalNode() {
433+
// visible for testing
434+
public DiscoveryNode getLocalNode() {
434435
return transportService.getLocalNode();
435436
}
436437

@@ -578,6 +579,10 @@ public void setInitialConfiguration(final VotingConfiguration votingConfiguratio
578579
final Builder builder = masterService.incrementVersion(currentState);
579580
builder.lastAcceptedConfiguration(votingConfiguration);
580581
builder.lastCommittedConfiguration(votingConfiguration);
582+
MetaData.Builder metaDataBuilder = MetaData.builder();
583+
// automatically generate a UID for the metadata if we need to
584+
metaDataBuilder.generateClusterUuidIfNeeded(); // TODO generate UUID in bootstrapping tool?
585+
builder.metaData(metaDataBuilder);
581586
coordinationState.get().setInitialState(builder.build());
582587
preVoteCollector.update(getPreVoteResponse(), null); // pick up the change to last-accepted version
583588
startElectionScheduler();

server/src/test/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsBlocksIT.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121

2222
import org.elasticsearch.cluster.block.ClusterBlockException;
2323
import org.elasticsearch.cluster.metadata.IndexMetaData;
24+
import org.elasticsearch.common.settings.Settings;
2425
import org.elasticsearch.test.ESIntegTestCase;
2526
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
27+
import org.elasticsearch.test.discovery.TestZenDiscovery;
2628

2729
import java.util.Arrays;
2830

@@ -33,6 +35,14 @@
3335

3436
@ClusterScope(scope = ESIntegTestCase.Scope.TEST)
3537
public class IndicesStatsBlocksIT extends ESIntegTestCase {
38+
39+
@Override
40+
protected Settings nodeSettings(int nodeOrdinal) {
41+
return Settings.builder().put(super.nodeSettings(nodeOrdinal))
42+
.put(TestZenDiscovery.USE_ZEN2.getKey(), true)
43+
.build();
44+
}
45+
3646
public void testIndicesStatsWithBlocks() {
3747
createIndex("ro");
3848
ensureGreen("ro");

server/src/test/java/org/elasticsearch/cluster/coordination/CoordinationStateTests.java

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -809,44 +809,7 @@ public static ClusterState setValue(ClusterState clusterState, long value) {
809809
public static long value(ClusterState clusterState) {
810810
return clusterState.metaData().persistentSettings().getAsLong("value", 0L);
811811
}
812-
813-
public static class InMemoryPersistedState implements PersistedState {
814-
// TODO add support and tests for behaviour with persistence-layer failures
815-
816-
private long currentTerm;
817-
private ClusterState acceptedState;
818-
819-
public InMemoryPersistedState(long term, ClusterState acceptedState) {
820-
this.currentTerm = term;
821-
this.acceptedState = acceptedState;
822-
823-
assert currentTerm >= 0;
824-
assert getLastAcceptedState().term() <= currentTerm :
825-
"last accepted term " + getLastAcceptedState().term() + " cannot be above current term " + currentTerm;
826-
}
827-
828-
@Override
829-
public void setCurrentTerm(long currentTerm) {
830-
assert this.currentTerm <= currentTerm;
831-
this.currentTerm = currentTerm;
832-
}
833-
834-
@Override
835-
public void setLastAcceptedState(ClusterState clusterState) {
836-
this.acceptedState = clusterState;
837-
}
838-
839-
@Override
840-
public long getCurrentTerm() {
841-
return currentTerm;
842-
}
843-
844-
@Override
845-
public ClusterState getLastAcceptedState() {
846-
return acceptedState;
847-
}
848-
}
849-
812+
850813
static class ClusterNode {
851814

852815
final DiscoveryNode localNode;

server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.elasticsearch.cluster.ESAllocationTestCase;
2929
import org.elasticsearch.cluster.coordination.ClusterStatePublisher.AckListener;
3030
import org.elasticsearch.cluster.coordination.CoordinationState.PersistedState;
31-
import org.elasticsearch.cluster.coordination.CoordinationStateTests.InMemoryPersistedState;
3231
import org.elasticsearch.cluster.coordination.CoordinatorTests.Cluster.ClusterNode;
3332
import org.elasticsearch.cluster.node.DiscoveryNode;
3433
import org.elasticsearch.cluster.service.ClusterApplier;

server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected void onSendRequest(long requestId, String action, TransportRequest req
164164
transportService,
165165
ESAllocationTestCase.createAllocationService(Settings.EMPTY),
166166
masterService,
167-
() -> new CoordinationStateTests.InMemoryPersistedState(term, initialState), r -> emptyList(),
167+
() -> new InMemoryPersistedState(term, initialState), r -> emptyList(),
168168
new NoOpClusterApplier(),
169169
random);
170170
transportService.start();

server/src/test/java/org/elasticsearch/cluster/coordination/PreVoteCollectorTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.Version;
2323
import org.elasticsearch.cluster.ClusterState;
2424
import org.elasticsearch.cluster.ClusterState.VotingConfiguration;
25-
import org.elasticsearch.cluster.coordination.CoordinationStateTests.InMemoryPersistedState;
2625
import org.elasticsearch.cluster.node.DiscoveryNode;
2726
import org.elasticsearch.common.lease.Releasable;
2827
import org.elasticsearch.common.settings.Settings;

server/src/test/java/org/elasticsearch/cluster/coordination/PublicationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class MockNode {
6262
this.localNode = localNode;
6363
ClusterState initialState = CoordinationStateTests.clusterState(0L, 0L, localNode,
6464
VotingConfiguration.EMPTY_CONFIG, VotingConfiguration.EMPTY_CONFIG, 0L);
65-
coordinationState = new CoordinationState(settings, localNode, new CoordinationStateTests.InMemoryPersistedState(0L,
65+
coordinationState = new CoordinationState(settings, localNode, new InMemoryPersistedState(0L,
6666
initialState));
6767
}
6868

server/src/test/java/org/elasticsearch/recovery/RelocationIT.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.elasticsearch.test.ESIntegTestCase.Scope;
5757
import org.elasticsearch.test.InternalSettingsPlugin;
5858
import org.elasticsearch.test.MockIndexEventListener;
59+
import org.elasticsearch.test.discovery.TestZenDiscovery;
5960
import org.elasticsearch.test.junit.annotations.TestLogging;
6061
import org.elasticsearch.test.transport.MockTransportService;
6162
import org.elasticsearch.test.transport.StubbableTransport;
@@ -99,6 +100,13 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
99100
return Arrays.asList(InternalSettingsPlugin.class, MockTransportService.TestPlugin.class, MockIndexEventListener.TestPlugin.class);
100101
}
101102

103+
@Override
104+
protected Settings nodeSettings(int nodeOrdinal) {
105+
return Settings.builder().put(super.nodeSettings(nodeOrdinal))
106+
.put(TestZenDiscovery.USE_ZEN2.getKey(), true)
107+
.build();
108+
}
109+
102110
@Override
103111
protected void beforeIndexDeletion() throws Exception {
104112
super.beforeIndexDeletion();
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.cluster.coordination;
20+
21+
import org.elasticsearch.cluster.ClusterState;
22+
23+
public class InMemoryPersistedState implements CoordinationState.PersistedState {
24+
// TODO add support and tests for behaviour with persistence-layer failures
25+
26+
private long currentTerm;
27+
private ClusterState acceptedState;
28+
29+
public InMemoryPersistedState(long term, ClusterState acceptedState) {
30+
this.currentTerm = term;
31+
this.acceptedState = acceptedState;
32+
33+
assert currentTerm >= 0;
34+
assert getLastAcceptedState().term() <= currentTerm :
35+
"last accepted term " + getLastAcceptedState().term() + " cannot be above current term " + currentTerm;
36+
}
37+
38+
@Override
39+
public void setCurrentTerm(long currentTerm) {
40+
assert this.currentTerm <= currentTerm;
41+
this.currentTerm = currentTerm;
42+
}
43+
44+
@Override
45+
public void setLastAcceptedState(ClusterState clusterState) {
46+
this.acceptedState = clusterState;
47+
}
48+
49+
@Override
50+
public long getCurrentTerm() {
51+
return currentTerm;
52+
}
53+
54+
@Override
55+
public ClusterState getLastAcceptedState() {
56+
return acceptedState;
57+
}
58+
}

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,16 +1944,17 @@ protected TestCluster buildTestCluster(Scope scope, long seed) throws IOExceptio
19441944
}
19451945

19461946
protected NodeConfigurationSource getNodeConfigSource() {
1947-
Settings.Builder networkSettings = Settings.builder();
1947+
Settings.Builder initialNodeSettings = Settings.builder();
1948+
Settings.Builder initialTransportClientSettings = Settings.builder();
19481949
if (addMockTransportService()) {
1949-
networkSettings.put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType());
1950+
initialNodeSettings.put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType());
1951+
initialTransportClientSettings.put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType());
19501952
}
1951-
19521953
return new NodeConfigurationSource() {
19531954
@Override
19541955
public Settings nodeSettings(int nodeOrdinal) {
19551956
return Settings.builder()
1956-
.put(networkSettings.build())
1957+
.put(initialNodeSettings.build())
19571958
.put(ESIntegTestCase.this.nodeSettings(nodeOrdinal)).build();
19581959
}
19591960

@@ -1969,7 +1970,7 @@ public Collection<Class<? extends Plugin>> nodePlugins() {
19691970

19701971
@Override
19711972
public Settings transportClientSettings() {
1972-
return Settings.builder().put(networkSettings.build())
1973+
return Settings.builder().put(initialTransportClientSettings.build())
19731974
.put(ESIntegTestCase.this.transportClientSettings()).build();
19741975
}
19751976

0 commit comments

Comments
 (0)