code:     public void testRestoreToShadow() throws ExecutionException, InterruptedException {
          Settings nodeSettings = nodeSettings();
  
          internalCluster().startNodesAsync(3, nodeSettings).get();
          final Path dataPath = newTempDir().toPath();
          Settings idxSettings = ImmutableSettings.builder()
                  .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
                  .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build();
          assertAcked(prepareCreate("foo").setSettings(idxSettings));
          ensureGreen();
          final int numDocs = randomIntBetween(10, 100);
          for (int i = 0; i < numDocs; i++) {
              client().prepareIndex("foo", "doc", ""+i).setSource("foo", "bar").get();
          }
          assertNoFailures(client().admin().indices().prepareFlush().setForce(true).setWaitIfOngoing(true).execute().actionGet());
  
          assertAcked(client().admin().cluster().preparePutRepository("test-repo")
                  .setType("fs").setSettings(ImmutableSettings.settingsBuilder()
                          .put("location", newTempDir().toPath())));
          CreateSnapshotResponse createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("foo").get();
          assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
          assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
          assertThat(client().admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
  
          Settings shadowSettings = ImmutableSettings.builder()
                  .put(IndexMetaData.SETTING_DATA_PATH, dataPath.toAbsolutePath().toString())
                  .put(IndexMetaData.SETTING_SHADOW_REPLICAS, true)
                  .put(IndexMetaData.SETTING_SHARED_FILESYSTEM, true)
                  .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 2).build();
  
          logger.info("--> restore the index into shadow replica index");
          RestoreSnapshotResponse restoreSnapshotResponse = client().admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap")
                  .setIndexSettings(shadowSettings).setWaitForCompletion(true)
                  .setRenamePattern("(.+)").setRenameReplacement("$1-copy")
                  .execute().actionGet();
          assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
          ensureGreen();
          refresh();
  
          for (IndicesService service : internalCluster().getDataNodeInstances(IndicesService.class)) {
              if (service.hasIndex("foo-copy")) {
                  IndexShard shard = service.indexServiceSafe("foo-copy").shard(0);
                  if (shard.routingEntry().primary()) {
                      assertFalse(shard instanceof ShadowIndexShard);
                  } else {
                      assertTrue(shard instanceof ShadowIndexShard);
                  }
              }
          }
          logger.info("--> performing query");
          SearchResponse resp = client().prepareSearch("foo-copy").setQuery(matchAllQuery()).get();
          assertHitCount(resp, numDocs);
  
      }
  
      @Test
  