From eeb149fa03a951b74209d258c6d2d93ee366b087 Mon Sep 17 00:00:00 2001 From: Suraj Singh Date: Sat, 18 Feb 2023 18:58:18 -0800 Subject: [PATCH] [Segment Replication] Wait for segment replication to be completed and marked done before assertion (#6370) * [Segment Replication] Wait for segment replication to be completed and marked done before assertion Signed-off-by: Suraj Singh * Spotless fix Signed-off-by: Suraj Singh --------- Signed-off-by: Suraj Singh --- .../SegmentReplicationStatsIT.java | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationStatsIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationStatsIT.java index 3dbaed9e03c80..9350897e15f08 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationStatsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationStatsIT.java @@ -18,10 +18,7 @@ import org.opensearch.transport.TransportService; import java.util.concurrent.CountDownLatch; - import static java.util.Arrays.asList; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; @OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) public class SegmentReplicationStatsIT extends SegmentReplicationBaseIT { @@ -40,15 +37,17 @@ public void testSegmentReplicationStatsResponse() throws Exception { refresh(INDEX_NAME); waitForSearchableDocs(10L, asList(primaryNode, replicaNode)); - SegmentReplicationStatsResponse response = client().admin() - .indices() - .prepareSegmentReplicationStats(INDEX_NAME) - .execute() - .actionGet(); - // Verify API Response - assertThat(response.shardSegmentReplicationStates().size(), equalTo(SHARD_COUNT)); - assertThat(response.shardSegmentReplicationStates().get(INDEX_NAME).get(0).getStage(), equalTo(SegmentReplicationState.Stage.DONE)); - assertThat(response.shardSegmentReplicationStates().get(INDEX_NAME).get(0).getIndex().recoveredFileCount(), greaterThan(0)); + assertBusy(() -> { + final SegmentReplicationStatsResponse response = client().admin() + .indices() + .prepareSegmentReplicationStats(INDEX_NAME) + .execute() + .actionGet(); + // Verify API Response + assertEquals(response.shardSegmentReplicationStates().size(), SHARD_COUNT); + assertEquals(response.shardSegmentReplicationStates().get(INDEX_NAME).get(0).getStage(), SegmentReplicationState.Stage.DONE); + assertTrue(response.shardSegmentReplicationStates().get(INDEX_NAME).get(0).getIndex().recoveredFileCount() > 0); + }); } public void testSegmentReplicationStatsResponseForActiveAndCompletedOnly() throws Exception { @@ -105,9 +104,9 @@ public void testSegmentReplicationStatsResponseForActiveAndCompletedOnly() throw .setActiveOnly(true) .execute() .actionGet(); - assertThat( + assertEquals( activeOnlyResponse.shardSegmentReplicationStates().get(INDEX_NAME).get(0).getStage(), - equalTo(SegmentReplicationState.Stage.GET_FILES) + SegmentReplicationState.Stage.GET_FILES ); // verifying completed_only by checking if current stage is DONE @@ -117,10 +116,10 @@ public void testSegmentReplicationStatsResponseForActiveAndCompletedOnly() throw .setCompletedOnly(true) .execute() .actionGet(); - assertThat(completedOnlyResponse.shardSegmentReplicationStates().size(), equalTo(SHARD_COUNT)); - assertThat( + assertEquals(completedOnlyResponse.shardSegmentReplicationStates().size(), SHARD_COUNT); + assertEquals( completedOnlyResponse.shardSegmentReplicationStates().get(INDEX_NAME).get(0).getStage(), - equalTo(SegmentReplicationState.Stage.DONE) + SegmentReplicationState.Stage.DONE ); waitForAssertions.countDown(); }