diff --git a/src/test/java/io/github/hectorvent/floci/core/storage/StorageFactoryDuplicateBackendTest.java b/src/test/java/io/github/hectorvent/floci/core/storage/StorageFactoryDuplicateBackendTest.java
index ea55e886e0..a53cde729a 100644
--- a/src/test/java/io/github/hectorvent/floci/core/storage/StorageFactoryDuplicateBackendTest.java
+++ b/src/test/java/io/github/hectorvent/floci/core/storage/StorageFactoryDuplicateBackendTest.java
@@ -1,10 +1,11 @@
package io.github.hectorvent.floci.core.storage;
import com.fasterxml.jackson.core.type.TypeReference;
+import io.github.hectorvent.floci.testing.PerServicePersistentStorageProfile;
import io.quarkus.test.junit.QuarkusTest;
-import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -13,18 +14,22 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
+import static io.github.hectorvent.floci.testing.PerServicePersistentStorageProfile.STORAGE_DIR;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Reproduces issue #1921: two components request the same storage file, the factory hands out
* two independent backends, and on graceful shutdown the stale duplicate flushes last and
* clobbers the persisted state written by the active instance.
+ *
+ *
DynamoDB on persistent storage comes from {@link PerServicePersistentStorageProfile}, which
+ * this class shares with other classes that each call a different service. The placeholder
+ * entries it writes go into DynamoDB's table store, so it clears them again after the test.
*/
@QuarkusTest
-@TestProfile(StorageFactoryDuplicateBackendTest.PersistentProfile.class)
+@TestProfile(PerServicePersistentStorageProfile.class)
class StorageFactoryDuplicateBackendTest {
- private static final String STORAGE_PATH = "/tmp/floci-dedupe-backend-test";
private static final String FILE_NAME = "dynamodb-tables.json";
@Inject
@@ -36,7 +41,12 @@ class StorageFactoryDuplicateBackendTest {
// exist and hold in-memory state from app startup. Clear all backends (wipes memory + disk),
// then remove the file so both create() calls below start from an empty store.
storageFactory.clearAll();
- Files.deleteIfExists(Path.of(STORAGE_PATH, FILE_NAME));
+ Files.deleteIfExists(Path.of(STORAGE_DIR, FILE_NAME));
+ }
+
+ @AfterEach
+ void clearPlaceholders() throws IOException {
+ reset();
}
@Test
@@ -59,21 +69,10 @@ class StorageFactoryDuplicateBackendTest {
// Read the persisted file back with an independent reader.
PersistentStorage reader =
- new PersistentStorage<>(Path.of(STORAGE_PATH, FILE_NAME), typeRef);
+ new PersistentStorage<>(Path.of(STORAGE_DIR, FILE_NAME), typeRef);
reader.load();
assertEquals(60, reader.keys().size(),
"persisted table definitions should survive flushAll despite the duplicate backend");
}
-
- public static final class PersistentProfile implements QuarkusTestProfile {
- @Override
- public Map getConfigOverrides() {
- return Map.of(
- "floci.storage.mode", "memory",
- "floci.storage.services.dynamodb.mode", "persistent",
- "floci.storage.persistent-path", STORAGE_PATH
- );
- }
- }
}
diff --git a/src/test/java/io/github/hectorvent/floci/core/storage/StorageFactoryServiceCatalogIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/core/storage/StorageFactoryServiceCatalogIntegrationTest.java
index ee6d06406b..9c1c6ebcd6 100644
--- a/src/test/java/io/github/hectorvent/floci/core/storage/StorageFactoryServiceCatalogIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/core/storage/StorageFactoryServiceCatalogIntegrationTest.java
@@ -1,43 +1,61 @@
package io.github.hectorvent.floci.core.storage;
import com.fasterxml.jackson.core.type.TypeReference;
+import io.github.hectorvent.floci.config.EmulatorConfig;
+import io.github.hectorvent.floci.core.common.ServiceConfigAccess;
+import io.github.hectorvent.floci.testing.PerServicePersistentStorageProfile;
import io.quarkus.test.junit.QuarkusTest;
-import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Map;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static io.github.hectorvent.floci.testing.PerServicePersistentStorageProfile.STORAGE_DIR;
import static org.junit.jupiter.api.Assertions.assertTrue;
+/**
+ * A per-service storage mode takes effect: with the test default, memory, for storage as a whole
+ * and ACM's own mode set to persistent, an ACM store writes through to its file.
+ *
+ * The ACM override comes from {@link PerServicePersistentStorageProfile}, which also puts
+ * DynamoDB and S3 on disk for the other classes on it. This class creates only the ACM store, so
+ * those two never reach it. It creates that store on a factory of its own, built from the
+ * application's configuration, so the application never holds it and no later flush of the
+ * application's stores writes the file back after the test deletes it.
+ */
@QuarkusTest
-@TestProfile(StorageFactoryServiceCatalogIntegrationTest.AcmPersistentStorageProfile.class)
+@TestProfile(PerServicePersistentStorageProfile.class)
class StorageFactoryServiceCatalogIntegrationTest {
+ private static final String FILE_NAME = "acm-test.json";
+
@Inject
- StorageFactory storageFactory;
+ EmulatorConfig config;
+
+ @Inject
+ ServiceConfigAccess serviceConfigAccess;
@Test
- void acmStorageOverrideIsApplied() {
- StorageBackend backend = storageFactory.create(
+ void acmStorageOverrideIsApplied() throws IOException {
+ Path file = Path.of(STORAGE_DIR, FILE_NAME);
+ Files.deleteIfExists(file);
+ StorageFactory factory = new StorageFactory(config, serviceConfigAccess);
+ StorageBackend backend = factory.create(
"acm",
- "acm-test.json",
+ FILE_NAME,
new TypeReference