Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;

import org.apache.camel.CamelExecutionException;
import org.apache.camel.Exchange;
Expand All @@ -35,6 +36,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -333,10 +335,11 @@ public void configure() {
context.getRouteController().startRoute("renameTest");
mock.assertIsSatisfied();

// Verify source file is gone and target file exists
Thread.sleep(500);
assertTrue(!sourceFile.exists(), "Source file should be moved");
assertTrue(ftpFile("done/rename-source.txt").toFile().exists(), "Moved file should exist in done folder");
// Wait for the post-processing file move to complete on the filesystem
await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
assertTrue(!sourceFile.exists(), "Source file should be moved");
assertTrue(ftpFile("done/rename-source.txt").toFile().exists(), "Moved file should exist in done folder");
});

// Verify content is intact (no download/upload)
assertEquals("Rename test content",
Expand Down Expand Up @@ -378,9 +381,10 @@ public void configure() {
context.getRouteController().startRoute("renameSubTest");
mock.assertIsSatisfied();

Thread.sleep(500);
assertTrue(!ftpFile("subdir/rename-sub.txt").toFile().exists(), "Source should be moved");
assertTrue(ftpFile("subdir/processed/rename-sub.txt").toFile().exists(), "Target should exist");
await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
assertTrue(!ftpFile("subdir/rename-sub.txt").toFile().exists(), "Source should be moved");
assertTrue(ftpFile("subdir/processed/rename-sub.txt").toFile().exists(), "Target should exist");
});

context.getRouteController().stopRoute("renameSubTest");
}
Expand Down Expand Up @@ -437,10 +441,12 @@ public void configure() {
context.getRouteController().startRoute("sizePreserveTest");
mock.assertIsSatisfied();

Thread.sleep(500);
// Verify moved file has same size
long movedSize = ftpFile("moved/size-preserve.txt").toFile().length();
assertEquals(originalSize, movedSize, "Moved file should have same size (server-side rename)");
// Wait for the post-processing file move to complete on the filesystem
await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
assertTrue(ftpFile("moved/size-preserve.txt").toFile().exists(), "Moved file should exist");
long movedSize = ftpFile("moved/size-preserve.txt").toFile().length();
assertEquals(originalSize, movedSize, "Moved file should have same size (server-side rename)");
});

context.getRouteController().stopRoute("sizePreserveTest");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ public void testConcurrentReadAndWrite() throws Exception {
template.sendBodyAndHeader(baseUri(), "Write content " + i,
Exchange.FILE_NAME, "write-" + i + ".txt");
writeSuccess.incrementAndGet();
Thread.sleep(50); // Small delay between writes
}
} catch (Exception e) {
errorCount.incrementAndGet();
Expand All @@ -291,7 +290,6 @@ public void testConcurrentReadAndWrite() throws Exception {
readSuccess.incrementAndGet();
}
}
Thread.sleep(100); // Small delay between reads
}
} catch (Exception e) {
errorCount.incrementAndGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.security.MessageDigest;
import java.util.concurrent.TimeUnit;

import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
Expand All @@ -31,6 +32,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -296,9 +298,10 @@ public void configure() {
context.getRouteController().startRoute("zeroDelete");
mock.assertIsSatisfied();

// Verify the file was deleted
Thread.sleep(1000); // Give time for delete
assertTrue(!ftpFile("zero-delete.txt").toFile().exists(), "Zero-byte file should be deleted after consumption");
// Wait for the post-processing file delete to complete on the filesystem
await().atMost(10, TimeUnit.SECONDS)
.untilAsserted(() -> assertTrue(!ftpFile("zero-delete.txt").toFile().exists(),
"Zero-byte file should be deleted after consumption"));

context.getRouteController().stopRoute("zeroDelete");
}
Expand Down Expand Up @@ -329,10 +332,11 @@ public void configure() {
context.getRouteController().startRoute("zeroMove");
mock.assertIsSatisfied();

// Verify the file was moved
Thread.sleep(1000);
assertTrue(!ftpFile("zero-move.txt").toFile().exists(), "Original zero-byte file should not exist");
assertTrue(ftpFile("done/zero-move.txt").toFile().exists(), "Zero-byte file should be in done folder");
// Wait for the post-processing file move to complete on the filesystem
await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
assertTrue(!ftpFile("zero-move.txt").toFile().exists(), "Original zero-byte file should not exist");
assertTrue(ftpFile("done/zero-move.txt").toFile().exists(), "Zero-byte file should be in done folder");
});

context.getRouteController().stopRoute("zeroMove");
}
Expand Down Expand Up @@ -442,14 +446,15 @@ public void testFilePermissionsMetadata() throws Exception {
@Test
@Timeout(60)
public void testPreserveTimestampOnDownload() throws Exception {
// Create a file
// Create a file and set its modification time to a known value in the past.
// This avoids Thread.sleep() — instead of waiting for clock drift, we explicitly
// set a past timestamp and verify the consumer reports it correctly.
template.sendBodyAndHeader(baseUri(), "Timestamp test", Exchange.FILE_NAME, "timestamp-test.txt");

// Record original timestamp
long originalModified = ftpFile("timestamp-test.txt").toFile().lastModified();

// Wait a bit to ensure time difference would be noticeable
Thread.sleep(2000);
File timestampFile = ftpFile("timestamp-test.txt").toFile();
long pastTimestamp = System.currentTimeMillis() - 60_000; // 1 minute ago
timestampFile.setLastModified(pastTimestamp);
long originalModified = timestampFile.lastModified();

MockEndpoint mock = getMockEndpoint("mock:timestamp");
mock.expectedMessageCount(1);
Expand All @@ -471,8 +476,8 @@ public void configure() {
Long headerModified = exchange.getIn().getHeader(Exchange.FILE_LAST_MODIFIED, Long.class);

assertNotNull(headerModified, "FILE_LAST_MODIFIED header should be present");
// The header should reflect the file's modification time from the server
// Allow for some timestamp granularity differences (within 2 seconds)
// The header should reflect the file's modification time from the server.
// Allow for some timestamp granularity differences (within 2 seconds).
assertTrue(Math.abs(headerModified - originalModified) < 2000,
"Timestamp in header should be close to original file timestamp");

Expand Down