diff --git a/server/src/test/java/org/opensearch/index/shard/RemoteIndexShardTests.java b/server/src/test/java/org/opensearch/index/shard/RemoteIndexShardTests.java index c22fbdd8850ff..86f58066455f6 100644 --- a/server/src/test/java/org/opensearch/index/shard/RemoteIndexShardTests.java +++ b/server/src/test/java/org/opensearch/index/shard/RemoteIndexShardTests.java @@ -315,6 +315,34 @@ public void testRepicaCleansUpOldCommitsWhenReceivingNew() throws Exception { } } + public void testPrimaryRestart() throws Exception { + final Path remotePath = createTempDir(); + try (ReplicationGroup shards = createGroup(0, getIndexSettings(), indexMapping, new NRTReplicationEngineFactory(), remotePath)) { + shards.startAll(); + // ensure primary has uploaded something + shards.indexDocs(10); + IndexShard primary = shards.getPrimary(); + if (randomBoolean()) { + flushShard(primary); + } else { + primary.refresh("test"); + } + assertDocCount(primary, 10); + // get a metadata map - we'll use segrep diff to ensure segments on reader are identical after restart. + final Map metadataBeforeRestart = primary.getSegmentMetadataMap(); + // restart the primary + shards.reinitPrimaryShard(remotePath); + // the store is open at this point but the shard has not yet run through recovery + primary = shards.getPrimary(); + shards.startPrimary(); + assertDocCount(primary, 10); + final Store.RecoveryDiff diff = Store.segmentReplicationDiff(metadataBeforeRestart, primary.getSegmentMetadataMap()); + assertTrue(diff.missing.isEmpty()); + logger.info("DIFF FILE {}", diff.different); + assertTrue(diff.different.isEmpty()); + } + } + private void assertSingleSegmentFile(IndexShard shard, String fileName) throws IOException { final Set segmentsFileNames = Arrays.stream(shard.store().directory().listAll()) .filter(file -> file.startsWith(IndexFileNames.SEGMENTS)) diff --git a/server/src/test/java/org/opensearch/index/shard/SegmentReplicationIndexShardTests.java b/server/src/test/java/org/opensearch/index/shard/SegmentReplicationIndexShardTests.java index 88fcae17bf091..070bcae1b4a4b 100644 --- a/server/src/test/java/org/opensearch/index/shard/SegmentReplicationIndexShardTests.java +++ b/server/src/test/java/org/opensearch/index/shard/SegmentReplicationIndexShardTests.java @@ -62,7 +62,6 @@ import org.opensearch.transport.TransportService; import java.io.IOException; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -774,33 +773,6 @@ public void testNoDuplicateSeqNo() throws Exception { } } - public void testPrimaryRestart() throws Exception { - final Path remotePath = createTempDir(); - try (ReplicationGroup shards = createGroup(0, getIndexSettings(), indexMapping, new NRTReplicationEngineFactory(), remotePath)) { - shards.startAll(); - // ensure primary has uploaded something - shards.indexDocs(10); - IndexShard primary = shards.getPrimary(); - if (randomBoolean()) { - flushShard(primary); - } else { - primary.refresh("test"); - } - assertDocCount(primary, 10); - // get a metadata map - we'll use segrep diff to ensure segments on reader are identical after restart. - final Map metadataBeforeRestart = primary.getSegmentMetadataMap(); - // restart the primary - shards.reinitPrimaryShard(remotePath); - // the store is open at this point but the shard has not yet run through recovery - primary = shards.getPrimary(); - shards.startPrimary(); - assertDocCount(primary, 10); - final Store.RecoveryDiff diff = Store.segmentReplicationDiff(metadataBeforeRestart, primary.getSegmentMetadataMap()); - assertTrue(diff.missing.isEmpty()); - assertTrue(diff.different.isEmpty()); - } - } - /** * Assert persisted and searchable doc counts. This method should not be used while docs are concurrently indexed because * it asserts point in time seqNos are relative to the doc counts.