From 6372b315f059a4a05a64e1cf19bc39e1c86da043 Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Wed, 18 Nov 2026 20:48:39 -0400 Subject: [PATCH] test: fold the DSQL external backend profile into a shared sidecar profile (#8923) DsqlExternalBackendIntegrationTest runs on SidecarAccessEnforcementProfile now, renamed SidecarServiceSettingsProfile since it no longer holds only access settings, and that profile takes ExternalPostgresResource as its test resource. DsqlExternalBackendProfile goes. The DSQL backend is chosen once per application, so the external one cannot join SidecarContainersProfile, whose DSQL classes run each cluster in a container of its own. The Redshift classes here create no DSQL cluster, and the DSQL class sends no S3 request and runs no Spectrum query, so neither side's settings reach the other's requests. Since the application is shared now, a PostgreSQL server that does not start no longer fails the boot: the resource records why, and only the DSQL class fails, with that cause. In CI a failed image pull is such a failure rather than a skip, as a sidecar image's is. The container carries the run's sidecar namespace, so the next run removes it when a killed run leaves it behind. --- .../DsqlExternalBackendIntegrationTest.java | 9 +++++- .../dsql/DsqlExternalBackendProfile.java | 13 --------- .../dsql/ExternalPostgresResource.java | 15 +++++++--- .../services/dsql/ExternalPostgresServer.java | 16 +++++++++-- ...tSpectrumLakeFormationIntegrationTest.java | 6 ++-- ...SpectrumS3AuthEnforcedIntegrationTest.java | 4 +-- ...iftUnloadParquetS3AuthIntegrationTest.java | 4 +-- ...ava => SidecarServiceSettingsProfile.java} | 28 +++++++++++++++---- 8 files changed, 62 insertions(+), 33 deletions(-) delete mode 100644 src/test/java/io/floci/aws/services/dsql/DsqlExternalBackendProfile.java rename src/test/java/io/floci/aws/testing/{SidecarAccessEnforcementProfile.java => SidecarServiceSettingsProfile.java} (56%) 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)); + } }