diff --git a/src/test/java/io/floci/aws/services/dsql/DsqlExternalBackendIntegrationTest.java b/src/test/java/io/floci/aws/services/dsql/DsqlExternalBackendIntegrationTest.java index ceff631911..6e1ace396d 100644 --- a/src/test/java/io/floci/aws/services/dsql/DsqlExternalBackendIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/dsql/DsqlExternalBackendIntegrationTest.java @@ -3,6 +3,7 @@ package io.floci.aws.services.dsql; import com.github.dockerjava.api.DockerClient; import io.floci.aws.services.dsql.dataplane.DsqlEndpoint; import io.floci.aws.services.iam.IamService; +import io.floci.aws.testing.SidecarServiceSettingsProfile; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; import jakarta.inject.Inject; @@ -24,6 +25,7 @@ import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -34,6 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Aurora DSQL's data plane with every cluster on one external PostgreSQL server that wants @@ -41,7 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * logs in to the cluster's own database as the cluster's backend admin. */ @QuarkusTest -@TestProfile(DsqlExternalBackendProfile.class) +@TestProfile(SidecarServiceSettingsProfile.class) @TestInstance(TestInstance.Lifecycle.PER_CLASS) @Tag("docker") class DsqlExternalBackendIntegrationTest { @@ -64,6 +67,9 @@ class DsqlExternalBackendIntegrationTest { @ConfigProperty(name = "floci.services.dsql.external.port") int serverPort; + @ConfigProperty(name = ExternalPostgresResource.START_FAILURE) + Optional serverStartFailure; + private static final String ROLE_ARN = "arn:aws:iam::" + DsqlClusterFixture.ACCOUNT + ":role/service/app-role"; private ExternalPostgresServer.Superuser postgres; @@ -72,6 +78,7 @@ class DsqlExternalBackendIntegrationTest { @BeforeAll void createCluster() { + serverStartFailure.ifPresent(cause -> fail("The external PostgreSQL did not start: " + cause)); postgres = new ExternalPostgresServer.Superuser(serverPort, ExternalPostgresResource.PASSWORD); cluster = new DsqlClusterFixture(httpPort, endpoint); cluster.create(dockerClient); diff --git a/src/test/java/io/floci/aws/services/dsql/DsqlExternalBackendProfile.java b/src/test/java/io/floci/aws/services/dsql/DsqlExternalBackendProfile.java deleted file mode 100644 index 38f1d6ca99..0000000000 --- a/src/test/java/io/floci/aws/services/dsql/DsqlExternalBackendProfile.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.floci.aws.services.dsql; - -import io.quarkus.test.junit.QuarkusTestProfile; - -import java.util.List; - -/** Clusters on one external PostgreSQL server, {@link ExternalPostgresResource}, instead of a container each. */ -public final class DsqlExternalBackendProfile implements QuarkusTestProfile { - @Override - public List testResources() { - return List.of(new TestResourceEntry(ExternalPostgresResource.class)); - } -} diff --git a/src/test/java/io/floci/aws/services/dsql/ExternalPostgresResource.java b/src/test/java/io/floci/aws/services/dsql/ExternalPostgresResource.java index 5c4c5c60b1..068bed7121 100644 --- a/src/test/java/io/floci/aws/services/dsql/ExternalPostgresResource.java +++ b/src/test/java/io/floci/aws/services/dsql/ExternalPostgresResource.java @@ -10,8 +10,10 @@ import java.util.Map; /** * A throwaway PostgreSQL 16 that wants SCRAM-SHA-256 passwords, as a shared server does, started * before Floci boots and set as the external DSQL backend. Without Docker the overrides point at a - * port where nothing listens, and {@link DsqlClusterFixture#create} skips the test class; any other - * failure to start the server fails the boot, with its cause. + * port where nothing listens, and {@link DsqlClusterFixture#create} skips the test class. Any other + * failure to start the server points them there too and sets {@link #START_FAILURE} to its cause, + * for the test class to fail with: the application still boots, since classes that need no + * PostgreSQL share it. */ public final class ExternalPostgresResource implements QuarkusTestResourceLifecycleManager { @@ -19,6 +21,9 @@ public final class ExternalPostgresResource implements QuarkusTestResourceLifecy public static final String PASSWORD = "floci-test"; + /** Why the server did not start, when that fails the test class rather than skips it. */ + public static final String START_FAILURE = "floci-test.dsql-external.start-failure"; + private ExternalPostgresServer server; @Override @@ -39,8 +44,10 @@ public final class ExternalPostgresResource implements QuarkusTestResourceLifecy LOG.warnv(e, "No external PostgreSQL for the DSQL tests; they skip"); // Nothing listens on port 1; the tests skip before they create a cluster. port = 1; - } catch (SQLException e) { - throw new IllegalStateException("The external PostgreSQL for the DSQL tests did not start", e); + } catch (SQLException | RuntimeException e) { + LOG.errorv(e, "The external PostgreSQL for the DSQL tests did not start"); + overrides.put(START_FAILURE, String.valueOf(e)); + port = 1; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("Interrupted while the external PostgreSQL started", e); diff --git a/src/test/java/io/floci/aws/services/dsql/ExternalPostgresServer.java b/src/test/java/io/floci/aws/services/dsql/ExternalPostgresServer.java index e4769582d1..a6736228ce 100644 --- a/src/test/java/io/floci/aws/services/dsql/ExternalPostgresServer.java +++ b/src/test/java/io/floci/aws/services/dsql/ExternalPostgresServer.java @@ -9,6 +9,7 @@ import com.github.dockerjava.api.model.PortBinding; import com.github.dockerjava.api.model.Ports; import io.floci.aws.services.dsql.dataplane.DsqlDatabases; import io.floci.aws.testing.DockerAvailability; +import io.floci.aws.testing.SidecarContainersProfile; import io.floci.aws.testing.TestDockerClients; import org.jboss.logging.Logger; @@ -21,6 +22,7 @@ import java.sql.Statement; import java.time.Duration; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -29,7 +31,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** * A throwaway PostgreSQL 16 in Docker for the external DSQL backend's tests, bound to a free port * on 127.0.0.1, whose superuser is {@code postgres}. {@link #close()} removes the container and - * always closes the Docker client. + * always closes the Docker client. The container carries this run's + * {@link SidecarContainersProfile#namespace() sidecar namespace}, so the next run on the host + * removes it when this one is killed before it could. */ public final class ExternalPostgresServer implements AutoCloseable { @@ -86,7 +90,10 @@ public final class ExternalPostgresServer implements AutoCloseable { } } - /** Docker, or the image, is not there; a test skips rather than fails. Its cause says why. */ + /** + * Docker is not there, or, outside CI, the image; a test skips rather than fails. Its cause + * says why. + */ public static final class DockerUnavailableException extends Exception { DockerUnavailableException(String message, Throwable cause) { super(message, cause); @@ -110,6 +117,10 @@ public final class ExternalPostgresServer implements AutoCloseable { try { dockerClient.pullImageCmd(IMAGE).start().awaitCompletion(120, TimeUnit.SECONDS); } catch (RuntimeException e) { + if ("true".equals(System.getenv("CI"))) { + // In CI a missing image fails, as a sidecar's does, so a vanished tag cannot pass silently. + throw e; + } throw new DockerUnavailableException("Docker or " + IMAGE + " is not available: " + e.getMessage(), e); } List environment = new ArrayList<>(List.of("POSTGRES_USER=postgres")); @@ -117,6 +128,7 @@ public final class ExternalPostgresServer implements AutoCloseable { ExposedPort exposed = ExposedPort.tcp(5432); containerId = dockerClient.createContainerCmd(IMAGE) .withName(name + "-" + UUID.randomUUID()) + .withLabels(Map.of("floci_namespace", SidecarContainersProfile.namespace())) .withEnv(environment) .withExposedPorts(exposed) .withHostConfig(HostConfig.newHostConfig() diff --git a/src/test/java/io/floci/aws/services/redshift/RedshiftSpectrumLakeFormationIntegrationTest.java b/src/test/java/io/floci/aws/services/redshift/RedshiftSpectrumLakeFormationIntegrationTest.java index 33448dcb77..ead4bd1ee3 100644 --- a/src/test/java/io/floci/aws/services/redshift/RedshiftSpectrumLakeFormationIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/redshift/RedshiftSpectrumLakeFormationIntegrationTest.java @@ -17,8 +17,8 @@ import io.floci.aws.services.redshift.spectrum.ExternalStatement; import io.floci.aws.services.redshift.spectrum.ExternalStatementParser; import io.floci.aws.services.redshift.spectrum.GlueTableBuilder; import io.floci.aws.services.s3.S3Service; -import io.floci.aws.testing.SidecarAccessEnforcementProfile; import io.floci.aws.testing.SidecarContainersProfile; +import io.floci.aws.testing.SidecarServiceSettingsProfile; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; import jakarta.inject.Inject; @@ -44,11 +44,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * grant on the table, and a revoke stops the next query even though the table is already cached. * *

It takes new tables away from IAM in the account's Data Lake settings, and puts AWS's defaults - * back when it is done, since the other classes on {@link SidecarAccessEnforcementProfile} read + * back when it is done, since the other classes on {@link SidecarServiceSettingsProfile} read * their external tables with no Lake Formation grant. */ @QuarkusTest -@TestProfile(SidecarAccessEnforcementProfile.class) +@TestProfile(SidecarServiceSettingsProfile.class) class RedshiftSpectrumLakeFormationIntegrationTest { private static final String REGION = "us-east-1"; diff --git a/src/test/java/io/floci/aws/services/redshift/RedshiftSpectrumS3AuthEnforcedIntegrationTest.java b/src/test/java/io/floci/aws/services/redshift/RedshiftSpectrumS3AuthEnforcedIntegrationTest.java index 6ec9b37ea3..ea8cfac605 100644 --- a/src/test/java/io/floci/aws/services/redshift/RedshiftSpectrumS3AuthEnforcedIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/redshift/RedshiftSpectrumS3AuthEnforcedIntegrationTest.java @@ -9,8 +9,8 @@ import io.floci.aws.services.redshift.spectrum.ExternalStatementParser; import io.floci.aws.services.redshift.spectrum.GlueTableBuilder; import io.floci.aws.services.s3.S3Service; import io.floci.aws.testing.RestAssuredJsonUtils; -import io.floci.aws.testing.SidecarAccessEnforcementProfile; import io.floci.aws.testing.SidecarContainersProfile; +import io.floci.aws.testing.SidecarServiceSettingsProfile; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; import jakarta.inject.Inject; @@ -37,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * role stops the next query with SQLSTATE 42501 even though the table is already cached. */ @QuarkusTest -@TestProfile(SidecarAccessEnforcementProfile.class) +@TestProfile(SidecarServiceSettingsProfile.class) class RedshiftSpectrumS3AuthEnforcedIntegrationTest { private static final String ROLE_NAME = "SpectrumAuthItRole"; diff --git a/src/test/java/io/floci/aws/services/redshift/RedshiftUnloadParquetS3AuthIntegrationTest.java b/src/test/java/io/floci/aws/services/redshift/RedshiftUnloadParquetS3AuthIntegrationTest.java index f2d8fe1235..052d0f9217 100644 --- a/src/test/java/io/floci/aws/services/redshift/RedshiftUnloadParquetS3AuthIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/redshift/RedshiftUnloadParquetS3AuthIntegrationTest.java @@ -4,8 +4,8 @@ import io.floci.aws.services.iam.IamService; import io.floci.aws.services.redshift.model.Cluster; import io.floci.aws.services.s3.S3Service; import io.floci.aws.services.s3.model.S3Object; -import io.floci.aws.testing.SidecarAccessEnforcementProfile; import io.floci.aws.testing.SidecarContainersProfile; +import io.floci.aws.testing.SidecarServiceSettingsProfile; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; import jakarta.inject.Inject; @@ -25,7 +25,7 @@ import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.*; @QuarkusTest -@TestProfile(SidecarAccessEnforcementProfile.class) +@TestProfile(SidecarServiceSettingsProfile.class) class RedshiftUnloadParquetS3AuthIntegrationTest { @Inject RedshiftService redshift; diff --git a/src/test/java/io/floci/aws/testing/SidecarAccessEnforcementProfile.java b/src/test/java/io/floci/aws/testing/SidecarServiceSettingsProfile.java similarity index 56% rename from src/test/java/io/floci/aws/testing/SidecarAccessEnforcementProfile.java rename to src/test/java/io/floci/aws/testing/SidecarServiceSettingsProfile.java index 0bef43f270..30fbaa5db6 100644 --- a/src/test/java/io/floci/aws/testing/SidecarAccessEnforcementProfile.java +++ b/src/test/java/io/floci/aws/testing/SidecarServiceSettingsProfile.java @@ -1,13 +1,16 @@ package io.floci.aws.testing; +import io.floci.aws.services.dsql.ExternalPostgresResource; + import java.util.HashMap; +import java.util.List; import java.util.Map; /** - * {@link SidecarContainersProfile} with S3 request authentication and Lake Formation enforced on - * Spectrum queries, for the Redshift classes that check what a cluster's role may read and write. - * Quarkus builds the application once per distinct profile class, and keeps every one it built for - * the rest of the test JVM, so they share this one rather than each declaring their own. + * {@link SidecarContainersProfile}'s namespace and port with service settings its own classes + * cannot take, for the container-backed classes that each rely on one of them. Quarkus builds the + * application once per distinct profile class, and keeps every one it built for the rest of the + * test JVM, so they share this one rather than each declaring their own. * *

The overrides, on top of the sidecar settings, and who relies on them: *

    @@ -19,6 +22,11 @@ import java.util.Map; *
  • {@code floci.services.redshift.spectrum-lake-formation-enforcement=true} lets a Spectrum * query read an external table only when Lake Formation lets the external schema's role select * from it. {@code RedshiftSpectrumLakeFormationIntegrationTest} relies on it.
  • + *
  • {@link ExternalPostgresResource} starts a PostgreSQL server before Floci boots and makes it + * the DSQL backend, with {@code floci.services.dsql.mock=false}, so every cluster's database is + * on that one server instead of in a container of its own. + * {@code DsqlExternalBackendIntegrationTest} relies on it. A server that does not start fails + * only that class: the resource records why, and the application boots anyway.
  • *
* *

Each is inert where no class relies on it. Lake Formation leaves a table to IAM while the @@ -26,12 +34,15 @@ import java.util.Map; * query of the S3 class passes it. The Lake Formation class takes new tables away from IAM to * check its grants, and puts AWS's defaults back once it is done. Its role may read the bucket it * queries, so the signed session it gets under S3 authentication reads the table as before. The - * UNLOAD class reads no external table. + * UNLOAD class reads no external table. The Redshift classes create no DSQL cluster, and the DSQL + * class sends no S3 request and runs no Spectrum query. The DSQL classes on + * {@link SidecarContainersProfile} run each cluster in a container of its own, the default + * backend, which is why the external one is here rather than there. * *

A class joins if every setting here is either one it relies on or one that never reaches its * requests, and if any setting it adds never reaches the requests of a class already here. */ -public class SidecarAccessEnforcementProfile extends SidecarContainersProfile { +public class SidecarServiceSettingsProfile extends SidecarContainersProfile { @Override public Map getConfigOverrides() { @@ -40,4 +51,9 @@ public class SidecarAccessEnforcementProfile extends SidecarContainersProfile { overrides.put("floci.services.redshift.spectrum-lake-formation-enforcement", "true"); return overrides; } + + @Override + public List testResources() { + return List.of(new TestResourceEntry(ExternalPostgresResource.class)); + } }