1212import com .carrotsearch .randomizedtesting .annotations .Name ;
1313
1414import org .elasticsearch .client .Request ;
15+ import org .elasticsearch .common .Strings ;
1516import org .elasticsearch .common .settings .Settings ;
1617import org .elasticsearch .test .rest .ObjectPath ;
1718
1819import java .io .IOException ;
1920import java .util .Collection ;
2021
22+ import static org .elasticsearch .upgrades .SnapshotBasedRecoveryIT .indexDocs ;
23+ import static org .hamcrest .Matchers .empty ;
2124import static org .hamcrest .Matchers .equalTo ;
2225import static org .hamcrest .Matchers .not ;
2326
@@ -34,18 +37,22 @@ public void testRunningSnapshotCompleteAfterUpgrade() throws Exception {
3437 final var nodeIds = getNodesInfo (client ()).keySet ();
3538
3639 if (isOldCluster ()) {
40+ registerRepository (repositoryName , "fs" , randomBoolean (), Settings .builder ().put ("location" , "backup" ).build ());
3741 // create an index to have one shard per node
3842 createIndex (indexName , indexSettings (3 , 0 ).put ("index.routing.allocation.total_shards_per_node" , 1 ).build ());
3943 ensureGreen (indexName );
44+ if (randomBoolean ()) {
45+ indexDocs (indexName , between (10 , 50 ));
46+ }
4047 flush (indexName , true );
4148 // Signal shutdown to prevent snapshot from being completed
4249 putShutdownMetadata (nodeIds );
43- registerRepository (repositoryName , "fs" , randomBoolean (), Settings .builder ().put ("location" , "backup" ).build ());
4450 createSnapshot (repositoryName , snapshotName , false );
4551 assertRunningSnapshot (repositoryName , snapshotName );
4652 } else {
4753 if (isUpgradedCluster ()) {
4854 deleteShutdownMetadata (nodeIds );
55+ assertNoShutdownMetadata (nodeIds );
4956 ensureGreen (indexName );
5057 assertBusy (() -> assertCompletedSnapshot (repositoryName , snapshotName ));
5158 } else {
@@ -73,6 +80,13 @@ private void deleteShutdownMetadata(Collection<String> nodeIds) throws IOExcepti
7380 }
7481 }
7582
83+ private void assertNoShutdownMetadata (Collection <String > nodeIds ) throws IOException {
84+ final ObjectPath responsePath = assertOKAndCreateObjectPath (
85+ client ().performRequest (new Request ("GET" , "/_nodes/" + Strings .collectionToCommaDelimitedString (nodeIds ) + "/shutdown" ))
86+ );
87+ assertThat (responsePath .evaluate ("nodes" ), empty ());
88+ }
89+
7690 private void assertRunningSnapshot (String repositoryName , String snapshotName ) throws IOException {
7791 final Request request = new Request ("GET" , "/_snapshot/" + repositoryName + "/_current" );
7892 final ObjectPath responsePath = assertOKAndCreateObjectPath (client ().performRequest (request ));
0 commit comments