Fix and unmute GetSnapshotsIT (#129741)

Closes: 129740
This commit is contained in:
Nick Tindall 2025-06-20 18:29:47 +10:00 committed by GitHub
parent 9e19b85783
commit f715f63137
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 27 deletions

View File

@ -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:
#

View File

@ -71,6 +71,7 @@ import java.util.stream.Collectors;
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 class GetSnapshotsIT extends AbstractSnapshotIntegTestCase {
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);
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 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 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 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"));
// 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));