diff --git a/src/test/java/io/github/hectorvent/floci/services/bedrockruntime/BedrockProxyCancellationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/bedrockruntime/BedrockProxyCancellationIntegrationTest.java index 67f5670014..9c1bebd434 100644 --- a/src/test/java/io/github/hectorvent/floci/services/bedrockruntime/BedrockProxyCancellationIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/bedrockruntime/BedrockProxyCancellationIntegrationTest.java @@ -1,8 +1,8 @@ package io.github.hectorvent.floci.services.bedrockruntime; +import io.github.hectorvent.floci.testing.BedrockProxyBackendProfile; import io.quarkus.test.common.http.TestHTTPResource; import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.QuarkusTestProfile; import io.quarkus.test.junit.TestProfile; import org.junit.jupiter.api.Test; @@ -17,17 +17,26 @@ import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; import java.time.Duration; -import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import static io.github.hectorvent.floci.testing.BedrockProxyBackendProfile.PORT; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +/** + * Verifies that a caller who disconnects closes the upstream request, whether the upstream has + * sent nothing yet, part of a response, or one streamed token. + * + *
The backend URL and passthrough come from {@link BedrockProxyBackendProfile}, which this class
+ * shares with the other proxy classes that talk to a stand-in. The {@code fixture} model id is not
+ * in that profile's mapping, so it reaches the stand-in through passthrough. The profile keeps the
+ * default 60-second request timeout, far longer than these tests wait, so only the disconnect can
+ * close an upstream that stalls before its headers.
+ */
@QuarkusTest
-@TestProfile(BedrockProxyCancellationIntegrationTest.Profile.class)
+@TestProfile(BedrockProxyBackendProfile.class)
class BedrockProxyCancellationIntegrationTest {
- private static final int PORT = 18939;
@TestHTTPResource
URI base;
@@ -169,13 +178,4 @@ class BedrockProxyCancellationIntegrationTest {
}
}
}
-
- public static final class Profile implements QuarkusTestProfile {
- @Override
- public Map The backend, its URL, the API key and the model mapping come from
+ * {@link BedrockProxyBackendProfile}, which this class shares with the other proxy classes that
+ * talk to a stand-in. That profile also turns passthrough on, which no test here reaches, since
+ * every call names the mapped model id. The case with no mapping, no default model and no
+ * passthrough is in {@code BedrockProxyTimeoutIntegrationTest}, where passthrough stays off.
*/
@QuarkusTest
-@TestProfile(BedrockProxyIntegrationTest.ProxyBackendProfile.class)
+@TestProfile(BedrockProxyBackendProfile.class)
class BedrockProxyIntegrationTest {
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/bedrock/aws4_request";
- private static final int PORT = 18930;
- private static final String MAPPED_MODEL_ID = "anthropic.claude-3-haiku-20240307-v1:0";
@Inject
ObjectMapper objectMapper;
@@ -1322,32 +1327,4 @@ class BedrockProxyIntegrationTest {
.statusCode(400)
.body("__type", equalTo("ValidationException"));
}
-
- @Test
- void converse_noMappingNoDefaultNoPassthrough_returns400() {
- given()
- .contentType("application/json")
- .header("Authorization", AUTH_HEADER)
- .body("""
- {"messages": [{"role": "user", "content": [{"text": "hi"}]}]}
- """)
- .when()
- .post("/model/unmapped.model-v1:0/converse")
- .then()
- .statusCode(400)
- .body("__type", equalTo("ValidationException"));
- }
-
- public static final class ProxyBackendProfile implements QuarkusTestProfile {
- @Override
- public Map The backend URL and passthrough come from {@link BedrockProxyBackendProfile}, which this class
+ * shares with the other proxy classes that talk to a stand-in. The {@code fixture} model id is not
+ * in that profile's mapping, so it reaches the stand-in through passthrough.
+ */
@QuarkusTest
-@TestProfile(BedrockProxyCancellationIntegrationTest.Profile.class)
+@TestProfile(BedrockProxyBackendProfile.class)
class BedrockProxyLoggingIntegrationTest {
@TestHTTPResource
@@ -43,7 +53,7 @@ class BedrockProxyLoggingIntegrationTest {
@ValueSource(strings = {"converse", "converse-stream"})
void upstreamErrorIsLoggedWithoutResponseBody(String operation) throws IOException {
String marker = "synthetic-private-upstream-content";
- HttpServer backend = HttpServer.create(new InetSocketAddress("127.0.0.1", 18939), 0);
+ HttpServer backend = HttpServer.create(new InetSocketAddress("127.0.0.1", PORT), 0);
backend.createContext("/v1/chat/completions", exchange -> {
exchange.getRequestBody().readAllBytes();
byte[] body = ("{\"error\":\"" + marker + "\"}").getBytes(StandardCharsets.UTF_8);
@@ -80,7 +90,7 @@ class BedrockProxyLoggingIntegrationTest {
@Test
void streamingErrorBodyReadIsBoundedWithoutWaitingForEof() throws Exception {
CountDownLatch release = new CountDownLatch(1);
- HttpServer backend = HttpServer.create(new InetSocketAddress("127.0.0.1", 18939), 0);
+ HttpServer backend = HttpServer.create(new InetSocketAddress("127.0.0.1", PORT), 0);
backend.createContext("/v1/chat/completions", exchange -> {
exchange.getRequestBody().readAllBytes();
exchange.sendResponseHeaders(503, 32768);
diff --git a/src/test/java/io/github/hectorvent/floci/services/bedrockruntime/BedrockProxyPassthroughIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/bedrockruntime/BedrockProxyPassthroughIntegrationTest.java
index 65df8e3fb4..9927b83f61 100644
--- a/src/test/java/io/github/hectorvent/floci/services/bedrockruntime/BedrockProxyPassthroughIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/bedrockruntime/BedrockProxyPassthroughIntegrationTest.java
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.bedrockruntime;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.net.httpserver.HttpServer;
+import io.github.hectorvent.floci.testing.BedrockProxyBackendProfile;
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;
@@ -14,9 +14,9 @@ import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
-import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
+import static io.github.hectorvent.floci.testing.BedrockProxyBackendProfile.PORT;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -24,16 +24,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Verifies that with {@code proxy.passthrough=true} the raw Bedrock model id is forwarded
* as-is to the OpenAI-compatible backend, bypassing the mapping/default-model requirement.
- * Kept in a separate class/profile since {@code @TestProfile} config overrides require a
- * fresh Quarkus application context, one per distinct override set.
+ *
+ * Passthrough and the backend URL come from {@link BedrockProxyBackendProfile}, which this class
+ * shares with the other proxy classes that talk to a stand-in. The raw model id is not in that
+ * profile's mapping, so it reaches the backend through passthrough alone.
*/
@QuarkusTest
-@TestProfile(BedrockProxyPassthroughIntegrationTest.PassthroughProfile.class)
+@TestProfile(BedrockProxyBackendProfile.class)
class BedrockProxyPassthroughIntegrationTest {
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/bedrock/aws4_request";
- private static final int PORT = 18931;
private static final String RAW_MODEL_ID = "meta.llama3-8b-instruct-v1:0";
@Inject
@@ -87,15 +88,4 @@ class BedrockProxyPassthroughIntegrationTest {
JsonNode sentRequest = objectMapper.readTree(receivedBody.get());
assertEquals(RAW_MODEL_ID, sentRequest.path("model").asText());
}
-
- public static final class PassthroughProfile implements QuarkusTestProfile {
- @Override
- public Map Its profile leaves passthrough off and the default model unset, so this class also checks that
+ * a model id with no mapping is refused before any backend call. It stays apart from
+ * {@code BedrockProxyBackendProfile}, which the other proxy classes share: that profile turns
+ * passthrough on, and a one-second timeout there would also close the upstreams that
+ * {@code BedrockProxyCancellationIntegrationTest} stalls before their headers, so those tests
+ * would pass without a disconnect closing them.
*/
@QuarkusTest
@TestProfile(BedrockProxyTimeoutIntegrationTest.SlowProxyBackendProfile.class)
@@ -74,6 +82,21 @@ class BedrockProxyTimeoutIntegrationTest {
.body("__type", equalTo("ModelTimeoutException"));
}
+ @Test
+ void converse_noMappingNoDefaultNoPassthrough_returns400() {
+ given()
+ .contentType("application/json")
+ .header("Authorization", AUTH_HEADER)
+ .body("""
+ {"messages": [{"role": "user", "content": [{"text": "hi"}]}]}
+ """)
+ .when()
+ .post("/model/unmapped.model-v1:0/converse")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ValidationException"));
+ }
+
public static final class SlowProxyBackendProfile implements QuarkusTestProfile {
@Override
public Map The overrides, all under {@code floci.services.bedrock-runtime}, and who relies on them:
+ * Each override is inert for the classes that do not rely on it. Only the stand-in in
+ * {@code BedrockProxyIntegrationTest} reads the {@code Authorization} header. The other classes
+ * call model ids the mapping does not name, and every call in {@code BedrockProxyIntegrationTest}
+ * names the mapped id, which the mapping resolves before passthrough is consulted.
+ *
+ * {@code BedrockProxyTimeoutIntegrationTest} stays apart. Its one-second request timeout would
+ * also close an upstream that stalls before its headers, so the cancellation tests would pass
+ * without the disconnect handling they check. It also holds the test that needs passthrough off.
+ */
+public class BedrockProxyBackendProfile implements QuarkusTestProfile {
+
+ public static final int PORT = 18930;
+ public static final String MAPPED_MODEL_ID = "anthropic.claude-3-haiku-20240307-v1:0";
+
+ @Override
+ public Map
+ *
+ *
+ *