Skip to content

Commit

Permalink
Fix limit check for listing S3 objects (#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]>
(cherry picked from commit e017a9c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Jan 25, 2024
1 parent f588880 commit 87cc38a
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 87cc38a

Please sign in to comment.