Skip to content

Commit 8a91b96

Browse files
committed
Ensure block is removed before teardown
1 parent ea828f9 commit 8a91b96

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

server/src/internalClusterTest/java/org/elasticsearch/snapshots/GetSnapshotsIT.java

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -661,38 +661,42 @@ public void testFilterByState() throws Exception {
661661

662662
// Create a snapshot in progress
663663
blockAllDataNodes(repoName);
664-
startFullSnapshot(repoName, "snapshot-in-progress");
665-
awaitNumberOfSnapshotsInProgress(1);
666-
667-
// Fetch snapshots with state=IN_PROGRESS
668-
snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.IN_PROGRESS));
669-
assertThat(snapshots, hasSize(1));
670-
assertThat(snapshots.getFirst().state(), is(SnapshotState.IN_PROGRESS));
671-
672-
// Fetch snapshots with multiple states (SUCCESS, IN_PROGRESS)
673-
snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.SUCCESS, SnapshotState.IN_PROGRESS));
674-
assertThat(snapshots, hasSize(2));
675-
var states = snapshots.stream().map(SnapshotInfo::state).collect(Collectors.toSet());
676-
assertThat(states, hasItem(SnapshotState.SUCCESS));
677-
assertThat(states, hasItem(SnapshotState.IN_PROGRESS));
678-
679-
// Fetch all snapshots (without state)
680-
snapshots = clusterAdmin().prepareGetSnapshots(TEST_REQUEST_TIMEOUT, repoName).get().getSnapshots();
681-
assertThat(snapshots, hasSize(2));
682-
683-
// Fetch snapshots with an invalid state
684-
IllegalArgumentException e = expectThrows(
685-
IllegalArgumentException.class,
686-
() -> getSnapshotsForStates.apply(EnumSet.of(SnapshotState.valueOf("FOO")))
687-
);
688-
assertThat(e.getMessage(), is("No enum constant org.elasticsearch.snapshots.SnapshotState.FOO"));
664+
try {
665+
startFullSnapshot(repoName, "snapshot-in-progress");
666+
awaitNumberOfSnapshotsInProgress(1);
667+
668+
// Fetch snapshots with state=IN_PROGRESS
669+
snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.IN_PROGRESS));
670+
assertThat(snapshots, hasSize(1));
671+
assertThat(snapshots.getFirst().state(), is(SnapshotState.IN_PROGRESS));
672+
673+
// Fetch snapshots with multiple states (SUCCESS, IN_PROGRESS)
674+
snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.SUCCESS, SnapshotState.IN_PROGRESS));
675+
assertThat(snapshots, hasSize(2));
676+
var states = snapshots.stream().map(SnapshotInfo::state).collect(Collectors.toSet());
677+
assertThat(states, hasItem(SnapshotState.SUCCESS));
678+
assertThat(states, hasItem(SnapshotState.IN_PROGRESS));
679+
680+
// Fetch all snapshots (without state)
681+
snapshots = clusterAdmin().prepareGetSnapshots(TEST_REQUEST_TIMEOUT, repoName).get().getSnapshots();
682+
assertThat(snapshots, hasSize(2));
683+
684+
// Fetch snapshots with an invalid state
685+
IllegalArgumentException e = expectThrows(
686+
IllegalArgumentException.class,
687+
() -> getSnapshotsForStates.apply(EnumSet.of(SnapshotState.valueOf("FOO")))
688+
);
689+
assertThat(e.getMessage(), is("No enum constant org.elasticsearch.snapshots.SnapshotState.FOO"));
690+
} finally {
691+
// Allow the IN_PROGRESS snapshot to finish, then verify GET using SUCCESS has results and IN_PROGRESS does not.
692+
// Do this in a finally, so the block doesn't interfere with teardown in the event of a failure
693+
unblockAllDataNodes(repoName);
694+
}
689695

690-
// Allow the IN_PROGRESS snapshot to finish, then verify GET using SUCCESS has results and IN_PROGRESS does not.
691-
unblockAllDataNodes(repoName);
692696
awaitNumberOfSnapshotsInProgress(0);
693697
snapshots = clusterAdmin().prepareGetSnapshots(TEST_REQUEST_TIMEOUT, repoName).get().getSnapshots();
694698
assertThat(snapshots, hasSize(2));
695-
states = snapshots.stream().map(SnapshotInfo::state).collect(Collectors.toSet());
699+
var states = snapshots.stream().map(SnapshotInfo::state).collect(Collectors.toSet());
696700
assertThat(states, hasSize(1));
697701
assertTrue(states.contains(SnapshotState.SUCCESS));
698702
snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.IN_PROGRESS));

0 commit comments

Comments
 (0)