You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2020/03/10 16:27:38 UTC

[camel-quarkus] branch pull/864/head created (now 0ba28ed)

This is an automated email from the ASF dual-hosted git repository.

ppalaga pushed a change to branch pull/864/head
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git.


      at 0ba28ed  Make the file-watch tests more resilient

This branch includes the following new commits:

     new 0ba28ed  Make the file-watch tests more resilient

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel-quarkus] 01/01: Make the file-watch tests more resilient

Posted by pp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ppalaga pushed a commit to branch pull/864/head
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 0ba28ed6f0ba1f4ed9732daca1603c99d59271fb
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Tue Mar 10 17:26:45 2020 +0100

    Make the file-watch tests more resilient
---
 .../camel/quarkus/component/file/it/FileTest.java  | 68 ++++++++--------------
 1 file changed, 24 insertions(+), 44 deletions(-)

diff --git a/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/FileTest.java b/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/FileTest.java
index efb6f62..ace21af 100644
--- a/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/FileTest.java
+++ b/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/FileTest.java
@@ -27,6 +27,7 @@ import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
 import io.restassured.http.ContentType;
 import io.restassured.path.json.JsonPath;
+import io.restassured.response.ValidatableResponse;
 import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
@@ -70,63 +71,42 @@ class FileTest {
         final Path file = dir.resolve("file.txt");
         Files.write(file, "a file content".getBytes(StandardCharsets.UTF_8));
 
-        RestAssured.given()
-                .queryParam("path", dir.toString())
-                .get("/file-watch/get-events")
-                .then()
-                .statusCode(200)
-                .body("type", equalTo("CREATE"))
-                .body("path", equalTo(file.toString()));
+        awaitEvent(dir, file, "CREATE");
 
         Files.write(file, "changed content".getBytes(StandardCharsets.UTF_8));
 
-        RestAssured.given()
-                .queryParam("path", dir.toString())
-                .get("/file-watch/get-events")
-                .then()
-                .statusCode(200)
-                .body("type", equalTo("MODIFY"))
-                .body("path", equalTo(file.toString()));
-
-    }
-
-    @Test
-    public void fileWatchCreateDelete() throws IOException, InterruptedException {
-        final Path dir = Files.createTempDirectory(FileTest.class.getSimpleName()).toAbsolutePath().normalize();
-        RestAssured.given()
-                .queryParam("path", dir.toString())
-                .get("/file-watch/get-events")
-                .then()
-                .statusCode(204);
+        awaitEvent(dir, file, "MODIFY");
 
-        final Path file = dir.resolve("file.txt");
-        Files.write(file, "a file content".getBytes(StandardCharsets.UTF_8));
+        Files.delete(file);
 
-        RestAssured.given()
-                .queryParam("path", dir.toString())
-                .get("/file-watch/get-events")
-                .then()
-                .statusCode(200)
-                .body("type", equalTo("CREATE"))
-                .body("path", equalTo(file.toString()));
+        awaitEvent(dir, file, "DELETE");
 
-        Files.delete(file);
+    }
 
-        /* The DELETE event may be preceded by MODIFY */
+    private static void awaitEvent(final Path dir, final Path file, final String type) {
         Awaitility.await()
                 .pollInterval(10, TimeUnit.MILLISECONDS)
                 .atMost(10, TimeUnit.SECONDS)
                 .until(() -> {
-                    final JsonPath json = RestAssured.given()
+                    final ValidatableResponse response = RestAssured.given()
                             .queryParam("path", dir.toString())
                             .get("/file-watch/get-events")
-                            .then()
-                            .statusCode(200)
-                            .extract()
-                            .jsonPath();
-                    return file.toString().equals(json.getString("path")) && "DELETE".equals(json.getString("type"));
+                            .then();
+                    switch (response.extract().statusCode()) {
+                    case 204:
+                        /*
+                         * the event may come with some delay through all the OS and Java layers so it is
+                         * rather normal to get 204 before getting the expected event
+                         */
+                        return false;
+                    case 200:
+                        final JsonPath json = response
+                                .extract()
+                                .jsonPath();
+                        return file.toString().equals(json.getString("path")) && type.equals(json.getString("type"));
+                    default:
+                        throw new RuntimeException("Unexpected status code " + response.extract().statusCode());
+                    }
                 });
-
     }
-
 }