2323import org .elasticsearch .common .settings .Settings ;
2424import org .elasticsearch .common .unit .ByteSizeUnit ;
2525import org .elasticsearch .common .unit .TimeValue ;
26+ import org .elasticsearch .index .snapshots .IndexShardSnapshotStatus ;
2627import org .elasticsearch .plugins .Plugin ;
2728import org .elasticsearch .snapshots .mockstore .MockRepository ;
2829import org .elasticsearch .test .ESIntegTestCase ;
3132
3233import java .util .Arrays ;
3334import java .util .Collection ;
35+ import java .util .List ;
3436import java .util .concurrent .TimeUnit ;
37+ import java .util .stream .Collectors ;
3538
3639import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
3740import 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 )
4045public 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