Light, fluffy, and always free - The AWS Local Emulator alternative
feat(rds): model Aurora Serverless v2 scaling configuration on DB clusters (#1829)
Alex Bannad778a6e393ab
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.javaindex 1e6ee8804d..c945e711d3 100644--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java@@ -39,6 +39,7 @@ class RdsControlPlaneTest {private static RdsClient rds;private static String subnetGroupName;private static String proxyName;+ private static String serverlessClusterName;private static List<String> subnetIds;@BeforeAll@@ -46,6 +47,7 @@ class RdsControlPlaneTest {rds = TestFixtures.rdsClient();subnetGroupName = TestFixtures.uniqueName("rds-subnets");proxyName = TestFixtures.uniqueName("rds-proxy");+ serverlessClusterName = TestFixtures.uniqueName("rds-serverless");try (Ec2Client ec2 = TestFixtures.ec2Client()) {DescribeSubnetsResponse response = ec2.describeSubnets();subnetIds = response.subnets().stream()@@ -60,6 +62,14 @@ class RdsControlPlaneTest {@AfterAllstatic void cleanup() {if (rds != null) {+ try {+ rds.deleteDBCluster(b -> b+ .dbClusterIdentifier(serverlessClusterName)+ .skipFinalSnapshot(true));+ } catch (Exception e) {+ LOG.log(Level.FINE, "RDS Serverless v2 cluster already absent during cleanup "+ + serverlessClusterName, e);+ }try {rds.deleteDBProxy(b -> b.dbProxyName(proxyName));} catch (Exception e) {@@ -74,6 +84,44 @@ class RdsControlPlaneTest {}}+ @Test+ void sdkRoundTripsAuroraServerlessV2ScalingConfiguration() {+ var created = rds.createDBCluster(b -> b+ .dbClusterIdentifier(serverlessClusterName)+ .engine("aurora-postgresql")+ .masterUsername("admin")+ .masterUserPassword("password")+ .serverlessV2ScalingConfiguration(c -> c+ .minCapacity(0.0)+ .maxCapacity(16.0)));++ assertThat(created.dbCluster().engine()).isEqualTo("aurora-postgresql");+ assertThat(created.dbCluster().serverlessV2ScalingConfiguration().minCapacity())+ .isEqualTo(0.0);+ assertThat(created.dbCluster().serverlessV2ScalingConfiguration().maxCapacity())+ .isEqualTo(16.0);+ assertThat(created.dbCluster().serverlessV2ScalingConfiguration().secondsUntilAutoPause())+ .isEqualTo(300);++ var modified = rds.modifyDBCluster(b -> b+ .dbClusterIdentifier(serverlessClusterName)+ .serverlessV2ScalingConfiguration(c -> c+ .secondsUntilAutoPause(600)));+ assertThat(modified.dbCluster().serverlessV2ScalingConfiguration().minCapacity())+ .isEqualTo(0.0);+ assertThat(modified.dbCluster().serverlessV2ScalingConfiguration().maxCapacity())+ .isEqualTo(16.0);+ assertThat(modified.dbCluster().serverlessV2ScalingConfiguration().secondsUntilAutoPause())+ .isEqualTo(600);++ var described = rds.describeDBClusters(b -> b+ .dbClusterIdentifier(serverlessClusterName)).dbClusters().get(0);+ assertThat(described.serverlessV2ScalingConfiguration().minCapacity()).isEqualTo(0.0);+ assertThat(described.serverlessV2ScalingConfiguration().maxCapacity()).isEqualTo(16.0);+ assertThat(described.serverlessV2ScalingConfiguration().secondsUntilAutoPause())+ .isEqualTo(600);+ }+@Testvoid sdkUnmarshalsDbSubnetGroupSubnets() {CreateDbSubnetGroupResponse createResponse = rds.createDBSubnetGroup(b -> bdiff --git a/docs/services/rds.md b/docs/services/rds.mdindex 700042e775..1fa2f831a9 100644--- a/docs/services/rds.md+++ b/docs/services/rds.md@@ -136,6 +136,29 @@ services:DB proxies currently support `IPV4` for both endpoint and target connections; `IPV6` and `DUAL`endpoint networking require additional listener and Docker-network support.+## Aurora Serverless v2 scaling++`CreateDBCluster`, `ModifyDBCluster`, and `DescribeDBClusters` support the AWS+`ServerlessV2ScalingConfiguration` Query shape for `aurora-mysql` and `aurora-postgresql`+clusters. Requests that apply this configuration to another engine fail with+`InvalidParameterCombination`.++The minimum and maximum capacities use half-ACU increments; the maximum must be at least 1 ACU and+no greater than 256 ACUs. AWS's actual maximum depends on the Aurora engine and platform version,+while Floci currently applies the 256-ACU ceiling uniformly.++When `MinCapacity` is zero, `SecondsUntilAutoPause` accepts 300–86,400 seconds and defaults to 300.+Changing the minimum to a nonzero value removes the auto-pause interval, matching the AWS response+shape. AWS limits zero-capacity auto-pause to compatible Aurora versions; Floci does not currently+enforce that version matrix. `ModifyDBCluster` accepts partial scaling updates and preserves omitted+values. `AWS::RDS::DBCluster` creation also maps the equivalent CloudFormation property.++If a persisted cluster record does not contain its original AWS engine identifier, Floci rejects a+new scaling configuration instead of assuming that the cluster is Aurora.++This is control-plane compatibility: Floci persists and returns the scaling configuration, but it+does not resize or automatically pause the backing Docker container.+## Examples```bashdiff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.javaindex c76974e31c..1e673c25b1 100644--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java@@ -1682,18 +1682,33 @@ public class CloudFormationResourceProvisioner {cluster = rdsService.modifyDbCluster(id,resolveDynamicReferences(resolveOptional(props, "MasterUserPassword", engine), region, true),- parseBoolProp(props, "EnableIAMDatabaseAuthentication", engine));- } else {- cluster = rdsService.createDbCluster(- id,- resolveOptional(props, "Engine", engine),- resolveOptional(props, "EngineVersion", engine),- resolveDynamicReferences(resolveOptional(props, "MasterUsername", engine), region, false),- resolveDynamicReferences(resolveOptional(props, "MasterUserPassword", engine), region, true),- resolveOptional(props, "DatabaseName", engine),parseBoolProp(props, "EnableIAMDatabaseAuthentication", engine),- resolveOptional(props, "DBClusterParameterGroupName", engine),- null, null, false, region);+ parseServerlessV2Capacity(props, "MinCapacity", engine),+ parseServerlessV2Capacity(props, "MaxCapacity", engine),+ parseServerlessV2SecondsUntilAutoPause(props, engine), region);+ } else {+ Double serverlessV2MinCapacity = parseServerlessV2Capacity(props, "MinCapacity", engine);+ Double serverlessV2MaxCapacity = parseServerlessV2Capacity(props, "MaxCapacity", engine);+ Integer serverlessV2SecondsUntilAutoPause =+ parseServerlessV2SecondsUntilAutoPause(props, engine);+ String engineName = resolveOptional(props, "Engine", engine);+ String engineVersion = resolveOptional(props, "EngineVersion", engine);+ String masterUsername = resolveDynamicReferences(+ resolveOptional(props, "MasterUsername", engine), region, false);+ String masterPassword = resolveDynamicReferences(+ resolveOptional(props, "MasterUserPassword", engine), region, true);+ String databaseName = resolveOptional(props, "DatabaseName", engine);+ boolean iamEnabled = parseBoolProp(props, "EnableIAMDatabaseAuthentication", engine);+ String parameterGroup = resolveOptional(props, "DBClusterParameterGroupName", engine);+ if (serverlessV2MinCapacity == null && serverlessV2MaxCapacity == null+ && serverlessV2SecondsUntilAutoPause == null) {+ cluster = rdsService.createDbCluster(id, engineName, engineVersion, masterUsername,+ masterPassword, databaseName, iamEnabled, parameterGroup, null, null, false, region);+ } else {+ cluster = rdsService.createDbCluster(id, engineName, engineVersion, masterUsername,+ masterPassword, databaseName, iamEnabled, parameterGroup, null, null, false, region,+ serverlessV2MinCapacity, serverlessV2MaxCapacity, serverlessV2SecondsUntilAutoPause);+ }deleteRenamedResource(priorPhysicalId, id, rdsService::deleteDbCluster, "DB cluster");}r.setPhysicalId(cluster.getDbClusterIdentifier());@@ -1710,6 +1725,42 @@ public class CloudFormationResourceProvisioner {}}+ private Double parseServerlessV2Capacity(JsonNode props, String field,+ CloudFormationTemplateEngine engine) {+ JsonNode config = props.get("ServerlessV2ScalingConfiguration");+ if (config == null || config.isNull()) {+ return null;+ }+ String resolved = resolveOptional(config, field, engine);+ if (resolved == null || resolved.isBlank()) {+ return null;+ }+ try {+ return Double.valueOf(resolved.trim());+ } catch (NumberFormatException e) {+ throw new AwsException("ValidationError",+ "ServerlessV2ScalingConfiguration " + field + " must be a number.", 400);+ }+ }++ private Integer parseServerlessV2SecondsUntilAutoPause(+ JsonNode props, CloudFormationTemplateEngine engine) {+ JsonNode config = props.get("ServerlessV2ScalingConfiguration");+ if (config == null || config.isNull()) {+ return null;+ }+ String resolved = resolveOptional(config, "SecondsUntilAutoPause", engine);+ if (resolved == null || resolved.isBlank()) {+ return null;+ }+ try {+ return Integer.valueOf(resolved.trim());+ } catch (NumberFormatException e) {+ throw new AwsException("ValidationError",+ "ServerlessV2ScalingConfiguration SecondsUntilAutoPause must be an integer.", 400);+ }+ }+private void provisionDbProxy(StackResource r, JsonNode props, CloudFormationTemplateEngine engine,String region) {String name = resolveOptional(props, "DBProxyName", engine);diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.javaindex ee8dff3663..c6e5840d0b 100644--- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java@@ -397,9 +397,14 @@ public class RdsQueryHandler {}try {+ Double serverlessV2Min = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MinCapacity");+ Double serverlessV2Max = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MaxCapacity");+ Integer serverlessV2SecondsUntilAutoPause = parseIntegerParam(+ params, "ServerlessV2ScalingConfiguration.SecondsUntilAutoPause");DbCluster cluster = service.createDbCluster(id, engine, engineVersion, masterUsername,masterPassword, databaseName, iamEnabled, paramGroupName,- dbSubnetGroupName, availabilityZone, multiAz, region);+ dbSubnetGroupName, availabilityZone, multiAz, region,+ serverlessV2Min, serverlessV2Max, serverlessV2SecondsUntilAutoPause);String result = dbClusterXml(cluster);return Response.ok(AwsQueryResponse.envelope("CreateDBCluster", AwsNamespaces.RDS, result)).build();} catch (AwsException e) {@@ -407,6 +412,30 @@ public class RdsQueryHandler {}}+ private static Double parseDoubleParam(MultivaluedMap<String, String> params, String name) {+ String value = params.getFirst(name);+ if (value == null || value.isBlank()) {+ return null;+ }+ try {+ return Double.valueOf(value.trim());+ } catch (NumberFormatException e) {+ throw new AwsException("InvalidParameterValue", name + " must be a number.", 400);+ }+ }++ private static Integer parseIntegerParam(MultivaluedMap<String, String> params, String name) {+ String value = params.getFirst(name);+ if (value == null || value.isBlank()) {+ return null;+ }+ try {+ return Integer.valueOf(value.trim());+ } catch (NumberFormatException e) {+ throw new AwsException("InvalidParameterValue", name + " must be an integer.", 400);+ }+ }+private Response handleDescribeDbClusters(MultivaluedMap<String, String> params, String region) {String identifier = params.getFirst("DBClusterIdentifier");@@ -460,7 +489,12 @@ public class RdsQueryHandler {String iamStr = params.getFirst("EnableIAMDatabaseAuthentication");Boolean iamEnabled = iamStr != null ? Boolean.parseBoolean(iamStr) : null;try {- DbCluster cluster = service.modifyDbCluster(id, newPassword, iamEnabled, region);+ Double serverlessV2Min = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MinCapacity");+ Double serverlessV2Max = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MaxCapacity");+ Integer serverlessV2SecondsUntilAutoPause = parseIntegerParam(+ params, "ServerlessV2ScalingConfiguration.SecondsUntilAutoPause");+ DbCluster cluster = service.modifyDbCluster(id, newPassword, iamEnabled,+ serverlessV2Min, serverlessV2Max, serverlessV2SecondsUntilAutoPause, region);String result = dbClusterXml(cluster);return Response.ok(AwsQueryResponse.envelope("ModifyDBCluster", AwsNamespaces.RDS, result)).build();} catch (AwsException e) {@@ -1295,7 +1329,9 @@ public class RdsQueryHandler {private String dbClusterInnerXml(DbCluster c) {DbEndpoint ep = c.getEndpoint();DbEndpoint readerEp = c.getReaderEndpoint();- String engineStr = c.getEngine() != null ? c.getEngine().name() : "";+ String engineStr = c.getEngineIdentifier() != null+ ? c.getEngineIdentifier()+ : c.getEngine() != null ? c.getEngine().name() : "";String statusStr = c.getStatus() != null ? statusLabel(c.getStatus()) : "available";XmlBuilder xml = new XmlBuilder()@@ -1327,8 +1363,21 @@ public class RdsQueryHandler {.end("VpcSecurityGroups").elem("DBSubnetGroup", c.getDbSubnetGroupName() != null ? c.getDbSubnetGroupName() : "default").elem("DbClusterResourceId", c.getDbClusterResourceId())- .elem("DBClusterArn", c.getDbClusterArn())- .start("DBClusterMembers");+ .elem("DBClusterArn", c.getDbClusterArn());+ if (c.getServerlessV2MinCapacity() != null || c.getServerlessV2MaxCapacity() != null) {+ xml.start("ServerlessV2ScalingConfiguration");+ if (c.getServerlessV2MinCapacity() != null) {+ xml.elem("MinCapacity", String.valueOf(c.getServerlessV2MinCapacity()));+ }+ if (c.getServerlessV2MaxCapacity() != null) {+ xml.elem("MaxCapacity", String.valueOf(c.getServerlessV2MaxCapacity()));+ }+ if (c.getServerlessV2SecondsUntilAutoPause() != null) {+ xml.elem("SecondsUntilAutoPause", String.valueOf(c.getServerlessV2SecondsUntilAutoPause()));+ }+ xml.end("ServerlessV2ScalingConfiguration");+ }+ xml.start("DBClusterMembers");if (c.getDbClusterMembers() != null) {for (String memberId : c.getDbClusterMembers()) {xml.start("member")diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.javaindex 96d781db81..47e6a20f30 100644--- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java+++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java@@ -47,6 +47,7 @@ import java.util.Collection;import java.util.Comparator;import java.util.LinkedHashMap;import java.util.List;+import java.util.Locale;import java.util.Map;import java.util.Objects;import java.util.Optional;@@ -134,6 +135,8 @@ public class RdsService implements Resettable {private final Set<Integer> usedPorts = ConcurrentHashMap.newKeySet();private static final Pattern IMAGE_TAG_VERSION_PATTERN = Pattern.compile("^(\\d+(?:\\.\\d+)*)(.*)$");private static final Pattern SAFE_IMAGE_TAG_PATTERN = Pattern.compile("[A-Za-z0-9._-]+");+ private static final int SERVERLESS_V2_DEFAULT_AUTO_PAUSE_SECONDS = 300;+ private static final int SERVERLESS_V2_MAX_AUTO_PAUSE_SECONDS = 86_400;private static final Pattern DB_PROXY_NAME_PATTERN =Pattern.compile("[a-zA-Z](?:-?[a-zA-Z0-9]+)*");/**@@ -1114,6 +1117,29 @@ public class RdsService implements Resettable {String databaseName, boolean iamEnabled,String paramGroupName, String dbSubnetGroupName,String availabilityZone, boolean multiAz, String region) {+ return createDbCluster(id, engineParam, engineVersion, masterUsername, masterPassword,+ databaseName, iamEnabled, paramGroupName, dbSubnetGroupName, availabilityZone,+ multiAz, region, null, null);+ }++ public DbCluster createDbCluster(String id, String engineParam, String engineVersion,+ String masterUsername, String masterPassword,+ String databaseName, boolean iamEnabled,+ String paramGroupName, String dbSubnetGroupName,+ String availabilityZone, boolean multiAz, String region,+ Double serverlessV2MinCapacity, Double serverlessV2MaxCapacity) {+ return createDbCluster(id, engineParam, engineVersion, masterUsername, masterPassword,+ databaseName, iamEnabled, paramGroupName, dbSubnetGroupName, availabilityZone,+ multiAz, region, serverlessV2MinCapacity, serverlessV2MaxCapacity, null);+ }++ public DbCluster createDbCluster(String id, String engineParam, String engineVersion,+ String masterUsername, String masterPassword,+ String databaseName, boolean iamEnabled,+ String paramGroupName, String dbSubnetGroupName,+ String availabilityZone, boolean multiAz, String region,+ Double serverlessV2MinCapacity, Double serverlessV2MaxCapacity,+ Integer serverlessV2SecondsUntilAutoPause) {String effectiveRegion = effectiveRegion(region);String clusterResourceId = "cluster-" + java.util.UUID.randomUUID().toString().replace("-", "").substring(0, 24).toUpperCase();@@ -1123,8 +1149,12 @@ public class RdsService implements Resettable {throw new AwsException("DBClusterAlreadyExistsFault","DB cluster " + id + " already exists.", 400);}-DatabaseEngine engine = resolveEngine(engineParam);+ validateServerlessV2Engine(+ engineParam, serverlessV2MinCapacity, serverlessV2MaxCapacity,+ serverlessV2SecondsUntilAutoPause);+ Integer effectiveAutoPauseSeconds = validateServerlessV2ScalingConfiguration(+ serverlessV2MinCapacity, serverlessV2MaxCapacity, serverlessV2SecondsUntilAutoPause);validateClusterParameterGroup(paramGroupName, engineParam, engineVersion, effectiveRegion);PlacementResolution placement = resolvePlacement(dbSubnetGroupName, availabilityZone, multiAz, effectiveRegion);@@ -1137,6 +1167,7 @@ public class RdsService implements Resettable {DbCluster cluster = new DbCluster(id, engine, engineVersion, masterUsername, masterPassword,databaseName, DbInstanceStatus.AVAILABLE, endpoint, endpoint,iamEnabled, new ArrayList<>(), paramGroupName, Instant.now(), proxyPort);+ cluster.setEngineIdentifier(effectiveEngineName(engineParam).toLowerCase(Locale.ROOT));cluster.setContainerStorageResourceId(clusterResourceId);if (!mock) {String image = imageForEngine(engine, engineVersion);@@ -1174,12 +1205,88 @@ public class RdsService implements Resettable {accountId, clusterRegion, id, user, pw));}+ cluster.setServerlessV2MinCapacity(serverlessV2MinCapacity);+ cluster.setServerlessV2MaxCapacity(serverlessV2MaxCapacity);+ cluster.setServerlessV2SecondsUntilAutoPause(effectiveAutoPauseSeconds);putClusterForScope(currentAccountId(), effectiveRegion, id, cluster);LOG.infov("DB cluster {0} created (mock={1}), engine={2}, endpoint={3}:{4}",id, String.valueOf(mock), engine, endpoint.address(), String.valueOf(endpoint.port()));return cluster;}+ /**+ * Validates an Aurora Serverless v2 scaling configuration against the AWS ACU constraints:+ * capacities are specified in half-step (0.5) increments; MinCapacity ranges 0–256 (0 requires an+ * auto-pause-capable engine version, otherwise the smallest value is 0.5) and MaxCapacity is+ * greater than or equal to 1.0 and at most 256, with MaxCapacity at least MinCapacity. A null capacity is left+ * unset.+ */+ void validateServerlessV2Capacity(Double minCapacity, Double maxCapacity) {+ validateServerlessV2ScalingConfiguration(minCapacity, maxCapacity, null);+ }++ Integer validateServerlessV2ScalingConfiguration(+ Double minCapacity, Double maxCapacity, Integer secondsUntilAutoPause) {+ if (minCapacity == null && maxCapacity == null && secondsUntilAutoPause == null) {+ return null;+ }+ // A complete effective configuration requires both bounds. Modify requests merge omitted+ // members with the stored configuration before reaching this validation.+ if (minCapacity == null || maxCapacity == null) {+ throw new AwsException("InvalidParameterCombination",+ "ServerlessV2ScalingConfiguration requires both MinCapacity and MaxCapacity.", 400);+ }+ validateAcu("MinCapacity", minCapacity, 0.0);+ validateAcu("MaxCapacity", maxCapacity, 1.0);+ if (maxCapacity < minCapacity) {+ throw new AwsException("InvalidParameterCombination",+ "MaxCapacity must be greater than or equal to MinCapacity.", 400);+ }+ if (secondsUntilAutoPause != null+ && (secondsUntilAutoPause < SERVERLESS_V2_DEFAULT_AUTO_PAUSE_SECONDS+ || secondsUntilAutoPause > SERVERLESS_V2_MAX_AUTO_PAUSE_SECONDS)) {+ throw new AwsException("InvalidParameterValue",+ "SecondsUntilAutoPause must be between 300 and 86400 seconds.", 400);+ }+ if (minCapacity > 0.0) {+ return null;+ }+ return secondsUntilAutoPause != null+ ? secondsUntilAutoPause+ : SERVERLESS_V2_DEFAULT_AUTO_PAUSE_SECONDS;+ }++ private static void validateAcu(String field, double value, double smallest) {+ if (!Double.isFinite(value) || value < smallest || value > 256.0) {+ throw new AwsException("InvalidParameterValue",+ field + " must be between " + smallest + " and 256.0 ACUs.", 400);+ }+ // ACUs are only valid in half-step increments (0.5, 1, 1.5, ...).+ if (Math.abs(value * 2.0 - Math.rint(value * 2.0)) > 1e-9) {+ throw new AwsException("InvalidParameterValue",+ field + " must be specified in half-step (0.5) increments.", 400);+ }+ }++ private void validateServerlessV2Engine(+ String engineIdentifier, Double minCapacity, Double maxCapacity,+ Integer secondsUntilAutoPause) {+ boolean hasScalingConfiguration = minCapacity != null+ || maxCapacity != null+ || secondsUntilAutoPause != null;+ if (hasScalingConfiguration && !isAuroraEngine(engineIdentifier)) {+ throw new AwsException("InvalidParameterCombination",+ invalidParameterCombinationMessage(),+ 400);+ }+ }++ private static boolean isAuroraEngine(String engineIdentifier) {+ return engineIdentifier != null+ && ("aurora-mysql".equalsIgnoreCase(engineIdentifier)+ || "aurora-postgresql".equalsIgnoreCase(engineIdentifier));+ }+/*** Whether RDS holds a cluster or instance under this identifier.*@@ -1241,20 +1348,63 @@ public class RdsService implements Resettable {}public DbCluster modifyDbCluster(String id, String newPassword, Boolean iamEnabled) {- return modifyDbCluster(id, newPassword, iamEnabled,+ return modifyDbCluster(id, newPassword, iamEnabled, null, null, null,+ regionResolver.getDefaultRegion());+ }++ public DbCluster modifyDbCluster(String id, String newPassword, Boolean iamEnabled,+ Double serverlessV2MinCapacity, Double serverlessV2MaxCapacity,+ Integer serverlessV2SecondsUntilAutoPause) {+ return modifyDbCluster(id, newPassword, iamEnabled, serverlessV2MinCapacity,+ serverlessV2MaxCapacity, serverlessV2SecondsUntilAutoPause,regionResolver.getDefaultRegion());}- public DbCluster modifyDbCluster(- String id, String newPassword, Boolean iamEnabled, String region) {+ public DbCluster modifyDbCluster(String id, String newPassword, Boolean iamEnabled,+ String region) {+ return modifyDbCluster(id, newPassword, iamEnabled, null, null, null, region);+ }++ public DbCluster modifyDbCluster(String id, String newPassword, Boolean iamEnabled,+ Double serverlessV2MinCapacity, Double serverlessV2MaxCapacity,+ Integer serverlessV2SecondsUntilAutoPause, String region) {String effectiveRegion = effectiveRegion(region);DbCluster cluster = getDbCluster(id, effectiveRegion);+ boolean modifiesServerlessV2Scaling = serverlessV2MinCapacity != null+ || serverlessV2MaxCapacity != null+ || serverlessV2SecondsUntilAutoPause != null;+ if (modifiesServerlessV2Scaling) {+ validateServerlessV2Engine(+ cluster.getEngineIdentifier(), serverlessV2MinCapacity,+ serverlessV2MaxCapacity, serverlessV2SecondsUntilAutoPause);+ }+ Double effectiveMinCapacity = serverlessV2MinCapacity;+ Double effectiveMaxCapacity = serverlessV2MaxCapacity;+ Integer effectiveAutoPauseSeconds = null;+ if (modifiesServerlessV2Scaling) {+ effectiveMinCapacity = serverlessV2MinCapacity != null+ ? serverlessV2MinCapacity+ : cluster.getServerlessV2MinCapacity();+ effectiveMaxCapacity = serverlessV2MaxCapacity != null+ ? serverlessV2MaxCapacity+ : cluster.getServerlessV2MaxCapacity();+ Integer requestedOrExistingAutoPause = serverlessV2SecondsUntilAutoPause != null+ ? serverlessV2SecondsUntilAutoPause+ : cluster.getServerlessV2SecondsUntilAutoPause();+ effectiveAutoPauseSeconds = validateServerlessV2ScalingConfiguration(+ effectiveMinCapacity, effectiveMaxCapacity, requestedOrExistingAutoPause);+ }if (newPassword != null && !newPassword.isBlank()) {cluster.setMasterPassword(newPassword);}if (iamEnabled != null) {cluster.setIamDatabaseAuthenticationEnabled(iamEnabled);}+ if (modifiesServerlessV2Scaling) {+ cluster.setServerlessV2MinCapacity(effectiveMinCapacity);+ cluster.setServerlessV2MaxCapacity(effectiveMaxCapacity);+ cluster.setServerlessV2SecondsUntilAutoPause(effectiveAutoPauseSeconds);+ }putClusterForScope(currentAccountId(), effectiveRegion, id, cluster);LOG.infov("DB cluster {0} modified", id);return cluster;diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbCluster.java b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbCluster.javaindex 90c4463e8e..f082f61fdc 100644--- a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbCluster.java+++ b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbCluster.java@@ -13,6 +13,7 @@ public class DbCluster {private String dbClusterIdentifier;private DatabaseEngine engine;+ private String engineIdentifier;private String engineVersion;private String masterUsername;private String masterPassword;@@ -38,6 +39,11 @@ public class DbCluster {private String volumeId;private String containerStorageResourceId;+ // Aurora Serverless v2 scaling (ACUs). Null when the cluster is not Serverless v2.+ private Double serverlessV2MinCapacity;+ private Double serverlessV2MaxCapacity;+ private Integer serverlessV2SecondsUntilAutoPause;+// Transient — not persistedprivate transient String containerId;private transient String containerHost;@@ -72,6 +78,9 @@ public class DbCluster {public DatabaseEngine getEngine() { return engine; }public void setEngine(DatabaseEngine engine) { this.engine = engine; }+ public String getEngineIdentifier() { return engineIdentifier; }+ public void setEngineIdentifier(String engineIdentifier) { this.engineIdentifier = engineIdentifier; }+public String getEngineVersion() { return engineVersion; }public void setEngineVersion(String engineVersion) { this.engineVersion = engineVersion; }@@ -157,4 +166,15 @@ public class DbCluster {public int getContainerPort() { return containerPort; }public void setContainerPort(int containerPort) { this.containerPort = containerPort; }++ public Double getServerlessV2MinCapacity() { return serverlessV2MinCapacity; }+ public void setServerlessV2MinCapacity(Double serverlessV2MinCapacity) { this.serverlessV2MinCapacity = serverlessV2MinCapacity; }++ public Double getServerlessV2MaxCapacity() { return serverlessV2MaxCapacity; }+ public void setServerlessV2MaxCapacity(Double serverlessV2MaxCapacity) { this.serverlessV2MaxCapacity = serverlessV2MaxCapacity; }++ public Integer getServerlessV2SecondsUntilAutoPause() { return serverlessV2SecondsUntilAutoPause; }+ public void setServerlessV2SecondsUntilAutoPause(Integer serverlessV2SecondsUntilAutoPause) {+ this.serverlessV2SecondsUntilAutoPause = serverlessV2SecondsUntilAutoPause;+ }}diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/RdsCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/RdsCfnProvisionerTest.javaindex 9e642b0e0e..5eb06aadb1 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/RdsCfnProvisionerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/RdsCfnProvisionerTest.java@@ -199,6 +199,49 @@ class RdsCfnProvisionerTest {null, null, null, false, null, null, null, false, "us-west-2");}+ @Test+ void provisionsDbClusterWithServerlessV2Scaling() {+ DbCluster cluster = mock(DbCluster.class);+ when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");+ when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),+ any(), any(), anyBoolean(), any(), any(), any(), any()))+ .thenReturn(cluster);++ provision("Cluster", "AWS::RDS::DBCluster", """+ {"DBClusterIdentifier":"mycluster","Engine":"aurora-postgresql",+ "ServerlessV2ScalingConfiguration":{+ "MinCapacity":0,"MaxCapacity":16,"SecondsUntilAutoPause":600}}+ """);++ verify(rdsService).createDbCluster("mycluster", "aurora-postgresql", null,+ null, null, null, false, null, null, null, false, "us-east-1",+ 0.0, 16.0, 600);+ }++ @Test+ void rejectsNonNumericServerlessV2Capacity() {+ // A non-numeric capacity is invalid input, not an absent value: the stack fails rather than+ // silently dropping the scaling configuration.+ StackResource r = provision("Cluster", "AWS::RDS::DBCluster", """+ {"DBClusterIdentifier":"mycluster","Engine":"aurora-postgresql",+ "ServerlessV2ScalingConfiguration":{"MinCapacity":"abc","MaxCapacity":16}}+ """);+ assertEquals("CREATE_FAILED", r.getStatus());+ assertTrue(r.getStatusReason().contains("MinCapacity"), r.getStatusReason());+ }++ @Test+ void rejectsNonIntegerServerlessV2AutoPauseInterval() {+ StackResource r = provision("Cluster", "AWS::RDS::DBCluster", """+ {"DBClusterIdentifier":"mycluster","Engine":"aurora-postgresql",+ "ServerlessV2ScalingConfiguration":{+ "MinCapacity":0,"MaxCapacity":16,"SecondsUntilAutoPause":"300.5"}}+ """);++ assertEquals("CREATE_FAILED", r.getStatus());+ assertTrue(r.getStatusReason().contains("SecondsUntilAutoPause"), r.getStatusReason());+ }+@Testvoid resolvesSecretsManagerDynamicReferencesInDbClusterCredentials() {SecretVersion version = mock(SecretVersion.class);@@ -1100,7 +1143,8 @@ class RdsCfnProvisionerTest {when(rdsService.getDbCluster("mycluster")).thenReturn(existing);DbCluster reconciled = mock(DbCluster.class);when(reconciled.getDbClusterIdentifier()).thenReturn("mycluster");- when(rdsService.modifyDbCluster(eq("mycluster"), any(), anyBoolean())).thenReturn(reconciled);+ when(rdsService.modifyDbCluster(eq("mycluster"), any(), anyBoolean(),+ any(), any(), any(), eq("us-east-1"))).thenReturn(reconciled);StackResource r = provisionUpdate("Cluster", "AWS::RDS::DBCluster", """{"DBClusterIdentifier":"mycluster","Engine":"aurora-postgresql",@@ -1110,7 +1154,8 @@ class RdsCfnProvisionerTest {assertEquals("mycluster", r.getPhysicalId());verify(rdsService, never()).createDbCluster(any(), any(), any(), any(), any(), any(),anyBoolean(), any(), any(), any(), anyBoolean(), any());- verify(rdsService).modifyDbCluster("mycluster", "secret", false);+ verify(rdsService).modifyDbCluster("mycluster", "secret", false,+ null, null, null, "us-east-1");}@Testdiff --git a/src/test/java/io/github/hectorvent/floci/services/docdb/SharedClusterIdentifierIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/docdb/SharedClusterIdentifierIntegrationTest.javaindex 6d89846a6a..49de8de0c6 100644--- a/src/test/java/io/github/hectorvent/floci/services/docdb/SharedClusterIdentifierIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/docdb/SharedClusterIdentifierIntegrationTest.java@@ -252,9 +252,7 @@ class SharedClusterIdentifierIntegrationTest {.when().post("/").then().statusCode(200)- // Floci reports the aurora-postgresql request as its postgres engine; what matters- // here is that RDS answered at all rather than DocumentDB refusing it as existing.- .body(containsString("<Engine>postgres</Engine>"));+ .body(containsString("<Engine>aurora-postgresql</Engine>"));// And each region's describe answers from the service that owns the record there.queryIn("us-east-1", "DescribeDBClusters")@@ -262,7 +260,7 @@ class SharedClusterIdentifierIntegrationTest {.when().post("/").then().statusCode(200)- .body(containsString("<Engine>postgres</Engine>"))+ .body(containsString("<Engine>aurora-postgresql</Engine>")).body(not(containsString("docdb")));queryIn("eu-west-1", "DescribeDBClusters")@@ -309,7 +307,7 @@ class SharedClusterIdentifierIntegrationTest {.when().post("/").then().statusCode(200)- .body(containsString("<Engine>postgres</Engine>"));+ .body(containsString("<Engine>aurora-postgresql</Engine>"));rdsService.deleteDbCluster(id, "us-east-1");}diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.javaindex 52c41ea033..bc35f470da 100644--- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java@@ -215,7 +215,8 @@ class RdsQueryHandlerTest {when(service.rebootDbInstance("mydb", "us-west-2")).thenReturn(instance);when(service.listDbClusters(null, "us-west-2")).thenReturn(List.of());when(service.getDbCluster("mycluster", "us-west-2")).thenReturn(cluster);- when(service.modifyDbCluster("mycluster", null, null, "us-west-2"))+ when(service.modifyDbCluster("mycluster", null, null,+ null, null, null, "us-west-2")).thenReturn(cluster);handler.handle("DescribeDBInstances", params(), "us-west-2");@@ -240,7 +241,8 @@ class RdsQueryHandlerTest {verify(service).listDbClusters(null, "us-west-2");verify(service).getDbCluster("mycluster", "us-west-2");verify(service).deleteDbCluster("mycluster", "us-west-2");- verify(service).modifyDbCluster("mycluster", null, null, "us-west-2");+ verify(service).modifyDbCluster("mycluster", null, null,+ null, null, null, "us-west-2");}@Testdiff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.javaindex 5bddf578e6..40a0938cbb 100644--- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java@@ -792,6 +792,219 @@ class RdsServiceTest {any(), any(), any(), any());}+ @Test+ void createDbClusterAppliesServerlessV2Scaling() {+ when(config.services().rds().mock()).thenReturn(true);++ DbCluster cluster = rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",+ "admin", "password", "dbname", false, null, null, null, false, "us-east-1",+ 0.0, 16.0, 600);++ assertEquals(0.0, cluster.getServerlessV2MinCapacity());+ assertEquals(16.0, cluster.getServerlessV2MaxCapacity());+ assertEquals(600, cluster.getServerlessV2SecondsUntilAutoPause());+ }++ @Test+ void createDbClusterRejectsServerlessV2ScalingForNonAuroraEngines() {+ when(config.services().rds().mock()).thenReturn(true);++ for (String engine : List.of("postgres", "mysql", "mariadb")) {+ String clusterId = "cluster-" + engine;+ AwsException exception = assertThrows(AwsException.class,+ () -> rdsService.createDbCluster(+ clusterId, engine, null, "admin", "password", "dbname",+ false, null, null, null, false, "us-east-1",+ 0.5, 16.0, null));++ assertEquals("InvalidParameterCombination", exception.getErrorCode());+ assertEquals(400, exception.getHttpStatus());+ assertEquals(+ "Parameters that must not be used together were used together. "+ + "Remove one of the conflicting parameters and try again.",+ exception.getMessage());+ assertTrue(rdsService.listDbClusters(clusterId).isEmpty());+ }+ }++ @Test+ void createDbClusterDefaultsAndClearsServerlessV2AutoPauseInterval() {+ when(config.services().rds().mock()).thenReturn(true);++ DbCluster autoPauseCluster = rdsService.createDbCluster(+ "auto-pause", "aurora-postgresql", "16.3",+ "admin", "password", "dbname", false, null, null, null, false, "us-east-1",+ 0.0, 16.0);+ DbCluster alwaysActiveCluster = rdsService.createDbCluster(+ "always-active", "aurora-postgresql", "16.3",+ "admin", "password", "dbname", false, null, null, null, false, "us-east-1",+ 0.5, 16.0, 600);++ assertEquals(300, autoPauseCluster.getServerlessV2SecondsUntilAutoPause());+ assertNull(alwaysActiveCluster.getServerlessV2SecondsUntilAutoPause());+ }++ @Test+ void modifyDbClusterAppliesServerlessV2ScalingConfiguration() {+ when(config.services().rds().mock()).thenReturn(true);+ rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",+ "admin", "password", "dbname", false, null, null, null, false, "us-east-1",+ 0.0, 16.0, 600);++ DbCluster widerRange = rdsService.modifyDbCluster(+ "cluster1", null, null, null, 32.0, null);++ assertEquals(0.0, widerRange.getServerlessV2MinCapacity());+ assertEquals(32.0, widerRange.getServerlessV2MaxCapacity());+ assertEquals(600, widerRange.getServerlessV2SecondsUntilAutoPause());++ DbCluster longerAutoPause = rdsService.modifyDbCluster(+ "cluster1", null, null, null, null, 900);++ assertEquals(0.0, longerAutoPause.getServerlessV2MinCapacity());+ assertEquals(32.0, longerAutoPause.getServerlessV2MaxCapacity());+ assertEquals(900, longerAutoPause.getServerlessV2SecondsUntilAutoPause());++ DbCluster alwaysActiveCluster = rdsService.modifyDbCluster(+ "cluster1", null, null, 0.5, null, null);+ assertEquals(0.5, alwaysActiveCluster.getServerlessV2MinCapacity());+ assertEquals(32.0, alwaysActiveCluster.getServerlessV2MaxCapacity());+ assertNull(alwaysActiveCluster.getServerlessV2SecondsUntilAutoPause());++ DbCluster autoPauseAgain = rdsService.modifyDbCluster(+ "cluster1", null, null, 0.0, null, null);+ assertEquals(300, autoPauseAgain.getServerlessV2SecondsUntilAutoPause());++ DbCluster passwordOnlyChange = rdsService.modifyDbCluster(+ "cluster1", "new-password", null);+ assertEquals(0.0, passwordOnlyChange.getServerlessV2MinCapacity());+ assertEquals(32.0, passwordOnlyChange.getServerlessV2MaxCapacity());+ assertEquals(300, passwordOnlyChange.getServerlessV2SecondsUntilAutoPause());+ }++ @Test+ void modifyDbClusterRejectsServerlessV2ScalingForNonAuroraCluster() {+ when(config.services().rds().mock()).thenReturn(true);+ DbCluster cluster = rdsService.createDbCluster(+ "cluster1", "postgres", "16.3", "admin", "original-password",+ "dbname", false, null);++ AwsException exception = assertThrows(AwsException.class,+ () -> rdsService.modifyDbCluster(+ "cluster1", "new-password", true, 0.5, 16.0, null));++ assertEquals("InvalidParameterCombination", exception.getErrorCode());+ assertEquals(400, exception.getHttpStatus());+ assertEquals(+ "Parameters that must not be used together were used together. "+ + "Remove one of the conflicting parameters and try again.",+ exception.getMessage());+ assertEquals("original-password", cluster.getMasterPassword());+ assertFalse(cluster.isIamDatabaseAuthenticationEnabled());+ assertNull(cluster.getServerlessV2MinCapacity());+ assertNull(cluster.getServerlessV2MaxCapacity());+ }++ @Test+ void modifyDbClusterCanAddServerlessV2ScalingToExistingAuroraCluster() {+ when(config.services().rds().mock()).thenReturn(true);+ rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",+ "admin", "password", "dbname", false, null);++ DbCluster cluster = rdsService.modifyDbCluster(+ "cluster1", null, null, 0.5, 16.0, null);++ assertEquals("aurora-postgresql", cluster.getEngineIdentifier());+ assertEquals(0.5, cluster.getServerlessV2MinCapacity());+ assertEquals(16.0, cluster.getServerlessV2MaxCapacity());+ }++ @Test+ void modifyDbClusterRejectsScalingWhenPersistedEngineIdentityIsMissing() {+ when(config.services().rds().mock()).thenReturn(true);+ DbCluster cluster = rdsService.createDbCluster(+ "cluster1", "aurora-postgresql", "16.3", "admin", "password",+ "dbname", false, null);+ cluster.setEngineIdentifier(null);++ AwsException exception = assertThrows(AwsException.class,+ () -> rdsService.modifyDbCluster(+ "cluster1", null, null, 0.5, 16.0, null));++ assertEquals("InvalidParameterCombination", exception.getErrorCode());+ assertEquals(400, exception.getHttpStatus());+ assertNull(cluster.getServerlessV2MinCapacity());+ assertNull(cluster.getServerlessV2MaxCapacity());+ }++ @Test+ void modifyDbClusterRejectsPartialScalingWithoutAnExistingConfiguration() {+ when(config.services().rds().mock()).thenReturn(true);+ DbCluster cluster = rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",+ "admin", "original-password", "dbname", false, null);++ assertThrows(AwsException.class, () -> rdsService.modifyDbCluster(+ "cluster1", "new-password", true, null, 16.0, null));++ assertEquals("original-password", cluster.getMasterPassword());+ assertFalse(cluster.isIamDatabaseAuthenticationEnabled());+ assertNull(cluster.getServerlessV2MinCapacity());+ assertNull(cluster.getServerlessV2MaxCapacity());+ }++ @Test+ void modifyDbClusterValidatesScalingBeforeApplyingOtherChanges() {+ when(config.services().rds().mock()).thenReturn(true);+ DbCluster cluster = rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",+ "admin", "original-password", "dbname", false, null);++ assertThrows(AwsException.class, () -> rdsService.modifyDbCluster(+ "cluster1", "new-password", true, 0.0, 16.0, 299));++ assertEquals("original-password", cluster.getMasterPassword());+ assertFalse(cluster.isIamDatabaseAuthenticationEnabled());+ assertNull(cluster.getServerlessV2MinCapacity());+ assertNull(cluster.getServerlessV2MaxCapacity());+ }++ @Test+ void serverlessV2CapacityValidationEnforcesAcuConstraints() {+ // Non-half-step increment.+ assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(0.3, 16.0));+ // Above the 256-ACU ceiling.+ assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(0.5, 300.0));+ // AWS requires MaxCapacity to be greater than 0.5 ACUs.+ assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(0.0, 0.5));+ // Non-finite values are not valid AWS Query numbers.+ assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(Double.NaN, 16.0));+ assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(0.5, Double.NaN));+ assertThrows(AwsException.class,+ () -> rdsService.validateServerlessV2Capacity(0.5, Double.POSITIVE_INFINITY));+ assertThrows(AwsException.class,+ () -> rdsService.validateServerlessV2Capacity(Double.NEGATIVE_INFINITY, 16.0));+ // MaxCapacity below MinCapacity.+ assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(16.0, 8.0));+ // Valid: 0 (auto-pause), the 256 ceiling, and half-step values.+ assertDoesNotThrow(() -> rdsService.validateServerlessV2Capacity(0.0, 256.0));+ assertDoesNotThrow(() -> rdsService.validateServerlessV2Capacity(0.5, 128.0));+ // Both null is a no-op (not a Serverless v2 cluster).+ assertDoesNotThrow(() -> rdsService.validateServerlessV2Capacity(null, null));+ // A create-time or otherwise incomplete effective configuration requires both bounds.+ assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(0.5, null));+ assertThrows(AwsException.class, () -> rdsService.validateServerlessV2Capacity(null, 16.0));+ assertThrows(AwsException.class,+ () -> rdsService.validateServerlessV2ScalingConfiguration(0.0, 16.0, 299));+ assertThrows(AwsException.class,+ () -> rdsService.validateServerlessV2ScalingConfiguration(0.0, 16.0, 86_401));+ assertThrows(AwsException.class,+ () -> rdsService.validateServerlessV2ScalingConfiguration(null, null, 300));+ assertEquals(300,+ rdsService.validateServerlessV2ScalingConfiguration(0.0, 16.0, null));+ assertEquals(86_400,+ rdsService.validateServerlessV2ScalingConfiguration(0.0, 16.0, 86_400));+ assertNull(rdsService.validateServerlessV2ScalingConfiguration(0.5, 16.0, 600));+ }+@Testvoid mockModeCreatesClusterInstanceAvailableWithoutContainer() {when(config.services().rds().mock()).thenReturn(true);diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/model/DbClusterPersistenceTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/model/DbClusterPersistenceTest.javanew file mode 100644index 0000000000..2294c632f0--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/rds/model/DbClusterPersistenceTest.java@@ -0,0 +1,41 @@+package io.github.hectorvent.floci.services.rds.model;++import com.fasterxml.jackson.core.type.TypeReference;+import io.github.hectorvent.floci.core.storage.PersistentStorage;+import org.junit.jupiter.api.Test;+import org.junit.jupiter.api.io.TempDir;++import java.nio.file.Path;+import java.util.Map;++import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertTrue;++class DbClusterPersistenceTest {++ @Test+ void serverlessV2ScalingConfigurationPersistsAcrossInstances(@TempDir Path directory) {+ Path file = directory.resolve("rds-clusters.json");+ DbCluster cluster = new DbCluster();+ cluster.setDbClusterIdentifier("serverless-cluster");+ cluster.setEngineIdentifier("aurora-postgresql");+ cluster.setServerlessV2MinCapacity(0.0);+ cluster.setServerlessV2MaxCapacity(16.0);+ cluster.setServerlessV2SecondsUntilAutoPause(600);++ var writer = new PersistentStorage<String, DbCluster>(+ file, new TypeReference<Map<String, DbCluster>>() {});+ writer.put(cluster.getDbClusterIdentifier(), cluster);++ var reader = new PersistentStorage<String, DbCluster>(+ file, new TypeReference<Map<String, DbCluster>>() {});+ reader.load();++ var restored = reader.get(cluster.getDbClusterIdentifier());+ assertTrue(restored.isPresent());+ assertEquals("aurora-postgresql", restored.get().getEngineIdentifier());+ assertEquals(0.0, restored.get().getServerlessV2MinCapacity());+ assertEquals(16.0, restored.get().getServerlessV2MaxCapacity());+ assertEquals(600, restored.get().getServerlessV2SecondsUntilAutoPause());+ }+}