mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(kinesis): cap ListShards page size at 1000 (#8387)
This commit is contained in:
1 parent
92a61c2b86
commit
4fc41cc683
2 files changed
+25
-1
No files matched your search
@@ -33,6 +33,7 @@ import java.util.function.Supplier;
|
||||
@ApplicationScoped
|
||||
public class KinesisJsonHandler {
|
||||
|
||||
private static final int LIST_SHARDS_MAX_PAGE_SIZE = 1000;
|
||||
private static final String EXPLICIT_HASH_KEY_FIELD = "ExplicitHashKey";
|
||||
private static final String EXPLICIT_HASH_KEY_NOT_STRING_MESSAGE =
|
||||
"ExplicitHashKey must be a string.";
|
||||
@@ -781,7 +782,9 @@ public class KinesisJsonHandler {
|
||||
}
|
||||
}
|
||||
|
||||
int maxResults = request.has("MaxResults") ? request.path("MaxResults").asInt(1000) : 1000;
|
||||
int maxResults = request.has("MaxResults")
|
||||
? Math.min(request.path("MaxResults").asInt(LIST_SHARDS_MAX_PAGE_SIZE), LIST_SHARDS_MAX_PAGE_SIZE)
|
||||
: LIST_SHARDS_MAX_PAGE_SIZE;
|
||||
|
||||
List<KinesisShard> snapshot = List.copyOf(shards);
|
||||
int start = token == null ? 0 : resumeShardIndex(token, snapshot);
|
||||
|
||||
@@ -2305,6 +2305,27 @@ class KinesisJsonHandlerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void listShardsCapsPageAt1000EvenWhenMaxResultsIsLarger() {
|
||||
createStream("test-stream", 1001);
|
||||
|
||||
ObjectNode first = MAPPER.createObjectNode();
|
||||
first.put("StreamName", "test-stream");
|
||||
first.put("MaxResults", 10000);
|
||||
ObjectNode firstPage = responseEntity(handler.handle("ListShards", first, REGION));
|
||||
|
||||
assertEquals(1000, firstPage.get("Shards").size());
|
||||
assertTrue(firstPage.hasNonNull("NextToken"), "a token is returned for the remaining shard");
|
||||
|
||||
ObjectNode second = MAPPER.createObjectNode();
|
||||
second.put("NextToken", firstPage.get("NextToken").asText());
|
||||
second.put("MaxResults", 10000);
|
||||
ObjectNode secondPage = responseEntity(handler.handle("ListShards", second, REGION));
|
||||
|
||||
assertEquals(1, secondPage.get("Shards").size());
|
||||
assertFalse(secondPage.hasNonNull("NextToken"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listShardsRejectsStreamNameTogetherWithNextToken() {
|
||||
createStream("test-stream", 3);
|
||||
|
||||
Reference in new issue
Block a user