diff --git a/integration-tests/file/src/main/java/org/apache/camel/quarkus/component/file/it/FileRoutes.java b/integration-tests/file/src/main/java/org/apache/camel/quarkus/component/file/it/FileRoutes.java index 85c89403477c..b24c260b4ba7 100644 --- a/integration-tests/file/src/main/java/org/apache/camel/quarkus/component/file/it/FileRoutes.java +++ b/integration-tests/file/src/main/java/org/apache/camel/quarkus/component/file/it/FileRoutes.java @@ -38,7 +38,7 @@ public class FileRoutes extends RouteBuilder { @Override public void configure() { - from("file://target/" + READ_LOCK_IN + "?" + from("file://target/test-files/read-lock-in?" + "initialDelay=0&" + "move=.done&" + "delay=1000&" @@ -48,7 +48,7 @@ public void configure() { + "readLockCheckInterval=2000&" + "readLockLoggingLevel=TRACE&" + "readLockTimeout=5000") - .to("file://target/" + READ_LOCK_OUT); + .to("file://target/test-files/read-lock-out"); from("file://target/test-files/quartz-scheduled?scheduler=quartz&scheduler.cron=0/1+*+*+*+*+?&repeatCount=0") .convertBodyTo(String.class) 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 10fe1e76503a..d3693021fc43 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 @@ -21,9 +21,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.LinkedList; -import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -34,7 +31,6 @@ import io.restassured.path.json.JsonPath; import io.restassured.response.ValidatableResponse; import org.apache.camel.quarkus.core.util.FileUtils; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import static org.apache.camel.quarkus.component.file.it.FileResource.CONSUME_BATCH; @@ -50,21 +46,6 @@ class FileTest { private static final String FILE_CONTENT_02 = "Hello2"; private static final String FILE_CONTENT_03 = "Hello3"; - private List pathsToDelete = new LinkedList<>(); - - @AfterEach - public void afterEach() { - pathsToDelete.stream().forEach(p -> { - try { - Files.delete(p); - } catch (IOException e) { - // ignore - } - }); - - pathsToDelete.clear(); - } - @Test public void batch() throws InterruptedException, UnsupportedEncodingException { // Create 2 files @@ -126,42 +107,6 @@ public void fileWatchCreateUpdate() throws IOException, InterruptedException { awaitEvent(dir, file, "DELETE"); } - @Test - public void fileReadLock_minLength() throws Exception { - // Create a new file - String filePath = RestAssured.given() - .contentType(ContentType.BINARY) - .body(new byte[] {}) - .post("/file/create/{name}", FileRoutes.READ_LOCK_IN) - .then() - .statusCode(201) - .extract() - .body() - .asString(); - - String fileName = Paths.get(filePath).getFileName().toString(); - - Thread.sleep(10_000L); - - // Read the file that should not be there (.done folder) - RestAssured - .get("/file/get/{folder}/{name}", FileRoutes.READ_LOCK_IN + "/.done", fileName) - .then() - .statusCode(204); - - // Read the file that should not be there (output folder) - RestAssured - .get("/file/get/{folder}/{name}", FileRoutes.READ_LOCK_OUT, fileName) - .then() - .statusCode(204); - - // Read the file that should be there (input folder) - RestAssured - .get("/file/get/{folder}/{name}", FileRoutes.READ_LOCK_IN, fileName) - .then() - .statusCode(200); - } - private static String createFile(String content, String path) throws UnsupportedEncodingException { return createFile(content, path, "UTF-8", null); } 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 dff751bbfb59..1ac431639ca6 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 @@ -30,25 +30,14 @@ import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; -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.TEST_FILES_FOLDER; +import static org.apache.camel.quarkus.component.file.it.NonFlakyFileTestResource.*; import static org.apache.commons.io.FileUtils.readFileToString; import static org.awaitility.Awaitility.await; import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * This is an attempt to rewrite file tests from scratch in a cleaner way. It aims at having the test logic more @@ -172,7 +161,22 @@ void writeFileWithIso8859_1CharsetShouldSucceed() throws IOException { await().atMost(1, TimeUnit.SECONDS).until(() -> Files.exists(expectedFilePath)); assertEquals(CHARSET_WRITE_FILE_CONTENT, readFileToString(expectedFilePath.toFile(), charset)); - } + @Test + void readLockCantBeAcquiredOnFileSmallerThanReadLockMinLength() throws InterruptedException { + + Path inputFilePath = TEST_FILES_FOLDER.resolve(Paths.get(READ_LOCK_FOLDER_IN, READ_LOCK_FILE_NAME)); + Path doneFilePath = TEST_FILES_FOLDER.resolve(Paths.get(READ_LOCK_FOLDER_IN, ".done", READ_LOCK_FILE_NAME)); + Path outputFilePath = TEST_FILES_FOLDER.resolve(Paths.get(READ_LOCK_FOLDER_OUT, READ_LOCK_FILE_NAME)); + + Thread.sleep(10_000L); + + // Check that the input file still reside in input folder + assertTrue(Files.exists(inputFilePath)); + + // Check that .done and output folder do not contain the input file + assertFalse(Files.exists(doneFilePath)); + assertFalse(Files.exists(outputFilePath)); + } } diff --git a/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/NonFlakyFileTestResource.java b/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/NonFlakyFileTestResource.java index b228847d60f1..56b2ec1c8205 100644 --- a/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/NonFlakyFileTestResource.java +++ b/integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/NonFlakyFileTestResource.java @@ -52,6 +52,9 @@ public class NonFlakyFileTestResource implements QuarkusTestResourceLifecycleMan static final String FILE_CREATION_FOLDER = "file-creation"; static final String FILE_CREATION_FILE_NAME = "should-be-created"; static final String FILE_CREATION_FILE_CONTENT = FILE_CREATION_FILE_NAME + "-CONTENT"; + static final String READ_LOCK_FOLDER_IN = "read-lock-in"; + static final String READ_LOCK_FOLDER_OUT = "read-lock-out"; + static final String READ_LOCK_FILE_NAME = "read-lock-file"; private final Map createdTestFilesExpectedContent = new HashMap<>(); @@ -71,8 +74,11 @@ public Map start() { createTestFile("charset-read", CHARSET_READ_FILE_NAME, CHARSET_READ_FILE_CONTENT, StandardCharsets.ISO_8859_1); + createTestFile("read-lock-in", READ_LOCK_FILE_NAME); + // Do not use createTestFile("file-creation"... as it is already reserved by the createFileShouldSucceed test // Do not use createTestFile("charset-write"... as it is already reserved by the writeFileWithIso8859_1CharsetShouldSucceed test + // Do not use createTestFile("read-lock-out"... as it is already reserved by the readLockCantBeAcquiredOnFileSmallerThanReadLockMinLength test ensureAllTestFilesCreatedWithExpectedContent(); } catch (Exception ex) {