You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2025/08/01 10:09:40 UTC
(camel-quarkus) branch main updated: Fixes #5679 Stabilize throttle test
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 283e056f6e Fixes #5679 Stabilize throttle test
283e056f6e is described below
commit 283e056f6eb584e9dee6c1f8533b9c14b79942cc
Author: Lukas Lowinger <ll...@redhat.com>
AuthorDate: Fri Aug 1 12:09:35 2025 +0200
Fixes #5679 Stabilize throttle test
---
.../apache/camel/quarkus/eip/it/EipResource.java | 8 +++
.../org/apache/camel/quarkus/eip/it/EipRoutes.java | 13 ++++-
.../eip/src/main/resources/application.properties | 19 -------
.../org/apache/camel/quarkus/eip/it/EipTest.java | 62 +++++++++++++++++-----
4 files changed, 70 insertions(+), 32 deletions(-)
diff --git a/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipResource.java b/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipResource.java
index 54f753ef9e..bfdd282c66 100644
--- a/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipResource.java
+++ b/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipResource.java
@@ -117,4 +117,12 @@ public class EipResource {
}
}
+ @Path("/mock/{name}/body")
+ @Produces(MediaType.TEXT_PLAIN)
+ @GET
+ public String mockBody(@PathParam("name") String name) {
+ MockEndpoint mock = context.getEndpoint("mock:" + name, MockEndpoint.class);
+ return mock.getExchanges().stream().map(e -> e.getMessage().getBody(String.class)).collect(Collectors.joining(","));
+ }
+
}
diff --git a/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipRoutes.java b/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipRoutes.java
index f179eaf04d..34b18e59bf 100644
--- a/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipRoutes.java
+++ b/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipRoutes.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.quarkus.eip.it;
+import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;
@@ -23,9 +24,11 @@ import jakarta.inject.Singleton;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.ClaimCheckOperation;
+import org.apache.camel.processor.ThrottlerRejectedExecutionException;
import org.apache.camel.processor.loadbalancer.RoundRobinLoadBalancer;
@ApplicationScoped
+@RegisterForReflection(targets = ThrottlerRejectedExecutionException.class)
public class EipRoutes extends RouteBuilder {
public static final int THROTTLE_TIMEOUT = 5000;
@@ -35,6 +38,8 @@ public class EipRoutes extends RouteBuilder {
@Override
public void configure() {
+ onException(ThrottlerRejectedExecutionException.class).handled(true).to("mock:throttleRejectionError");
+
from("direct:claimCheckByHeader")
.claimCheck(ClaimCheckOperation.Set, "${header.claimCheckId}")
.transform().constant("Bye World")
@@ -125,10 +130,16 @@ public class EipRoutes extends RouteBuilder {
from("direct:throttle")
.log("Receiving '${body}' before throttle.")
- .throttle(THROTTLE_MAXIMUM_REQUEST_COUNT).rejectExecution(true).delay(THROTTLE_TIMEOUT)
+ .throttle(THROTTLE_MAXIMUM_REQUEST_COUNT).timePeriodMillis(THROTTLE_TIMEOUT)
.log("Sending '${body}' to mock throttle.")
.to("mock:throttle");
+ from("direct:throttleRejection")
+ .log("Receiving '${body}' before throttleRejection.")
+ .throttle(THROTTLE_MAXIMUM_REQUEST_COUNT).rejectExecution(true).timePeriodMillis(THROTTLE_TIMEOUT)
+ .log("Sending '${body}' to mock throttleRejection.")
+ .to("mock:throttleRejection");
+
from("direct:tryCatchFinally")
.doTry()
.process(e -> {
diff --git a/integration-test-groups/foundation/eip/src/main/resources/application.properties b/integration-test-groups/foundation/eip/src/main/resources/application.properties
deleted file mode 100644
index ec52f5c0a5..0000000000
--- a/integration-test-groups/foundation/eip/src/main/resources/application.properties
+++ /dev/null
@@ -1,19 +0,0 @@
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-
-# Reduces noise from throttler ThrottlerRejectedExecutionException
-quarkus.log.category."org.apache.camel.processor".level = OFF
diff --git a/integration-test-groups/foundation/eip/src/test/java/org/apache/camel/quarkus/eip/it/EipTest.java b/integration-test-groups/foundation/eip/src/test/java/org/apache/camel/quarkus/eip/it/EipTest.java
index 479e6c0f19..fde2b86a35 100644
--- a/integration-test-groups/foundation/eip/src/test/java/org/apache/camel/quarkus/eip/it/EipTest.java
+++ b/integration-test-groups/foundation/eip/src/test/java/org/apache/camel/quarkus/eip/it/EipTest.java
@@ -484,31 +484,69 @@ class EipTest {
.extract().statusCode();
}
- await().atMost(EipRoutes.THROTTLE_TIMEOUT + 5000, TimeUnit.MILLISECONDS)
- .pollDelay(EipRoutes.THROTTLE_TIMEOUT, TimeUnit.MILLISECONDS).until(() -> {
- String samples = RestAssured.get("/eip/mock/throttle/2/5000/body")
+ //wait for two first throttled messages
+ await().atMost(EipRoutes.THROTTLE_TIMEOUT, TimeUnit.MILLISECONDS)
+ .pollInterval(500, TimeUnit.MILLISECONDS).until(() -> {
+ String throttleBodies = RestAssured.get("/eip/mock/throttle/body")
.then()
.statusCode(200)
.extract()
.body().asString();
-
- return samples.split(",").length == EipRoutes.THROTTLE_MAXIMUM_REQUEST_COUNT;
+ LOG.infof("Mock throttle received: %s", throttleBodies);
+ return throttleBodies.split(",").length == EipRoutes.THROTTLE_MAXIMUM_REQUEST_COUNT;
});
- //wait for another 2 messages
+ //wait for remaining messages
+ //THROTTLE_TIMEOUT-time taken after read 1/2 messages + THROTTLE_TIMEOUT for 3/4 messages + time for camel to throttle the last 5/6 messages
long startTime = System.currentTimeMillis();
+ await().atMost(3 * EipRoutes.THROTTLE_TIMEOUT, TimeUnit.MILLISECONDS)
+ .pollInterval(1, TimeUnit.SECONDS).until(() -> {
+ String throttleBodies = RestAssured.get("/eip/mock/throttle/body")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().asString();
+ LOG.infof("Mock throttle received: %s", throttleBodies);
+ return throttleBodies.split(",").length == 3 * EipRoutes.THROTTLE_MAXIMUM_REQUEST_COUNT;
+ });
+ long endTime = System.currentTimeMillis();
+ //the time of waiting has to be bigger then throttle_Period (assert that it is > throttle_period + 500)
+ Assertions.assertThat(endTime - startTime).isGreaterThan(EipRoutes.THROTTLE_TIMEOUT + 500);
+ }
+
+ @Test
+ public void throttleRejectExecution() throws InterruptedException {
+ LOG.infof("About to sent 6 messages");
+ for (int i = 0; i < 6; i++) {
+ RestAssured.given()
+ .contentType(ContentType.TEXT)
+ .body("message-" + i)
+ .post("/eip/routeAsync/throttleRejection")
+ .then()
+ .extract().statusCode();
+ }
+
await().atMost(EipRoutes.THROTTLE_TIMEOUT + 5000, TimeUnit.MILLISECONDS)
- .pollDelay(EipRoutes.THROTTLE_TIMEOUT, TimeUnit.MILLISECONDS).until(() -> {
- String samples = RestAssured.get("/eip/mock/throttle/2/5000/body")
+ .pollInterval(1, TimeUnit.SECONDS).until(() -> {
+ String throttleBodies = RestAssured.get("/eip/mock/throttleRejection/body")
.then()
.statusCode(200)
.extract()
.body().asString();
+ LOG.infof("Mock throttleRejection received: %s", throttleBodies);
+ return throttleBodies.split(",").length == EipRoutes.THROTTLE_MAXIMUM_REQUEST_COUNT;
+ });
- return samples.split(",").length == EipRoutes.THROTTLE_MAXIMUM_REQUEST_COUNT;
+ //wait for another 4 messages in error mock
+ await().atMost(EipRoutes.THROTTLE_TIMEOUT + 5000, TimeUnit.MILLISECONDS)
+ .pollInterval(1, TimeUnit.SECONDS).until(() -> {
+ String throttleBodies = RestAssured.get("/eip/mock/throttleRejectionError/body")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().asString();
+ LOG.infof("Mock throttleRejectionError received: %s", throttleBodies);
+ return throttleBodies.split(",").length == 4;
});
- long endTime = System.currentTimeMillis();
- //the time of waiting has to be similar to throttle_Period (assert that it is > throttle_period/2)
- Assertions.assertThat(endTime - startTime).isGreaterThan(EipRoutes.THROTTLE_TIMEOUT / 2);
}
@Test