feat(ses): paginate the tenant and import job lists (#4819)

* feat(ses): paginate the tenant and import job lists

Page ListTenants, ListTenantResources, ListResourceTenants and ListImportJobs
on the shared SES paging, each with its own token namespace, and delete
SesTenantService.validateListPaging. The tenant lists answer the probed SES
rules: PageSize 1 to 100 with the Smithy validation messages, an empty
NextToken refused with its Smithy message before the tenant or resource is
looked up, an unreadable token answered "Invalid Next Token", tenants listed
by name, a tenant's resources by ARN and a resource's tenants in association
order. ListImportJobs could not be probed and is modelled on the tenant lists,
keeping Floci's oldest-first order. Without a PageSize all four lists serve up
to 100, a Floci assumption where nothing could be measured.

* fix(ses): follow the probed order, aggregation and token binding on the tenant lists

A second probe of real SES showed three differences on ListTenantResources and
ListResourceTenants: the tenant or resource is looked up, and the filter
checked, before the page size and token; a page size outside the bound and an
empty NextToken are reported together in one validation message; and a token
is refused once the tenant, resource or filter changes. ListImportJobs, which
cannot be probed, follows the same rules. The service docs keep the per-list
paging detail and gain a paragraph for these four lists.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-10-01 13:10:03 -04:00
1 parent bcf1045536
commit a22e65f993
14 files changed
+988 -91

No files matched your search

@@ -0,0 +1,95 @@
package com.floci.test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
import software.amazon.awssdk.services.s3.model.DeleteBucketRequest;
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.sesv2.SesV2Client;
import software.amazon.awssdk.services.sesv2.model.CreateImportJobRequest;
import software.amazon.awssdk.services.sesv2.model.DataFormat;
import software.amazon.awssdk.services.sesv2.model.ImportDataSource;
import software.amazon.awssdk.services.sesv2.model.ImportDestination;
import software.amazon.awssdk.services.sesv2.model.ImportJobSummary;
import software.amazon.awssdk.services.sesv2.model.ListImportJobsRequest;
import software.amazon.awssdk.services.sesv2.model.ListImportJobsResponse;
import software.amazon.awssdk.services.sesv2.model.SuppressionListDestination;
import software.amazon.awssdk.services.sesv2.model.SuppressionListImportAction;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Paging of the SES v2 import-job list through the SDK paginator: every job created here is listed
* exactly once across small pages. The jobs delete an address that was never suppressed, so they
* leave no state behind whatever their outcome; import jobs themselves cannot be deleted.
*/
@DisplayName("SES import job list paging")
class SesImportJobPagingTest {
private static final String KEY = "delete.csv";
private static SesV2Client sesV2;
private static S3Client s3;
private static String bucket;
private static List<String> jobIds;
@BeforeAll
static void setup() {
sesV2 = TestFixtures.sesV2Client();
s3 = TestFixtures.s3Client();
bucket = "floci-ses-import-paging-" + TestFixtures.uniqueName();
jobIds = new ArrayList<>();
s3.createBucket(CreateBucketRequest.builder().bucket(bucket).build());
s3.putObject(PutObjectRequest.builder().bucket(bucket).key(KEY).build(),
RequestBody.fromString("never-suppressed@example.com\n"));
for (int i = 0; i < 3; i++) {
jobIds.add(sesV2.createImportJob(CreateImportJobRequest.builder()
.importDataSource(ImportDataSource.builder()
.s3Url("s3://" + bucket + "/" + KEY).dataFormat(DataFormat.CSV).build())
.importDestination(ImportDestination.builder()
.suppressionListDestination(SuppressionListDestination.builder()
.suppressionListImportAction(SuppressionListImportAction.DELETE).build())
.build())
.build()).jobId());
}
}
@AfterAll
static void cleanup() {
if (s3 != null) {
try {
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucket).key(KEY).build());
s3.deleteBucket(DeleteBucketRequest.builder().bucket(bucket).build());
} catch (Exception ignored) {
// Best-effort cleanup; a leftover bucket does not affect other tests.
}
s3.close();
}
if (sesV2 != null) {
sesV2.close();
}
}
@Test
@DisplayName("ListImportJobs paginator walks small pages over every job once")
void paginatorWalksEveryJobOnce() {
List<String> listed = new ArrayList<>();
for (ListImportJobsResponse page : sesV2.listImportJobsPaginator(
ListImportJobsRequest.builder().pageSize(2).build())) {
assertThat(page.importJobs()).hasSizeLessThanOrEqualTo(2);
page.importJobs().stream().map(ImportJobSummary::jobId).forEach(listed::add);
}
assertThat(listed).doesNotHaveDuplicates();
assertThat(listed.stream().filter(jobIds::contains)).containsExactlyInAnyOrderElementsOf(jobIds);
}
}
@@ -0,0 +1,133 @@
package com.floci.test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.sesv2.SesV2Client;
import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityRequest;
import software.amazon.awssdk.services.sesv2.model.CreateTenantRequest;
import software.amazon.awssdk.services.sesv2.model.CreateTenantResponse;
import software.amazon.awssdk.services.sesv2.model.CreateTenantResourceAssociationRequest;
import software.amazon.awssdk.services.sesv2.model.DeleteEmailIdentityRequest;
import software.amazon.awssdk.services.sesv2.model.DeleteTenantRequest;
import software.amazon.awssdk.services.sesv2.model.ListResourceTenantsRequest;
import software.amazon.awssdk.services.sesv2.model.ListResourceTenantsResponse;
import software.amazon.awssdk.services.sesv2.model.ListTenantResourcesRequest;
import software.amazon.awssdk.services.sesv2.model.ListTenantResourcesResponse;
import software.amazon.awssdk.services.sesv2.model.ListTenantsRequest;
import software.amazon.awssdk.services.sesv2.model.ListTenantsResponse;
import software.amazon.awssdk.services.sesv2.model.ResourceTenantMetadata;
import software.amazon.awssdk.services.sesv2.model.TenantInfo;
import software.amazon.awssdk.services.sesv2.model.TenantResource;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Paging of the SES v2 tenant lists through the SDK paginators: every tenant, tenant resource and
* resource tenant created here is listed exactly once across small pages. Tenants are reversible
* (create + delete), so cleanup restores the account.
*/
@DisplayName("SES tenant list paging")
class SesTenantPagingTest {
private static SesV2Client sesV2;
private static List<String> tenants;
private static List<String> identities;
private static List<String> identityArns;
@BeforeAll
static void setup() {
sesV2 = TestFixtures.sesV2Client();
String prefix = "sdk-page-" + TestFixtures.uniqueName();
tenants = List.of(prefix + "-b", prefix + "-c", prefix + "-a");
identities = List.of(prefix + "-b.test", prefix + "-c.test", prefix + "-a.test");
identityArns = new ArrayList<>();
String arnPrefix = null;
for (String tenant : tenants) {
CreateTenantResponse created = sesV2.createTenant(CreateTenantRequest.builder().tenantName(tenant).build());
arnPrefix = created.tenantArn().substring(0, created.tenantArn().indexOf(":tenant/") + 1);
}
for (String identity : identities) {
sesV2.createEmailIdentity(CreateEmailIdentityRequest.builder().emailIdentity(identity).build());
identityArns.add(arnPrefix + "identity/" + identity);
}
// Every identity is associated with the first tenant, and the first identity with every tenant.
for (String arn : identityArns) {
associate(tenants.get(0), arn);
}
for (String tenant : tenants.subList(1, tenants.size())) {
associate(tenant, identityArns.get(0));
}
}
@AfterAll
static void cleanup() {
if (sesV2 != null) {
// DeleteTenant cascades the associations, so the identities can go afterwards.
for (String tenant : tenants) {
try {
sesV2.deleteTenant(DeleteTenantRequest.builder().tenantName(tenant).build());
} catch (Exception ignored) {
// Best-effort cleanup; a leftover tenant does not affect other tests.
}
}
for (String identity : identities) {
try {
sesV2.deleteEmailIdentity(DeleteEmailIdentityRequest.builder().emailIdentity(identity).build());
} catch (Exception ignored) {
// Best-effort cleanup; a leftover identity does not affect other tests.
}
}
sesV2.close();
}
}
@Test
@DisplayName("ListTenants paginator walks small pages over every tenant once")
void listTenantsPaginatorWalksEveryTenantOnce() {
List<String> listed = new ArrayList<>();
for (ListTenantsResponse page : sesV2.listTenantsPaginator(ListTenantsRequest.builder().pageSize(2).build())) {
assertThat(page.tenants()).hasSizeLessThanOrEqualTo(2);
page.tenants().stream().map(TenantInfo::tenantName).forEach(listed::add);
}
assertThat(listed).doesNotHaveDuplicates();
assertThat(listed.stream().filter(tenants::contains)).containsExactlyInAnyOrderElementsOf(tenants);
}
@Test
@DisplayName("ListTenantResources paginator walks small pages over every resource once")
void listTenantResourcesPaginatorWalksEveryResourceOnce() {
List<String> listed = new ArrayList<>();
for (ListTenantResourcesResponse page : sesV2.listTenantResourcesPaginator(
ListTenantResourcesRequest.builder().tenantName(tenants.get(0)).pageSize(2).build())) {
assertThat(page.tenantResources()).hasSizeLessThanOrEqualTo(2);
page.tenantResources().stream().map(TenantResource::resourceArn).forEach(listed::add);
}
assertThat(listed).doesNotHaveDuplicates().containsExactlyInAnyOrderElementsOf(identityArns);
}
@Test
@DisplayName("ListResourceTenants paginator walks small pages over every tenant once")
void listResourceTenantsPaginatorWalksEveryTenantOnce() {
List<String> listed = new ArrayList<>();
for (ListResourceTenantsResponse page : sesV2.listResourceTenantsPaginator(
ListResourceTenantsRequest.builder().resourceArn(identityArns.get(0)).pageSize(2).build())) {
assertThat(page.resourceTenants()).hasSizeLessThanOrEqualTo(2);
page.resourceTenants().stream().map(ResourceTenantMetadata::tenantName).forEach(listed::add);
}
assertThat(listed).doesNotHaveDuplicates().containsExactlyInAnyOrderElementsOf(tenants);
}
private static void associate(String tenant, String arn) {
sesV2.createTenantResourceAssociation(CreateTenantResourceAssociationRequest.builder()
.tenantName(tenant).resourceArn(arn).build());
}
}