Skip to content

Commit d725416

Browse files
committed
Add full cluster restart base class (#33577)
This commit adds a base class for full cluster restart tests.
1 parent e084a0a commit d725416

File tree

4 files changed

+115
-124
lines changed

4 files changed

+115
-124
lines changed

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

Lines changed: 33 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@
6464
* version is started with the same data directories and then this is rerun
6565
* with {@code tests.is_old_cluster} set to {@code false}.
6666
*/
67-
public class FullClusterRestartIT extends ESRestTestCase {
68-
private final boolean runningAgainstOldCluster = Booleans.parseBoolean(System.getProperty("tests.is_old_cluster"));
69-
private final Version oldClusterVersion = Version.fromString(System.getProperty("tests.old_cluster_version"));
70-
private final boolean supportsLenientBooleans = oldClusterVersion.before(Version.V_6_0_0_alpha1);
67+
public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
68+
private final boolean supportsLenientBooleans = getOldClusterVersion().before(Version.V_6_0_0_alpha1);
7169
private static final Version VERSION_5_1_0_UNRELEASED = Version.fromString("5.1.0");
7270

7371
private String index;
@@ -77,29 +75,9 @@ public void setIndex() {
7775
index = getTestName().toLowerCase(Locale.ROOT);
7876
}
7977

80-
@Override
81-
protected boolean preserveIndicesUponCompletion() {
82-
return true;
83-
}
84-
85-
@Override
86-
protected boolean preserveSnapshotsUponCompletion() {
87-
return true;
88-
}
89-
90-
@Override
91-
protected boolean preserveReposUponCompletion() {
92-
return true;
93-
}
94-
95-
@Override
96-
protected boolean preserveTemplatesUponCompletion() {
97-
return true;
98-
}
99-
10078
public void testSearch() throws Exception {
10179
int count;
102-
if (runningAgainstOldCluster) {
80+
if (isRunningAgainstOldCluster()) {
10381
XContentBuilder mappingsAndSettings = jsonBuilder();
10482
mappingsAndSettings.startObject();
10583
{
@@ -165,7 +143,7 @@ public void testSearch() throws Exception {
165143
}
166144

167145
public void testNewReplicasWork() throws Exception {
168-
if (runningAgainstOldCluster) {
146+
if (isRunningAgainstOldCluster()) {
169147
XContentBuilder mappingsAndSettings = jsonBuilder();
170148
mappingsAndSettings.startObject();
171149
{
@@ -236,10 +214,10 @@ public void testNewReplicasWork() throws Exception {
236214
*/
237215
public void testAliasWithBadName() throws Exception {
238216
assumeTrue("Can only test bad alias name if old cluster is on 5.1.0 or before",
239-
oldClusterVersion.before(VERSION_5_1_0_UNRELEASED));
217+
getOldClusterVersion().before(VERSION_5_1_0_UNRELEASED));
240218

241219
int count;
242-
if (runningAgainstOldCluster) {
220+
if (isRunningAgainstOldCluster()) {
243221
XContentBuilder mappingsAndSettings = jsonBuilder();
244222
mappingsAndSettings.startObject();
245223
{
@@ -290,7 +268,7 @@ public void testAliasWithBadName() throws Exception {
290268
Map<String, Object> searchRsp = entityAsMap(client().performRequest(new Request("GET", "/" + aliasName + "/_search")));
291269
int totalHits = (int) XContentMapValues.extractValue("hits.total", searchRsp);
292270
assertEquals(count, totalHits);
293-
if (runningAgainstOldCluster == false) {
271+
if (isRunningAgainstOldCluster() == false) {
294272
// We can remove the alias.
295273
Response response = client().performRequest(new Request("DELETE", "/" + index + "/_alias/" + aliasName));
296274
assertEquals(200, response.getStatusLine().getStatusCode());
@@ -301,7 +279,7 @@ public void testAliasWithBadName() throws Exception {
301279
}
302280

303281
public void testClusterState() throws Exception {
304-
if (runningAgainstOldCluster) {
282+
if (isRunningAgainstOldCluster()) {
305283
XContentBuilder mappingsAndSettings = jsonBuilder();
306284
mappingsAndSettings.startObject();
307285
mappingsAndSettings.field("template", index);
@@ -340,14 +318,14 @@ public void testClusterState() throws Exception {
340318
assertEquals("0", numberOfReplicas);
341319
Version version = Version.fromId(Integer.valueOf((String) XContentMapValues.extractValue("metadata.indices." + index +
342320
".settings.index.version.created", clusterState)));
343-
assertEquals(oldClusterVersion, version);
321+
assertEquals(getOldClusterVersion(), version);
344322

345323
}
346324

347325
public void testShrink() throws IOException {
348326
String shrunkenIndex = index + "_shrunk";
349327
int numDocs;
350-
if (runningAgainstOldCluster) {
328+
if (isRunningAgainstOldCluster()) {
351329
XContentBuilder mappingsAndSettings = jsonBuilder();
352330
mappingsAndSettings.startObject();
353331
{
@@ -412,12 +390,12 @@ public void testShrink() throws IOException {
412390
public void testShrinkAfterUpgrade() throws IOException {
413391
String shrunkenIndex = index + "_shrunk";
414392
int numDocs;
415-
if (runningAgainstOldCluster) {
393+
if (isRunningAgainstOldCluster()) {
416394
XContentBuilder mappingsAndSettings = jsonBuilder();
417395
mappingsAndSettings.startObject();
418396
// single type was added in 5.5.0 (see #24317)
419-
if (oldClusterVersion.onOrAfter(Version.V_5_5_0) &&
420-
oldClusterVersion.before(Version.V_6_0_0_beta1) &&
397+
if (getOldClusterVersion().onOrAfter(Version.V_5_5_0) &&
398+
getOldClusterVersion().before(Version.V_6_0_0_beta1) &&
421399
randomBoolean()) {
422400
{
423401
// test that mapping.single_type is correctly propagated on the shrinked index,
@@ -478,7 +456,7 @@ public void testShrinkAfterUpgrade() throws IOException {
478456
int totalHits = (int) XContentMapValues.extractValue("hits.total", response);
479457
assertEquals(numDocs, totalHits);
480458

481-
if (runningAgainstOldCluster == false) {
459+
if (isRunningAgainstOldCluster() == false) {
482460
response = entityAsMap(client().performRequest(new Request("GET", "/" + shrunkenIndex + "/_search")));
483461
assertNoFailures(response);
484462
totalShards = (int) XContentMapValues.extractValue("_shards.total", response);
@@ -503,7 +481,7 @@ public void testShrinkAfterUpgrade() throws IOException {
503481
* </ol>
504482
*/
505483
public void testRollover() throws IOException {
506-
if (runningAgainstOldCluster) {
484+
if (isRunningAgainstOldCluster()) {
507485
Request createIndex = new Request("PUT", "/" + index + "-000001");
508486
createIndex.setJsonEntity("{"
509487
+ " \"aliases\": {"
@@ -524,7 +502,7 @@ public void testRollover() throws IOException {
524502
bulkRequest.addParameter("refresh", "");
525503
assertThat(EntityUtils.toString(client().performRequest(bulkRequest).getEntity()), containsString("\"errors\":false"));
526504

527-
if (runningAgainstOldCluster) {
505+
if (isRunningAgainstOldCluster()) {
528506
Request rolloverRequest = new Request("POST", "/" + index + "_write/_rollover");
529507
rolloverRequest.setJsonEntity("{"
530508
+ " \"conditions\": {"
@@ -542,7 +520,7 @@ public void testRollover() throws IOException {
542520
Map<String, Object> count = entityAsMap(client().performRequest(countRequest));
543521
assertNoFailures(count);
544522

545-
int expectedCount = bulkCount + (runningAgainstOldCluster ? 0 : bulkCount);
523+
int expectedCount = bulkCount + (isRunningAgainstOldCluster() ? 0 : bulkCount);
546524
assertEquals(expectedCount, (int) XContentMapValues.extractValue("hits.total", count));
547525
}
548526

@@ -701,7 +679,7 @@ public void testSingleDoc() throws IOException {
701679
String docLocation = "/" + index + "/doc/1";
702680
String doc = "{\"test\": \"test\"}";
703681

704-
if (runningAgainstOldCluster) {
682+
if (isRunningAgainstOldCluster()) {
705683
Request createDoc = new Request("PUT", docLocation);
706684
createDoc.setJsonEntity(doc);
707685
client().performRequest(createDoc);
@@ -716,7 +694,7 @@ public void testSingleDoc() throws IOException {
716694
public void testEmptyShard() throws IOException {
717695
final String index = "test_empty_shard";
718696

719-
if (runningAgainstOldCluster) {
697+
if (isRunningAgainstOldCluster()) {
720698
Settings.Builder settings = Settings.builder()
721699
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
722700
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 1)
@@ -739,7 +717,7 @@ public void testEmptyShard() throws IOException {
739717
public void testRecovery() throws Exception {
740718
int count;
741719
boolean shouldHaveTranslog;
742-
if (runningAgainstOldCluster) {
720+
if (isRunningAgainstOldCluster()) {
743721
count = between(200, 300);
744722
/* We've had bugs in the past where we couldn't restore
745723
* an index without a translog so we randomize whether
@@ -785,7 +763,7 @@ public void testRecovery() throws Exception {
785763
String countResponse = toStr(client().performRequest(countRequest));
786764
assertThat(countResponse, containsString("\"total\":" + count));
787765

788-
if (false == runningAgainstOldCluster) {
766+
if (false == isRunningAgainstOldCluster()) {
789767
boolean restoredFromTranslog = false;
790768
boolean foundPrimary = false;
791769
Request recoveryRequest = new Request("GET", "/_cat/recovery/" + index);
@@ -813,7 +791,7 @@ public void testRecovery() throws Exception {
813791
assertEquals("mismatch while checking for translog recovery\n" + recoveryResponse, shouldHaveTranslog, restoredFromTranslog);
814792

815793
String currentLuceneVersion = Version.CURRENT.luceneVersion.toString();
816-
String bwcLuceneVersion = oldClusterVersion.luceneVersion.toString();
794+
String bwcLuceneVersion = getOldClusterVersion().luceneVersion.toString();
817795
if (shouldHaveTranslog && false == currentLuceneVersion.equals(bwcLuceneVersion)) {
818796
int numCurrentVersion = 0;
819797
int numBwcVersion = 0;
@@ -853,7 +831,7 @@ public void testRecovery() throws Exception {
853831
*/
854832
public void testSnapshotRestore() throws IOException {
855833
int count;
856-
if (runningAgainstOldCluster) {
834+
if (isRunningAgainstOldCluster()) {
857835
// Create the index
858836
count = between(200, 300);
859837
indexRandomDocuments(count, true, true, i -> jsonBuilder().startObject().field("field", "value").endObject());
@@ -873,7 +851,7 @@ public void testSnapshotRestore() throws IOException {
873851
// Stick a routing attribute into to cluster settings so we can see it after the restore
874852
Request addRoutingSettings = new Request("PUT", "/_cluster/settings");
875853
addRoutingSettings.setJsonEntity(
876-
"{\"persistent\": {\"cluster.routing.allocation.exclude.test_attr\": \"" + oldClusterVersion + "\"}}");
854+
"{\"persistent\": {\"cluster.routing.allocation.exclude.test_attr\": \"" + getOldClusterVersion() + "\"}}");
877855
client().performRequest(addRoutingSettings);
878856

879857
// Stick a template into the cluster so we can see it after the restore
@@ -898,7 +876,7 @@ public void testSnapshotRestore() throws IOException {
898876
templateBuilder.startObject("alias2"); {
899877
templateBuilder.startObject("filter"); {
900878
templateBuilder.startObject("term"); {
901-
templateBuilder.field("version", runningAgainstOldCluster ? oldClusterVersion : Version.CURRENT);
879+
templateBuilder.field("version", isRunningAgainstOldCluster() ? getOldClusterVersion() : Version.CURRENT);
902880
}
903881
templateBuilder.endObject();
904882
}
@@ -911,7 +889,7 @@ public void testSnapshotRestore() throws IOException {
911889
createTemplateRequest.setJsonEntity(Strings.toString(templateBuilder));
912890
client().performRequest(createTemplateRequest);
913891

914-
if (runningAgainstOldCluster) {
892+
if (isRunningAgainstOldCluster()) {
915893
// Create the repo
916894
XContentBuilder repoConfig = JsonXContent.contentBuilder().startObject(); {
917895
repoConfig.field("type", "fs");
@@ -927,19 +905,19 @@ public void testSnapshotRestore() throws IOException {
927905
client().performRequest(createRepoRequest);
928906
}
929907

930-
Request createSnapshot = new Request("PUT", "/_snapshot/repo/" + (runningAgainstOldCluster ? "old_snap" : "new_snap"));
908+
Request createSnapshot = new Request("PUT", "/_snapshot/repo/" + (isRunningAgainstOldCluster() ? "old_snap" : "new_snap"));
931909
createSnapshot.addParameter("wait_for_completion", "true");
932910
createSnapshot.setJsonEntity("{\"indices\": \"" + index + "\"}");
933911
client().performRequest(createSnapshot);
934912

935-
checkSnapshot("old_snap", count, oldClusterVersion);
936-
if (false == runningAgainstOldCluster) {
913+
checkSnapshot("old_snap", count, getOldClusterVersion());
914+
if (false == isRunningAgainstOldCluster()) {
937915
checkSnapshot("new_snap", count, Version.CURRENT);
938916
}
939917
}
940918

941919
public void testHistoryUUIDIsAdded() throws Exception {
942-
if (runningAgainstOldCluster) {
920+
if (isRunningAgainstOldCluster()) {
943921
XContentBuilder mappingsAndSettings = jsonBuilder();
944922
mappingsAndSettings.startObject();
945923
{
@@ -977,7 +955,7 @@ public void testHistoryUUIDIsAdded() throws Exception {
977955
private void checkSnapshot(String snapshotName, int count, Version tookOnVersion) throws IOException {
978956
// Check the snapshot metadata, especially the version
979957
Request listSnapshotRequest = new Request("GET", "/_snapshot/repo/" + snapshotName);
980-
if (false == (runningAgainstOldCluster && oldClusterVersion.before(Version.V_5_5_0))) {
958+
if (false == (isRunningAgainstOldCluster() && getOldClusterVersion().before(Version.V_5_5_0))) {
981959
listSnapshotRequest.addParameter("verbose", "true");
982960
}
983961
Map<String, Object> listSnapshotResponse = entityAsMap(client().performRequest(listSnapshotRequest));
@@ -1038,7 +1016,7 @@ private void checkSnapshot(String snapshotName, int count, Version tookOnVersion
10381016
Map<String, Object> expectedClusterSettings = new HashMap<>();
10391017
expectedClusterSettings.put("transient", emptyMap());
10401018
expectedClusterSettings.put("persistent",
1041-
singletonMap("cluster.routing.allocation.exclude.test_attr", oldClusterVersion.toString()));
1019+
singletonMap("cluster.routing.allocation.exclude.test_attr", getOldClusterVersion().toString()));
10421020
if (expectedClusterSettings.equals(clusterSettingsResponse) == false) {
10431021
NotEqualMessageBuilder builder = new NotEqualMessageBuilder();
10441022
builder.compareMaps(clusterSettingsResponse, expectedClusterSettings);
@@ -1048,7 +1026,7 @@ private void checkSnapshot(String snapshotName, int count, Version tookOnVersion
10481026
// Check that the template was restored successfully
10491027
Map<String, Object> getTemplateResponse = entityAsMap(client().performRequest(new Request("GET", "/_template/test_template")));
10501028
Map<String, Object> expectedTemplate = new HashMap<>();
1051-
if (runningAgainstOldCluster && oldClusterVersion.before(Version.V_6_0_0_beta1)) {
1029+
if (isRunningAgainstOldCluster() && getOldClusterVersion().before(Version.V_6_0_0_beta1)) {
10521030
expectedTemplate.put("template", "evil_*");
10531031
} else {
10541032
expectedTemplate.put("index_patterns", singletonList("evil_*"));

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/QueryBuilderBWCIT.java

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.Version;
2424
import org.elasticsearch.client.Request;
2525
import org.elasticsearch.client.Response;
26-
import org.elasticsearch.common.Booleans;
2726
import org.elasticsearch.common.Strings;
2827
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
2928
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
@@ -48,7 +47,6 @@
4847
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
4948
import org.elasticsearch.index.query.functionscore.RandomScoreFunctionBuilder;
5049
import org.elasticsearch.search.SearchModule;
51-
import org.elasticsearch.test.rest.ESRestTestCase;
5250

5351
import java.io.ByteArrayInputStream;
5452
import java.io.IOException;
@@ -71,7 +69,7 @@
7169
* The queries to test are specified in json format, which turns out to work because we tend break here rarely. If the
7270
* json format of a query being tested here then feel free to change this.
7371
*/
74-
public class QueryBuilderBWCIT extends ESRestTestCase {
72+
public class QueryBuilderBWCIT extends AbstractFullClusterRestartTestCase {
7573

7674
private static final List<Object[]> CANDIDATES = new ArrayList<>();
7775

@@ -145,33 +143,10 @@ private static void addCandidate(String querySource, QueryBuilder expectedQb) {
145143
CANDIDATES.add(new Object[]{"{\"query\": {" + querySource + "}}", expectedQb});
146144
}
147145

148-
private final Version oldClusterVersion = Version.fromString(System.getProperty("tests.old_cluster_version"));
149-
private final boolean runningAgainstOldCluster = Booleans.parseBoolean(System.getProperty("tests.is_old_cluster"));
150-
151-
@Override
152-
protected boolean preserveIndicesUponCompletion() {
153-
return true;
154-
}
155-
156-
@Override
157-
protected boolean preserveSnapshotsUponCompletion() {
158-
return true;
159-
}
160-
161-
@Override
162-
protected boolean preserveReposUponCompletion() {
163-
return true;
164-
}
165-
166-
@Override
167-
protected boolean preserveTemplatesUponCompletion() {
168-
return true;
169-
}
170-
171146
public void testQueryBuilderBWC() throws Exception {
172-
assumeTrue("5.x not supported", oldClusterVersion.onOrAfter(Version.V_6_0_0_alpha1));
147+
assumeTrue("5.x not supported", getOldClusterVersion().onOrAfter(Version.V_6_0_0_alpha1));
173148
String index = "queries";
174-
if (runningAgainstOldCluster) {
149+
if (isRunningAgainstOldCluster()) {
175150
XContentBuilder mappingsAndSettings = jsonBuilder();
176151
mappingsAndSettings.startObject();
177152
{
@@ -231,7 +206,7 @@ public void testQueryBuilderBWC() throws Exception {
231206
byte[] qbSource = Base64.getDecoder().decode(queryBuilderStr);
232207
try (InputStream in = new ByteArrayInputStream(qbSource, 0, qbSource.length)) {
233208
try (StreamInput input = new NamedWriteableAwareStreamInput(new InputStreamStreamInput(in), registry)) {
234-
input.setVersion(oldClusterVersion);
209+
input.setVersion(getOldClusterVersion());
235210
QueryBuilder queryBuilder = input.readNamedWriteable(QueryBuilder.class);
236211
assert in.read() == -1;
237212
assertEquals(expectedQueryBuilder, queryBuilder);

0 commit comments

Comments
 (0)