64
64
* version is started with the same data directories and then this is rerun
65
65
* with {@code tests.is_old_cluster} set to {@code false}.
66
66
*/
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 );
71
69
private static final Version VERSION_5_1_0_UNRELEASED = Version .fromString ("5.1.0" );
72
70
73
71
private String index ;
@@ -77,29 +75,9 @@ public void setIndex() {
77
75
index = getTestName ().toLowerCase (Locale .ROOT );
78
76
}
79
77
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
-
100
78
public void testSearch () throws Exception {
101
79
int count ;
102
- if (runningAgainstOldCluster ) {
80
+ if (isRunningAgainstOldCluster () ) {
103
81
XContentBuilder mappingsAndSettings = jsonBuilder ();
104
82
mappingsAndSettings .startObject ();
105
83
{
@@ -165,7 +143,7 @@ public void testSearch() throws Exception {
165
143
}
166
144
167
145
public void testNewReplicasWork () throws Exception {
168
- if (runningAgainstOldCluster ) {
146
+ if (isRunningAgainstOldCluster () ) {
169
147
XContentBuilder mappingsAndSettings = jsonBuilder ();
170
148
mappingsAndSettings .startObject ();
171
149
{
@@ -236,10 +214,10 @@ public void testNewReplicasWork() throws Exception {
236
214
*/
237
215
public void testAliasWithBadName () throws Exception {
238
216
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 ));
240
218
241
219
int count ;
242
- if (runningAgainstOldCluster ) {
220
+ if (isRunningAgainstOldCluster () ) {
243
221
XContentBuilder mappingsAndSettings = jsonBuilder ();
244
222
mappingsAndSettings .startObject ();
245
223
{
@@ -290,7 +268,7 @@ public void testAliasWithBadName() throws Exception {
290
268
Map <String , Object > searchRsp = entityAsMap (client ().performRequest (new Request ("GET" , "/" + aliasName + "/_search" )));
291
269
int totalHits = (int ) XContentMapValues .extractValue ("hits.total" , searchRsp );
292
270
assertEquals (count , totalHits );
293
- if (runningAgainstOldCluster == false ) {
271
+ if (isRunningAgainstOldCluster () == false ) {
294
272
// We can remove the alias.
295
273
Response response = client ().performRequest (new Request ("DELETE" , "/" + index + "/_alias/" + aliasName ));
296
274
assertEquals (200 , response .getStatusLine ().getStatusCode ());
@@ -301,7 +279,7 @@ public void testAliasWithBadName() throws Exception {
301
279
}
302
280
303
281
public void testClusterState () throws Exception {
304
- if (runningAgainstOldCluster ) {
282
+ if (isRunningAgainstOldCluster () ) {
305
283
XContentBuilder mappingsAndSettings = jsonBuilder ();
306
284
mappingsAndSettings .startObject ();
307
285
mappingsAndSettings .field ("template" , index );
@@ -340,14 +318,14 @@ public void testClusterState() throws Exception {
340
318
assertEquals ("0" , numberOfReplicas );
341
319
Version version = Version .fromId (Integer .valueOf ((String ) XContentMapValues .extractValue ("metadata.indices." + index +
342
320
".settings.index.version.created" , clusterState )));
343
- assertEquals (oldClusterVersion , version );
321
+ assertEquals (getOldClusterVersion () , version );
344
322
345
323
}
346
324
347
325
public void testShrink () throws IOException {
348
326
String shrunkenIndex = index + "_shrunk" ;
349
327
int numDocs ;
350
- if (runningAgainstOldCluster ) {
328
+ if (isRunningAgainstOldCluster () ) {
351
329
XContentBuilder mappingsAndSettings = jsonBuilder ();
352
330
mappingsAndSettings .startObject ();
353
331
{
@@ -412,12 +390,12 @@ public void testShrink() throws IOException {
412
390
public void testShrinkAfterUpgrade () throws IOException {
413
391
String shrunkenIndex = index + "_shrunk" ;
414
392
int numDocs ;
415
- if (runningAgainstOldCluster ) {
393
+ if (isRunningAgainstOldCluster () ) {
416
394
XContentBuilder mappingsAndSettings = jsonBuilder ();
417
395
mappingsAndSettings .startObject ();
418
396
// 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 ) &&
421
399
randomBoolean ()) {
422
400
{
423
401
// test that mapping.single_type is correctly propagated on the shrinked index,
@@ -478,7 +456,7 @@ public void testShrinkAfterUpgrade() throws IOException {
478
456
int totalHits = (int ) XContentMapValues .extractValue ("hits.total" , response );
479
457
assertEquals (numDocs , totalHits );
480
458
481
- if (runningAgainstOldCluster == false ) {
459
+ if (isRunningAgainstOldCluster () == false ) {
482
460
response = entityAsMap (client ().performRequest (new Request ("GET" , "/" + shrunkenIndex + "/_search" )));
483
461
assertNoFailures (response );
484
462
totalShards = (int ) XContentMapValues .extractValue ("_shards.total" , response );
@@ -503,7 +481,7 @@ public void testShrinkAfterUpgrade() throws IOException {
503
481
* </ol>
504
482
*/
505
483
public void testRollover () throws IOException {
506
- if (runningAgainstOldCluster ) {
484
+ if (isRunningAgainstOldCluster () ) {
507
485
Request createIndex = new Request ("PUT" , "/" + index + "-000001" );
508
486
createIndex .setJsonEntity ("{"
509
487
+ " \" aliases\" : {"
@@ -524,7 +502,7 @@ public void testRollover() throws IOException {
524
502
bulkRequest .addParameter ("refresh" , "" );
525
503
assertThat (EntityUtils .toString (client ().performRequest (bulkRequest ).getEntity ()), containsString ("\" errors\" :false" ));
526
504
527
- if (runningAgainstOldCluster ) {
505
+ if (isRunningAgainstOldCluster () ) {
528
506
Request rolloverRequest = new Request ("POST" , "/" + index + "_write/_rollover" );
529
507
rolloverRequest .setJsonEntity ("{"
530
508
+ " \" conditions\" : {"
@@ -542,7 +520,7 @@ public void testRollover() throws IOException {
542
520
Map <String , Object > count = entityAsMap (client ().performRequest (countRequest ));
543
521
assertNoFailures (count );
544
522
545
- int expectedCount = bulkCount + (runningAgainstOldCluster ? 0 : bulkCount );
523
+ int expectedCount = bulkCount + (isRunningAgainstOldCluster () ? 0 : bulkCount );
546
524
assertEquals (expectedCount , (int ) XContentMapValues .extractValue ("hits.total" , count ));
547
525
}
548
526
@@ -701,7 +679,7 @@ public void testSingleDoc() throws IOException {
701
679
String docLocation = "/" + index + "/doc/1" ;
702
680
String doc = "{\" test\" : \" test\" }" ;
703
681
704
- if (runningAgainstOldCluster ) {
682
+ if (isRunningAgainstOldCluster () ) {
705
683
Request createDoc = new Request ("PUT" , docLocation );
706
684
createDoc .setJsonEntity (doc );
707
685
client ().performRequest (createDoc );
@@ -716,7 +694,7 @@ public void testSingleDoc() throws IOException {
716
694
public void testEmptyShard () throws IOException {
717
695
final String index = "test_empty_shard" ;
718
696
719
- if (runningAgainstOldCluster ) {
697
+ if (isRunningAgainstOldCluster () ) {
720
698
Settings .Builder settings = Settings .builder ()
721
699
.put (IndexMetaData .INDEX_NUMBER_OF_SHARDS_SETTING .getKey (), 1 )
722
700
.put (IndexMetaData .INDEX_NUMBER_OF_REPLICAS_SETTING .getKey (), 1 )
@@ -739,7 +717,7 @@ public void testEmptyShard() throws IOException {
739
717
public void testRecovery () throws Exception {
740
718
int count ;
741
719
boolean shouldHaveTranslog ;
742
- if (runningAgainstOldCluster ) {
720
+ if (isRunningAgainstOldCluster () ) {
743
721
count = between (200 , 300 );
744
722
/* We've had bugs in the past where we couldn't restore
745
723
* an index without a translog so we randomize whether
@@ -785,7 +763,7 @@ public void testRecovery() throws Exception {
785
763
String countResponse = toStr (client ().performRequest (countRequest ));
786
764
assertThat (countResponse , containsString ("\" total\" :" + count ));
787
765
788
- if (false == runningAgainstOldCluster ) {
766
+ if (false == isRunningAgainstOldCluster () ) {
789
767
boolean restoredFromTranslog = false ;
790
768
boolean foundPrimary = false ;
791
769
Request recoveryRequest = new Request ("GET" , "/_cat/recovery/" + index );
@@ -813,7 +791,7 @@ public void testRecovery() throws Exception {
813
791
assertEquals ("mismatch while checking for translog recovery\n " + recoveryResponse , shouldHaveTranslog , restoredFromTranslog );
814
792
815
793
String currentLuceneVersion = Version .CURRENT .luceneVersion .toString ();
816
- String bwcLuceneVersion = oldClusterVersion .luceneVersion .toString ();
794
+ String bwcLuceneVersion = getOldClusterVersion () .luceneVersion .toString ();
817
795
if (shouldHaveTranslog && false == currentLuceneVersion .equals (bwcLuceneVersion )) {
818
796
int numCurrentVersion = 0 ;
819
797
int numBwcVersion = 0 ;
@@ -853,7 +831,7 @@ public void testRecovery() throws Exception {
853
831
*/
854
832
public void testSnapshotRestore () throws IOException {
855
833
int count ;
856
- if (runningAgainstOldCluster ) {
834
+ if (isRunningAgainstOldCluster () ) {
857
835
// Create the index
858
836
count = between (200 , 300 );
859
837
indexRandomDocuments (count , true , true , i -> jsonBuilder ().startObject ().field ("field" , "value" ).endObject ());
@@ -873,7 +851,7 @@ public void testSnapshotRestore() throws IOException {
873
851
// Stick a routing attribute into to cluster settings so we can see it after the restore
874
852
Request addRoutingSettings = new Request ("PUT" , "/_cluster/settings" );
875
853
addRoutingSettings .setJsonEntity (
876
- "{\" persistent\" : {\" cluster.routing.allocation.exclude.test_attr\" : \" " + oldClusterVersion + "\" }}" );
854
+ "{\" persistent\" : {\" cluster.routing.allocation.exclude.test_attr\" : \" " + getOldClusterVersion () + "\" }}" );
877
855
client ().performRequest (addRoutingSettings );
878
856
879
857
// Stick a template into the cluster so we can see it after the restore
@@ -898,7 +876,7 @@ public void testSnapshotRestore() throws IOException {
898
876
templateBuilder .startObject ("alias2" ); {
899
877
templateBuilder .startObject ("filter" ); {
900
878
templateBuilder .startObject ("term" ); {
901
- templateBuilder .field ("version" , runningAgainstOldCluster ? oldClusterVersion : Version .CURRENT );
879
+ templateBuilder .field ("version" , isRunningAgainstOldCluster () ? getOldClusterVersion () : Version .CURRENT );
902
880
}
903
881
templateBuilder .endObject ();
904
882
}
@@ -911,7 +889,7 @@ public void testSnapshotRestore() throws IOException {
911
889
createTemplateRequest .setJsonEntity (Strings .toString (templateBuilder ));
912
890
client ().performRequest (createTemplateRequest );
913
891
914
- if (runningAgainstOldCluster ) {
892
+ if (isRunningAgainstOldCluster () ) {
915
893
// Create the repo
916
894
XContentBuilder repoConfig = JsonXContent .contentBuilder ().startObject (); {
917
895
repoConfig .field ("type" , "fs" );
@@ -927,19 +905,19 @@ public void testSnapshotRestore() throws IOException {
927
905
client ().performRequest (createRepoRequest );
928
906
}
929
907
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" ));
931
909
createSnapshot .addParameter ("wait_for_completion" , "true" );
932
910
createSnapshot .setJsonEntity ("{\" indices\" : \" " + index + "\" }" );
933
911
client ().performRequest (createSnapshot );
934
912
935
- checkSnapshot ("old_snap" , count , oldClusterVersion );
936
- if (false == runningAgainstOldCluster ) {
913
+ checkSnapshot ("old_snap" , count , getOldClusterVersion () );
914
+ if (false == isRunningAgainstOldCluster () ) {
937
915
checkSnapshot ("new_snap" , count , Version .CURRENT );
938
916
}
939
917
}
940
918
941
919
public void testHistoryUUIDIsAdded () throws Exception {
942
- if (runningAgainstOldCluster ) {
920
+ if (isRunningAgainstOldCluster () ) {
943
921
XContentBuilder mappingsAndSettings = jsonBuilder ();
944
922
mappingsAndSettings .startObject ();
945
923
{
@@ -977,7 +955,7 @@ public void testHistoryUUIDIsAdded() throws Exception {
977
955
private void checkSnapshot (String snapshotName , int count , Version tookOnVersion ) throws IOException {
978
956
// Check the snapshot metadata, especially the version
979
957
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 ))) {
981
959
listSnapshotRequest .addParameter ("verbose" , "true" );
982
960
}
983
961
Map <String , Object > listSnapshotResponse = entityAsMap (client ().performRequest (listSnapshotRequest ));
@@ -1038,7 +1016,7 @@ private void checkSnapshot(String snapshotName, int count, Version tookOnVersion
1038
1016
Map <String , Object > expectedClusterSettings = new HashMap <>();
1039
1017
expectedClusterSettings .put ("transient" , emptyMap ());
1040
1018
expectedClusterSettings .put ("persistent" ,
1041
- singletonMap ("cluster.routing.allocation.exclude.test_attr" , oldClusterVersion .toString ()));
1019
+ singletonMap ("cluster.routing.allocation.exclude.test_attr" , getOldClusterVersion () .toString ()));
1042
1020
if (expectedClusterSettings .equals (clusterSettingsResponse ) == false ) {
1043
1021
NotEqualMessageBuilder builder = new NotEqualMessageBuilder ();
1044
1022
builder .compareMaps (clusterSettingsResponse , expectedClusterSettings );
@@ -1048,7 +1026,7 @@ private void checkSnapshot(String snapshotName, int count, Version tookOnVersion
1048
1026
// Check that the template was restored successfully
1049
1027
Map <String , Object > getTemplateResponse = entityAsMap (client ().performRequest (new Request ("GET" , "/_template/test_template" )));
1050
1028
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 )) {
1052
1030
expectedTemplate .put ("template" , "evil_*" );
1053
1031
} else {
1054
1032
expectedTemplate .put ("index_patterns" , singletonList ("evil_*" ));
0 commit comments