mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(dms): add replication subnet group lifecycle and tagging (#3630)
* feat(dms): add replication subnet group lifecycle AWS DMS was entirely absent, so every terraform-aws-data-storage example using aws_dms_replication_subnet_group failed at plan with UnknownOperationException. Adds a minimal dms service on AWS JSON 1.1 (X-Amz-Target prefix AmazonDMSv20160101.) implementing CreateReplicationSubnetGroup, DescribeReplicationSubnetGroups and DeleteReplicationSubnetGroup. Subnets are resolved against the emulated EC2 service, so the VpcId and Availability Zones a group reports are the ones its subnets actually have, and AWS's own rules are enforced: the identifier is stored lowercase, "default" is reserved, subnets must share a VPC, and a group must cover at least two Availability Zones. Tagging actions and replication instances, endpoints and tasks are out of scope and still report UnknownOperationException. * feat(dms): add resource tagging for replication subnet groups Terraform's aws_dms_replication_subnet_group reads tags back through ListTagsForResource, so without the tagging trio the resource could be created but never read cleanly. Adds ListTagsForResource, AddTagsToResource and RemoveTagsFromResource, and stores the Tags member of CreateReplicationSubnetGroup with the group. DMS does not return a subnet group ARN from describe, so the provider builds arn:aws:dms:<region>:<account>:subgrp:<id> client side; Floci parses that form back to the stored group and rejects anything else, including another account's ARN, with ResourceNotFoundFault. * fix(dms): address review findings Emit IsReadOnly on ReplicationSubnetGroup, the one member of the model's seven the response was missing. It is always false: a read-only group is one DMS manages for a zero-ETL integration, which Floci does not emulate. Fault a cross-Region ARN the way a cross-account one already faulted. Storage is keyed by the caller's Region, so honouring an eu-west-1 ARN from a us-east-1 caller silently reached the caller's own group of that name rather than the one named. Reject a subnet with no Availability Zone as InvalidSubnet. Set.copyOf rejects nulls, so such a subnet raised a NullPointerException and surfaced as a 500 instead of a client error. Adds the user-realistic minimum-AZ case: two subnets sharing one AZ, which the previous tests did not cover because they passed one subnet. * fix(dms): reject wrongly-typed tag, filter and arn-list members A present member of the wrong JSON type was coerced rather than rejected. asText() on an object yields the empty string, so a tag whose Value was an object stored an empty value and reported success; a Filters or ResourceArnList member that was not a list was ignored outright, which turned a filtered describe into an unfiltered one. Every string member now answers SerializationException when it is present with another JSON type, matching what AWS returns when a json-1.1 member will not deserialize, and matching how Kinesis, Cognito and KMS already report the same class of error here. An absent member stays a parameter error: missing and mistyped are different faults. * fix(dms): paginate DescribeReplicationSubnetGroups and validate the description DescribeReplicationSubnetGroups returned every matching group in one response and ignored both MaxRecords and Marker, so an SDK or Terraform paginator diverged from a live account as soon as more than one page of groups existed. Page through the shared opaque-cursor helper, keyed on the group identifier, so a Marker stays resumable across groups created or deleted between requests. MaxRecords defaults to 100 and is rejected outside the documented 20 to 100 range rather than clamped, with the InvalidParameterValueException a live account answers. Marker is emitted only while a further page remains: an SDK paginator treats any Marker as "ask again", so one on the final page loops forever. ReplicationSubnetGroupDescription now also enforces the model's printable-character constraint, so a value carrying a control character such as 0x01 is rejected instead of persisted. * docs(dms): describe the Marker as the opaque cursor it is * fix(test): DmsTest must compile at the sdk-test-java module's Java 17 target List.getFirst() is a Java 21 SequencedCollection method. The main project compiles at 21, but compatibility-tests/sdk-test-java pins source/target 17, and DmsTest was the only file in that module using getFirst() -- so the native arm64 sdk-test-java image failed to build and every test in it was skipped. This was not caught earlier because the previous head of this PR had no CI rollup at all; the merge that made the branch mergeable is what first ran the job. Replaced with get(0), which is what the rest of the module uses. * style(test): import Objects and Collectors instead of naming them inline AGENTS.md asks for imports rather than inline fully-qualified names. DmsServiceTest had two: java.util.Objects::nonNull and java.util.stream.Collectors.toMap. Neither was imported; both now are.
This commit is contained in:
1 parent
09b1dc0803
commit
532bae5525
19 files changed
+1945
-3
No files matched your search
@@ -0,0 +1,381 @@
|
||||
package io.github.hectorvent.floci.services.dms;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.everyItem;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
class DmsIntegrationTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String TARGET_PREFIX = "AmazonDMSv20160101.";
|
||||
private static final String ACCOUNT_ID = "723679240095";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=" + ACCOUNT_ID + "/20260101/us-east-1/dms/aws4_request";
|
||||
private static final String SUBNET_A = "subnet-default-us-east-1-a";
|
||||
private static final String SUBNET_B = "subnet-default-us-east-1-b";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void subnetGroupLifecycleIsReadableThroughDescribe() {
|
||||
dms("CreateReplicationSubnetGroup")
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"Tf-Lifecycle\","
|
||||
+ "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
|
||||
+ "\"SubnetIds\":[\"" + SUBNET_A + "\",\"" + SUBNET_B + "\"]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ReplicationSubnetGroup.ReplicationSubnetGroupIdentifier", equalTo("tf-lifecycle"));
|
||||
|
||||
dms("DescribeReplicationSubnetGroups")
|
||||
.body("{\"Filters\":[{\"Name\":\"replication-subnet-group-id\","
|
||||
+ "\"Values\":[\"tf-lifecycle\"]}]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ReplicationSubnetGroups", hasSize(1))
|
||||
.body("ReplicationSubnetGroups[0].ReplicationSubnetGroupDescription",
|
||||
equalTo("terraform managed"))
|
||||
.body("ReplicationSubnetGroups[0].VpcId", equalTo("vpc-default-us-east-1"))
|
||||
.body("ReplicationSubnetGroups[0].SubnetGroupStatus", equalTo("Complete"))
|
||||
.body("ReplicationSubnetGroups[0].Subnets.SubnetIdentifier", contains(SUBNET_A, SUBNET_B))
|
||||
.body("ReplicationSubnetGroups[0].Subnets.find { it.SubnetIdentifier == '"
|
||||
+ SUBNET_A + "' }.SubnetAvailabilityZone.Name", equalTo("us-east-1a"))
|
||||
.body("ReplicationSubnetGroups[0].Subnets.find { it.SubnetIdentifier == '"
|
||||
+ SUBNET_B + "' }.SubnetAvailabilityZone.Name", equalTo("us-east-1b"))
|
||||
.body("ReplicationSubnetGroups[0].Subnets.SubnetStatus", everyItem(equalTo("Active")))
|
||||
.body("ReplicationSubnetGroups[0].SupportedNetworkTypes", contains("IPV4"))
|
||||
.body("ReplicationSubnetGroups[0].IsReadOnly", equalTo(false));
|
||||
|
||||
dms("DeleteReplicationSubnetGroup")
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"tf-lifecycle\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
dms("DescribeReplicationSubnetGroups")
|
||||
.body("{\"Filters\":[{\"Name\":\"replication-subnet-group-id\","
|
||||
+ "\"Values\":[\"tf-lifecycle\"]}]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundFault"));
|
||||
}
|
||||
|
||||
/**
|
||||
* DMS pages at a minimum MaxRecords of 20, so a second page needs more than 20 groups. Walk the
|
||||
* pages on the wire and check Marker resumes where the previous page stopped and is absent from
|
||||
* the final response.
|
||||
*/
|
||||
@Test
|
||||
void describePagesOnMarkerAndOmitsItFromTheFinalPage() {
|
||||
List<String> created = new ArrayList<>();
|
||||
for (int i = 0; i < 25; i++) {
|
||||
String identifier = "tf-page-" + String.format("%02d", i);
|
||||
created.add(identifier);
|
||||
dms("CreateReplicationSubnetGroup")
|
||||
.body(createBody(identifier))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
try {
|
||||
List<String> walked = new ArrayList<>();
|
||||
String marker = null;
|
||||
int pages = 0;
|
||||
do {
|
||||
String body = marker == null
|
||||
? "{\"MaxRecords\":20}"
|
||||
: "{\"MaxRecords\":20,\"Marker\":\"" + marker + "\"}";
|
||||
Response page = dms("DescribeReplicationSubnetGroups")
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().response();
|
||||
pages++;
|
||||
marker = page.path("Marker");
|
||||
List<String> identifiers =
|
||||
page.path("ReplicationSubnetGroups.ReplicationSubnetGroupIdentifier");
|
||||
if (marker != null) {
|
||||
assertEquals(20, identifiers.size(), "a non-final page must be full");
|
||||
}
|
||||
walked.addAll(identifiers);
|
||||
} while (marker != null);
|
||||
|
||||
assertNull(marker, "the final page must not carry a Marker");
|
||||
assertTrue(pages > 1, "25 groups at MaxRecords=20 must span more than one page");
|
||||
assertEquals(walked.size(), walked.stream().distinct().count(), "a group was returned twice");
|
||||
assertEquals(created, walked.stream().filter(id -> id.startsWith("tf-page-")).sorted().toList());
|
||||
} finally {
|
||||
created.forEach(identifier -> dms("DeleteReplicationSubnetGroup")
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"" + identifier + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeRejectsMaxRecordsOutsideTheDocumentedRange() {
|
||||
for (int outOfRange : new int[] {19, 101}) {
|
||||
dms("DescribeReplicationSubnetGroups")
|
||||
.body("{\"MaxRecords\":" + outOfRange + "}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterValueException"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsADescriptionCarryingAControlCharacter() {
|
||||
dms("CreateReplicationSubnetGroup")
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"tf-control-char\","
|
||||
+ "\"ReplicationSubnetGroupDescription\":\"terraform\\u0001managed\","
|
||||
+ "\"SubnetIds\":[\"" + SUBNET_A + "\",\"" + SUBNET_B + "\"]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterValueException"));
|
||||
|
||||
dms("DescribeReplicationSubnetGroups")
|
||||
.body("{\"Filters\":[{\"Name\":\"replication-subnet-group-id\","
|
||||
+ "\"Values\":[\"tf-control-char\"]}]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundFault"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsADuplicateIdentifier() {
|
||||
dms("CreateReplicationSubnetGroup")
|
||||
.body(createBody("tf-duplicate"))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
dms("CreateReplicationSubnetGroup")
|
||||
.body(createBody("tf-duplicate"))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceAlreadyExistsFault"));
|
||||
|
||||
dms("DeleteReplicationSubnetGroup")
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"tf-duplicate\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsSubnetsInASingleAvailabilityZone() {
|
||||
dms("CreateReplicationSubnetGroup")
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"tf-one-az\","
|
||||
+ "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
|
||||
+ "\"SubnetIds\":[\"" + SUBNET_A + "\"]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ReplicationSubnetGroupDoesNotCoverEnoughAZs"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsAnUnknownSubnet() {
|
||||
dms("CreateReplicationSubnetGroup")
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"tf-bad-subnet\","
|
||||
+ "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
|
||||
+ "\"SubnetIds\":[\"" + SUBNET_A + "\",\"subnet-does-not-exist\"]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidSubnet"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsAMissingDescription() {
|
||||
dms("CreateReplicationSubnetGroup")
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"tf-no-description\","
|
||||
+ "\"SubnetIds\":[\"" + SUBNET_A + "\",\"" + SUBNET_B + "\"]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterValueException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteOfAMissingSubnetGroupFaults() {
|
||||
dms("DeleteReplicationSubnetGroup")
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"tf-absent\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundFault"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTagValueOfTheWrongTypeIsASerializationErrorOnTheWire() {
|
||||
dms("CreateReplicationSubnetGroup")
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"tf-object-tag\","
|
||||
+ "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
|
||||
+ "\"SubnetIds\":[\"" + SUBNET_A + "\",\"" + SUBNET_B + "\"],"
|
||||
+ "\"Tags\":[{\"Key\":\"env\",\"Value\":{\"nested\":1}}]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"));
|
||||
|
||||
dms("DescribeReplicationSubnetGroups")
|
||||
.body("{\"Filters\":[{\"Name\":\"replication-subnet-group-id\","
|
||||
+ "\"Values\":[\"tf-object-tag\"]}]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundFault"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unsupportedDmsActionReportsUnknownOperation() {
|
||||
dms("CreateReplicationInstance")
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("UnknownOperationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagsSurviveCreateAndAreReadableThroughListTagsForResource() {
|
||||
dms("CreateReplicationSubnetGroup")
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"tf-tagged\","
|
||||
+ "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
|
||||
+ "\"SubnetIds\":[\"" + SUBNET_A + "\",\"" + SUBNET_B + "\"],"
|
||||
+ "\"Tags\":[{\"Key\":\"env\",\"Value\":\"test\"}]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
dms("ListTagsForResource")
|
||||
.body("{\"ResourceArn\":\"" + arn("tf-tagged") + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TagList", hasSize(1))
|
||||
.body("TagList[0].Key", equalTo("env"))
|
||||
.body("TagList[0].Value", equalTo("test"))
|
||||
.body("TagList[0].ResourceArn", nullValue());
|
||||
|
||||
dms("AddTagsToResource")
|
||||
.body("{\"ResourceArn\":\"" + arn("tf-tagged") + "\","
|
||||
+ "\"Tags\":[{\"Key\":\"owner\",\"Value\":\"data\"}]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
dms("ListTagsForResource")
|
||||
.body("{\"ResourceArn\":\"" + arn("tf-tagged") + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TagList.Key", containsInAnyOrder("env", "owner"));
|
||||
|
||||
dms("RemoveTagsFromResource")
|
||||
.body("{\"ResourceArn\":\"" + arn("tf-tagged") + "\",\"TagKeys\":[\"env\"]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
dms("ListTagsForResource")
|
||||
.body("{\"ResourceArnList\":[\"" + arn("tf-tagged") + "\"]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TagList", hasSize(1))
|
||||
.body("TagList[0].Key", equalTo("owner"))
|
||||
.body("TagList[0].ResourceArn", equalTo(arn("tf-tagged")));
|
||||
|
||||
dms("DeleteReplicationSubnetGroup")
|
||||
.body("{\"ReplicationSubnetGroupIdentifier\":\"tf-tagged\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTagsForAnUnknownArnFaults() {
|
||||
dms("ListTagsForResource")
|
||||
.body("{\"ResourceArn\":\"" + arn("tf-never-created") + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundFault"));
|
||||
}
|
||||
|
||||
private static String arn(String identifier) {
|
||||
return "arn:aws:dms:us-east-1:" + ACCOUNT_ID + ":subgrp:" + identifier;
|
||||
}
|
||||
|
||||
private static String createBody(String identifier) {
|
||||
return "{\"ReplicationSubnetGroupIdentifier\":\"" + identifier + "\","
|
||||
+ "\"ReplicationSubnetGroupDescription\":\"terraform managed\","
|
||||
+ "\"SubnetIds\":[\"" + SUBNET_A + "\",\"" + SUBNET_B + "\"]}";
|
||||
}
|
||||
|
||||
private static RequestSpecification dms(String action) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + action)
|
||||
.header("Authorization", AUTH_HEADER);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,573 @@
|
||||
package io.github.hectorvent.floci.services.dms;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.dms.model.ReplicationSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.dms.model.ResourceTag;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Subnet;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.ArgumentMatchers.anyMap;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class DmsServiceTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT_ID = "123456789012";
|
||||
private static final String VPC_ID = "vpc-0dms";
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private DmsService service;
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void setUp() {
|
||||
StorageFactory storageFactory = mock(StorageFactory.class);
|
||||
AccountAwareStorageBackend<ReplicationSubnetGroup> store =
|
||||
AccountAwareStorageBackend.inMemory(ACCOUNT_ID);
|
||||
when(storageFactory.create(eq("dms"), eq("dms-replication-subnet-groups.json"), any(TypeReference.class)))
|
||||
.thenReturn((AccountAwareStorageBackend) store);
|
||||
|
||||
Ec2Service ec2Service = mock(Ec2Service.class);
|
||||
when(ec2Service.describeSubnets(eq(REGION), anyList(), anyMap())).thenAnswer(invocation -> {
|
||||
List<String> requested = invocation.getArgument(1);
|
||||
return requested.stream().map(DmsServiceTest::subnet).filter(Objects::nonNull).toList();
|
||||
});
|
||||
RegionResolver regionResolver = mock(RegionResolver.class);
|
||||
when(regionResolver.getAccountId()).thenReturn(ACCOUNT_ID);
|
||||
service = new DmsService(storageFactory, ec2Service, regionResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStoresGroupUnderLowercasedIdentifier() {
|
||||
service.createReplicationSubnetGroup(
|
||||
createRequest("Tf-Example", "example", "subnet-a", "subnet-b"), REGION);
|
||||
|
||||
List<ReplicationSubnetGroup> described =
|
||||
service.describeReplicationSubnetGroups(filterRequest("tf-example"), REGION).items();
|
||||
|
||||
assertEquals(1, described.size());
|
||||
ReplicationSubnetGroup group = described.getFirst();
|
||||
assertEquals("tf-example", group.getReplicationSubnetGroupIdentifier());
|
||||
assertEquals("example", group.getReplicationSubnetGroupDescription());
|
||||
assertEquals(VPC_ID, group.getVpcId());
|
||||
assertEquals("Complete", group.getSubnetGroupStatus());
|
||||
assertEquals(List.of("subnet-a", "subnet-b"), group.getSubnetIds());
|
||||
assertEquals(Map.of("subnet-a", "us-east-1a", "subnet-b", "us-east-1b"),
|
||||
group.getSubnetAvailabilityZones());
|
||||
assertEquals(List.of("IPV4"), group.getSupportedNetworkTypes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsDuplicateIdentifierRegardlessOfCase() {
|
||||
service.createReplicationSubnetGroup(createRequest("dup", "first", "subnet-a", "subnet-b"), REGION);
|
||||
|
||||
AwsException duplicate = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
|
||||
createRequest("DUP", "second", "subnet-a", "subnet-b"), REGION));
|
||||
assertEquals("ResourceAlreadyExistsFault", duplicate.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsUnknownSubnets() {
|
||||
AwsException invalid = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
|
||||
createRequest("bad-subnets", "example", "subnet-a", "subnet-missing"), REGION));
|
||||
assertEquals("InvalidSubnet", invalid.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsSubnetsInASingleAvailabilityZone() {
|
||||
AwsException tooFewZones = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
|
||||
createRequest("one-az", "example", "subnet-a"), REGION));
|
||||
assertEquals("ReplicationSubnetGroupDoesNotCoverEnoughAZs", tooFewZones.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsTwoSubnetsSharingOneAvailabilityZone() {
|
||||
AwsException tooFewZones = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
|
||||
createRequest("same-az", "example", "subnet-a", "subnet-a2"), REGION));
|
||||
assertEquals("ReplicationSubnetGroupDoesNotCoverEnoughAZs", tooFewZones.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsASubnetWithNoAvailabilityZone() {
|
||||
AwsException noZone = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
|
||||
createRequest("no-az", "example", "subnet-a", "subnet-no-az"), REGION));
|
||||
assertEquals("InvalidSubnet", noZone.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsSubnetsSpanningVpcs() {
|
||||
AwsException crossVpc = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
|
||||
createRequest("cross-vpc", "example", "subnet-a", "subnet-other-vpc"), REGION));
|
||||
assertEquals("InvalidSubnet", crossVpc.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsMissingDescription() {
|
||||
ObjectNode request = createRequest("no-description", null, "subnet-a", "subnet-b");
|
||||
AwsException missing = assertThrows(AwsException.class,
|
||||
() -> service.createReplicationSubnetGroup(request, REGION));
|
||||
assertEquals("InvalidParameterValueException", missing.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsReservedDefaultIdentifier() {
|
||||
AwsException reserved = assertThrows(AwsException.class, () -> service.createReplicationSubnetGroup(
|
||||
createRequest("Default", "example", "subnet-a", "subnet-b"), REGION));
|
||||
assertEquals("InvalidParameterValueException", reserved.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeIsScopedToTheRequestRegion() {
|
||||
service.createReplicationSubnetGroup(createRequest("scoped", "example", "subnet-a", "subnet-b"), REGION);
|
||||
|
||||
assertTrue(service.describeReplicationSubnetGroups(mapper.createObjectNode(), "eu-west-1")
|
||||
.items().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeOfMissingGroupFaults() {
|
||||
AwsException notFound = assertThrows(AwsException.class,
|
||||
() -> service.describeReplicationSubnetGroups(filterRequest("absent"), REGION));
|
||||
assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeWalksEveryGroupAcrossPagesWithoutDuplicatesOrOmissions() {
|
||||
List<String> created = createGroups(25);
|
||||
|
||||
PaginatedResult<ReplicationSubnetGroup> first =
|
||||
service.describeReplicationSubnetGroups(pageRequest(20, null), REGION);
|
||||
assertEquals(20, first.items().size());
|
||||
assertNotNull(first.nextToken());
|
||||
|
||||
PaginatedResult<ReplicationSubnetGroup> second =
|
||||
service.describeReplicationSubnetGroups(pageRequest(20, first.nextToken()), REGION);
|
||||
assertEquals(5, second.items().size());
|
||||
assertNull(second.nextToken(), "the final page must not carry a Marker");
|
||||
|
||||
List<String> walked = new ArrayList<>();
|
||||
first.items().forEach(group -> walked.add(group.getReplicationSubnetGroupIdentifier()));
|
||||
second.items().forEach(group -> walked.add(group.getReplicationSubnetGroupIdentifier()));
|
||||
assertEquals(created, walked);
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeResumesAfterTheMarkerEvenWhenAnEarlierGroupIsDeleted() {
|
||||
createGroups(25);
|
||||
|
||||
PaginatedResult<ReplicationSubnetGroup> first =
|
||||
service.describeReplicationSubnetGroups(pageRequest(20, null), REGION);
|
||||
service.deleteReplicationSubnetGroup(identifierRequest("page-00"), REGION);
|
||||
|
||||
PaginatedResult<ReplicationSubnetGroup> second =
|
||||
service.describeReplicationSubnetGroups(pageRequest(20, first.nextToken()), REGION);
|
||||
|
||||
assertEquals(List.of("page-20", "page-21", "page-22", "page-23", "page-24"),
|
||||
second.items().stream().map(ReplicationSubnetGroup::getReplicationSubnetGroupIdentifier).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeDefaultsToOneHundredRecordsPerPage() {
|
||||
createGroups(25);
|
||||
|
||||
PaginatedResult<ReplicationSubnetGroup> page =
|
||||
service.describeReplicationSubnetGroups(mapper.createObjectNode(), REGION);
|
||||
|
||||
assertEquals(25, page.items().size());
|
||||
assertNull(page.nextToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeRejectsMaxRecordsBelowTwenty() {
|
||||
AwsException tooSmall = assertThrows(AwsException.class,
|
||||
() -> service.describeReplicationSubnetGroups(pageRequest(19, null), REGION));
|
||||
assertEquals("InvalidParameterValueException", tooSmall.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeRejectsMaxRecordsAboveOneHundred() {
|
||||
AwsException tooLarge = assertThrows(AwsException.class,
|
||||
() -> service.describeReplicationSubnetGroups(pageRequest(101, null), REGION));
|
||||
assertEquals("InvalidParameterValueException", tooLarge.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeRejectsMaxRecordsThatIsNotAnInteger() {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("MaxRecords", "20");
|
||||
|
||||
AwsException wrongType = assertThrows(AwsException.class,
|
||||
() -> service.describeReplicationSubnetGroups(request, REGION));
|
||||
assertEquals("SerializationException", wrongType.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsADescriptionCarryingAControlCharacter() {
|
||||
ObjectNode request = createRequest("control-char", "terraform\u0001managed", "subnet-a", "subnet-b");
|
||||
|
||||
AwsException nonPrintable = assertThrows(AwsException.class,
|
||||
() -> service.createReplicationSubnetGroup(request, REGION));
|
||||
assertEquals("InvalidParameterValueException", nonPrintable.getErrorCode());
|
||||
AwsException notStored = assertThrows(AwsException.class,
|
||||
() -> service.describeReplicationSubnetGroups(filterRequest("control-char"), REGION));
|
||||
assertEquals("ResourceNotFoundFault", notStored.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRemovesTheGroup() {
|
||||
service.createReplicationSubnetGroup(createRequest("doomed", "example", "subnet-a", "subnet-b"), REGION);
|
||||
service.deleteReplicationSubnetGroup(identifierRequest("doomed"), REGION);
|
||||
|
||||
AwsException notFound = assertThrows(AwsException.class,
|
||||
() -> service.describeReplicationSubnetGroups(filterRequest("doomed"), REGION));
|
||||
assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteOfMissingGroupFaults() {
|
||||
AwsException notFound = assertThrows(AwsException.class,
|
||||
() -> service.deleteReplicationSubnetGroup(identifierRequest("absent"), REGION));
|
||||
assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearRemovesPersistedState() {
|
||||
service.createReplicationSubnetGroup(createRequest("reset-me", "example", "subnet-a", "subnet-b"), REGION);
|
||||
service.clear();
|
||||
|
||||
assertTrue(service.describeReplicationSubnetGroups(mapper.createObjectNode(), REGION).items().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStoresTagsReadableThroughListTagsForResource() {
|
||||
ObjectNode request = createRequest("tagged", "example", "subnet-a", "subnet-b");
|
||||
tagList(request.putArray("Tags"), "env", "test", "team", "platform");
|
||||
service.createReplicationSubnetGroup(request, REGION);
|
||||
|
||||
assertEquals(Map.of("env", "test", "team", "platform"), tagsOf("tagged"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void addTagsMergesWithExistingTagsAndOverwritesByKey() {
|
||||
ObjectNode request = createRequest("merge-me", "example", "subnet-a", "subnet-b");
|
||||
tagList(request.putArray("Tags"), "env", "test");
|
||||
service.createReplicationSubnetGroup(request, REGION);
|
||||
|
||||
ObjectNode addRequest = mapper.createObjectNode();
|
||||
addRequest.put("ResourceArn", arn("merge-me"));
|
||||
tagList(addRequest.putArray("Tags"), "env", "prod", "owner", "data");
|
||||
service.addTagsToResource(addRequest, REGION);
|
||||
|
||||
assertEquals(Map.of("env", "prod", "owner", "data"), tagsOf("merge-me"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeTagsDropsOnlyTheNamedKeys() {
|
||||
ObjectNode request = createRequest("trim-me", "example", "subnet-a", "subnet-b");
|
||||
tagList(request.putArray("Tags"), "env", "test", "owner", "data");
|
||||
service.createReplicationSubnetGroup(request, REGION);
|
||||
|
||||
ObjectNode removeRequest = mapper.createObjectNode();
|
||||
removeRequest.put("ResourceArn", arn("trim-me"));
|
||||
removeRequest.putArray("TagKeys").add("env").add("absent-key");
|
||||
service.removeTagsFromResource(removeRequest, REGION);
|
||||
|
||||
assertEquals(Map.of("owner", "data"), tagsOf("trim-me"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTagsByArnListCarriesTheOwningArnOnEachTag() {
|
||||
ObjectNode request = createRequest("arn-list", "example", "subnet-a", "subnet-b");
|
||||
tagList(request.putArray("Tags"), "env", "test");
|
||||
service.createReplicationSubnetGroup(request, REGION);
|
||||
|
||||
ObjectNode listRequest = mapper.createObjectNode();
|
||||
listRequest.putArray("ResourceArnList").add(arn("arn-list"));
|
||||
List<ResourceTag> tags = service.listTagsForResource(listRequest, REGION);
|
||||
|
||||
assertEquals(List.of(new ResourceTag(arn("arn-list"), "env", "test")), tags);
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTagsBySingleArnOmitsTheArnOnEachTag() {
|
||||
ObjectNode request = createRequest("single-arn", "example", "subnet-a", "subnet-b");
|
||||
tagList(request.putArray("Tags"), "env", "test");
|
||||
service.createReplicationSubnetGroup(request, REGION);
|
||||
|
||||
assertEquals(List.of(new ResourceTag(null, "env", "test")),
|
||||
service.listTagsForResource(arnRequest("single-arn"), REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagOperationsOnAnUnknownArnFault() {
|
||||
String missing = "arn:aws:dms:" + REGION + ":" + ACCOUNT_ID + ":subgrp:not-there";
|
||||
ObjectNode listRequest = mapper.createObjectNode();
|
||||
listRequest.put("ResourceArn", missing);
|
||||
|
||||
AwsException notFound = assertThrows(AwsException.class,
|
||||
() -> service.listTagsForResource(listRequest, REGION));
|
||||
assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagOperationsOnAnotherAccountsArnFault() {
|
||||
ObjectNode request = createRequest("other-account", "example", "subnet-a", "subnet-b");
|
||||
tagList(request.putArray("Tags"), "env", "test");
|
||||
service.createReplicationSubnetGroup(request, REGION);
|
||||
|
||||
ObjectNode listRequest = mapper.createObjectNode();
|
||||
listRequest.put("ResourceArn", "arn:aws:dms:" + REGION + ":999999999999:subgrp:other-account");
|
||||
|
||||
AwsException notFound = assertThrows(AwsException.class,
|
||||
() -> service.listTagsForResource(listRequest, REGION));
|
||||
assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagOperationsOnAnotherRegionsArnFault() {
|
||||
ObjectNode request = createRequest("other-region", "example", "subnet-a", "subnet-b");
|
||||
tagList(request.putArray("Tags"), "env", "test");
|
||||
service.createReplicationSubnetGroup(request, REGION);
|
||||
|
||||
ObjectNode listRequest = mapper.createObjectNode();
|
||||
listRequest.put("ResourceArn", "arn:aws:dms:eu-west-1:" + ACCOUNT_ID + ":subgrp:other-region");
|
||||
|
||||
AwsException notFound = assertThrows(AwsException.class,
|
||||
() -> service.listTagsForResource(listRequest, REGION));
|
||||
assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagOperationsOnANonSubnetGroupArnFault() {
|
||||
ObjectNode listRequest = mapper.createObjectNode();
|
||||
listRequest.put("ResourceArn", "arn:aws:dms:" + REGION + ":" + ACCOUNT_ID + ":rep:Example");
|
||||
|
||||
AwsException notFound = assertThrows(AwsException.class,
|
||||
() -> service.listTagsForResource(listRequest, REGION));
|
||||
assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void reservedTagKeyPrefixesAreRejected() {
|
||||
ObjectNode request = createRequest("reserved-tag", "example", "subnet-a", "subnet-b");
|
||||
tagList(request.putArray("Tags"), "aws:created-by", "someone");
|
||||
|
||||
AwsException reserved = assertThrows(AwsException.class,
|
||||
() -> service.createReplicationSubnetGroup(request, REGION));
|
||||
assertEquals("InvalidParameterValueException", reserved.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingAGroupDropsItsTags() {
|
||||
ObjectNode request = createRequest("tags-die", "example", "subnet-a", "subnet-b");
|
||||
tagList(request.putArray("Tags"), "env", "test");
|
||||
service.createReplicationSubnetGroup(request, REGION);
|
||||
service.deleteReplicationSubnetGroup(identifierRequest("tags-die"), REGION);
|
||||
|
||||
AwsException notFound = assertThrows(AwsException.class,
|
||||
() -> service.listTagsForResource(arnRequest("tags-die"), REGION));
|
||||
assertEquals("ResourceNotFoundFault", notFound.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsATagValueThatIsNotAString() {
|
||||
ObjectNode request = createRequest("object-tag-value", "example", "subnet-a", "subnet-b");
|
||||
request.putArray("Tags").addObject().put("Key", "env").putObject("Value").put("nested", 1);
|
||||
|
||||
AwsException wrongType = assertThrows(AwsException.class,
|
||||
() -> service.createReplicationSubnetGroup(request, REGION));
|
||||
assertEquals("SerializationException", wrongType.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsATagsMemberThatIsNotAList() {
|
||||
ObjectNode request = createRequest("scalar-tags", "example", "subnet-a", "subnet-b");
|
||||
request.put("Tags", "env=test");
|
||||
|
||||
AwsException wrongType = assertThrows(AwsException.class,
|
||||
() -> service.createReplicationSubnetGroup(request, REGION));
|
||||
assertEquals("SerializationException", wrongType.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsASubnetIdThatIsNotAString() {
|
||||
ObjectNode request = identifierRequest("numeric-subnet");
|
||||
request.put("ReplicationSubnetGroupDescription", "example");
|
||||
request.putArray("SubnetIds").add("subnet-a").add(42);
|
||||
|
||||
AwsException wrongType = assertThrows(AwsException.class,
|
||||
() -> service.createReplicationSubnetGroup(request, REGION));
|
||||
assertEquals("SerializationException", wrongType.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeRejectsFilterValuesThatAreNotAList() {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
ObjectNode filter = request.putArray("Filters").addObject();
|
||||
filter.put("Name", "replication-subnet-group-id");
|
||||
filter.put("Values", "tf-example");
|
||||
|
||||
AwsException wrongType = assertThrows(AwsException.class,
|
||||
() -> service.describeReplicationSubnetGroups(request, REGION));
|
||||
assertEquals("SerializationException", wrongType.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeRejectsAFilterValueThatIsNotAString() {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
ObjectNode filter = request.putArray("Filters").addObject();
|
||||
filter.put("Name", "replication-subnet-group-id");
|
||||
filter.putArray("Values").addObject().put("Value", "tf-example");
|
||||
|
||||
AwsException wrongType = assertThrows(AwsException.class,
|
||||
() -> service.describeReplicationSubnetGroups(request, REGION));
|
||||
assertEquals("SerializationException", wrongType.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTagsRejectsAnArnListElementThatIsNotAString() {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.putArray("ResourceArnList").addObject().put("ResourceArn", arn("whatever"));
|
||||
|
||||
AwsException wrongType = assertThrows(AwsException.class,
|
||||
() -> service.listTagsForResource(request, REGION));
|
||||
assertEquals("SerializationException", wrongType.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeTagsRejectsATagKeyThatIsNotAString() {
|
||||
ObjectNode request = createRequest("bad-tag-keys", "example", "subnet-a", "subnet-b");
|
||||
service.createReplicationSubnetGroup(request, REGION);
|
||||
|
||||
ObjectNode removeRequest = mapper.createObjectNode();
|
||||
removeRequest.put("ResourceArn", arn("bad-tag-keys"));
|
||||
removeRequest.putArray("TagKeys").add(7);
|
||||
|
||||
AwsException wrongType = assertThrows(AwsException.class,
|
||||
() -> service.removeTagsFromResource(removeRequest, REGION));
|
||||
assertEquals("SerializationException", wrongType.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsAnIdentifierThatIsNotAString() {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("ReplicationSubnetGroupIdentifier", 12345);
|
||||
request.put("ReplicationSubnetGroupDescription", "example");
|
||||
request.putArray("SubnetIds").add("subnet-a").add("subnet-b");
|
||||
|
||||
AwsException wrongType = assertThrows(AwsException.class,
|
||||
() -> service.createReplicationSubnetGroup(request, REGION));
|
||||
assertEquals("SerializationException", wrongType.getErrorCode());
|
||||
}
|
||||
|
||||
private Map<String, String> tagsOf(String identifier) {
|
||||
return service.listTagsForResource(arnRequest(identifier), REGION).stream()
|
||||
.collect(Collectors.toMap(ResourceTag::key, ResourceTag::value));
|
||||
}
|
||||
|
||||
private ObjectNode arnRequest(String identifier) {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("ResourceArn", arn(identifier));
|
||||
return request;
|
||||
}
|
||||
|
||||
private String arn(String identifier) {
|
||||
return "arn:aws:dms:" + REGION + ":" + ACCOUNT_ID + ":subgrp:" + identifier;
|
||||
}
|
||||
|
||||
private static void tagList(ArrayNode tags, String... keysAndValues) {
|
||||
for (int i = 0; i < keysAndValues.length; i += 2) {
|
||||
tags.addObject().put("Key", keysAndValues[i]).put("Value", keysAndValues[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
private ObjectNode createRequest(String identifier, String description, String... subnetIds) {
|
||||
ObjectNode request = identifierRequest(identifier);
|
||||
if (description != null) {
|
||||
request.put("ReplicationSubnetGroupDescription", description);
|
||||
}
|
||||
ArrayNode subnets = request.putArray("SubnetIds");
|
||||
for (String subnetId : subnetIds) {
|
||||
subnets.add(subnetId);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
private ObjectNode identifierRequest(String identifier) {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("ReplicationSubnetGroupIdentifier", identifier);
|
||||
return request;
|
||||
}
|
||||
|
||||
private List<String> createGroups(int count) {
|
||||
List<String> identifiers = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
String identifier = String.format("page-%02d", i);
|
||||
service.createReplicationSubnetGroup(
|
||||
createRequest(identifier, "example", "subnet-a", "subnet-b"), REGION);
|
||||
identifiers.add(identifier);
|
||||
}
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
private ObjectNode pageRequest(int maxRecords, String marker) {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("MaxRecords", maxRecords);
|
||||
if (marker != null) {
|
||||
request.put("Marker", marker);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
private ObjectNode filterRequest(String identifier) {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
ObjectNode filter = request.putArray("Filters").addObject();
|
||||
filter.put("Name", "replication-subnet-group-id");
|
||||
filter.putArray("Values").add(identifier);
|
||||
return request;
|
||||
}
|
||||
|
||||
private static Subnet subnet(String subnetId) {
|
||||
return switch (subnetId) {
|
||||
case "subnet-a" -> subnet(subnetId, VPC_ID, "us-east-1a");
|
||||
case "subnet-b" -> subnet(subnetId, VPC_ID, "us-east-1b");
|
||||
case "subnet-a2" -> subnet(subnetId, VPC_ID, "us-east-1a");
|
||||
case "subnet-no-az" -> subnet(subnetId, VPC_ID, null);
|
||||
case "subnet-other-vpc" -> subnet(subnetId, "vpc-0other", "us-east-1b");
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
private static Subnet subnet(String subnetId, String vpcId, String availabilityZone) {
|
||||
Subnet subnet = new Subnet();
|
||||
subnet.setSubnetId(subnetId);
|
||||
subnet.setVpcId(vpcId);
|
||||
subnet.setAvailabilityZone(availabilityZone);
|
||||
subnet.setRegion(REGION);
|
||||
return subnet;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user