You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zh...@apache.org on 2024/03/06 01:27:46 UTC
(camel-quarkus) branch main updated: Migrate file watch tests to new harness #3584 (#5840)
This is an automated email from the ASF dual-hosted git repository.
zhfeng 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 771d92245f Migrate file watch tests to new harness #3584 (#5840)
771d92245f is described below
commit 771d92245f602cfefaa7206ce2ee716c640f578b
Author: Alexandre Gallice <al...@gmail.com>
AuthorDate: Wed Mar 6 02:27:41 2024 +0100
Migrate file watch tests to new harness #3584 (#5840)
---
.../camel/quarkus/component/file/it/FileIT.java | 24 ------
.../camel/quarkus/component/file/it/FileTest.java | 88 ----------------------
.../component/file/it/NonFlakyFileTest.java | 74 +++++++++++++++++-
3 files changed, 73 insertions(+), 113 deletions(-)
diff --git a/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/FileIT.java b/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/FileIT.java
deleted file mode 100644
index 62dda77376..0000000000
--- a/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/FileIT.java
+++ /dev/null
@@ -1,24 +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.
- */
-package org.apache.camel.quarkus.component.file.it;
-
-import io.quarkus.test.junit.QuarkusIntegrationTest;
-
-@QuarkusIntegrationTest
-class FileIT extends FileTest {
-
-}
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
deleted file mode 100644
index 12238e8cc6..0000000000
--- a/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/FileTest.java
+++ /dev/null
@@ -1,88 +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.
- */
-package org.apache.camel.quarkus.component.file.it;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.concurrent.TimeUnit;
-
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import io.restassured.path.json.JsonPath;
-import io.restassured.response.ValidatableResponse;
-import org.apache.camel.quarkus.core.util.FileUtils;
-import org.junit.jupiter.api.Test;
-
-import static org.awaitility.Awaitility.await;
-
-@QuarkusTest
-class FileTest {
-
- @Test
- public void fileWatchCreateUpdate() throws IOException {
- final Path dir = Files.createTempDirectory(FileTest.class.getSimpleName()).toRealPath();
- RestAssured.given()
- .queryParam("path", dir.toString())
- .get("/file-watch/get-events")
- .then()
- .statusCode(204);
-
- final Path file = dir.resolve("file.txt");
- Files.write(file, "a file content".getBytes(StandardCharsets.UTF_8));
-
- awaitEvent(dir, file, "CREATE");
-
- Files.write(file, "changed content".getBytes(StandardCharsets.UTF_8));
-
- awaitEvent(dir, file, "MODIFY");
-
- Files.delete(file);
-
- awaitEvent(dir, file, "DELETE");
- }
-
- private static void awaitEvent(final Path dir, final Path file, final String type) {
- await()
- .pollInterval(10, TimeUnit.MILLISECONDS)
- .atMost(20, TimeUnit.SECONDS)
- .until(() -> {
- final ValidatableResponse response = RestAssured.given()
- .queryParam("path", dir.toString())
- .get("/file-watch/get-events")
- .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();
- String expectedPath = FileUtils.nixifyPath(file);
- String actualPath = json.getString("path");
- return expectedPath.equals(actualPath) && type.equals(json.getString("type"));
- default:
- throw new RuntimeException("Unexpected status code " + response.extract().statusCode());
- }
- });
- }
-}
diff --git a/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/NonFlakyFileTest.java b/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/NonFlakyFileTest.java
index 6854d55288..77a1afd429 100644
--- a/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/NonFlakyFileTest.java
+++ b/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/NonFlakyFileTest.java
@@ -17,6 +17,7 @@
package org.apache.camel.quarkus.component.file.it;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -28,12 +29,35 @@ import io.quarkus.test.common.QuarkusTestResource;
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.apache.camel.quarkus.core.util.FileUtils;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import static org.apache.camel.quarkus.component.file.it.FileResource.SEPARATOR;
import static org.apache.camel.quarkus.component.file.it.FileResource.SORT_BY;
-import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.*;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.BATCH_FILE_NAME_1_CONTENT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.BATCH_FILE_NAME_2_CONTENT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.CHARSET_READ_FILE_CONTENT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.CHARSET_WRITE_FILE_CONTENT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.CHARSET_WRITE_FILE_CREATION_FOLDER;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.CHARSET_WRITE_FILE_NAME;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.FILE_CREATION_FILE_CONTENT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.FILE_CREATION_FILE_NAME;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.FILE_CREATION_FOLDER;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.FILTER_NON_SKIPPED_FILE_CONTENT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.IDEMPOTENT_FILE_CONTENT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.IDEMPOTENT_FILE_NAME;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.POLL_ENRICH_FILE_CONTENT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.QUARTZ_SCHEDULED_FILE_CONTENT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.READ_LOCK_FILE_NAME;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.READ_LOCK_FOLDER_IN;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.READ_LOCK_FOLDER_OUT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.SORT_BY_NAME_1_CONTENT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.SORT_BY_NAME_2_CONTENT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.SORT_BY_NAME_3_CONTENT;
+import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.TEST_FILES_FOLDER;
import static org.apache.commons.io.FileUtils.readFileToString;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.core.IsEqual.equalTo;
@@ -208,4 +232,52 @@ class NonFlakyFileTest {
equalTo(SORT_BY_NAME_3_CONTENT + SEPARATOR + SORT_BY_NAME_2_CONTENT + SEPARATOR + SORT_BY_NAME_1_CONTENT));
}
+ @Test
+ public void fileWatchShouldCatchCreateModifyAndDeleteEvents() throws IOException {
+ final Path fileWatchDirectory = Files.createTempDirectory(NonFlakyFileTest.class.getSimpleName()).toRealPath();
+ RestAssured.given()
+ .queryParam("path", fileWatchDirectory.toString())
+ .get("/file-watch/get-events")
+ .then()
+ .statusCode(204);
+
+ final Path watchedFilePath = fileWatchDirectory.resolve("watched-file.txt");
+ Files.write(watchedFilePath, "a file content".getBytes(StandardCharsets.UTF_8));
+ awaitEvent(fileWatchDirectory, watchedFilePath, "CREATE");
+
+ Files.write(watchedFilePath, "changed content".getBytes(StandardCharsets.UTF_8));
+ awaitEvent(fileWatchDirectory, watchedFilePath, "MODIFY");
+
+ Files.delete(watchedFilePath);
+ awaitEvent(fileWatchDirectory, watchedFilePath, "DELETE");
+ }
+
+ private static void awaitEvent(final Path fileWatchDirectory, final Path watchedFile, final String extepecteEventType) {
+ await()
+ .pollInterval(100, TimeUnit.MILLISECONDS)
+ .atMost(20, TimeUnit.SECONDS)
+ .until(() -> {
+ final ValidatableResponse getEventsResponse = RestAssured.given()
+ .queryParam("path", fileWatchDirectory.toString())
+ .get("/file-watch/get-events")
+ .then();
+ switch (getEventsResponse.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 = getEventsResponse.extract().jsonPath();
+
+ String expectedPath = FileUtils.nixifyPath(watchedFile);
+ String actualPath = json.getString("path");
+ return expectedPath.equals(actualPath) && extepecteEventType.equals(json.getString("type"));
+ default:
+ throw new RuntimeException("Unexpected status code " + getEventsResponse.extract().statusCode());
+ }
+ });
+ }
+
}