mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(elasticache,rds): prevent orphaned Docker containers on shutdown and restart (#398)
ElastiCache and RDS container managers used deterministic container names without conflict handling, causing 409 errors when restarting after an interrupted run. Containers were also never cleaned up on shutdown. - Force-remove stale containers by name before creating new ones - Track active containers in ConcurrentHashMap with stopAll() for shutdown - Add container cleanup to EmulatorLifecycle.onStop() (proxies first, then containers) - Add @AfterAll safety net to ElastiCacheIntegrationTest
This commit is contained in:
5 files changed
+90
-3
No files matched your search
@@ -5,7 +5,9 @@ import io.github.hectorvent.floci.core.common.ServiceRegistry;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.lifecycle.inithook.InitializationHook;
|
||||
import io.github.hectorvent.floci.lifecycle.inithook.InitializationHooksRunner;
|
||||
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerManager;
|
||||
import io.github.hectorvent.floci.services.elasticache.proxy.ElastiCacheProxyManager;
|
||||
import io.github.hectorvent.floci.services.rds.container.RdsContainerManager;
|
||||
import io.github.hectorvent.floci.services.rds.proxy.RdsProxyManager;
|
||||
import io.quarkus.runtime.StartupEvent;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -29,7 +31,9 @@ class EmulatorLifecycleTest {
|
||||
@Mock private ServiceRegistry serviceRegistry;
|
||||
@Mock private EmulatorConfig config;
|
||||
@Mock private EmulatorConfig.StorageConfig storageConfig;
|
||||
@Mock private ElastiCacheContainerManager elastiCacheContainerManager;
|
||||
@Mock private ElastiCacheProxyManager elastiCacheProxyManager;
|
||||
@Mock private RdsContainerManager rdsContainerManager;
|
||||
@Mock private RdsProxyManager rdsProxyManager;
|
||||
@Mock private InitializationHooksRunner initializationHooksRunner;
|
||||
|
||||
@@ -42,7 +46,8 @@ class EmulatorLifecycleTest {
|
||||
when(storageConfig.persistentPath()).thenReturn("/app/data");
|
||||
emulatorLifecycle = new EmulatorLifecycle(
|
||||
storageFactory, serviceRegistry, config,
|
||||
elastiCacheProxyManager, rdsProxyManager, initializationHooksRunner);
|
||||
elastiCacheContainerManager, elastiCacheProxyManager,
|
||||
rdsContainerManager, rdsProxyManager, initializationHooksRunner);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+24
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.elasticache;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
@@ -9,6 +10,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
@@ -43,6 +45,28 @@ class ElastiCacheIntegrationTest {
|
||||
Assumptions.assumeTrue(isDockerAvailable(), "Docker daemon must be available for ElastiCache integration tests");
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
// Best-effort cleanup of any resources created during tests.
|
||||
// Prevents orphaned containers/state if a test fails mid-way.
|
||||
for (String groupId : List.of(CROSS_GROUP_ID, GROUP_ID, GROUP_ID + "-reused")) {
|
||||
try {
|
||||
given()
|
||||
.formParam("Action", "DeleteReplicationGroup")
|
||||
.formParam("ReplicationGroupId", groupId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.post("/");
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
try {
|
||||
given()
|
||||
.formParam("Action", "DeleteUser")
|
||||
.formParam("UserId", USER_ID)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.post("/");
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createReplicationGroup() {
|
||||
|
||||
Reference in new issue
Block a user