Skip to content

Commit

Permalink
Fix MultiVersionRepositoryAccessIT Tests
Browse files Browse the repository at this point in the history
We need the same fix we did in `7.x` (elastic#50797) and only get snapshot status
for the current version or older. Otherwise these tests break for
e.g.`7.0.1` due to the same index metadata incompatibility.

Closes elastic#50819
  • Loading branch information
original-brownbear committed Jan 10, 2020
1 parent ce50e8e commit c4652dc
Showing 1 changed file with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,20 @@ public void testCreateAndRestoreSnapshot() throws IOException {
deleteSnapshot(client, repoName, snapshotToDeleteName);
final List<Map<String, Object>> snapshots = listSnapshots(repoName);
assertThat(snapshots, hasSize(TEST_STEP.ordinal() + 1));
assertSnapshotStatusSuccessful(client, repoName, snapshots);
switch (TEST_STEP) {
case STEP2_NEW_CLUSTER:
case STEP4_NEW_CLUSTER:
assertSnapshotStatusSuccessful(client, repoName,
snapshots.stream().map(sn -> (String) sn.get("snapshot")).toArray(String[]::new));
break;
case STEP1_OLD_CLUSTER:
assertSnapshotStatusSuccessful(client, repoName, "snapshot-" + TEST_STEP);
break;
case STEP3_OLD_CLUSTER:
assertSnapshotStatusSuccessful(
client, repoName, "snapshot-" + TEST_STEP, "snapshot-" + TestStep.STEP3_OLD_CLUSTER);
break;
}
if (TEST_STEP == TestStep.STEP3_OLD_CLUSTER) {
ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
} else if (TEST_STEP == TestStep.STEP4_NEW_CLUSTER) {
Expand Down Expand Up @@ -163,7 +176,12 @@ public void testReadOnlyRepo() throws IOException {
assertThat(snapshots, hasSize(2));
break;
}
assertSnapshotStatusSuccessful(client, repoName, snapshots);
if (TEST_STEP == TestStep.STEP1_OLD_CLUSTER || TEST_STEP == TestStep.STEP3_OLD_CLUSTER) {
assertSnapshotStatusSuccessful(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER);
} else {
assertSnapshotStatusSuccessful(client, repoName,
"snapshot-" + TestStep.STEP1_OLD_CLUSTER, "snapshot-" + TestStep.STEP2_NEW_CLUSTER);
}
if (TEST_STEP == TestStep.STEP3_OLD_CLUSTER) {
ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
} else if (TEST_STEP == TestStep.STEP4_NEW_CLUSTER) {
Expand All @@ -187,7 +205,8 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
final List<Map<String, Object>> snapshots = listSnapshots(repoName);
// Every step creates one snapshot
assertThat(snapshots, hasSize(TEST_STEP.ordinal() + 1));
assertSnapshotStatusSuccessful(client, repoName, snapshots);
assertSnapshotStatusSuccessful(client, repoName,
snapshots.stream().map(sn -> (String) sn.get("snapshot")).toArray(String[]::new));
if (TEST_STEP == TestStep.STEP1_OLD_CLUSTER) {
ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
} else {
Expand All @@ -205,9 +224,9 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
}

private static void assertSnapshotStatusSuccessful(RestHighLevelClient client, String repoName,
List<Map<String, Object>> snapshots) throws IOException {
final SnapshotsStatusResponse statusResponse = client.snapshot().status(new SnapshotsStatusRequest(repoName,
snapshots.stream().map(sn -> (String) sn.get("snapshot")).toArray(String[]::new)), RequestOptions.DEFAULT);
String... snapshots) throws IOException {
final SnapshotsStatusResponse statusResponse = client.snapshot()
.status(new SnapshotsStatusRequest(repoName, snapshots), RequestOptions.DEFAULT);
for (SnapshotStatus status : statusResponse.getSnapshots()) {
assertThat(status.getShardsStats().getFailedShards(), is(0));
}
Expand Down

0 comments on commit c4652dc

Please sign in to comment.