Skip to content

Commit

Permalink
file: migrate quartz scheduled file polling to new test harness #3584
Browse files Browse the repository at this point in the history
  • Loading branch information
aldettinger authored and jamesnetherton committed Sep 11, 2023
1 parent c5213d3 commit fa2fc25
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public void configure() {
+ "readLockTimeout=5000")
.to("file://target/" + READ_LOCK_OUT);

from("file://target/quartz?scheduler=quartz&scheduler.cron=0/1+*+*+*+*+?&repeatCount=0")
.to("file://target/quartz/out");
from("file://target/test-files/quartz-scheduled?scheduler=quartz&scheduler.cron=0/1+*+*+*+*+?&repeatCount=0")
.convertBodyTo(String.class)
.to("mock:quartzScheduledFilePolling");

from("file://target/" + CONSUME_BATCH + "?"
+ "initialDelay=0&delay=100")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,6 @@ public void fileReadLock_minLength() throws Exception {
.statusCode(200);
}

@Test
public void quartzSchedulerFilePollingConsumer() throws InterruptedException, UnsupportedEncodingException {
String fileName = createFile(FILE_BODY, "/file/create/quartz");

String targetFileName = Paths.get(fileName).toFile().getName();
await().atMost(10, TimeUnit.SECONDS).until(() -> {
return Files.exists(Paths.get("target/quartz/out", targetFileName));
});

RestAssured
.get("/file/get/{folder}/{name}", "quartz/out", targetFileName)
.then()
.statusCode(200)
.body(equalTo(FILE_BODY));
}

private static String createFile(String content, String path) throws UnsupportedEncodingException {
return createFile(content, path, "UTF-8", null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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.awaitility.Awaitility.await;
import static org.hamcrest.core.IsEqual.equalTo;
Expand Down Expand Up @@ -95,4 +96,14 @@ public void pollEnrichShouldSetExchangeBodyWithFileContent() {
.body(Matchers.is(POLL_ENRICH_FILE_CONTENT));
}

@Test
public void quartzScheduledFilePollingShouldSucceed() {
await().atMost(10, TimeUnit.SECONDS).until(
() -> RestAssured
.get("/file/getFromMock/quartzScheduledFilePolling")
.then()
.extract().asString(),
equalTo(QUARTZ_SCHEDULED_FILE_CONTENT));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class NonFlakyFileTestResource implements QuarkusTestResourceLifecycleMan
static final String IDEMPOTENT_FILE_CONTENT = IDEMPOTENT_FILE_NAME + "-CONTENT";
static final String POLL_ENRICH_FILE_NAME = "poll-enrich-file";
static final String POLL_ENRICH_FILE_CONTENT = POLL_ENRICH_FILE_NAME + "-CONTENT";
static final String QUARTZ_SCHEDULED_FILE_NAME = "quartz-schedule-file";
static final String QUARTZ_SCHEDULED_FILE_CONTENT = QUARTZ_SCHEDULED_FILE_NAME + "-CONTENT";

private final List<Path> createdTestFiles = new ArrayList<Path>();

Expand All @@ -55,6 +57,8 @@ public Map<String, String> start() {

createTestFile("poll-enrich", POLL_ENRICH_FILE_NAME);

createTestFile("quartz-scheduled", QUARTZ_SCHEDULED_FILE_NAME);

ensureAllTestFilesCreatedWithExpectedContent();
} catch (Exception ex) {
throw new RuntimeException("Problem while initializing test files", ex);
Expand Down

0 comments on commit fa2fc25

Please sign in to comment.