diff --git a/core/src/test/java/org/elasticsearch/snapshots/SnapshotSharedTest.java b/core/src/test/java/org/elasticsearch/snapshots/SnapshotSharedTest.java index a0a667254d228..3c26614405f25 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/SnapshotSharedTest.java +++ b/core/src/test/java/org/elasticsearch/snapshots/SnapshotSharedTest.java @@ -114,8 +114,14 @@ public static void testBasicWorkflow(ESLogger logger, ESIntegTestCase testCase, assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); + String snapshotName; + if (ESIntegTestCase.getMinimumVersionInCluster().onOrAfter(Version.V_2_2_0)) { + snapshotName = randomFrom("test-snap", "_all", "*", "*-snap", "test*"); + } else { + snapshotName = "test-snap"; + } SnapshotInfo snapshotInfo = client().admin().cluster().prepareGetSnapshots("test-repo") - .setSnapshots(randomFrom("test-snap", "_all", "*", "*-snap", "test*")).get().getSnapshots().get(0); + .setSnapshots(snapshotName).get().getSnapshots().get(0); assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS)); assertThat(snapshotInfo.version(), snapshotVersion); diff --git a/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java b/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java index ea98d74204ffa..d18c9566fc513 100644 --- a/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java @@ -33,6 +33,7 @@ import org.apache.lucene.util.TestUtil; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; @@ -1914,6 +1915,18 @@ public Set assertAllShardsOnNodes(String index, String... pattern) { return nodes; } + // returns the minimum Version of all nodes in the current cluster + public static Version getMinimumVersionInCluster() { + NodesInfoResponse nodesInfoResponse = client().admin().cluster().prepareNodesInfo().get(); + Version minimumVersionInCluster = Version.CURRENT; + for (NodeInfo nodeInfo : nodesInfoResponse) { + if (nodeInfo.getVersion().before(minimumVersionInCluster)) { + minimumVersionInCluster = nodeInfo.getVersion(); + } + } + return minimumVersionInCluster; + } + protected static class NumShards { public final int numPrimaries; public final int numReplicas;