Skip to content

Commit

Permalink
Added await for throttle test
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek committed Dec 11, 2023
1 parent 34640f1 commit 2ab36e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions integration-test-groups/foundation/eip/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@ApplicationScoped
public class EipRoutes extends RouteBuilder {

public static final int THROTTLE_TIMEOUT = 10000;
public static final int THROTTLE_TIMEOUT = 5000;
public static final int THROTTLE_MAXIMUM_REQUEST_COUNT = 2;
public static final int WEIGHTED_1 = 2;
public static final int WEIGHTED_2 = 1;
Expand Down Expand Up @@ -125,6 +125,7 @@ public void configure() {

from("direct:throttle")
.throttle(THROTTLE_MAXIMUM_REQUEST_COUNT).rejectExecution(true).delay(THROTTLE_TIMEOUT)
.log("Sending '${body}' to mock throttle.")
.to("mock:throttle");

from("direct:tryCatchFinally")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
Expand All @@ -29,6 +30,8 @@
import org.jboss.logging.Logger;
import org.junit.jupiter.api.Test;

import static org.awaitility.Awaitility.await;

@QuarkusTest
class EipTest {

Expand Down Expand Up @@ -480,15 +483,17 @@ public void throttle() {
.then()
.extract().statusCode();
}
String[] samples = RestAssured.get("/eip/mock/throttle/2/5000/body")
.then()
.statusCode(200)
.extract()
.body().asString().split(",");
LOG.infof("%d messages passed the route", samples.length);
Assertions.assertThat(samples.length).isEqualTo(EipRoutes.THROTTLE_MAXIMUM_REQUEST_COUNT);
Assertions.assertThat("message-0").isIn(samples);
Assertions.assertThat("message-1").isIn(samples);

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")
.then()
.statusCode(200)
.extract()
.body().asString();

return samples.split(",").length == 2 && samples.contains("message-0") && samples.contains("message-1");
});
}

@Test
Expand Down

0 comments on commit 2ab36e3

Please sign in to comment.