Skip to content

Commit 85da45d

Browse files
committed
do not use sleep
1 parent cb73eea commit 85da45d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

core/src/test/java/org/elasticsearch/snapshots/SnapshotShardsServiceIT.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.common.settings.Settings;
2424
import org.elasticsearch.common.unit.ByteSizeUnit;
2525
import org.elasticsearch.common.unit.TimeValue;
26+
import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;
2627
import org.elasticsearch.plugins.Plugin;
2728
import org.elasticsearch.snapshots.mockstore.MockRepository;
2829
import org.elasticsearch.test.ESIntegTestCase;
@@ -31,10 +32,14 @@
3132

3233
import java.util.Arrays;
3334
import java.util.Collection;
35+
import java.util.List;
3436
import java.util.concurrent.TimeUnit;
37+
import java.util.stream.Collectors;
3538

3639
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
3740
import static org.hamcrest.Matchers.equalTo;
41+
import static org.hamcrest.Matchers.everyItem;
42+
import static org.hamcrest.Matchers.hasSize;
3843

3944
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, transportClientRatio = 0)
4045
public class SnapshotShardsServiceIT extends AbstractSnapshotIntegTestCase {
@@ -71,6 +76,9 @@ public void testRetryPostingSnapshotStatusMessages() throws Exception {
7176
.get();
7277
waitForBlock(blockedNode, "test-repo", TimeValue.timeValueSeconds(60));
7378

79+
final SnapshotId snapshotId = client().admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap")
80+
.get().getSnapshots().get(0).snapshotId();
81+
7482
logger.info("--> start disrupting cluster");
7583
final NetworkDisruption networkDisruption = new NetworkDisruption(new NetworkDisruption.TwoPartitions(masterNode, dataNode),
7684
NetworkDisruption.NetworkDelay.random(random()));
@@ -79,16 +87,27 @@ public void testRetryPostingSnapshotStatusMessages() throws Exception {
7987

8088
logger.info("--> unblocking repository");
8189
unblockNode("test-repo", blockedNode);
82-
Thread.sleep(200);
90+
91+
// Retrieve snapshot status from the data node.
92+
SnapshotShardsService snapshotShardsService = internalCluster().getInstance(SnapshotShardsService.class, blockedNode);
93+
assertBusy(() -> {
94+
final Snapshot snapshot = new Snapshot("test-repo", snapshotId);
95+
List<IndexShardSnapshotStatus.Stage> stages = snapshotShardsService.currentSnapshotShards(snapshot)
96+
.values().stream().map(IndexShardSnapshotStatus::stage).collect(Collectors.toList());
97+
assertThat(stages, hasSize(shards));
98+
assertThat(stages, everyItem(equalTo(IndexShardSnapshotStatus.Stage.DONE)));
99+
});
100+
83101
logger.info("--> stop disrupting cluster");
102+
networkDisruption.stopDisrupting();
84103
internalCluster().clearDisruptionScheme(true);
85104

86105
assertBusy(() -> {
87106
GetSnapshotsResponse snapshotsStatusResponse = client().admin().cluster()
88107
.prepareGetSnapshots("test-repo")
89108
.setSnapshots("test-snap").get();
90-
logger.info("Status size [{}]", snapshotsStatusResponse.getSnapshots().get(0).successfulShards());
91109
SnapshotInfo snapshotInfo = snapshotsStatusResponse.getSnapshots().get(0);
110+
logger.info("Snapshot status [{}], successfulShards [{}]", snapshotInfo.state(), snapshotInfo.successfulShards());
92111
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
93112
assertThat(snapshotInfo.successfulShards(), equalTo(shards));
94113
}, 10, TimeUnit.SECONDS);

0 commit comments

Comments
 (0)