|
71 | 71 | import static org.elasticsearch.repositories.blobstore.BlobStoreRepository.getRepositoryDataBlobName; |
72 | 72 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
73 | 73 | import static org.hamcrest.Matchers.empty; |
| 74 | +import static org.hamcrest.Matchers.hasItem; |
74 | 75 | import static org.hamcrest.Matchers.hasSize; |
75 | 76 | import static org.hamcrest.Matchers.in; |
76 | 77 | import static org.hamcrest.Matchers.is; |
@@ -655,40 +656,47 @@ public void testFilterByState() throws Exception { |
655 | 656 | assertThat(snapshots, hasSize(1)); |
656 | 657 | assertThat(snapshots.getFirst().state(), is(SnapshotState.SUCCESS)); |
657 | 658 |
|
| 659 | + // Add some more state (so the next snapshot has some work to do) |
| 660 | + indexRandomDocs(randomIdentifier(), 100); |
| 661 | + |
658 | 662 | // Create a snapshot in progress |
659 | 663 | 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 | + } |
685 | 695 |
|
686 | | - // Allow the IN_PROGRESS snapshot to finish, then verify GET using SUCCESS has results and IN_PROGRESS does not. |
687 | | - unblockAllDataNodes(repoName); |
688 | 696 | awaitNumberOfSnapshotsInProgress(0); |
689 | 697 | snapshots = clusterAdmin().prepareGetSnapshots(TEST_REQUEST_TIMEOUT, repoName).get().getSnapshots(); |
690 | 698 | 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()); |
692 | 700 | assertThat(states, hasSize(1)); |
693 | 701 | assertTrue(states.contains(SnapshotState.SUCCESS)); |
694 | 702 | snapshots = getSnapshotsForStates.apply(EnumSet.of(SnapshotState.IN_PROGRESS)); |
|
0 commit comments