diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ElastiCacheServerlessCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ElastiCacheServerlessCfnIntegrationTest.java index 603e8a655c..d1b1649495 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ElastiCacheServerlessCfnIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ElastiCacheServerlessCfnIntegrationTest.java @@ -1,14 +1,12 @@ package io.github.hectorvent.floci.services.cloudformation; import io.github.hectorvent.floci.core.common.XmlParser; -import io.github.hectorvent.floci.services.elasticache.ServerlessTestProfile; -import io.github.hectorvent.floci.testing.DockerAvailability; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; +import io.github.hectorvent.floci.testing.SidecarContainersProfile; import io.quarkus.test.common.http.TestHTTPResource; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; import io.restassured.specification.RequestSpecification; -import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; @@ -33,9 +31,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * Provisions AWS::ElastiCache::ServerlessCache through CloudFormation. Output values are asserted, * not only the stack status: an unmapped type is stubbed as CREATE_COMPLETE, and its Fn::GetAtt * resolves to the literal "LogicalId.Attr". + * + *

The cache containers are namespaced by {@link SidecarContainersProfile}, which this class + * shares with the other classes whose managers start real containers. The profile it used before + * also mocked RDS and DocumentDB; the stack creates neither, and ElastiCache does not reach them, + * so the shared profile leaves both at the test default. */ @QuarkusTest -@TestProfile(ServerlessTestProfile.class) +@TestProfile(SidecarContainersProfile.class) class ElastiCacheServerlessCfnIntegrationTest { private static final String CFN_AUTH = @@ -85,7 +88,7 @@ class ElastiCacheServerlessCfnIntegrationTest { @Test void serverlessCacheExposesEndpointsAndIsRemovedWithTheStack() throws Exception { - Assumptions.assumeTrue(DockerAvailability.isAvailable(), "Docker is required for the cache data plane"); + SidecarContainersProfile.requireDocker(); cloudFormation(STACK, "CreateStack", TEMPLATE); String stacks = describeStacks(STACK, "CREATE_COMPLETE"); diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiDockerIntegrationTest.java index 50eee4ee10..def19ff616 100644 --- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiDockerIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiDockerIntegrationTest.java @@ -1,8 +1,12 @@ package io.github.hectorvent.floci.services.codeartifact; +import io.github.hectorvent.floci.config.EmulatorConfig; +import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; +import io.github.hectorvent.floci.testing.SidecarContainersProfile; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; +import jakarta.inject.Inject; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; @@ -12,6 +16,7 @@ import org.junit.jupiter.api.TestMethodOrder; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Base64; +import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -23,6 +28,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -34,13 +40,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * is already covered by its own unit tests and by {@code CodeArtifactPypiControllerTest}, so what * this class needs to prove is the real container's behavior, not the parser's fidelity to one * exact client's byte-for-byte output. + * + *

The containers are namespaced by {@link SidecarContainersProfile}, which this class shares + * with the other sidecar classes, so its last test deletes the repositories and domains it created. */ @QuarkusTest -@TestProfile(CodeArtifactPypiSidecarProfile.class) +@TestProfile(SidecarContainersProfile.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) class CodeArtifactPypiDockerIntegrationTest { private static final String AUTH = "AWS4-HMAC-SHA256 Credential=AKID/20260904/us-east-1/codeartifact/aws4_request"; + private static final String NON_DEFAULT_REGION_AUTH = + "AWS4-HMAC-SHA256 Credential=AKID/20260904/us-west-2/codeartifact/aws4_request"; + private static final String OTHER_ACCOUNT_AUTH = + "AWS4-HMAC-SHA256 Credential=111122223333/20260904/us-east-1/codeartifact/aws4_request"; private static final String DOMAIN = "pypi-sidecar-domain"; private static final String REPO = "pypi-sidecar-repo"; private static final String PACKAGE_NAME = "floci-pypiserver-spike"; @@ -51,9 +64,12 @@ class CodeArtifactPypiDockerIntegrationTest { private static String bearerToken; + @Inject + EmulatorConfig config; + @BeforeAll static void setUp() { - CodeArtifactPypiSidecarProfile.requireDockerAndTheSidecarImage(); + SidecarContainersProfile.requireDockerAndImage("floci.services.codeartifact.pypi-image"); RestAssuredJsonUtils.configureAwsContentTypes(); } @@ -290,17 +306,15 @@ class CodeArtifactPypiDockerIntegrationTest { @Test @Order(10) void aDomainCreatedInANonDefaultRegionIsServedThroughTheTokensOwnRegion() { - String nonDefaultRegionAuth = - "AWS4-HMAC-SHA256 Credential=AKID/20260904/us-west-2/codeartifact/aws4_request"; String domain = "pypi-sidecar-non-default-region-domain"; - given().contentType("application/json").header("Authorization", nonDefaultRegionAuth).body("{}") + given().contentType("application/json").header("Authorization", NON_DEFAULT_REGION_AUTH).body("{}") .post("/v1/domain?domain=" + domain) .then().statusCode(200); - given().contentType("application/json").header("Authorization", nonDefaultRegionAuth).body("{}") + given().contentType("application/json").header("Authorization", NON_DEFAULT_REGION_AUTH).body("{}") .post("/v1/repository?domain=" + domain + "&repository=" + REPO) .then().statusCode(200); - String token = given().header("Authorization", nonDefaultRegionAuth) + String token = given().header("Authorization", NON_DEFAULT_REGION_AUTH) .post("/v1/authorization-token?domain=" + domain) .then().statusCode(200) .extract().jsonPath().getString("authorizationToken"); @@ -319,16 +333,15 @@ class CodeArtifactPypiDockerIntegrationTest { @Test @Order(11) void aDomainCreatedUnderANonDefaultAccountIsServedThroughTheTokensOwnAccount() { - String otherAccountAuth = "AWS4-HMAC-SHA256 Credential=111122223333/20260904/us-east-1/codeartifact/aws4_request"; String domain = "pypi-sidecar-cross-account-domain"; - given().contentType("application/json").header("Authorization", otherAccountAuth).body("{}") + given().contentType("application/json").header("Authorization", OTHER_ACCOUNT_AUTH).body("{}") .post("/v1/domain?domain=" + domain) .then().statusCode(200); - given().contentType("application/json").header("Authorization", otherAccountAuth).body("{}") + given().contentType("application/json").header("Authorization", OTHER_ACCOUNT_AUTH).body("{}") .post("/v1/repository?domain=" + domain + "&repository=" + REPO) .then().statusCode(200); - String token = given().header("Authorization", otherAccountAuth) + String token = given().header("Authorization", OTHER_ACCOUNT_AUTH) .post("/v1/authorization-token?domain=" + domain) .then().statusCode(200) .extract().jsonPath().getString("authorizationToken"); @@ -497,9 +510,34 @@ class CodeArtifactPypiDockerIntegrationTest { "state reset must stop reset-repo's pypiserver container"); } - private static int runningPypiserverTestContainerCount() throws IOException, InterruptedException { + /** + * Last, since the class shares {@link SidecarContainersProfile}'s application with the other + * sidecar classes: deletes the repositories and domains the tests above created, which also stops + * their pypiserver containers. + */ + @Test + @Order(99) + void cleanupDeletesTheRepositoriesAndDomainsItCreated() { + deleteDomain(AUTH, DOMAIN, REPO, "other-repo", "concurrent-repo", "reused-name"); + deleteDomain(AUTH, "other-pypi-token-domain"); + deleteDomain(NON_DEFAULT_REGION_AUTH, "pypi-sidecar-non-default-region-domain", REPO); + deleteDomain(OTHER_ACCOUNT_AUTH, "pypi-sidecar-cross-account-domain", REPO); + } + + private static void deleteDomain(String auth, String domain, String... repositories) { + for (String repository : repositories) { + given().header("Authorization", auth) + .delete("/v1/repository?domain=" + domain + "&repository=" + repository); + } + given().header("Authorization", auth).delete("/v1/domain?domain=" + domain); + List domains = given().contentType("application/json").header("Authorization", auth).body("{}") + .post("/v1/domains").then().statusCode(200).extract().jsonPath().getList("domains.name"); + assertFalse(domains.contains(domain), domain + " is still there"); + } + + private int runningPypiserverTestContainerCount() throws IOException, InterruptedException { Process process = new ProcessBuilder("docker", "ps", "-q", - "--filter", "name=floci-aws-codeartifact-pypi-test-pypiserver-") + "--filter", "name=" + ContainerStorageHelper.dockerName(config, "floci-pypiserver-")) .redirectErrorStream(true).start(); String output = new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8); process.waitFor(); diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiSidecarProfile.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiSidecarProfile.java deleted file mode 100644 index d247a98e41..0000000000 --- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiSidecarProfile.java +++ /dev/null @@ -1,52 +0,0 @@ -package io.github.hectorvent.floci.services.codeartifact; - -import io.quarkus.test.junit.QuarkusTestProfile; -import org.eclipse.microprofile.config.ConfigProvider; -import org.junit.jupiter.api.Assumptions; - -import java.util.Map; - -/** - * Shared by every CodeArtifact integration test that needs a real pypiserver sidecar container, - * started by {@link PypiserverSidecarManager} exactly as in production. Namespaces containers as - * {@code floci-codeartifact-pypi-test-*} so the manager's remove-before-start never touches a - * developer's real running Floci. Needs Docker; skipped without it. Locally it is also skipped - * when the pinned image is not present, so a developer without registry access is not stuck; in - * CI a missing image is a failure, since a vanished tag must not pass silently. - */ -public class CodeArtifactPypiSidecarProfile implements QuarkusTestProfile { - - @Override - public Map getConfigOverrides() { - return Map.of("floci.docker.resource-namespace", "codeartifact-pypi-test"); - } - - public static void requireDockerAndTheSidecarImage() { - Assumptions.assumeTrue(isDockerAvailable(), "Docker daemon must be available for CodeArtifact pypi " - + "sidecar integration tests"); - String image = ConfigProvider.getConfig().getValue("floci.services.codeartifact.pypi-image", String.class); - Assumptions.assumeTrue(imageUsable(image), "pypiserver sidecar image " + image + " is not present locally"); - } - - private static boolean isDockerAvailable() { - return run("docker", "version", "--format", "{{.Server.Version}}"); - } - - private static boolean imageUsable(String image) { - if ("true".equals(System.getenv("CI"))) { - return true; - } - return run("docker", "image", "inspect", image); - } - - private static boolean run(String... command) { - try { - Process process = new ProcessBuilder(command).redirectErrorStream(true).start(); - return process.waitFor() == 0; - } catch (Exception ignored) { - // Docker (or the image) isn't available; the caller turns this into a skipped test, - // not a failure, so there is nothing more useful to log here. - return false; - } - } -} diff --git a/src/test/java/io/github/hectorvent/floci/services/ecs/container/EcsContainerManagerEphemeralVolumesDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ecs/container/EcsContainerManagerEphemeralVolumesDockerIntegrationTest.java index 1c72e96506..fb1beda5ce 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ecs/container/EcsContainerManagerEphemeralVolumesDockerIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ecs/container/EcsContainerManagerEphemeralVolumesDockerIntegrationTest.java @@ -4,19 +4,19 @@ import com.github.dockerjava.api.DockerClient; import com.github.dockerjava.api.command.InspectContainerResponse.Mount; import com.github.dockerjava.api.exception.NotFoundException; import com.github.dockerjava.core.command.WaitContainerResultCallback; +import io.github.hectorvent.floci.config.EmulatorConfig; import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper; import io.github.hectorvent.floci.services.ecs.model.ContainerDefinition; import io.github.hectorvent.floci.services.ecs.model.EcsTask; import io.github.hectorvent.floci.services.ecs.model.MountPoint; import io.github.hectorvent.floci.services.ecs.model.TaskDefinition; import io.github.hectorvent.floci.services.ecs.model.Volume; +import io.github.hectorvent.floci.testing.SidecarContainersProfile; import io.github.hectorvent.floci.testing.TestImages; 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.Assumptions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -33,8 +33,16 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +/** + * Verifies that the containers of an ECS task share its ephemeral storage, that stopping the task + * removes it, and that a later run removes the containers and volumes an earlier run left behind. + * + *

The task containers and volumes carry the namespace of {@link SidecarContainersProfile} in + * their owner label, so the leftover removal under test can only reach those of this test run, + * never a developer's running Floci. + */ @QuarkusTest -@TestProfile(EcsContainerManagerEphemeralVolumesDockerIntegrationTest.VolumeProfile.class) +@TestProfile(SidecarContainersProfile.class) class EcsContainerManagerEphemeralVolumesDockerIntegrationTest { @Inject @@ -43,22 +51,14 @@ class EcsContainerManagerEphemeralVolumesDockerIntegrationTest { @Inject DockerClient dockerClient; - private final List handles = new ArrayList<>(); + @Inject + EmulatorConfig config; - public static class VolumeProfile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of("floci.docker.resource-namespace", "ecs-ephemeral-volumes-test"); - } - } + private final List handles = new ArrayList<>(); @BeforeEach void requireDocker() { - try { - dockerClient.pingCmd().exec(); - } catch (Exception unavailable) { - Assumptions.abort("Docker daemon must be available for ephemeral volume integration tests"); - } + SidecarContainersProfile.requireDocker(); } @AfterEach @@ -99,7 +99,8 @@ class EcsContainerManagerEphemeralVolumesDockerIntegrationTest { String volumeName = task.getTaskVolumeNames().iterator().next(); Map labels = dockerClient.inspectVolumeCmd(volumeName).exec().getLabels(); assertEquals("ecs", labels.get(ContainerStorageHelper.SERVICE_LABEL)); - assertEquals("ecs-ephemeral-volumes-test/4566", labels.get(ContainerStorageHelper.OWNER_LABEL)); + assertEquals(SidecarContainersProfile.namespace() + "/" + config.port(), + labels.get(ContainerStorageHelper.OWNER_LABEL)); assertTrue(labels.containsKey(EcsContainerManager.RUN_LABEL)); try { String nextRun = "next-run-" + UUID.randomUUID(); diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessIntegrationTest.java index a3f2fa6c28..6d6306bce4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessIntegrationTest.java @@ -1,12 +1,11 @@ package io.github.hectorvent.floci.services.elasticache; import io.github.hectorvent.floci.services.ec2.Ec2Service; -import io.github.hectorvent.floci.testing.DockerAvailability; +import io.github.hectorvent.floci.testing.SidecarContainersProfile; import io.quarkus.test.common.http.TestHTTPResource; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; import jakarta.inject.Inject; -import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; @@ -29,8 +28,17 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +/** + * Creates, updates and deletes serverless caches, and checks that a Valkey or Memcached cache keeps + * its data across metadata changes and authenticates the current members of its user group. + * + *

The cache containers are namespaced by {@link SidecarContainersProfile}, which this class + * shares with the other classes whose managers start real containers. The profile it used before + * also mocked RDS and DocumentDB; this class calls neither, and ElastiCache does not reach them, so + * the shared profile leaves both at the test default. + */ @QuarkusTest -@TestProfile(ServerlessTestProfile.class) +@TestProfile(SidecarContainersProfile.class) class ElastiCacheServerlessIntegrationTest { @TestHTTPResource URI endpoint; @@ -100,7 +108,7 @@ class ElastiCacheServerlessIntegrationTest { @Test void dockerValkeyPreservesDataAndAuthenticatesCurrentGroupMembers() throws Exception { - Assumptions.assumeTrue(DockerAvailability.isAvailable(), "Docker is required for the serverless data plane"); + SidecarContainersProfile.requireDocker(); try (ElastiCacheClient client = client()) { client.createUser(request -> request.userId("serverless-alice").userName("alice").engine("valkey") .accessString("on ~* +@all").passwords("alice-password-123")); @@ -164,7 +172,7 @@ class ElastiCacheServerlessIntegrationTest { @Test void dockerMemcachedPreservesValuesAcrossMetadataChanges() throws Exception { - Assumptions.assumeTrue(DockerAvailability.isAvailable(), "Docker is required for the serverless Memcached data plane"); + SidecarContainersProfile.requireDocker(); try (ElastiCacheClient client = client()) { try { ServerlessCache cache = client.createServerlessCache(request -> request.serverlessCacheName("serverless-memcached") diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/ServerlessTestProfile.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/ServerlessTestProfile.java deleted file mode 100644 index 18be39a490..0000000000 --- a/src/test/java/io/github/hectorvent/floci/services/elasticache/ServerlessTestProfile.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.hectorvent.floci.services.elasticache; - -import io.quarkus.test.junit.QuarkusTestProfile; - -import java.util.Map; - -public class ServerlessTestProfile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of("floci.services.rds.mock", "true", "floci.services.docdb.mock", "true", - "floci.docker.resource-namespace", "issue4650-serverless"); - } -} diff --git a/src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftSpectrumIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftSpectrumIntegrationTest.java index c467bf0ec5..52cac96454 100644 --- a/src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftSpectrumIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftSpectrumIntegrationTest.java @@ -11,13 +11,12 @@ import io.github.hectorvent.floci.services.redshift.spectrum.ExternalStatementPa import io.github.hectorvent.floci.services.redshift.spectrum.GlueTableBuilder; import io.github.hectorvent.floci.services.s3.S3Service; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; +import io.github.hectorvent.floci.testing.SidecarContainersProfile; import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.QuarkusTestProfile; import io.quarkus.test.junit.TestProfile; import jakarta.inject.Inject; import org.awaitility.Awaitility; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -36,7 +35,6 @@ import java.sql.Statement; import java.time.Duration; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; @@ -48,19 +46,19 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +/** + * Runs Redshift Spectrum queries that read external tables from Glue and S3 through the floci-duck + * sidecar, alone and joined with tables inside the cluster. + * + *

The sidecar reads the objects back from Floci's S3 at {@code floci.base-url}, which + * {@link SidecarContainersProfile} points at the port the test application listens on, and the + * profile namespaces the containers. The class shares that application with the other sidecar + * classes, so as each test ends it deletes the IAM role it created, and only one it created. + */ @QuarkusTest -@TestProfile(RedshiftSpectrumIntegrationTest.SpectrumProfile.class) +@TestProfile(SidecarContainersProfile.class) class RedshiftSpectrumIntegrationTest { - public static class SpectrumProfile implements QuarkusTestProfile { - @Override - public Map getConfigOverrides() { - return Map.of("quarkus.http.test-port", "17866", "quarkus.http.port", "17866", - "floci.base-url", "http://localhost:17866", - "floci.docker.resource-namespace", "spectrum-relational-tests"); - } - } - @Inject RedshiftService redshiftService; @@ -85,27 +83,17 @@ class RedshiftSpectrumIntegrationTest { private String clusterId; private String bucket; private String glueDatabase; + private boolean roleCreated; @BeforeAll static void requireDocker() { - Assumptions.assumeTrue(isDockerAvailable(), "Docker daemon must be available for Redshift Spectrum integration tests"); - } - - private static boolean isDockerAvailable() { - try { - Process process = new ProcessBuilder("docker", "version", "--format", "{{.Server.Version}}") - .redirectErrorStream(true) - .start(); - int exit = process.waitFor(); - return exit == 0; - } catch (Exception ignored) { - return false; - } + SidecarContainersProfile.requireDocker(); } private Cluster createClusterWithRole(String identifier) { if (iamService.findRole("000000000000", ROLE_NAME).isEmpty()) { iamService.createRole(ROLE_NAME, "/", TRUST_POLICY, null, 0, null); + roleCreated = true; iamService.putRolePolicy(ROLE_NAME, "AllowS3", """ {"Version":"2012-10-17","Statement":[{"Effect":"Allow", "Action":["s3:GetObject","s3:ListBucket"],"Resource":"*"}]}"""); @@ -127,6 +115,10 @@ class RedshiftSpectrumIntegrationTest { if (glueDatabase != null) { glueService.deleteDatabase(glueDatabase); } + if (roleCreated) { + iamService.deleteRolePolicy(ROLE_NAME, "AllowS3"); + iamService.deleteRole(ROLE_NAME); + } } @Test diff --git a/src/test/java/io/github/hectorvent/floci/testing/SidecarContainersProfile.java b/src/test/java/io/github/hectorvent/floci/testing/SidecarContainersProfile.java index 6eb4efe278..f060d2226b 100644 --- a/src/test/java/io/github/hectorvent/floci/testing/SidecarContainersProfile.java +++ b/src/test/java/io/github/hectorvent/floci/testing/SidecarContainersProfile.java @@ -17,9 +17,10 @@ import java.util.Map; /** * Shared by every integration test that runs a real sidecar container, started by its manager - * exactly as in production: the AppSync GraphQL sidecar, the CodeArtifact Reposilite and Verdaccio - * sidecars, the Verified Permissions Cedar sidecar, and the floci-duck sidecar behind the CUR - * Parquet emitter. Quarkus builds the application once per distinct profile class, so these + * exactly as in production: the AppSync GraphQL sidecar, the CodeArtifact Reposilite, Verdaccio, + * BaGetter and pypiserver sidecars, the Verified Permissions Cedar sidecar, the floci-duck sidecar + * behind the CUR Parquet emitter and Redshift Spectrum, ECS task containers and ElastiCache + * serverless caches. Quarkus builds the application once per distinct profile class, so these * classes share one application rather than each paying for their own. * *

Namespaces the containers as {@code floci-aws-sidecar-test---}. Each @@ -29,8 +30,9 @@ import java.util.Map; * other. The test JVM's process id keeps two runs on one machine apart, since two live processes * never share an id; the host key, a short hash of the host name and the process id namespace, * does the same for runs on other machines or in containers that share the Docker daemon, whose - * process ids mean nothing here. A normal shutdown stops the sidecars; those of a run that was - * killed are removed by the next run on the same host key, in {@link #removeAbandonedSidecars()}. + * process ids mean nothing here. A normal shutdown stops the sidecars; the containers and volumes + * of a run that was killed are removed by the next run on the same host key, in + * {@link #removeAbandonedSidecars()}. * *

Also sets the HTTP port, {@code floci.port} and {@code floci.base-url} together. The AppSync * resolver callback URL a launched container uses is built from {@code quarkus.http.port}, which in @@ -117,19 +119,29 @@ public class SidecarContainersProfile implements QuarkusTestProfile { * in CI a missing image is a failure, since a vanished tag must not pass silently. */ public static void requireDockerAndImage(String imageProperty) { - Assumptions.assumeTrue(isDockerAvailable(), "Docker daemon must be available for sidecar integration tests"); - removeAbandonedSidecars(); + requireDocker(); String image = ConfigProvider.getConfig().getValue(imageProperty, String.class); Assumptions.assumeTrue(imageUsable(image), "Sidecar image " + image + " is not present locally"); } /** - * Removes the sidecars of earlier runs that were killed before they could stop them: containers - * in a {@code sidecar-test--} namespace carrying this host key, whose process no - * longer exists. They would otherwise keep running and hold their published host ports, and no - * later run would ever share their names to replace them. Sidecars of this run and of any other - * live run are left alone, and so is every namespace with another host key, whose process id - * cannot be checked from here. Runs once per JVM, from the first class that needs Docker. + * Skips the calling class or test without Docker, for one whose manager pulls the image it + * needs itself, and removes what killed runs left behind, as {@link #requireDockerAndImage} does. + */ + public static void requireDocker() { + Assumptions.assumeTrue(isDockerAvailable(), "Docker daemon must be available for sidecar integration tests"); + removeAbandonedSidecars(); + } + + /** + * Removes the containers and volumes of earlier runs that were killed before they could remove + * them: those in a {@code sidecar-test--} namespace carrying this host key, whose + * process no longer exists. The containers would otherwise keep running and hold their published + * host ports, and no later run would ever share their names or owner label to replace them or + * sweep their volumes, such as an ECS task's. The containers go first, since a volume still + * mounted cannot be removed. Those of this run and of any other live run are left alone, and so + * is every namespace with another host key, whose process id cannot be checked from here. Runs + * once per JVM, from the first class that needs Docker. */ private static synchronized void removeAbandonedSidecars() { if (abandonedSidecarsRemoved) { @@ -143,6 +155,13 @@ public class SidecarContainersProfile implements QuarkusTestProfile { run("docker", "rm", "-f", idAndNamespace[0]); } } + for (String line : output("docker", "volume", "ls", "--filter", "label=floci_namespace", + "--format", "{{.Name}} {{.Label \"floci_namespace\"}}")) { + String[] nameAndNamespace = line.split(" ", 2); + if (nameAndNamespace.length == 2 && isAbandoned(nameAndNamespace[1])) { + run("docker", "volume", "rm", nameAndNamespace[0]); + } + } } private static boolean isAbandoned(String namespace) {