diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java index 2cd46e326dcfb..2ceb4e0908df3 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java @@ -237,14 +237,10 @@ public void testReplicationAfterPrimaryRefreshAndFlush() throws Exception { public void testIndexReopenClose() throws Exception { final String primary = internalCluster().startNode(); - createIndex(INDEX_NAME); - ensureYellowAndNoInitializingShards(INDEX_NAME); final String replica = internalCluster().startNode(); + createIndex(INDEX_NAME); ensureGreen(INDEX_NAME); - client().prepareIndex(INDEX_NAME).setId("1").setSource("foo", "bar").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); - refresh(INDEX_NAME); - final int initialDocCount = scaledRandomIntBetween(100, 200); try ( BackgroundIndexer indexer = new BackgroundIndexer( @@ -263,11 +259,18 @@ public void testIndexReopenClose() throws Exception { waitForReplicaUpdate(); } + assertHitCount(client(primary).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), initialDocCount); + assertHitCount(client(replica).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), initialDocCount); + logger.info("--> Closing the index "); client().admin().indices().prepareClose(INDEX_NAME).get(); logger.info("--> Opening the index"); client().admin().indices().prepareOpen(INDEX_NAME).get(); + + ensureGreen(INDEX_NAME); + assertHitCount(client(primary).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), initialDocCount); + assertHitCount(client(replica).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), initialDocCount); } public void testMultipleShards() throws Exception {