6868 * version is started with the same data directories and then this is rerun
6969 * with {@code tests.is_old_cluster} set to {@code false}.
7070 */
71- public class FullClusterRestartIT extends ESRestTestCase {
72- private final boolean runningAgainstOldCluster = Booleans .parseBoolean (System .getProperty ("tests.is_old_cluster" ));
73- private final Version oldClusterVersion = Version .fromString (System .getProperty ("tests.old_cluster_version" ));
74- private final boolean supportsLenientBooleans = oldClusterVersion .before (Version .V_6_0_0_alpha1 );
71+ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
72+ private final boolean supportsLenientBooleans = getOldClusterVersion ().before (Version .V_6_0_0_alpha1 );
7573 private static final Version VERSION_5_1_0_UNRELEASED = Version .fromString ("5.1.0" );
7674
7775 private String index ;
@@ -81,29 +79,9 @@ public void setIndex() {
8179 index = getTestName ().toLowerCase (Locale .ROOT );
8280 }
8381
84- @ Override
85- protected boolean preserveIndicesUponCompletion () {
86- return true ;
87- }
88-
89- @ Override
90- protected boolean preserveSnapshotsUponCompletion () {
91- return true ;
92- }
93-
94- @ Override
95- protected boolean preserveReposUponCompletion () {
96- return true ;
97- }
98-
99- @ Override
100- protected boolean preserveTemplatesUponCompletion () {
101- return true ;
102- }
103-
10482 public void testSearch () throws Exception {
10583 int count ;
106- if (runningAgainstOldCluster ) {
84+ if (isRunningAgainstOldCluster () ) {
10785 XContentBuilder mappingsAndSettings = jsonBuilder ();
10886 mappingsAndSettings .startObject ();
10987 {
@@ -169,7 +147,7 @@ public void testSearch() throws Exception {
169147 }
170148
171149 public void testNewReplicasWork () throws Exception {
172- if (runningAgainstOldCluster ) {
150+ if (isRunningAgainstOldCluster () ) {
173151 XContentBuilder mappingsAndSettings = jsonBuilder ();
174152 mappingsAndSettings .startObject ();
175153 {
@@ -237,10 +215,10 @@ public void testNewReplicasWork() throws Exception {
237215 */
238216 public void testAliasWithBadName () throws Exception {
239217 assumeTrue ("Can only test bad alias name if old cluster is on 5.1.0 or before" ,
240- oldClusterVersion .before (VERSION_5_1_0_UNRELEASED ));
218+ getOldClusterVersion () .before (VERSION_5_1_0_UNRELEASED ));
241219
242220 int count ;
243- if (runningAgainstOldCluster ) {
221+ if (isRunningAgainstOldCluster () ) {
244222 XContentBuilder mappingsAndSettings = jsonBuilder ();
245223 mappingsAndSettings .startObject ();
246224 {
@@ -291,7 +269,7 @@ public void testAliasWithBadName() throws Exception {
291269 Map <String , Object > searchRsp = entityAsMap (client ().performRequest (new Request ("GET" , "/" + aliasName + "/_search" )));
292270 int totalHits = (int ) XContentMapValues .extractValue ("hits.total" , searchRsp );
293271 assertEquals (count , totalHits );
294- if (runningAgainstOldCluster == false ) {
272+ if (isRunningAgainstOldCluster () == false ) {
295273 // We can remove the alias.
296274 Response response = client ().performRequest (new Request ("DELETE" , "/" + index + "/_alias/" + aliasName ));
297275 assertEquals (200 , response .getStatusLine ().getStatusCode ());
@@ -302,7 +280,7 @@ public void testAliasWithBadName() throws Exception {
302280 }
303281
304282 public void testClusterState () throws Exception {
305- if (runningAgainstOldCluster ) {
283+ if (isRunningAgainstOldCluster () ) {
306284 XContentBuilder mappingsAndSettings = jsonBuilder ();
307285 mappingsAndSettings .startObject ();
308286 mappingsAndSettings .field ("template" , index );
@@ -341,14 +319,14 @@ public void testClusterState() throws Exception {
341319 assertEquals ("0" , numberOfReplicas );
342320 Version version = Version .fromId (Integer .valueOf ((String ) XContentMapValues .extractValue ("metadata.indices." + index +
343321 ".settings.index.version.created" , clusterState )));
344- assertEquals (oldClusterVersion , version );
322+ assertEquals (getOldClusterVersion () , version );
345323
346324 }
347325
348326 public void testShrink () throws IOException {
349327 String shrunkenIndex = index + "_shrunk" ;
350328 int numDocs ;
351- if (runningAgainstOldCluster ) {
329+ if (isRunningAgainstOldCluster () ) {
352330 XContentBuilder mappingsAndSettings = jsonBuilder ();
353331 mappingsAndSettings .startObject ();
354332 {
@@ -413,7 +391,7 @@ public void testShrink() throws IOException {
413391 public void testShrinkAfterUpgrade () throws IOException {
414392 String shrunkenIndex = index + "_shrunk" ;
415393 int numDocs ;
416- if (runningAgainstOldCluster ) {
394+ if (isRunningAgainstOldCluster () ) {
417395 XContentBuilder mappingsAndSettings = jsonBuilder ();
418396 mappingsAndSettings .startObject ();
419397 {
@@ -465,7 +443,7 @@ public void testShrinkAfterUpgrade() throws IOException {
465443 int totalHits = (int ) XContentMapValues .extractValue ("hits.total" , response );
466444 assertEquals (numDocs , totalHits );
467445
468- if (runningAgainstOldCluster == false ) {
446+ if (isRunningAgainstOldCluster () == false ) {
469447 response = entityAsMap (client ().performRequest (new Request ("GET" , "/" + shrunkenIndex + "/_search" )));
470448 assertNoFailures (response );
471449 totalShards = (int ) XContentMapValues .extractValue ("_shards.total" , response );
@@ -490,7 +468,7 @@ public void testShrinkAfterUpgrade() throws IOException {
490468 * </ol>
491469 */
492470 public void testRollover () throws IOException {
493- if (runningAgainstOldCluster ) {
471+ if (isRunningAgainstOldCluster () ) {
494472 Request createIndex = new Request ("PUT" , "/" + index + "-000001" );
495473 createIndex .setJsonEntity ("{"
496474 + " \" aliases\" : {"
@@ -511,7 +489,7 @@ public void testRollover() throws IOException {
511489 bulkRequest .addParameter ("refresh" , "" );
512490 assertThat (EntityUtils .toString (client ().performRequest (bulkRequest ).getEntity ()), containsString ("\" errors\" :false" ));
513491
514- if (runningAgainstOldCluster ) {
492+ if (isRunningAgainstOldCluster () ) {
515493 Request rolloverRequest = new Request ("POST" , "/" + index + "_write/_rollover" );
516494 rolloverRequest .setJsonEntity ("{"
517495 + " \" conditions\" : {"
@@ -529,7 +507,7 @@ public void testRollover() throws IOException {
529507 Map <String , Object > count = entityAsMap (client ().performRequest (countRequest ));
530508 assertNoFailures (count );
531509
532- int expectedCount = bulkCount + (runningAgainstOldCluster ? 0 : bulkCount );
510+ int expectedCount = bulkCount + (isRunningAgainstOldCluster () ? 0 : bulkCount );
533511 assertEquals (expectedCount , (int ) XContentMapValues .extractValue ("hits.total" , count ));
534512 }
535513
@@ -688,7 +666,7 @@ public void testSingleDoc() throws IOException {
688666 String docLocation = "/" + index + "/doc/1" ;
689667 String doc = "{\" test\" : \" test\" }" ;
690668
691- if (runningAgainstOldCluster ) {
669+ if (isRunningAgainstOldCluster () ) {
692670 Request createDoc = new Request ("PUT" , docLocation );
693671 createDoc .setJsonEntity (doc );
694672 client ().performRequest (createDoc );
@@ -703,7 +681,7 @@ public void testSingleDoc() throws IOException {
703681 public void testEmptyShard () throws IOException {
704682 final String index = "test_empty_shard" ;
705683
706- if (runningAgainstOldCluster ) {
684+ if (isRunningAgainstOldCluster () ) {
707685 Settings .Builder settings = Settings .builder ()
708686 .put (IndexMetaData .INDEX_NUMBER_OF_SHARDS_SETTING .getKey (), 1 )
709687 .put (IndexMetaData .INDEX_NUMBER_OF_REPLICAS_SETTING .getKey (), 1 )
@@ -726,7 +704,7 @@ public void testEmptyShard() throws IOException {
726704 public void testRecovery () throws Exception {
727705 int count ;
728706 boolean shouldHaveTranslog ;
729- if (runningAgainstOldCluster ) {
707+ if (isRunningAgainstOldCluster () ) {
730708 count = between (200 , 300 );
731709 /* We've had bugs in the past where we couldn't restore
732710 * an index without a translog so we randomize whether
@@ -772,7 +750,7 @@ public void testRecovery() throws Exception {
772750 String countResponse = toStr (client ().performRequest (countRequest ));
773751 assertThat (countResponse , containsString ("\" total\" :" + count ));
774752
775- if (false == runningAgainstOldCluster ) {
753+ if (false == isRunningAgainstOldCluster () ) {
776754 boolean restoredFromTranslog = false ;
777755 boolean foundPrimary = false ;
778756 Request recoveryRequest = new Request ("GET" , "/_cat/recovery/" + index );
@@ -800,7 +778,7 @@ public void testRecovery() throws Exception {
800778 assertEquals ("mismatch while checking for translog recovery\n " + recoveryResponse , shouldHaveTranslog , restoredFromTranslog );
801779
802780 String currentLuceneVersion = Version .CURRENT .luceneVersion .toString ();
803- String bwcLuceneVersion = oldClusterVersion .luceneVersion .toString ();
781+ String bwcLuceneVersion = getOldClusterVersion () .luceneVersion .toString ();
804782 if (shouldHaveTranslog && false == currentLuceneVersion .equals (bwcLuceneVersion )) {
805783 int numCurrentVersion = 0 ;
806784 int numBwcVersion = 0 ;
@@ -840,7 +818,7 @@ public void testRecovery() throws Exception {
840818 */
841819 public void testSnapshotRestore () throws IOException {
842820 int count ;
843- if (runningAgainstOldCluster ) {
821+ if (isRunningAgainstOldCluster () ) {
844822 // Create the index
845823 count = between (200 , 300 );
846824 indexRandomDocuments (count , true , true , i -> jsonBuilder ().startObject ().field ("field" , "value" ).endObject ());
@@ -860,7 +838,7 @@ public void testSnapshotRestore() throws IOException {
860838 // Stick a routing attribute into to cluster settings so we can see it after the restore
861839 Request addRoutingSettings = new Request ("PUT" , "/_cluster/settings" );
862840 addRoutingSettings .setJsonEntity (
863- "{\" persistent\" : {\" cluster.routing.allocation.exclude.test_attr\" : \" " + oldClusterVersion + "\" }}" );
841+ "{\" persistent\" : {\" cluster.routing.allocation.exclude.test_attr\" : \" " + getOldClusterVersion () + "\" }}" );
864842 client ().performRequest (addRoutingSettings );
865843
866844 // Stick a template into the cluster so we can see it after the restore
@@ -885,7 +863,7 @@ public void testSnapshotRestore() throws IOException {
885863 templateBuilder .startObject ("alias2" ); {
886864 templateBuilder .startObject ("filter" ); {
887865 templateBuilder .startObject ("term" ); {
888- templateBuilder .field ("version" , runningAgainstOldCluster ? oldClusterVersion : Version .CURRENT );
866+ templateBuilder .field ("version" , isRunningAgainstOldCluster () ? getOldClusterVersion () : Version .CURRENT );
889867 }
890868 templateBuilder .endObject ();
891869 }
@@ -898,7 +876,7 @@ public void testSnapshotRestore() throws IOException {
898876 createTemplateRequest .setJsonEntity (Strings .toString (templateBuilder ));
899877 client ().performRequest (createTemplateRequest );
900878
901- if (runningAgainstOldCluster ) {
879+ if (isRunningAgainstOldCluster () ) {
902880 // Create the repo
903881 XContentBuilder repoConfig = JsonXContent .contentBuilder ().startObject (); {
904882 repoConfig .field ("type" , "fs" );
@@ -914,19 +892,19 @@ public void testSnapshotRestore() throws IOException {
914892 client ().performRequest (createRepoRequest );
915893 }
916894
917- Request createSnapshot = new Request ("PUT" , "/_snapshot/repo/" + (runningAgainstOldCluster ? "old_snap" : "new_snap" ));
895+ Request createSnapshot = new Request ("PUT" , "/_snapshot/repo/" + (isRunningAgainstOldCluster () ? "old_snap" : "new_snap" ));
918896 createSnapshot .addParameter ("wait_for_completion" , "true" );
919897 createSnapshot .setJsonEntity ("{\" indices\" : \" " + index + "\" }" );
920898 client ().performRequest (createSnapshot );
921899
922- checkSnapshot ("old_snap" , count , oldClusterVersion );
923- if (false == runningAgainstOldCluster ) {
900+ checkSnapshot ("old_snap" , count , getOldClusterVersion () );
901+ if (false == isRunningAgainstOldCluster () ) {
924902 checkSnapshot ("new_snap" , count , Version .CURRENT );
925903 }
926904 }
927905
928906 public void testHistoryUUIDIsAdded () throws Exception {
929- if (runningAgainstOldCluster ) {
907+ if (isRunningAgainstOldCluster () ) {
930908 XContentBuilder mappingsAndSettings = jsonBuilder ();
931909 mappingsAndSettings .startObject ();
932910 {
@@ -1022,7 +1000,7 @@ private void checkSnapshot(String snapshotName, int count, Version tookOnVersion
10221000 Map <String , Object > expectedClusterSettings = new HashMap <>();
10231001 expectedClusterSettings .put ("transient" , emptyMap ());
10241002 expectedClusterSettings .put ("persistent" ,
1025- singletonMap ("cluster.routing.allocation.exclude.test_attr" , oldClusterVersion .toString ()));
1003+ singletonMap ("cluster.routing.allocation.exclude.test_attr" , getOldClusterVersion () .toString ()));
10261004 if (expectedClusterSettings .equals (clusterSettingsResponse ) == false ) {
10271005 NotEqualMessageBuilder builder = new NotEqualMessageBuilder ();
10281006 builder .compareMaps (clusterSettingsResponse , expectedClusterSettings );
@@ -1032,7 +1010,7 @@ private void checkSnapshot(String snapshotName, int count, Version tookOnVersion
10321010 // Check that the template was restored successfully
10331011 Map <String , Object > getTemplateResponse = entityAsMap (client ().performRequest (new Request ("GET" , "/_template/test_template" )));
10341012 Map <String , Object > expectedTemplate = new HashMap <>();
1035- if (runningAgainstOldCluster && oldClusterVersion .before (Version .V_6_0_0_beta1 )) {
1013+ if (isRunningAgainstOldCluster () && getOldClusterVersion () .before (Version .V_6_0_0_beta1 )) {
10361014 expectedTemplate .put ("template" , "evil_*" );
10371015 } else {
10381016 expectedTemplate .put ("index_patterns" , singletonList ("evil_*" ));
0 commit comments