Skip to content

Commit

Permalink
Fix limit check for listing S3 objects (opensearch-project#12018)
Browse files Browse the repository at this point in the history
* Fix limit check for listing S3 objects

Signed-off-by: Bhumika Saini <[email protected]>

* Apply spotless fix

Signed-off-by: Bhumika Saini <[email protected]>

---------

Signed-off-by: Bhumika Saini <[email protected]>
  • Loading branch information
Bhumika Saini authored and rayshrey committed Mar 18, 2024
1 parent fa332f0 commit a500b54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ private static List<ListObjectsV2Response> executeListing(
for (ListObjectsV2Response listObjectsV2Response : listObjectsIterable) {
results.add(listObjectsV2Response);
totalObjects += listObjectsV2Response.contents().size();
if (limit != -1 && totalObjects > limit) {
if (limit != -1 && totalObjects >= limit) {
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,15 @@ public void testListBlobsByPrefixInLexicographicOrderWithLimitLessThanPageSize()
testListBlobsByPrefixInLexicographicOrder(2, 1, BlobContainer.BlobNameSortOrder.LEXICOGRAPHIC);
}

/**
* Test the boundary value at page size to ensure
* unnecessary calls are not made to S3 by fetching the next page.
* @throws IOException
*/
public void testListBlobsByPrefixInLexicographicOrderWithLimitEqualToPageSize() throws IOException {
testListBlobsByPrefixInLexicographicOrder(5, 1, BlobContainer.BlobNameSortOrder.LEXICOGRAPHIC);
}

public void testListBlobsByPrefixInLexicographicOrderWithLimitGreaterThanPageSize() throws IOException {
testListBlobsByPrefixInLexicographicOrder(8, 2, BlobContainer.BlobNameSortOrder.LEXICOGRAPHIC);
}
Expand Down

0 comments on commit a500b54

Please sign in to comment.