mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(core): give launched containers the port Floci listens on (#5754)
ContainerReachableEndpoint now picks the port a launched container can reach (quarkus.http.port, or floci.port under TLS), but three sites kept their own copy of the old logic: - FlociDuckClient built the sidecar's S3 endpoint from the floci.base-url port, which under -p 4811:4566 is a host-only port. It now calls ContainerReachableEndpoint.baseUrl(). - CodeBuildRunner set AWS_ENDPOINT_URL from floci.port. It now takes the port from ContainerReachableEndpoint.port(); hostname logic unchanged. - EmulatorLifecycle.onHttpStart compared the started server's port with floci.port (or a hardcoded 4510 under TLS), so start/ready hooks never ran with QUARKUS_HTTP_PORT overridden alone. It now compares against quarkus.http.port, which TlsConfigSource already pins to the TLS backend. The DuckDB-backed test profiles set quarkus.http.port alongside their test port, as SidecarContainersProfile does.
This commit is contained in:
1 parent
ae3ff3405a
commit
8362d0817d
9 files changed
+105
-47
No files matched your search
@@ -418,7 +418,6 @@ class EmulatorLifecycleTest {
|
||||
@Test
|
||||
@DisplayName("onHttpStart on port 4566 (non-TLS) triggers hook execution and marks lifecycle completed")
|
||||
void onHttpStart_nonTls_triggersHooksOnPort4566() throws IOException, InterruptedException {
|
||||
when(tlsConfig.enabled()).thenReturn(false);
|
||||
when(initializationHooksRunner.hasHooks(InitializationHook.START)).thenReturn(true);
|
||||
when(initializationHooksRunner.hasHooks(InitializationHook.READY)).thenReturn(false);
|
||||
|
||||
@@ -432,7 +431,7 @@ class EmulatorLifecycleTest {
|
||||
@DisplayName("onHttpStart on a non-default floci.port (non-TLS) triggers hook execution (#2437)")
|
||||
void onHttpStart_nonTls_triggersHooksOnCustomPort() throws IOException, InterruptedException {
|
||||
Mockito.lenient().when(config.port()).thenReturn(4577);
|
||||
when(tlsConfig.enabled()).thenReturn(false);
|
||||
emulatorLifecycle.httpPort = 4577;
|
||||
when(initializationHooksRunner.hasHooks(InitializationHook.START)).thenReturn(true);
|
||||
when(initializationHooksRunner.hasHooks(InitializationHook.READY)).thenReturn(true);
|
||||
|
||||
@@ -444,10 +443,23 @@ class EmulatorLifecycleTest {
|
||||
verify(initLifecycleState).markReadyCompleted();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("onHttpStart on quarkus.http.port overridden alone (non-TLS) triggers hook execution")
|
||||
void onHttpStart_nonTls_triggersHooksOnHttpPortOverride() throws IOException, InterruptedException {
|
||||
// QUARKUS_HTTP_PORT=4811 with floci.port left at 4566: the server listens on 4811.
|
||||
emulatorLifecycle.httpPort = 4811;
|
||||
when(initializationHooksRunner.hasHooks(InitializationHook.START)).thenReturn(true);
|
||||
when(initializationHooksRunner.hasHooks(InitializationHook.READY)).thenReturn(false);
|
||||
|
||||
emulatorLifecycle.onHttpStart(new HttpServerStart(new HttpServerOptions().setPort(4811)));
|
||||
|
||||
verify(initializationHooksRunner).run(InitializationHook.START);
|
||||
verify(initLifecycleState).markStartCompleted();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("onHttpStart on wrong port (non-TLS) is ignored")
|
||||
void onHttpStart_nonTls_ignoresWrongPort() throws IOException, InterruptedException {
|
||||
when(tlsConfig.enabled()).thenReturn(false);
|
||||
|
||||
emulatorLifecycle.onHttpStart(new HttpServerStart(new HttpServerOptions().setPort(4510)));
|
||||
|
||||
@@ -458,7 +470,8 @@ class EmulatorLifecycleTest {
|
||||
@Test
|
||||
@DisplayName("onHttpStart on port 4510 (TLS mode) triggers hook execution and marks lifecycle completed")
|
||||
void onHttpStart_tls_triggersHooksOnBackendPort4510() throws IOException, InterruptedException {
|
||||
when(tlsConfig.enabled()).thenReturn(true);
|
||||
// TlsConfigSource pins quarkus.http.port to the internal HTTP backend.
|
||||
emulatorLifecycle.httpPort = 4510;
|
||||
when(initializationHooksRunner.hasHooks(InitializationHook.START)).thenReturn(true);
|
||||
when(initializationHooksRunner.hasHooks(InitializationHook.READY)).thenReturn(false);
|
||||
|
||||
@@ -471,7 +484,8 @@ class EmulatorLifecycleTest {
|
||||
@Test
|
||||
@DisplayName("onHttpStart on port 4566 (TLS mode) is ignored — public port is not the backend port")
|
||||
void onHttpStart_tls_ignoresPublicPort4566() throws IOException, InterruptedException {
|
||||
when(tlsConfig.enabled()).thenReturn(true);
|
||||
// TlsConfigSource pins quarkus.http.port to the internal HTTP backend.
|
||||
emulatorLifecycle.httpPort = 4510;
|
||||
|
||||
emulatorLifecycle.onHttpStart(new HttpServerStart(new HttpServerOptions().setPort(4566)));
|
||||
|
||||
@@ -482,7 +496,6 @@ class EmulatorLifecycleTest {
|
||||
@Test
|
||||
@DisplayName("onHttpStart exits the process when a startup hook is interrupted")
|
||||
void onHttpStart_hookInterrupted_exitsProcess() throws IOException, InterruptedException {
|
||||
when(tlsConfig.enabled()).thenReturn(false);
|
||||
when(initializationHooksRunner.hasHooks(InitializationHook.START)).thenReturn(true);
|
||||
when(initializationHooksRunner.hasHooks(InitializationHook.READY)).thenReturn(false);
|
||||
doThrow(new InterruptedException("interrupted"))
|
||||
@@ -741,7 +754,6 @@ class EmulatorLifecycleTest {
|
||||
@Test
|
||||
@DisplayName("Should emit the parity \"Ready.\" line on the deferred onHttpStart ready path too")
|
||||
void shouldEmitParityReadyLineOnHttpStartPath() throws IOException, InterruptedException {
|
||||
when(tlsConfig.enabled()).thenReturn(false);
|
||||
when(initializationHooksRunner.hasHooks(InitializationHook.START)).thenReturn(true);
|
||||
when(initializationHooksRunner.hasHooks(InitializationHook.READY)).thenReturn(false);
|
||||
|
||||
|
||||
+19
-2
@@ -9,6 +9,9 @@ import com.github.dockerjava.api.command.InspectExecCmd;
|
||||
import com.github.dockerjava.api.command.InspectExecResponse;
|
||||
import com.github.dockerjava.api.model.Frame;
|
||||
import com.github.dockerjava.api.model.StreamType;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerReachableEndpoint;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -33,7 +36,7 @@ class CodeBuildRunnerTest {
|
||||
int chunkCount = 320;
|
||||
String lastLine = "error: build step failed\n";
|
||||
DockerClient dockerClient = dockerClientStreaming(chunk, chunkCount, lastLine, 2L);
|
||||
CodeBuildRunner runner = new CodeBuildRunner(dockerClient, null, null, null, null, null, null, null, null, null);
|
||||
CodeBuildRunner runner = new CodeBuildRunner(dockerClient, null, null, null, null, null, null, null, null, null, null);
|
||||
|
||||
CodeBuildRunner.PhaseResult result = runner.runPhase("container-1", "/src", List.of(),
|
||||
List.of("./build.sh"), 60, new AtomicBoolean(false));
|
||||
@@ -46,7 +49,7 @@ class CodeBuildRunnerTest {
|
||||
@Test
|
||||
void failureMessageIgnoresLongTrailingWhitespace() {
|
||||
DockerClient dockerClient = dockerClientStreaming(new byte[0], 0, "tests failed" + "\n".repeat(10_000), 1L);
|
||||
CodeBuildRunner runner = new CodeBuildRunner(dockerClient, null, null, null, null, null, null, null, null, null);
|
||||
CodeBuildRunner runner = new CodeBuildRunner(dockerClient, null, null, null, null, null, null, null, null, null, null);
|
||||
|
||||
CodeBuildRunner.PhaseResult result = runner.runPhase("container-1", "/src", List.of(),
|
||||
List.of("./test.sh"), 60, new AtomicBoolean(false));
|
||||
@@ -54,6 +57,20 @@ class CodeBuildRunnerTest {
|
||||
assertEquals("Exit code 1: tests failed", result.errorMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointUrlUsesListenPortNotFlociPort() {
|
||||
// QUARKUS_HTTP_PORT=4811 with floci.port left at 4566: the server listens on 4811.
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
when(config.tls()).thenReturn(mock(EmulatorConfig.TlsConfig.class));
|
||||
when(config.port()).thenReturn(4566);
|
||||
ContainerDetector containerDetector = mock(ContainerDetector.class);
|
||||
ContainerReachableEndpoint endpoint = new ContainerReachableEndpoint(config, null, null, 4811);
|
||||
CodeBuildRunner runner = new CodeBuildRunner(null, null, null, null, null, null, null,
|
||||
config, containerDetector, null, endpoint);
|
||||
|
||||
assertEquals("http://host.docker.internal:4811", runner.resolveEndpointUrl());
|
||||
}
|
||||
|
||||
private static DockerClient dockerClientStreaming(byte[] chunk, int chunkCount, String lastLine, long exitCode) {
|
||||
DockerClient dockerClient = mock(DockerClient.class);
|
||||
|
||||
|
||||
+36
-2
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerReachableEndpoint;
|
||||
import io.github.hectorvent.floci.core.common.docker.DockerHostResolver;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -53,11 +54,44 @@ class FlociDuckClientServiceTest {
|
||||
when(config.hostname()).thenReturn(Optional.of("floci.internal"));
|
||||
when(embeddedDnsServer.getServerIp()).thenReturn(Optional.of("127.0.0.1"));
|
||||
|
||||
FlociDuckClient client = new FlociDuckClient(
|
||||
duckManager, config, embeddedDnsServer, dockerHostResolver, mapper);
|
||||
when(config.tls()).thenReturn(mock(EmulatorConfig.TlsConfig.class));
|
||||
|
||||
FlociDuckClient client = new FlociDuckClient(duckManager, config,
|
||||
new ContainerReachableEndpoint(config, dockerHostResolver, embeddedDnsServer, 4566), mapper);
|
||||
client.execute("CREATE VIEW example AS SELECT 1", "", null);
|
||||
|
||||
assertEquals("CREATE VIEW example AS SELECT 1", requestBody.get().path("sql").asText());
|
||||
assertFalse(requestBody.get().has("output_s3_path"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void s3EndpointUsesListenPortNotAdvertisedPort() throws Exception {
|
||||
// docker run -p 4811:4566 -e FLOCI_BASE_URL=http://localhost:4811: 4811 exists only on the
|
||||
// host, so the sidecar must call Floci on the port it listens on.
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
AtomicReference<JsonNode> requestBody = new AtomicReference<>();
|
||||
server = HttpServer.create(new InetSocketAddress(0), 0);
|
||||
server.createContext("/execute", exchange -> {
|
||||
requestBody.set(mapper.readTree(exchange.getRequestBody().readAllBytes()));
|
||||
exchange.sendResponseHeaders(200, -1);
|
||||
exchange.close();
|
||||
});
|
||||
server.start();
|
||||
|
||||
FlociDuckManager duckManager = mock(FlociDuckManager.class);
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
DockerHostResolver dockerHostResolver = mock(DockerHostResolver.class);
|
||||
EmbeddedDnsServer embeddedDnsServer = mock(EmbeddedDnsServer.class);
|
||||
when(duckManager.ensureReady()).thenReturn("http://localhost:" + server.getAddress().getPort());
|
||||
when(config.baseUrl()).thenReturn("http://localhost:4811");
|
||||
when(config.tls()).thenReturn(mock(EmulatorConfig.TlsConfig.class));
|
||||
when(embeddedDnsServer.getServerIp()).thenReturn(Optional.empty());
|
||||
when(dockerHostResolver.resolve()).thenReturn("172.18.0.2");
|
||||
|
||||
FlociDuckClient client = new FlociDuckClient(duckManager, config,
|
||||
new ContainerReachableEndpoint(config, dockerHostResolver, embeddedDnsServer, 4566), mapper);
|
||||
client.execute("SELECT 1", "", null);
|
||||
|
||||
assertEquals("http://172.18.0.2:4566", requestBody.get().path("s3_endpoint").asText());
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -53,7 +53,8 @@ class RedshiftSpectrumIntegrationTest {
|
||||
public static class SpectrumProfile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of("quarkus.http.test-port", "17866", "floci.base-url", "http://localhost:17866",
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -16,6 +16,7 @@ public class SynchronousBillingEmissionProfile implements QuarkusTestProfile {
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of(
|
||||
"quarkus.http.test-port", "4566",
|
||||
"quarkus.http.port", "4566",
|
||||
"floci.base-url", "http://localhost:4566",
|
||||
"floci.services.cur.emit-mode", "synchronous",
|
||||
"floci.services.bcm-data-exports.emit-mode", "synchronous");
|
||||
|
||||
Reference in new issue
Block a user