feat(elasticache): add validation for cache parameter group existence in replication group operations (#2957)

Signed-off-by: Matheus André <matheusandr2@gmail.com>
This commit is contained in:
Matheus André authored and GitHub committed 2026-09-03 17:24:34 -04:00
1 parent df0e7bc79c
commit 6c9cc95d54
5 files changed
+127 -1

No files matched your search

@@ -336,7 +336,7 @@ class ElastiCacheIntegrationTest {
equalTo(GROUP_ID + "-reused"));
}
private static boolean isDockerAvailable() {
static boolean isDockerAvailable() {
try {
Process process = new ProcessBuilder("docker", "version", "--format", "{{.Server.Version}}")
.redirectErrorStream(true)
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.elasticache;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@@ -268,6 +269,75 @@ class ElastiCacheParameterGroupIntegrationTest {
.body(containsString("CacheParameterGroupnot found: absent-pg"));
}
@Test
@Order(4)
void aReplicationGroupCannotReferenceAnUnknownParameterGroup() {
// The lookup runs with the other validations, before any container is started, so the
// refusal carries the parameter group's own not-found rather than a provisioning failure.
query("CreateReplicationGroup")
.formParam("ReplicationGroupId", "pg-absent-rg")
.formParam("ReplicationGroupDescription", "references a missing group")
.formParam("CacheParameterGroupName", "absent-pg")
.when()
.post("/")
.then()
.statusCode(404)
.body(containsString("<Code>CacheParameterGroupNotFound</Code>"))
.body(containsString("CacheParameterGroup absent-pg not found."));
query("DescribeReplicationGroups")
.formParam("ReplicationGroupId", "pg-absent-rg")
.when()
.post("/")
.then()
.statusCode(404);
}
@Test
@Order(4)
void aParameterGroupInUseByAReplicationGroupCannotBeDeleted() {
// The replication group is a real one behind a container, so this case needs Docker
// where the rest of the class does not.
Assumptions.assumeTrue(ElastiCacheIntegrationTest.isDockerAvailable(),
"Docker daemon must be available to create a replication group");
String replicationGroupId = "pg-in-use-rg";
query("CreateReplicationGroup")
.formParam("ReplicationGroupId", replicationGroupId)
.formParam("ReplicationGroupDescription", "holds the parameter group in use")
.formParam("CacheParameterGroupName", GROUP)
.when()
.post("/")
.then()
.statusCode(200);
try {
query("DeleteCacheParameterGroup")
.formParam("CacheParameterGroupName", GROUP)
.when()
.post("/")
.then()
.statusCode(400)
.body(containsString("<Code>InvalidCacheParameterGroupState</Code>"))
.body(containsString("One or more cache clusters are still members of this parameter group "
+ GROUP + ", so the group cannot be deleted."));
query("DescribeCacheParameterGroups")
.formParam("CacheParameterGroupName", GROUP)
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("<CacheParameterGroupName>" + GROUP + "</CacheParameterGroupName>"));
} finally {
query("DeleteReplicationGroup")
.formParam("ReplicationGroupId", replicationGroupId)
.when()
.post("/")
.then()
.statusCode(200);
}
}
@Test
@Order(5)
void deleteRemovesItAndTheSecondDeleteReportsItMissing() {
@@ -677,4 +677,41 @@ class ElastiCacheServiceTest {
assertThrows(AwsException.class, () -> svc.getReplicationGroup("g1"),
"the deleted group must not come back from the modify");
}
private static ElastiCacheService.CreateReplicationGroupRequest requestWithParameterGroup(
String groupId, String parameterGroupName) {
return new ElastiCacheService.CreateReplicationGroupRequest(groupId, "test",
AuthMode.NO_AUTH, null, "us-east-1", null, null, null,
parameterGroupName, null, null, null, null,
null, null, null, ReplicationGroupSettings.defaults(), Map.of());
}
@Test
void createReferencingAnUnknownParameterGroupIsRefusedBeforeProvisioning() {
AwsException ex = assertThrows(AwsException.class,
() -> service.createReplicationGroup(requestWithParameterGroup("grp", "absent-pg")));
assertEquals("CacheParameterGroupNotFound", ex.getErrorCode());
assertEquals(404, ex.getHttpStatus());
verify(containerManager, never()).start(anyString(), anyString());
verify(containerManager, never()).start(anyString(), anyString(), any());
assertThrows(AwsException.class, () -> service.getReplicationGroup("grp"));
}
@Test
void aParameterGroupStillReferencedByAReplicationGroupCannotBeDeleted() {
service.createCacheParameterGroup("custom-pg", "redis7", "in use", Map.of());
service.createReplicationGroup(requestWithParameterGroup("grp", "custom-pg"));
AwsException ex = assertThrows(AwsException.class,
() -> service.deleteCacheParameterGroup("custom-pg"));
assertEquals("InvalidCacheParameterGroupState", ex.getErrorCode());
assertEquals(400, ex.getHttpStatus());
assertTrue(service.findParameterGroup("custom-pg").isPresent(),
"a refused delete must leave the group in place");
service.deleteReplicationGroup("grp");
service.deleteCacheParameterGroup("custom-pg");
assertTrue(service.findParameterGroup("custom-pg").isEmpty());
}
}