This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new d6b6e4b2b24c CAMEL-28061: camel-aws2-kinesis, camel-aws-bedrock -
tests no longer wait for the Netty shutdown of an async client (#31292)
d6b6e4b2b24c is described below
commit d6b6e4b2b24c798e08ab522fc7b77ab0f83c192d
Author: Aurélien Pupier <[email protected]>
AuthorDate: Wed Dec 2 21:36:10 2026 +0100
CAMEL-28061: camel-aws2-kinesis, camel-aws-bedrock - tests no longer wait
for the Netty shutdown of an async client (#31292)
Closing the last async client of the AWS SDK shuts down the shared Netty
event loop group, which waits for a quiet period of 2 seconds.
- camel-aws-bedrock: the endpoint builds a real async client when none is
given, so every test of 4 classes (29 tests) waited 2 seconds in doStop().
Bind a mocked BedrockRuntimeAsyncClient, as the other Bedrock tests do.
The sum of the test times goes from 61.5 s to 4.8 s.
- camel-aws2-kinesis: the 3 tests that build and close a real async client
keep one other async client open for the test JVM, so closing theirs
returns at once. KinesisClientFactoryTest and KinesisEndpointClientTest
go from 9 s to 0.5 s.
Co-authored-by: Bob (IBM) <[email protected]>
---
.../bedrock/runtime/BedrockApplyGuardrailTest.java | 10 ++++-
.../bedrock/runtime/BedrockCompletionsJqTest.java | 8 +++-
...BedrockInvokeTextModelUnsupportedModelTest.java | 8 +++-
.../bedrock/runtime/BedrockTextResultBodyTest.java | 9 +++-
.../aws2/kinesis/KeepAsyncClientOpenExtension.java | 52 ++++++++++++++++++++++
.../aws2/kinesis/KinesisClientFactoryTest.java | 2 +
.../aws2/kinesis/KinesisEndpointClientTest.java | 2 +
7 files changed, 86 insertions(+), 5 deletions(-)
diff --git
a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockApplyGuardrailTest.java
b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockApplyGuardrailTest.java
index 2c5dcc476e3d..1a8c5eb7a468 100644
---
a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockApplyGuardrailTest.java
+++
b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockApplyGuardrailTest.java
@@ -32,6 +32,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+import
software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeAsyncClient;
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient;
import
software.amazon.awssdk.services.bedrockruntime.model.ApplyGuardrailRequest;
import
software.amazon.awssdk.services.bedrockruntime.model.ApplyGuardrailResponse;
@@ -58,6 +59,10 @@ public class BedrockApplyGuardrailTest {
@Mock
private BedrockRuntimeClient client;
+ // the endpoint builds a real Netty async client when none is given, and
closing it waits 2 seconds
+ @Mock
+ private BedrockRuntimeAsyncClient asyncClient;
+
private CamelContext camelContext;
private ProducerTemplate template;
private AtomicReference<ApplyGuardrailRequest> capturedRequest;
@@ -72,13 +77,14 @@ public class BedrockApplyGuardrailTest {
SimpleRegistry registry = new SimpleRegistry();
registry.bind("bedrockClient", client);
+ registry.bind("bedrockAsyncClient", asyncClient);
camelContext = new DefaultCamelContext(registry);
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("direct:apply-guardrail-config")
.to("aws-bedrock://label"
- + "?bedrockRuntimeClient=#bedrockClient"
+ +
"?bedrockRuntimeClient=#bedrockClient&bedrockRuntimeAsyncClient=#bedrockAsyncClient"
+ "&operation=applyGuardrail"
+ "&guardrailIdentifier=endpoint-guardrail-id"
+ "&guardrailVersion=1"
@@ -88,7 +94,7 @@ public class BedrockApplyGuardrailTest {
from("direct:apply-guardrail-no-config")
.to("aws-bedrock://label2"
- + "?bedrockRuntimeClient=#bedrockClient"
+ +
"?bedrockRuntimeClient=#bedrockClient&bedrockRuntimeAsyncClient=#bedrockAsyncClient"
+ "&operation=applyGuardrail"
+ "®ion=us-east-1"
+ "&accessKey=unused"
diff --git
a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockCompletionsJqTest.java
b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockCompletionsJqTest.java
index 2a6494917f6f..4c1c0dc8538f 100644
---
a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockCompletionsJqTest.java
+++
b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockCompletionsJqTest.java
@@ -31,6 +31,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import software.amazon.awssdk.core.SdkBytes;
+import
software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeAsyncClient;
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient;
import software.amazon.awssdk.services.bedrockruntime.model.InvokeModelRequest;
import
software.amazon.awssdk.services.bedrockruntime.model.InvokeModelResponse;
@@ -47,6 +48,10 @@ public class BedrockCompletionsJqTest {
@Mock
private BedrockRuntimeClient client;
+ // the endpoint builds a real Netty async client when none is given, and
closing it waits 2 seconds
+ @Mock
+ private BedrockRuntimeAsyncClient asyncClient;
+
private CamelContext camelContext;
private ProducerTemplate template;
@@ -54,12 +59,13 @@ public class BedrockCompletionsJqTest {
public void setup() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
registry.bind("bedrockClient", client);
+ registry.bind("bedrockAsyncClient", asyncClient);
camelContext = new DefaultCamelContext(registry);
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("direct:start")
-
.to("aws-bedrock://label?bedrockRuntimeClient=#bedrockClient&operation=invokeTextModel"
+
.to("aws-bedrock://label?bedrockRuntimeClient=#bedrockClient&bedrockRuntimeAsyncClient=#bedrockAsyncClient&operation=invokeTextModel"
+
"&modelId=ai21.j2-ultra-v1®ion=us-east-1&accessKey=unused&secretKey=unused")
.split(body())
.transform().jq(".data.text", String.class)
diff --git
a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockInvokeTextModelUnsupportedModelTest.java
b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockInvokeTextModelUnsupportedModelTest.java
index 02d795a491ab..06f88b0317e3 100644
---
a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockInvokeTextModelUnsupportedModelTest.java
+++
b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockInvokeTextModelUnsupportedModelTest.java
@@ -34,6 +34,7 @@ import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import software.amazon.awssdk.core.SdkBytes;
+import
software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeAsyncClient;
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient;
import software.amazon.awssdk.services.bedrockruntime.model.InvokeModelRequest;
import
software.amazon.awssdk.services.bedrockruntime.model.InvokeModelResponse;
@@ -59,6 +60,10 @@ public class BedrockInvokeTextModelUnsupportedModelTest {
@Mock
private BedrockRuntimeClient client;
+ // the endpoint builds a real Netty async client when none is given, and
closing it waits 2 seconds
+ @Mock
+ private BedrockRuntimeAsyncClient asyncClient;
+
private CamelContext camelContext;
private ProducerTemplate template;
@@ -69,6 +74,7 @@ public class BedrockInvokeTextModelUnsupportedModelTest {
SimpleRegistry registry = new SimpleRegistry();
registry.bind("bedrockClient", client);
+ registry.bind("bedrockAsyncClient", asyncClient);
camelContext = new DefaultCamelContext(registry);
camelContext.start();
template = camelContext.createProducerTemplate();
@@ -147,7 +153,7 @@ public class BedrockInvokeTextModelUnsupportedModelTest {
private static String endpointUri(String modelId) {
return "aws-bedrock://label"
- + "?bedrockRuntimeClient=#bedrockClient"
+ +
"?bedrockRuntimeClient=#bedrockClient&bedrockRuntimeAsyncClient=#bedrockAsyncClient"
+ "&operation=invokeTextModel"
+ "&modelId=" + modelId
+ "®ion=us-east-1"
diff --git
a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockTextResultBodyTest.java
b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockTextResultBodyTest.java
index 0d12820b2468..8c80f2a29277 100644
---
a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockTextResultBodyTest.java
+++
b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockTextResultBodyTest.java
@@ -31,6 +31,7 @@ import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import software.amazon.awssdk.core.SdkBytes;
+import
software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeAsyncClient;
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient;
import software.amazon.awssdk.services.bedrockruntime.model.InvokeModelRequest;
import
software.amazon.awssdk.services.bedrockruntime.model.InvokeModelResponse;
@@ -48,6 +49,10 @@ public class BedrockTextResultBodyTest {
@Mock
private BedrockRuntimeClient client;
+ // the endpoint builds a real Netty async client when none is given, and
closing it waits 2 seconds
+ @Mock
+ private BedrockRuntimeAsyncClient asyncClient;
+
private CamelContext camelContext;
private ProducerTemplate template;
@@ -55,6 +60,7 @@ public class BedrockTextResultBodyTest {
public void setup() {
SimpleRegistry registry = new SimpleRegistry();
registry.bind("bedrockClient", client);
+ registry.bind("bedrockAsyncClient", asyncClient);
camelContext = new DefaultCamelContext(registry);
camelContext.start();
template = camelContext.createProducerTemplate();
@@ -76,7 +82,8 @@ public class BedrockTextResultBodyTest {
.thenReturn(InvokeModelResponse.builder()
.body(SdkBytes.fromUtf8String("{\"" + field +
"\":\"hello \\\"world\\\"\"}")).build());
- Exchange exchange =
template.send("aws-bedrock://label?bedrockRuntimeClient=#bedrockClient"
+ Exchange exchange = template.send(
+
"aws-bedrock://label?bedrockRuntimeClient=#bedrockClient&bedrockRuntimeAsyncClient=#bedrockAsyncClient"
+
"&operation=invokeTextModel&modelId=" + modelId
+
"®ion=us-east-1&accessKey=unused&secretKey=unused",
ex -> {
diff --git
a/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KeepAsyncClientOpenExtension.java
b/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KeepAsyncClientOpenExtension.java
new file mode 100644
index 000000000000..1a687d3457d1
--- /dev/null
+++
b/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KeepAsyncClientOpenExtension.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws2.kinesis;
+
+import org.apache.camel.component.aws2.kinesis.client.KinesisClientFactory;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
+
+/**
+ * Keeps one Kinesis async client open for the life of the test JVM.
+ * <p>
+ * The async clients of the AWS SDK share one Netty event loop group, which is
shut down when the last client that uses
+ * it is closed, and that shutdown waits for a quiet period of 2 seconds. A
test that creates an async client and closes
+ * it, with no other client open, waits these 2 seconds. With this client
open, closing the client of a test returns at
+ * once.
+ * <p>
+ * The client is never closed: it holds no connection, and the threads of the
event loop group are daemon threads, so
+ * the JVM of the tests exits without waiting for them.
+ */
+public class KeepAsyncClientOpenExtension implements BeforeAllCallback {
+
+ @SuppressWarnings("unused")
+ private static KinesisAsyncClient keeper;
+
+ @Override
+ public void beforeAll(ExtensionContext context) {
+ synchronized (KeepAsyncClientOpenExtension.class) {
+ if (keeper == null) {
+ Kinesis2Configuration configuration = new
Kinesis2Configuration();
+ configuration.setAccessKey("keeper");
+ configuration.setSecretKey("keeper");
+ configuration.setRegion("eu-west-1");
+ keeper =
KinesisClientFactory.getKinesisAsyncClient(configuration);
+ }
+ }
+ }
+}
diff --git
a/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisClientFactoryTest.java
b/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisClientFactoryTest.java
index d77fa7911985..f3cc22cc7a5a 100644
---
a/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisClientFactoryTest.java
+++
b/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisClientFactoryTest.java
@@ -18,11 +18,13 @@ package org.apache.camel.component.aws2.kinesis;
import org.apache.camel.component.aws2.kinesis.client.KinesisClientFactory;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
import software.amazon.awssdk.services.kinesis.KinesisClient;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+@ExtendWith(KeepAsyncClientOpenExtension.class)
class KinesisClientFactoryTest {
@Test
diff --git
a/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisEndpointClientTest.java
b/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisEndpointClientTest.java
index 69ce67583c3d..b5b0263b5127 100644
---
a/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisEndpointClientTest.java
+++
b/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisEndpointClientTest.java
@@ -23,6 +23,7 @@ import org.apache.camel.impl.DefaultCamelContext;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.services.kinesis.KinesisClient;
@@ -37,6 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertNotSame;
* Each aws2-kinesis endpoint uses the client of its own configuration, and
stopping one endpoint does not close the
* client of another.
*/
+@ExtendWith(KeepAsyncClientOpenExtension.class)
public class KinesisEndpointClientTest {
// nothing listens there: a call with an open client fails to connect, a
call with a closed client fails at once