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>() {} ); + try { + backend.put("probe", "persisted"); - assertInstanceOf(AccountAwareStorageBackend.class, backend); - } - - public static final class AcmPersistentStorageProfile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of( - "floci.storage.mode", "memory", - "floci.storage.services.acm.mode", "persistent", - "floci.storage.persistent-path", "/tmp/floci-service-registry-unification-tests" - ); + // A store in the test default mode, memory, never writes the file. + assertTrue(Files.exists(file), "the ACM store should write through to " + file); + } finally { + Files.deleteIfExists(file); } } } diff --git a/src/test/java/io/github/hectorvent/floci/services/athena/AthenaCreateWorkGroupPersistenceIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/athena/AthenaCreateWorkGroupPersistenceIntegrationTest.java index ddcb9110b9..0771a4f9ac 100644 --- a/src/test/java/io/github/hectorvent/floci/services/athena/AthenaCreateWorkGroupPersistenceIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/athena/AthenaCreateWorkGroupPersistenceIntegrationTest.java @@ -2,18 +2,21 @@ package io.github.hectorvent.floci.services.athena; import com.fasterxml.jackson.core.type.TypeReference; import io.github.hectorvent.floci.core.storage.PersistentStorage; +import io.github.hectorvent.floci.testing.PartitionCleanup; +import io.github.hectorvent.floci.testing.PersistentStorageProfile; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.QuarkusTestProfile; import io.quarkus.test.junit.TestProfile; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.Map; +import static io.github.hectorvent.floci.testing.PersistentStorageProfile.STORAGE_DIR; import static io.restassured.RestAssured.given; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -21,14 +24,24 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +/** + * CreateWorkGroup and UpdateWorkGroup write the workgroup, with its defaults filled in and its + * engine version resolved, to {@code workgroups.json}, and CreateWorkGroup does not write the + * primary workgroup there. + * + *

Persistent storage comes from {@link PersistentStorageProfile}, which this class shares with + * other classes that each read their own service's file, so it deletes the workgroups it creates. + */ @QuarkusTest -@TestProfile(AthenaCreateWorkGroupPersistenceIntegrationTest.PersistentStorageProfile.class) +@TestProfile(PersistentStorageProfile.class) class AthenaCreateWorkGroupPersistenceIntegrationTest { - static final String STORAGE_DIR = "target/athena-workgroups-it"; private static final Path WORKGROUPS_FILE = Path.of(STORAGE_DIR, "workgroups.json"); private static final String CONTENT_TYPE = "application/x-amz-json-1.1"; + @RegisterExtension + final PartitionCleanup cleanup = new PartitionCleanup(); + @BeforeAll static void setup() throws Exception { RestAssuredJsonUtils.configureAwsContentTypes(); @@ -67,6 +80,7 @@ class AthenaCreateWorkGroupPersistenceIntegrationTest { .post("/") .then() .statusCode(200); + cleanup.register(() -> deleteWorkGroup("analytics")); assertTrue(Files.exists(WORKGROUPS_FILE), "CreateWorkGroup should create workgroups.json"); @@ -120,6 +134,7 @@ class AthenaCreateWorkGroupPersistenceIntegrationTest { .post("/") .then() .statusCode(200); + cleanup.register(() -> deleteWorkGroup("defaulted-workgroup")); PersistentStorage> store = new PersistentStorage<>( WORKGROUPS_FILE, @@ -166,6 +181,7 @@ class AthenaCreateWorkGroupPersistenceIntegrationTest { .post("/") .then() .statusCode(200); + cleanup.register(() -> deleteWorkGroup("engine-normalized")); PersistentStorage> store = new PersistentStorage<>( WORKGROUPS_FILE, @@ -204,6 +220,7 @@ class AthenaCreateWorkGroupPersistenceIntegrationTest { .post("/") .then() .statusCode(200); + cleanup.register(() -> deleteWorkGroup("engine-explicit")); PersistentStorage> store = new PersistentStorage<>( WORKGROUPS_FILE, @@ -239,6 +256,7 @@ class AthenaCreateWorkGroupPersistenceIntegrationTest { .post("/") .then() .statusCode(200); + cleanup.register(() -> deleteWorkGroup("engine-empty")); PersistentStorage> store = new PersistentStorage<>( WORKGROUPS_FILE, @@ -276,6 +294,7 @@ class AthenaCreateWorkGroupPersistenceIntegrationTest { .post("/") .then() .statusCode(200); + cleanup.register(() -> deleteWorkGroup("engine-blank-selected")); PersistentStorage> store = new PersistentStorage<>( WORKGROUPS_FILE, @@ -312,6 +331,7 @@ class AthenaCreateWorkGroupPersistenceIntegrationTest { .post("/") .then() .statusCode(200); + cleanup.register(() -> deleteWorkGroup("persistent-update")); given() .header("X-Amz-Target", "AmazonAthena.UpdateWorkGroup") @@ -348,13 +368,14 @@ class AthenaCreateWorkGroupPersistenceIntegrationTest { assertNull(configuration.get("BytesScannedCutoffPerQuery")); } - public static final class PersistentStorageProfile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of( - "floci.storage.mode", "persistent", - "floci.storage.persistent-path", STORAGE_DIR - ); - } + private static void deleteWorkGroup(String name) { + given() + .header("X-Amz-Target", "AmazonAthena.DeleteWorkGroup") + .contentType(CONTENT_TYPE) + .body("{ \"WorkGroup\": \"" + name + "\", \"RecursiveDeleteOption\": true }") + .when() + .post("/") + .then() + .statusCode(200); } } diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPersistenceIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPersistenceIntegrationTest.java index e634b76277..d64defb538 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPersistenceIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationPersistenceIntegrationTest.java @@ -3,18 +3,21 @@ package io.github.hectorvent.floci.services.cloudformation; import com.fasterxml.jackson.core.type.TypeReference; import io.github.hectorvent.floci.core.storage.PersistentStorage; import io.github.hectorvent.floci.services.cloudformation.model.Stack; +import io.github.hectorvent.floci.testing.PartitionCleanup; +import io.github.hectorvent.floci.testing.PersistentStorageProfile; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.QuarkusTestProfile; import io.quarkus.test.junit.TestProfile; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; import java.util.Optional; +import static io.github.hectorvent.floci.testing.PersistentStorageProfile.STORAGE_DIR; import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -24,14 +27,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * End-to-end check that a created stack is written to persistent storage so it survives a restart * (criteria #10, #11). Runs with the {@code persistent} storage mode; verifies the on-disk file * directly with a fresh {@link PersistentStorage} (what the service would read on the next boot). + * + *

Persistent storage comes from {@link PersistentStorageProfile}, which this class shares with + * other classes that each read their own service's file, so it deletes its stack, and with it the + * bucket the stack created. */ @QuarkusTest -@TestProfile(CloudFormationPersistenceIntegrationTest.PersistentStorageProfile.class) +@TestProfile(PersistentStorageProfile.class) class CloudFormationPersistenceIntegrationTest { - static final String STORAGE_DIR = "target/cfn-persistence-it"; private static final Path STACKS_FILE = Path.of(STORAGE_DIR, "cloudformation-stacks.json"); + @RegisterExtension + final PartitionCleanup cleanup = new PartitionCleanup(); + @BeforeAll static void setup() throws Exception { RestAssuredJsonUtils.configureAwsContentTypes(); @@ -60,6 +69,19 @@ class CloudFormationPersistenceIntegrationTest { .post("/") .then() .statusCode(200); + cleanup.register(() -> { + given() + .contentType("application/x-www-form-urlencoded") + .formParam("Action", "DeleteStack") + .formParam("StackName", "persist-it-stack") + .when() + .post("/") + .then() + .statusCode(200); + // DeleteStack answers before the deletion runs, so wait for it, then for the bucket. + CfnStackWaits.awaitStackDeleted("persist-it-stack"); + given().when().head("/cfn-persist-it-bucket").then().statusCode(404); + }); given() .contentType("application/x-www-form-urlencoded") @@ -86,13 +108,4 @@ class CloudFormationPersistenceIntegrationTest { assertEquals("cfn-persist-it-bucket", loaded.get().getResources().get("PersistBucket").getPhysicalId()); } - - public static final class PersistentStorageProfile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of( - "floci.storage.mode", "persistent", - "floci.storage.persistent-path", STORAGE_DIR); - } - } } diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontS3DiskOriginServingTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontS3DiskOriginServingTest.java index b1fb090d7e..ad7beff5f3 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontS3DiskOriginServingTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontS3DiskOriginServingTest.java @@ -5,32 +5,42 @@ import io.github.hectorvent.floci.services.cloudfront.model.Distribution; import io.github.hectorvent.floci.services.cloudfront.model.DistributionConfig; import io.github.hectorvent.floci.services.cloudfront.model.Origin; import io.github.hectorvent.floci.services.s3.S3Service; +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 io.restassured.response.Response; import jakarta.inject.Inject; import org.junit.jupiter.api.Test; +import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.stream.Stream; +import static io.github.hectorvent.floci.testing.PerServicePersistentStorageProfile.STORAGE_DIR; import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * An S3 origin whose objects live on disk, where CloudFront streams the object file to the viewer * instead of reading it into memory first. + * + *

S3 on disk comes from {@link PerServicePersistentStorageProfile}, which this class shares + * with other classes that each call a different service, so it deletes its distribution as well + * as its bucket. */ @QuarkusTest -@TestProfile(CloudFrontS3DiskOriginServingTest.S3OnDiskProfile.class) +@TestProfile(PerServicePersistentStorageProfile.class) class CloudFrontS3DiskOriginServingTest { private static final String REGION = "us-east-1"; @@ -42,18 +52,23 @@ class CloudFrontS3DiskOriginServingTest { CloudFrontService cloudFrontService; @Test - void streamsAnObjectFileWithItsLength() { + void streamsAnObjectFileWithItsLength() throws IOException { String suffix = Long.toString(System.nanoTime(), 36); String bucket = "cf-disk-origin-" + suffix; // Larger than any one buffer on the way, so the body arrives over many writes. byte[] body = new byte[3 * 1024 * 1024 + 1]; new Random(5080).nextBytes(body); s3Service.createBucket(bucket, REGION); + Distribution dist = null; try { s3Service.putObject(bucket, "video.bin", body, "application/octet-stream", Map.of()); + // S3 in memory would serve the same bytes, so check the object really is a file first. + assertTrue(hasObjectFile(Path.of(STORAGE_DIR, "s3"), bucket, "video.bin", body.length), + "video.bin should be a file in " + bucket + "'s directory under " + + STORAGE_DIR + "/s3"); s3Service.putObject(bucket, "index.html", ("INDEX-ON-DISK-" + suffix).getBytes(StandardCharsets.UTF_8), "text/html", Map.of()); - Distribution dist = distributionFor(bucket); + dist = distributionFor(bucket); Response get = given().header("Host", dist.getDomainName()).when().get("/video.bin"); @@ -75,6 +90,9 @@ class CloudFrontS3DiskOriginServingTest { .header("Content-Length", equalTo(Integer.toString(("INDEX-ON-DISK-" + suffix).length()))) .body(containsString("INDEX-ON-DISK-" + suffix)); } finally { + if (dist != null) { + cloudFrontService.removeDistribution(dist.getId()); + } // The bucket is on disk and outlives the test, so it is removed rather than left for the next run. s3Service.deleteObject(bucket, "video.bin"); s3Service.deleteObject(bucket, "index.html"); @@ -82,6 +100,24 @@ class CloudFrontS3DiskOriginServingTest { } } + /** + * Whether a file named for {@code key}, of {@code size} bytes, sits in a directory named for + * {@code bucket}. The bucket name is new on every run, so a file an earlier run left behind + * cannot match. + */ + private static boolean hasObjectFile(Path dir, String bucket, String key, long size) + throws IOException { + if (!Files.isDirectory(dir)) { + return false; + } + try (Stream files = Files.walk(dir)) { + return files.anyMatch(f -> Files.isRegularFile(f) + && f.getParent().getFileName().toString().equals(bucket) + && f.getFileName().toString().startsWith(key) + && f.toFile().length() == size); + } + } + private Distribution distributionFor(String bucket) { Origin origin = new Origin(); origin.setId("disk-origin"); @@ -103,13 +139,4 @@ class CloudFrontS3DiskOriginServingTest { distribution.setConfig(config); return cloudFrontService.createDistribution(distribution, Map.of()); } - - public static final class S3OnDiskProfile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of( - "floci.storage.services.s3.mode", "persistent", - "floci.storage.persistent-path", "target/cloudfront-s3-disk-origin-it"); - } - } } diff --git a/src/test/java/io/github/hectorvent/floci/services/glue/GlueSecurityConfigurationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/glue/GlueSecurityConfigurationIntegrationTest.java index eae39ac90d..37c25614d8 100644 --- a/src/test/java/io/github/hectorvent/floci/services/glue/GlueSecurityConfigurationIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/glue/GlueSecurityConfigurationIntegrationTest.java @@ -3,19 +3,23 @@ package io.github.hectorvent.floci.services.glue; import com.fasterxml.jackson.core.type.TypeReference; import io.github.hectorvent.floci.core.storage.PersistentStorage; import io.github.hectorvent.floci.services.glue.model.SecurityConfiguration; +import io.github.hectorvent.floci.testing.PartitionCleanup; +import io.github.hectorvent.floci.testing.PersistentStorageProfile; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.QuarkusTestProfile; import io.quarkus.test.junit.TestProfile; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; import java.util.UUID; +import static io.github.hectorvent.floci.testing.PersistentStorageProfile.STORAGE_DIR; import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; @@ -23,12 +27,20 @@ import static org.hamcrest.Matchers.instanceOf; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +/** + * Glue security configurations: create, read, list and delete, the errors for a duplicate or a + * missing one, isolation by account and region, and the copy written to + * {@code security_configurations.json}. + * + *

Persistent storage comes from {@link PersistentStorageProfile}, which this class shares with + * other classes that each read their own service's file, so it deletes the configurations it + * creates. + */ @QuarkusTest -@TestProfile(GlueSecurityConfigurationIntegrationTest.PersistentStorageProfile.class) +@TestProfile(PersistentStorageProfile.class) class GlueSecurityConfigurationIntegrationTest { private static final String CONTENT_TYPE = "application/x-amz-json-1.1"; - private static final String STORAGE_DIR = "target/glue-security-configuration-it"; private static final Path STORAGE_FILE = Path.of(STORAGE_DIR, "security_configurations.json"); private static final String NAME = "security-" + UUID.randomUUID().toString().substring(0, 8); private static final String ENCRYPTION = """ @@ -36,6 +48,9 @@ class GlueSecurityConfigurationIntegrationTest { "JobBookmarksEncryption":{"JobBookmarksEncryptionMode":"CSE-KMS"}} """; + @RegisterExtension + final PartitionCleanup cleanup = new PartitionCleanup(); + @BeforeAll static void setup() throws Exception { RestAssuredJsonUtils.configureAwsContentTypes(); @@ -45,6 +60,7 @@ class GlueSecurityConfigurationIntegrationTest { @Test void securityConfigurationCrudAndEncryptionRoundTrip() { create(NAME, "us-east-1", "000000000000"); + cleanup.register(() -> deleteIfPresent(NAME, "us-east-1", "000000000000")); given().contentType(CONTENT_TYPE) .header("X-Amz-Target", "AWSGlue.GetSecurityConfiguration") @@ -77,6 +93,7 @@ class GlueSecurityConfigurationIntegrationTest { @Test void duplicateAndMissingConfigurationsUseAwsErrors() { create(NAME, "us-east-1", "000000000000"); + cleanup.register(() -> deleteIfPresent(NAME, "us-east-1", "000000000000")); given().contentType(CONTENT_TYPE) .header("X-Amz-Target", "AWSGlue.CreateSecurityConfiguration") @@ -98,6 +115,7 @@ class GlueSecurityConfigurationIntegrationTest { @Test void accountAndRegionAreIsolatedAndConfigurationIsPersisted() throws Exception { create(NAME, "us-east-1", "000000000001"); + cleanup.register(() -> delete(NAME, "us-east-1", "000000000001")); given().contentType(CONTENT_TYPE) .header("X-Amz-Target", "AWSGlue.GetSecurityConfiguration") @@ -142,17 +160,18 @@ class GlueSecurityConfigurationIntegrationTest { .then().statusCode(200); } + /** For cleanup: each test deletes its configuration itself, unless an assertion stops it. */ + private static void deleteIfPresent(String name, String region, String account) { + given().contentType(CONTENT_TYPE) + .header("X-Amz-Target", "AWSGlue.DeleteSecurityConfiguration") + .header("Authorization", authorization(account, region)) + .body("{\"Name\":\"" + name + "\"}") + .when().post("/") + .then().statusCode(anyOf(equalTo(200), equalTo(400))); + } + private static String authorization(String account, String region) { return "AWS4-HMAC-SHA256 Credential=" + account + "/20260918/" + region + "/glue/aws4_request, SignedHeaders=host, Signature=abc"; } - - public static final class PersistentStorageProfile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of( - "floci.storage.mode", "persistent", - "floci.storage.persistent-path", STORAGE_DIR); - } - } } diff --git a/src/test/java/io/github/hectorvent/floci/testing/PerServicePersistentStorageProfile.java b/src/test/java/io/github/hectorvent/floci/testing/PerServicePersistentStorageProfile.java new file mode 100644 index 0000000000..ee1f97191e --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/testing/PerServicePersistentStorageProfile.java @@ -0,0 +1,49 @@ +package io.github.hectorvent.floci.testing; + +import io.quarkus.test.junit.QuarkusTestProfile; + +import java.util.Map; + +/** + * DynamoDB, ACM and S3 on persistent storage while every other service stays on the test default, + * memory, for the classes that test a per-service storage mode. Quarkus builds the application + * once per distinct profile class, so they share this one rather than each declaring their own. + * + *

The overrides, and who relies on them: + *

+ * + *

Each override is inert for the other classes, since each reaches a single service and each + * class is the only one here that calls its service. {@code StorageFactoryDuplicateBackendTest} + * clears every store before and after it runs, and writes placeholder strings into DynamoDB's + * table store in between, so no other class here may call DynamoDB, and none may count on state + * outliving its own class. + * + *

Each class also deletes what it creates, so a class that joins later finds nothing left + * behind. A class joins only if no other class here calls its service, and it deletes what it + * creates. + */ +public class PerServicePersistentStorageProfile implements QuarkusTestProfile { + + public static final String STORAGE_DIR = "target/per-service-persistent-storage-it"; + + @Override + public Map getConfigOverrides() { + return Map.of( + "floci.storage.services.dynamodb.mode", "persistent", + "floci.storage.services.acm.mode", "persistent", + "floci.storage.services.s3.mode", "persistent", + "floci.storage.persistent-path", STORAGE_DIR); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/testing/PersistentStorageProfile.java b/src/test/java/io/github/hectorvent/floci/testing/PersistentStorageProfile.java new file mode 100644 index 0000000000..7c009e0a20 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/testing/PersistentStorageProfile.java @@ -0,0 +1,43 @@ +package io.github.hectorvent.floci.testing; + +import io.quarkus.test.junit.QuarkusTestProfile; + +import java.util.Map; + +/** + * Persistent storage as every service's default, in one directory, for the classes that read back + * the file a service writes. Quarkus builds the application once per distinct profile class, so + * they share this one rather than each declaring their own. + * + *

The overrides, and who relies on them: + *

+ * + *

The classes can share the directory because each one deletes and reads only its own + * service's file ({@code workgroups.json}, {@code cloudformation-stacks.json} and + * {@code security_configurations.json}), and is the only class here that calls its service. The + * CloudFormation stack also creates an S3 bucket, and no other class here calls S3. + * + *

Each class also deletes what it creates, so a class that joins later finds nothing left + * behind, in memory or on disk. A class joins only if no other class here calls its service, and + * it deletes what it creates. + */ +public class PersistentStorageProfile implements QuarkusTestProfile { + + public static final String STORAGE_DIR = "target/persistent-storage-it"; + + @Override + public Map getConfigOverrides() { + return Map.of( + "floci.storage.mode", "persistent", + "floci.storage.persistent-path", STORAGE_DIR); + } +}