Skip to content
Draft
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 @@ -17,6 +17,8 @@
package org.apache.camel.component.stream;

import java.io.File;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit6.CamelTestSupport;
Expand Down Expand Up @@ -45,7 +47,7 @@ public void doPreSetup() throws Exception {

@Test
public void testScanFile() throws Exception {
Thread.sleep(60000);
new CountDownLatch(1).await(60, TimeUnit.SECONDS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.File;
import java.io.FileOutputStream;
import java.util.concurrent.TimeUnit;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
Expand All @@ -26,6 +27,7 @@

import static org.apache.camel.test.junit6.TestSupport.createDirectory;
import static org.apache.camel.test.junit6.TestSupport.deleteDirectory;
import static org.awaitility.Awaitility.await;

/**
* Unit test for scan stream file
Expand Down Expand Up @@ -58,10 +60,9 @@ public void testScanFile() throws Exception {
FileOutputStream fos = new FileOutputStream(file);
try {
fos.write("Hello\n".getBytes());
Thread.sleep(150);
fos.flush();
fos.write("World\n".getBytes());
// ensure it does not read the file again
Thread.sleep(1000);
fos.flush();
} finally {
fos.close();
}
Expand All @@ -79,17 +80,17 @@ public void testScanRefreshedFile() throws Exception {
FileOutputStream fos = refreshFile(null);
try {
fos.write("Hello\nWorld\n".getBytes());
Thread.sleep(150);
fos.flush();

context.getRouteController().startAllRoutes();

// roll-over file
Thread.sleep(1500);
// wait for the initial 2 messages before rolling over the file
await().atMost(10, TimeUnit.SECONDS).until(() -> mock.getReceivedCounter() >= 2);

fos = refreshFile(fos);
fos.write("Bye\nWorld\n".getBytes());
fos.write("!\n".getBytes());
// ensure it does not read the file again
Thread.sleep(1500);
fos.flush();
} finally {
fos.close();
}
Expand All @@ -105,9 +106,8 @@ public void testScanFileAlreadyWritten() throws Exception {
FileOutputStream fos = refreshFile(null);
try {
fos.write("Hello\nthere\nWorld\n!\n".getBytes());
fos.flush();
context.getRouteController().startAllRoutes();
// ensure it does not read the file again
Thread.sleep(1000);
} finally {
fos.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,17 @@ public void testScanFile() throws Exception {

FileOutputStream fos = new FileOutputStream(file);
fos.write("Hello\n".getBytes());
Thread.sleep(150);
fos.write("World\n".getBytes());
Thread.sleep(150);
fos.write("Hello\n".getBytes());
Thread.sleep(150);
fos.write("World\n".getBytes());
Thread.sleep(150);
fos.write("Hello\n".getBytes());
Thread.sleep(150);
fos.write("World\n".getBytes());
Thread.sleep(150);
fos.write("Hello Boy\n".getBytes());
Thread.sleep(150);
fos.write("World\n".getBytes());
fos.flush();
fos.close();

MockEndpoint.assertIsSatisfied(context);

fos.close();
}

@Override
Expand Down