|
51 | 51 | import java.util.stream.Collectors; |
52 | 52 |
|
53 | 53 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
| 54 | +import static org.hamcrest.Matchers.allOf; |
54 | 55 | import static org.hamcrest.Matchers.equalTo; |
55 | 56 | import static org.hamcrest.Matchers.greaterThan; |
56 | 57 | import static org.hamcrest.Matchers.hasSize; |
57 | 58 | import static org.hamcrest.Matchers.instanceOf; |
58 | 59 | import static org.hamcrest.Matchers.is; |
| 60 | +import static org.hamcrest.Matchers.not; |
59 | 61 |
|
60 | 62 | public class SnapshotStatusApisIT extends AbstractSnapshotIntegTestCase { |
61 | 63 |
|
@@ -514,6 +516,38 @@ public void testGetSnapshotsRequest() throws Exception { |
514 | 516 | awaitNoMoreRunningOperations(); |
515 | 517 | } |
516 | 518 |
|
| 519 | + public void testConcurrentCreateAndStatusAPICalls() throws Exception { |
| 520 | + for (int i = 0; i < randomIntBetween(1, 10); i++) { |
| 521 | + createIndexWithContent("test-idx-" + i); |
| 522 | + } |
| 523 | + final String repoName = "test-repo"; |
| 524 | + createRepository(repoName, "fs"); |
| 525 | + final int snapshots = randomIntBetween(10, 20); |
| 526 | + final List<ActionFuture<SnapshotsStatusResponse>> statuses = new ArrayList<>(snapshots); |
| 527 | + final List<ActionFuture<GetSnapshotsResponse>> gets = new ArrayList<>(snapshots); |
| 528 | + final Client dataNodeClient = dataNodeClient(); |
| 529 | + final String[] snapshotNames = createNSnapshots(repoName, snapshots).toArray(Strings.EMPTY_ARRAY); |
| 530 | + |
| 531 | + for (int i = 0; i < snapshots; i++) { |
| 532 | + statuses.add(dataNodeClient.admin().cluster().prepareSnapshotStatus(repoName).setSnapshots(snapshotNames).execute()); |
| 533 | + gets.add(dataNodeClient.admin().cluster().prepareGetSnapshots(repoName).setSnapshots(snapshotNames).execute()); |
| 534 | + } |
| 535 | + |
| 536 | + for (ActionFuture<SnapshotsStatusResponse> status : statuses) { |
| 537 | + assertThat(status.get().getSnapshots(), hasSize(snapshots)); |
| 538 | + for (SnapshotStatus snapshot : status.get().getSnapshots()) { |
| 539 | + assertThat(snapshot.getState(), allOf(not(SnapshotsInProgress.State.FAILED), not(SnapshotsInProgress.State.ABORTED))); |
| 540 | + } |
| 541 | + } |
| 542 | + for (ActionFuture<GetSnapshotsResponse> get : gets) { |
| 543 | + final List<SnapshotInfo> snapshotInfos = get.get().getSnapshots(repoName); |
| 544 | + assertThat(snapshotInfos, hasSize(snapshots)); |
| 545 | + for (SnapshotInfo snapshotInfo : snapshotInfos) { |
| 546 | + assertThat(snapshotInfo.state(), is(SnapshotState.SUCCESS)); |
| 547 | + } |
| 548 | + } |
| 549 | + } |
| 550 | + |
517 | 551 | private static SnapshotIndexShardStatus stateFirstShard(SnapshotStatus snapshotStatus, String indexName) { |
518 | 552 | return snapshotStatus.getIndices().get(indexName).getShards().get(0); |
519 | 553 | } |
|
0 commit comments