You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2021/10/13 12:05:40 UTC
[camel] branch main updated: CAMEL-17045: added unit test for the
file resume strategy
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new eb7dbad CAMEL-17045: added unit test for the file resume strategy
eb7dbad is described below
commit eb7dbad7b975de1e1d323899bf1f3d43fc64e164
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Wed Oct 13 13:08:56 2021 +0200
CAMEL-17045: added unit test for the file resume strategy
---
.../file/FileConsumerResumeStrategyTest.java | 91 ++++++++++++++++++++++
1 file changed, 91 insertions(+)
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
new file mode 100644
index 0000000..5a804c1
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerResumeStrategyTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.component.file;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.file.consumer.FileConsumerResumeStrategy;
+import org.apache.camel.component.file.consumer.FileResumeInfo;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FileConsumerResumeStrategyTest extends ContextTestSupport {
+
+ private static class TestResumeStrategy implements FileConsumerResumeStrategy {
+ private static final Logger LOG = LoggerFactory.getLogger(TestResumeStrategy.class);
+
+ @Override
+ public void resume(FileResumeInfo resumeInfo) {
+ List<String> processedFiles = Arrays.asList("0.txt", "1.txt", "2.txt");
+ int count = 0;
+
+ File[] input = resumeInfo.getInputFiles();
+ File[] tmp = Arrays.copyOf(input, input.length);
+
+ for (File file : resumeInfo.getInputFiles()) {
+ if (!processedFiles.contains(file.getName())) {
+ LOG.info("Including file {}", file);
+ tmp[count] = file;
+ count++;
+ } else {
+ LOG.info("Skipping file {}", file);
+ }
+ }
+
+ resumeInfo.setOutputFiles(Arrays.copyOf(tmp, count));
+ }
+ }
+
+ @Test
+ public void testDepth() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceivedInAnyOrder("3", "4", "5", "6");
+
+ template.sendBodyAndHeader(fileUri("resume"), "0", Exchange.FILE_NAME, "0.txt");
+ template.sendBodyAndHeader(fileUri("resume"), "1", Exchange.FILE_NAME, "1.txt");
+ template.sendBodyAndHeader(fileUri("resume"), "2", Exchange.FILE_NAME, "2.txt");
+ template.sendBodyAndHeader(fileUri("resume"), "3", Exchange.FILE_NAME, "3.txt");
+ template.sendBodyAndHeader(fileUri("resume"), "4", Exchange.FILE_NAME, "4.txt");
+ template.sendBodyAndHeader(fileUri("resume"), "5", Exchange.FILE_NAME, "5.txt");
+ template.sendBodyAndHeader(fileUri("resume"), "6", Exchange.FILE_NAME, "6.txt");
+
+ // only expect 4 of the 6 sent
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
+ bindToRegistry("testResumeStrategy", new TestResumeStrategy());
+
+ from(fileUri("resume?noop=true&recursive=true&resumeStrategy=#testResumeStrategy"))
+ .convertBodyTo(String.class).to("mock:result");
+ }
+ };
+ }
+
+}