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 2020/10/09 08:44:39 UTC
[camel-quarkus] branch master updated: Fix twitter itest so it
initially waits when start polling tweets
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push:
new 4bfdc7b Fix twitter itest so it initially waits when start polling tweets
4bfdc7b is described below
commit 4bfdc7bac62508579e9f5bdce41c911f69ec2ce1
Author: Lukas Lowinger <ll...@redhat.com>
AuthorDate: Tue Oct 6 10:20:17 2020 +0200
Fix twitter itest so it initially waits when start polling tweets
---
integration-tests/twitter/pom.xml | 11 +++
.../component/twitter/CamelTwitterTest.java | 105 +++++++--------------
2 files changed, 44 insertions(+), 72 deletions(-)
diff --git a/integration-tests/twitter/pom.xml b/integration-tests/twitter/pom.xml
index 14fa2a4..1a19e89 100644
--- a/integration-tests/twitter/pom.xml
+++ b/integration-tests/twitter/pom.xml
@@ -54,6 +54,17 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
<dependency>
diff --git a/integration-tests/twitter/src/test/java/org/apache/camel/quarkus/component/twitter/CamelTwitterTest.java b/integration-tests/twitter/src/test/java/org/apache/camel/quarkus/component/twitter/CamelTwitterTest.java
index 14e26ac..e51d691 100644
--- a/integration-tests/twitter/src/test/java/org/apache/camel/quarkus/component/twitter/CamelTwitterTest.java
+++ b/integration-tests/twitter/src/test/java/org/apache/camel/quarkus/component/twitter/CamelTwitterTest.java
@@ -17,12 +17,14 @@
package org.apache.camel.quarkus.component.twitter;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
+import org.awaitility.Awaitility;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.hamcrest.core.StringContains;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
@@ -30,8 +32,11 @@ import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
@EnabledIfEnvironmentVariable(named = "TWITTER_CONSUMER_KEY", matches = "[a-zA-Z0-9]+")
public class CamelTwitterTest {
+ @ConfigProperty(name = "test.twitter.delay.initial", defaultValue = "60")
+ int testTwitterDelayInitial;
+
@Test
- public void direct() throws InterruptedException {
+ public void direct() {
final String uuid = UUID.randomUUID().toString().replace("-", "");
final String msg = String.format("Direct message from camel-quarkus-twitter %s", uuid);
/* Direct message */
@@ -40,31 +45,15 @@ public class CamelTwitterTest {
.then().statusCode(201);
/* Check that the above message or a message sent by a previous run of this test was polled by the consumer. */
- final int initialDelayMs = 60000;
final int retries = 5;
- final int delayMs = 3000;
- String body = null;
- boolean passed = false;
- Thread.sleep(initialDelayMs);
- for (int i = 0; i < retries; i++) {
- body = RestAssured.get("/twitter/directmessage").asString();
- if (body.contains(msg)) {
- /* test passed */
- passed = true;
- break;
- }
- if (i + 1 < retries) {
- try {
- Thread.sleep(delayMs);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
- }
- }
- if (!passed) {
- Assertions.fail("Could not find a message containing " + msg + " in user's direct messages within ~"
- + initialDelayMs + (retries * delayMs) + " ms; got messages: " + body);
- }
+ final int delayS = 3;
+ Awaitility.await()
+ .pollDelay(testTwitterDelayInitial, TimeUnit.SECONDS)
+ .pollInterval(delayS, TimeUnit.SECONDS)
+ .atMost(testTwitterDelayInitial + (retries * delayS), TimeUnit.SECONDS).until(() -> {
+ final String body = RestAssured.get("/twitter/directmessage").asString();
+ return body.contains(msg);
+ });
}
@Test
@@ -73,6 +62,7 @@ public class CamelTwitterTest {
final String uuid = UUID.randomUUID().toString().replace("-", "");
final String msg = String.format("Hello from camel-quarkus-twitter %s", uuid);
final String expectedMessage = ") " + msg;
+ final String searchKeyword = "camel-quarkus-twitter " + uuid;
/* Post a message */
final String messageId = RestAssured.given().contentType(ContentType.TEXT).body(msg).post("/twitter/timeline") //
@@ -81,28 +71,14 @@ public class CamelTwitterTest {
/* Check that the message is seen in the timeline by the polling consumer */
{
final int retries = 5;
- final int delayMs = 3000;
- String body = null;
- boolean passed = false;
- for (int i = 0; i < retries; i++) {
- body = RestAssured.given().param("sinceId", sinceId).get("/twitter/timeline").asString();
- if (body.contains(expectedMessage)) {
- /* test passed */
- passed = true;
- break;
- }
- if (i + 1 < retries) {
- try {
- Thread.sleep(delayMs);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
- }
- }
- if (!passed) {
- Assertions.fail("Could not find the expected message '" + expectedMessage + "' in user's timeline within ~"
- + (retries * delayMs) + " ms; got messages: " + body);
- }
+ final int delayS = 3;
+ Awaitility.await()
+ .pollDelay(testTwitterDelayInitial, TimeUnit.SECONDS)
+ .pollInterval(delayS, TimeUnit.SECONDS)
+ .atMost(testTwitterDelayInitial + (retries * delayS), TimeUnit.SECONDS).until(() -> {
+ final String body = RestAssured.given().param("sinceId", sinceId).get("/twitter/timeline").asString();
+ return body.contains(expectedMessage);
+ });
}
/*
@@ -110,30 +86,15 @@ public class CamelTwitterTest {
*/
{
final int retries = 4;
- final int delayMs = 10000;
- String body = null;
- boolean passed = false;
- for (int i = 0; i < retries; i++) {
- body = RestAssured.given()
- .param("keywords", "camel-quarkus-twitter")
- .get("/twitter/search").asString();
- if (body.contains("camel-quarkus-twitter")) {
- /* test passed */
- passed = true;
- break;
- }
- if (i + 1 < retries) {
- try {
- Thread.sleep(delayMs);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
- }
- }
- if (!passed) {
- Assertions.fail("Could not find the expected message '" + uuid + "' via twitter-search within "
- + (retries * delayMs) + " ms; got messages: " + body);
- }
+ final int delayS = 10;
+ Awaitility.await()
+ .pollInterval(delayS, TimeUnit.SECONDS)
+ .atMost(retries * delayS, TimeUnit.SECONDS).until(() -> {
+ final String body = RestAssured.given()
+ .param("keywords", searchKeyword)
+ .get("/twitter/search").asString();
+ return body.contains(expectedMessage);
+ });
}
}
}