From 85f2f11a2bd04c06ca6e704947b6b573087d2f4b Mon Sep 17 00:00:00 2001 From: Suraj Singh Date: Wed, 17 May 2023 17:39:24 -0700 Subject: [PATCH] Verify replica doc count only when it is assigned Signed-off-by: Suraj Singh --- .../org/opensearch/upgrades/IndexingIT.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/IndexingIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/IndexingIT.java index 689c9acd8fb73..cec43159ff116 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/IndexingIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/IndexingIT.java @@ -125,16 +125,19 @@ private void waitForSearchableDocs(String index, int shardCount) throws Exceptio final int primaryHits = ObjectPath.createFromResponse(searchTestIndexResponse).evaluate("hits.total"); logger.info("--> primaryHits {}", primaryHits); final int shardNum = shardNumber; - assertBusy(() -> { - Request replicaRequest = new Request("POST", "/" + index + "/_search"); - replicaRequest.addParameter(TOTAL_HITS_AS_INT_PARAM, "true"); - replicaRequest.addParameter("filter_path", "hits.total"); - replicaRequest.addParameter("preference", "_shards:" + shardNum + "|_only_nodes:" + replicaShardToNodeIDMap.get(shardNum)); - Response replicaResponse = client().performRequest(replicaRequest); - int replicaHits = ObjectPath.createFromResponse(replicaResponse).evaluate("hits.total"); - logger.info("--> ReplicaHits {}", replicaHits); - assertEquals(primaryHits, replicaHits); - }, 1, TimeUnit.MINUTES); + // Verify replica shard doc count only when available. + if (replicaShardToNodeIDMap.get(shardNum) != null) { + assertBusy(() -> { + Request replicaRequest = new Request("POST", "/" + index + "/_search"); + replicaRequest.addParameter(TOTAL_HITS_AS_INT_PARAM, "true"); + replicaRequest.addParameter("filter_path", "hits.total"); + replicaRequest.addParameter("preference", "_shards:" + shardNum + "|_only_nodes:" + replicaShardToNodeIDMap.get(shardNum)); + Response replicaResponse = client().performRequest(replicaRequest); + int replicaHits = ObjectPath.createFromResponse(replicaResponse).evaluate("hits.total"); + logger.info("--> ReplicaHits {}", replicaHits); + assertEquals(primaryHits, replicaHits); + }, 1, TimeUnit.MINUTES); + } } }