Skip to content

Commit

Permalink
Assert on row count before processing the result
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Singh <[email protected]>
  • Loading branch information
dreamer-89 committed Aug 3, 2023
1 parent 36f9ca5 commit a973066
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ private void waitForSearchableDocs(String index, int shardCount, int replicaCoun
Request segrepStatsRequest = new Request("GET", "/_cat/segments/" + index + "?s=shard,segment,primaryOrReplica");
segrepStatsRequest.addParameter("h", "index,shard,primaryOrReplica,segment,docs.count");
Response segrepStatsResponse = client().performRequest(segrepStatsRequest);
logger.info("--> _cat/segments response\n {}", EntityUtils.toString(segrepStatsResponse.getEntity()));
List<String> responseList = Streams.readAllLines(segrepStatsResponse.getEntity().getContent());
logger.info("--> _cat/segments response\n {}", responseList.toString().replace(',', '\n'));
// Ensure there is result for replica copies before processing the result. This results in retry when there
// are not enough number of rows vs failing with IndexOutOfBoundsException
assertEquals(0, responseList.size() % (replicaCount + 1));
for (int segmentsIndex=0; segmentsIndex < responseList.size();) {
String[] primaryRow = responseList.get(segmentsIndex++).split(" +");
String shardId = primaryRow[0] + primaryRow[1];
Expand Down

0 comments on commit a973066

Please sign in to comment.