fix(kinesisanalytics): paginate ListApplications (#6813)

* fix(kinesisanalytics): paginate ListApplications

* test(kinesisanalytics): cover default ListApplications page size

* fix(kinesisanalytics): resume list pages after deleted applications

* fix: share pagination bound validation
This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-10-28 16:58:30 -04:00
1 parent 6abd9d7ffb
commit 3d4fdfe7ca
6 files changed
+197 -8

No files matched your search

@@ -175,7 +175,8 @@ class PaginationTest {
@Test
void boundedNamespacedPaging_refusesOutOfRangeSizes() {
for (int size : new int[] {-1, 0, 4}) {
assertInvalid(() -> bounded(size, null));
AwsException error = assertInvalid(() -> bounded(size, null));
assertEquals("Page size must be between 1 and 3.", error.getMessage());
}
}
@@ -187,7 +188,13 @@ class PaginationTest {
assertTrue(bounded(1, boundary).items().isEmpty());
String token = Base64.getUrlEncoder().withoutPadding()
.encodeToString(("ns:" + "a".repeat(100)).getBytes(StandardCharsets.UTF_8));
assertInvalid(() -> bounded(1, token));
AwsException error = assertInvalid(() -> bounded(1, token));
assertEquals("Pagination token must not exceed 32 characters.", error.getMessage());
}
@Test
void boundedNamespacedPaging_treatsAnEmptyTokenAsTheFirstPage() {
assertThat(bounded(1, "").items(), contains("a"));
}
@Test
@@ -196,6 +203,31 @@ class PaginationTest {
assertInvalid(() -> bounded(1, page(1, null, "other").nextToken()));
}
@Test
void unencodedPagingReturnsTheRawCursorAndResumesAfterItIsDeleted() {
PaginatedResult<String> first = Pagination.paginateUnencoded(ITEMS, Function.identity(),
1, null, 2, 3, 128, "InvalidInput");
assertThat(first.items(), contains("a"));
assertEquals("a", first.nextToken());
PaginatedResult<String> rest = Pagination.paginateUnencoded(List.of("b", "c"),
Function.identity(), 1, first.nextToken(), 2, 3, 128, "InvalidInput");
assertThat(rest.items(), contains("b"));
assertEquals("b", rest.nextToken());
}
@Test
void unencodedPagingValidatesBoundsAndTokenLength() {
AwsException pageSizeError = assertInvalid(() -> Pagination.paginateUnencoded(ITEMS,
Function.identity(), 0, null, 2, 3, 128, "InvalidInput"));
assertEquals("Page size must be between 1 and 3.", pageSizeError.getMessage());
for (String token : List.of("", "x".repeat(129))) {
AwsException tokenError = assertInvalid(() -> Pagination.paginateUnencoded(ITEMS,
Function.identity(), 1, token, 2, 3, 128, "InvalidInput"));
assertEquals("Pagination token must be between 1 and 128 characters.", tokenError.getMessage());
}
}
@Test
void jsonPageSize_preservesOmittedNullZeroAndIntegerValues() throws Exception {
for (String field : List.of("MaxResults", "PageSize")) {
@@ -232,10 +264,11 @@ class PaginationTest {
return Pagination.paginate(ITEMS, Function.identity(), size, token, 2, 3, 32, "InvalidInput", "ns");
}
private static void assertInvalid(Executable call) {
private static AwsException assertInvalid(Executable call) {
AwsException error = assertThrows(AwsException.class, call);
assertEquals("InvalidInput", error.getErrorCode());
assertEquals(400, error.getHttpStatus());
return error;
}
private static PaginatedResult<String> page(int limit, String token, String namespace) {
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.kinesisanalytics;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.json.config.JsonPathConfig;
import io.restassured.response.Response;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -14,6 +15,8 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Drives the full JSON-1.1 dispatch path (AwsJson11Controller → ResolvedServiceCatalog →
@@ -136,6 +139,37 @@ class KinesisAnalyticsV2IntegrationTest {
.body("ApplicationSummaries.ApplicationName", hasItem("it-list"));
}
@Test
void listApplicationsPaginatesThroughJsonProtocol() {
createApplication("it-page-a-" + System.nanoTime());
createApplication("it-page-b-" + System.nanoTime());
Response firstPage = given()
.header("X-Amz-Target", "KinesisAnalytics_20180523.ListApplications")
.contentType(CONTENT_TYPE)
.body("{\"Limit\":1}")
.when()
.post("/")
.then()
.statusCode(200)
.body("ApplicationSummaries.size()", equalTo(1))
.extract().response();
String token = firstPage.path("NextToken");
assertNotNull(token);
String secondName = given()
.header("X-Amz-Target", "KinesisAnalytics_20180523.ListApplications")
.contentType(CONTENT_TYPE)
.body("{\"Limit\":1,\"NextToken\":\"" + token + "\"}")
.when()
.post("/")
.then()
.statusCode(200)
.body("ApplicationSummaries.size()", equalTo(1))
.extract().path("ApplicationSummaries[0].ApplicationName");
assertNotEquals(firstPage.path("ApplicationSummaries[0].ApplicationName"), secondName);
}
@Test
void deleteApplicationSucceeds() {
createApplication("it-delete");
@@ -101,6 +101,86 @@ class KinesisAnalyticsV2JsonHandlerTest {
assertEquals(2, summaries.size());
}
@Test
void listApplicationsHonorsLimitAndReturnsNextToken() {
String longName = "a".repeat(128);
createApplication(longName);
createApplication("demo-b");
ObjectNode request = MAPPER.createObjectNode().put("Limit", 1);
ObjectNode firstPage = entity(handler.handle("ListApplications", request, REGION));
assertEquals(1, firstPage.get("ApplicationSummaries").size());
assertEquals(longName, firstPage.get("ApplicationSummaries").get(0).get("ApplicationName").asText());
assertThat(firstPage.hasNonNull("NextToken"), is(true));
String token = firstPage.get("NextToken").asText();
assertEquals(longName, token);
createApplication("a0");
ObjectNode secondRequest = MAPPER.createObjectNode().put("Limit", 1).put("NextToken", token);
ObjectNode secondPage = entity(handler.handle("ListApplications", secondRequest, REGION));
assertEquals("demo-b", secondPage.get("ApplicationSummaries").get(0).get("ApplicationName").asText());
assertThat(secondPage.has("NextToken"), is(false));
}
@Test
void listApplicationsContinuesAfterTheLastReturnedApplicationIsDeleted() {
createApplication("demo-a");
createApplication("demo-b");
ObjectNode firstPage = entity(handler.handle("ListApplications",
MAPPER.createObjectNode().put("Limit", 1), REGION));
String firstName = firstPage.get("ApplicationSummaries").get(0).get("ApplicationName").asText();
String token = firstPage.get("NextToken").asText();
assertEquals(firstName, token);
ObjectNode describe = MAPPER.createObjectNode().put("ApplicationName", firstName);
double createTimestamp = entity(handler.handle("DescribeApplication", describe, REGION))
.get("ApplicationDetail").get("CreateTimestamp").asDouble();
ObjectNode delete = MAPPER.createObjectNode()
.put("ApplicationName", firstName)
.put("CreateTimestamp", createTimestamp);
assertThat(handler.handle("DeleteApplication", delete, REGION).getStatus(), is(200));
ObjectNode secondPage = entity(handler.handle("ListApplications",
MAPPER.createObjectNode().put("Limit", 1).put("NextToken", token), REGION));
assertEquals("demo-b", secondPage.get("ApplicationSummaries").get(0).get("ApplicationName").asText());
}
@Test
void listApplicationsUsesDefaultPageSizeAndEndsWithoutToken() {
for (int index = 0; index < 51; index++) {
createApplication(String.format("default-page-%02d", index));
}
ObjectNode firstPage = entity(handler.handle("ListApplications", MAPPER.createObjectNode(), REGION));
assertEquals(50, firstPage.get("ApplicationSummaries").size());
assertThat(firstPage.hasNonNull("NextToken"), is(true));
ObjectNode secondRequest = MAPPER.createObjectNode().put("NextToken",
firstPage.get("NextToken").asText());
ObjectNode secondPage = entity(handler.handle("ListApplications", secondRequest, REGION));
assertEquals(1, secondPage.get("ApplicationSummaries").size());
assertThat(secondPage.has("NextToken"), is(false));
}
@Test
void listApplicationsRejectsInvalidLimitAndToken() {
createApplication("demo-a");
for (int limit : new int[]{0, 51}) {
AwsException error = assertThrows(AwsException.class, () -> handler.handle("ListApplications",
MAPPER.createObjectNode().put("Limit", limit), REGION));
assertEquals("InvalidRequestException", error.getErrorCode());
}
for (String token : new String[]{"", "!", "x".repeat(129)}) {
AwsException error = assertThrows(AwsException.class, () -> handler.handle("ListApplications",
MAPPER.createObjectNode().put("NextToken", token), REGION));
assertEquals("InvalidRequestException", error.getErrorCode());
}
}
@Test
void deleteApplicationRemovesIt() {
createApplication("demo");