Skip to content

Commit f715f63

Browse files
authored
Fix and unmute GetSnapshotsIT (#129741)
Closes: 129740
1 parent 9e19b85 commit f715f63

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,6 @@ tests:
574574
- class: org.elasticsearch.streams.StreamsYamlTestSuiteIT
575575
method: test {yaml=streams/logs/10_basic/Check for repeated toggle to same state}
576576
issue: https://github.com/elastic/elasticsearch/issues/129735
577-
- class: org.elasticsearch.snapshots.GetSnapshotsIT
578-
method: testFilterByState
579-
issue: https://github.com/elastic/elasticsearch/issues/129740
580577

581578
# Examples:
582579
#

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

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import static org.elasticsearch.repositories.blobstore.BlobStoreRepository.getRepositoryDataBlobName;
7272
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
7373
import static org.hamcrest.Matchers.empty;
74+
import static org.hamcrest.Matchers.hasItem;
7475
import static org.hamcrest.Matchers.hasSize;
7576
import static org.hamcrest.Matchers.in;
7677
import static org.hamcrest.Matchers.is;
@@ -655,40 +656,47 @@ public void testFilterByState() throws Exception {
655656
assertThat(snapshots, hasSize(1));
656657
assertThat(snapshots.getFirst().state(), is(SnapshotState.SUCCESS));
657658

659+
// Add some more state (so the next snapshot has some work to do)
660+
indexRandomDocs(randomIdentifier(), 100);
661+
658662
// Create a snapshot in progress
659663
blockAllDataNodes(repoName);
660-
startFullSnapshot(repoName, "snapshot-in-progress");
661-
awaitNumberOfSnapshotsInProgress(1);
662-
663-
// Fetch snapshots with state=IN_PROGRESS
664-
snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.IN_PROGRESS));
665-
assertThat(snapshots, hasSize(1));
666-
assertThat(snapshots.getFirst().state(), is(SnapshotState.IN_PROGRESS));
667-
668-
// Fetch snapshots with multiple states (SUCCESS, IN_PROGRESS)
669-
snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.SUCCESS, SnapshotState.IN_PROGRESS));
670-
assertThat(snapshots, hasSize(2));
671-
var states = snapshots.stream().map(SnapshotInfo::state).collect(Collectors.toSet());
672-
assertTrue(states.contains(SnapshotState.SUCCESS));
673-
assertTrue(states.contains(SnapshotState.IN_PROGRESS));
674-
675-
// Fetch all snapshots (without state)
676-
snapshots = clusterAdmin().prepareGetSnapshots(TEST_REQUEST_TIMEOUT, repoName).get().getSnapshots();
677-
assertThat(snapshots, hasSize(2));
678-
679-
// Fetch snapshots with an invalid state
680-
IllegalArgumentException e = expectThrows(
681-
IllegalArgumentException.class,
682-
() -> getSnapshotsForStates.apply(EnumSet.of(SnapshotState.valueOf("FOO")))
683-
);
684-
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+
}
685695

686-
// Allow the IN_PROGRESS snapshot to finish, then verify GET using SUCCESS has results and IN_PROGRESS does not.
687-
unblockAllDataNodes(repoName);
688696
awaitNumberOfSnapshotsInProgress(0);
689697
snapshots = clusterAdmin().prepareGetSnapshots(TEST_REQUEST_TIMEOUT, repoName).get().getSnapshots();
690698
assertThat(snapshots, hasSize(2));
691-
states = snapshots.stream().map(SnapshotInfo::state).collect(Collectors.toSet());
699+
var states = snapshots.stream().map(SnapshotInfo::state).collect(Collectors.toSet());
692700
assertThat(states, hasSize(1));
693701
assertTrue(states.contains(SnapshotState.SUCCESS));
694702
snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.IN_PROGRESS));

0 commit comments

Comments
 (0)