Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use assertThat/hasItem to give a more detailed failure message


// 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);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just put this in a finally because I noticed when the block is applied and the test fails, it messes with the teardown.


// 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));
Expand Down