Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Kale <kalsac@amazon.com>
  • Loading branch information
Sachin Kale committed Oct 4, 2023
1 parent 1f8e6aa commit 3647267
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@

import org.opensearch.action.admin.cluster.remotestore.restore.RestoreRemoteStoreRequest;
import org.opensearch.action.admin.cluster.remotestore.restore.RestoreRemoteStoreResponse;
import org.opensearch.action.admin.indices.get.GetIndexRequest;
import org.opensearch.action.admin.indices.get.GetIndexResponse;
import org.opensearch.action.support.PlainActionFuture;
import org.opensearch.cluster.health.ClusterHealthStatus;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.repositories.RepositoriesService;
import org.opensearch.test.CorruptionUtils;
import org.opensearch.test.InternalTestCluster;
import org.opensearch.test.OpenSearchIntegTestCase;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount;
Expand Down Expand Up @@ -416,5 +423,30 @@ public void testRateLimitedRemoteDownloads() throws Exception {
verifyRestoredData(indexStats, INDEX_NAME);
}

public void testRestoreCorruptSegmentShouldFail() throws IOException, ExecutionException, InterruptedException {
prepareCluster(1, 3, INDEX_NAME, 0, 1);
indexData(randomIntBetween(3, 4), true, INDEX_NAME);

GetIndexResponse getIndexResponse = client().admin().indices().getIndex(new GetIndexRequest()).get();
String indexUUID = getIndexResponse.getSettings().get(INDEX_NAME).get(IndexMetadata.SETTING_INDEX_UUID);

logger.info("--> Corrupting segment files in remote segment store");
Path path = segmentRepoPath.resolve(indexUUID).resolve("0").resolve("segments").resolve("data");
try (Stream<Path> dataPath = Files.list(path)) {
CorruptionUtils.corruptFile(random(), dataPath.toArray(Path[]::new));
}

logger.info("--> Stop primary");
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primaryNodeName(INDEX_NAME)));

logger.info("--> Close and restore the index");
client().admin()
.cluster()
.restoreRemoteStore(new RestoreRemoteStoreRequest().indices(INDEX_NAME).waitForCompletion(true), PlainActionFuture.newFuture());

logger.info("--> Check for index status, should be red due to corruption");
ensureRed(INDEX_NAME);
}

// TODO: Restore flow - index aliases
}

0 comments on commit 3647267

Please sign in to comment.