diff --git a/muted-tests.yml b/muted-tests.yml index e06f4c661ca1a..c7a730341666f 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -574,9 +574,6 @@ tests: - class: org.elasticsearch.streams.StreamsYamlTestSuiteIT method: test {yaml=streams/logs/10_basic/Check for repeated toggle to same state} issue: https://github.com/elastic/elasticsearch/issues/129735 -- class: org.elasticsearch.snapshots.GetSnapshotsIT - method: testFilterByState - issue: https://github.com/elastic/elasticsearch/issues/129740 # Examples: # diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/GetSnapshotsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/GetSnapshotsIT.java index a3132cff5dc95..e12c7a6d732f3 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/GetSnapshotsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/GetSnapshotsIT.java @@ -71,6 +71,7 @@ import static org.elasticsearch.repositories.blobstore.BlobStoreRepository.getRepositoryDataBlobName; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.in; import static org.hamcrest.Matchers.is; @@ -655,40 +656,47 @@ public void testFilterByState() throws Exception { assertThat(snapshots, hasSize(1)); assertThat(snapshots.getFirst().state(), is(SnapshotState.SUCCESS)); + // Add some more state (so the next snapshot has some work to do) + indexRandomDocs(randomIdentifier(), 100); + // Create a snapshot in progress blockAllDataNodes(repoName); - startFullSnapshot(repoName, "snapshot-in-progress"); - awaitNumberOfSnapshotsInProgress(1); - - // Fetch snapshots with state=IN_PROGRESS - snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.IN_PROGRESS)); - assertThat(snapshots, hasSize(1)); - assertThat(snapshots.getFirst().state(), is(SnapshotState.IN_PROGRESS)); - - // Fetch snapshots with multiple states (SUCCESS, IN_PROGRESS) - snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.SUCCESS, SnapshotState.IN_PROGRESS)); - assertThat(snapshots, hasSize(2)); - var states = snapshots.stream().map(SnapshotInfo::state).collect(Collectors.toSet()); - assertTrue(states.contains(SnapshotState.SUCCESS)); - assertTrue(states.contains(SnapshotState.IN_PROGRESS)); - - // Fetch all snapshots (without state) - snapshots = clusterAdmin().prepareGetSnapshots(TEST_REQUEST_TIMEOUT, repoName).get().getSnapshots(); - assertThat(snapshots, hasSize(2)); - - // Fetch snapshots with an invalid state - IllegalArgumentException e = expectThrows( - IllegalArgumentException.class, - () -> getSnapshotsForStates.apply(EnumSet.of(SnapshotState.valueOf("FOO"))) - ); - assertThat(e.getMessage(), is("No enum constant org.elasticsearch.snapshots.SnapshotState.FOO")); + try { + startFullSnapshot(repoName, "snapshot-in-progress"); + awaitNumberOfSnapshotsInProgress(1); + + // Fetch snapshots with state=IN_PROGRESS + snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.IN_PROGRESS)); + assertThat(snapshots, hasSize(1)); + assertThat(snapshots.getFirst().state(), is(SnapshotState.IN_PROGRESS)); + + // Fetch snapshots with multiple states (SUCCESS, IN_PROGRESS) + snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.SUCCESS, SnapshotState.IN_PROGRESS)); + assertThat(snapshots, hasSize(2)); + var states = snapshots.stream().map(SnapshotInfo::state).collect(Collectors.toSet()); + assertThat(states, hasItem(SnapshotState.SUCCESS)); + assertThat(states, hasItem(SnapshotState.IN_PROGRESS)); + + // Fetch all snapshots (without state) + snapshots = clusterAdmin().prepareGetSnapshots(TEST_REQUEST_TIMEOUT, repoName).get().getSnapshots(); + assertThat(snapshots, hasSize(2)); + + // Fetch snapshots with an invalid state + IllegalArgumentException e = expectThrows( + IllegalArgumentException.class, + () -> getSnapshotsForStates.apply(EnumSet.of(SnapshotState.valueOf("FOO"))) + ); + assertThat(e.getMessage(), is("No enum constant org.elasticsearch.snapshots.SnapshotState.FOO")); + } finally { + // Allow the IN_PROGRESS snapshot to finish, then verify GET using SUCCESS has results and IN_PROGRESS does not. + // Do this in a finally, so the block doesn't interfere with teardown in the event of a failure + unblockAllDataNodes(repoName); + } - // Allow the IN_PROGRESS snapshot to finish, then verify GET using SUCCESS has results and IN_PROGRESS does not. - unblockAllDataNodes(repoName); awaitNumberOfSnapshotsInProgress(0); snapshots = clusterAdmin().prepareGetSnapshots(TEST_REQUEST_TIMEOUT, repoName).get().getSnapshots(); assertThat(snapshots, hasSize(2)); - states = snapshots.stream().map(SnapshotInfo::state).collect(Collectors.toSet()); + var states = snapshots.stream().map(SnapshotInfo::state).collect(Collectors.toSet()); assertThat(states, hasSize(1)); assertTrue(states.contains(SnapshotState.SUCCESS)); snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.IN_PROGRESS));