Files
floci/src/test/java/io/floci/aws/services/dsql/ExternalPostgresResource.java
T
Joaquín Gamboa 3ebd1bc38c feat(dsql): back clusters with an external PostgreSQL server (#8795)
Aurora DSQL clusters needed Docker, so DSQL did not work where Floci has no Docker socket, such as ECS on Fargate. An opt-in external backend (floci.services.dsql.backend=external) now puts each cluster in a database and prefixed roles of its own on a PostgreSQL 16 or later server that is already running. Floci marks what it creates and changes nothing else, derives the backend roles' SCRAM verifiers from a per-cluster secret, and bounds every call to the server. A deleted cluster's sessions end before its roles are listed and dropped, and for both backends shutdown waits for starts and deletions still running. The differences a shared server cannot hide are listed with their reasons in the DSQL docs.

Closes #8486
2026-11-18 15:27:20 -04:00

59 lines
2.4 KiB
Java

package io.floci.aws.services.dsql;
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import org.jboss.logging.Logger;
import java.sql.SQLException;
import java.util.HashMap;
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.
*/
public final class ExternalPostgresResource implements QuarkusTestResourceLifecycleManager {
private static final Logger LOG = Logger.getLogger(ExternalPostgresResource.class);
public static final String PASSWORD = "floci-test";
private ExternalPostgresServer server;
@Override
public Map<String, String> start() {
Map<String, String> overrides = new HashMap<>();
// A real data plane for each cluster, its endpoint on an ephemeral port.
overrides.put("floci.services.dsql.mock", "false");
overrides.put("floci.services.dsql.port", "0");
overrides.put("floci.services.dsql.backend", "external");
overrides.put("floci.services.dsql.external.host", "127.0.0.1");
overrides.put("floci.services.dsql.external.password", PASSWORD);
int port;
try {
server = ExternalPostgresServer.start("floci-dsql-external", PASSWORD, "POSTGRES_PASSWORD=" + PASSWORD,
"POSTGRES_INITDB_ARGS=--auth-host=scram-sha-256");
port = server.port();
} catch (ExternalPostgresServer.DockerUnavailableException e) {
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 (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Interrupted while the external PostgreSQL started", e);
}
overrides.put("floci.services.dsql.external.port", String.valueOf(port));
return overrides;
}
@Override
public void stop() {
if (server != null) {
server.close();
}
}
}