You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/10/08 05:28:16 UTC

[camel] 02/02: CAMEL-15558 pollEnrich timeout issue added unit test

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.4.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit bc06e4d3b6ba06e6ff4587b0481b396d01eeed48
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Oct 8 07:20:04 2020 +0200

    CAMEL-15558 pollEnrich timeout issue added unit test
---
 .../component/file/GenericFilePollingConsumer.java |  2 +-
 .../processor/enricher/PollEnricherFileTest.java   | 52 ++++++++++++++++++++++
 .../src/test/resources/log4j2.properties           |  2 +-
 .../camel/support/ScheduledPollEndpoint.java       | 11 +++--
 4 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFilePollingConsumer.java b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFilePollingConsumer.java
index 95bbd6e..642e034 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFilePollingConsumer.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFilePollingConsumer.java
@@ -33,7 +33,7 @@ public class GenericFilePollingConsumer extends EventDrivenPollingConsumer {
 
     public GenericFilePollingConsumer(GenericFileEndpoint endpoint) throws Exception {
         super(endpoint);
-        this.delay = endpoint.getDefaultDelay();
+        this.delay = endpoint.getDelay() > 0 ? endpoint.getDelay() : endpoint.getDefaultDelay();
     }
 
     @Override
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnricherFileTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnricherFileTest.java
new file mode 100644
index 0000000..4abdf57
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnricherFileTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.processor.enricher;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class PollEnricherFileTest extends ContextTestSupport {
+
+    @Test
+    public void testPollEnrichFile() throws Exception {
+        getMockEndpoint("mock:2").expectedMessageCount(1);
+        getMockEndpoint("mock:2").message(0).body().isNull();
+
+        assertMockEndpointsSatisfied();
+
+        long ex1 = getMockEndpoint("mock:1").getExchanges().get(0).getProperty(Exchange.RECEIVED_TIMESTAMP, long.class);
+        long ex2 = getMockEndpoint("mock:2").getExchanges().get(0).getProperty(Exchange.RECEIVED_TIMESTAMP, long.class);
+        long delta = ex2 - ex1;
+        Assertions.assertTrue(delta > 800, "Should delay for at least 1 second, was " + delta + " millis");
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("timer:hello?repeatCount=1&delay=10")
+                    .to("log:1", "mock:1")
+                    .pollEnrich("file:target/temp?noop=true&fileName=doesnotexist.csv", 1000)
+                    .to("log:2", "mock:2");
+            }
+        };
+    }
+}
diff --git a/core/camel-core/src/test/resources/log4j2.properties b/core/camel-core/src/test/resources/log4j2.properties
index a5b53e0..5bf435b 100644
--- a/core/camel-core/src/test/resources/log4j2.properties
+++ b/core/camel-core/src/test/resources/log4j2.properties
@@ -43,7 +43,7 @@ logger.file-cluster.level = DEBUG
 rootLogger.level = INFO
 
 rootLogger.appenderRef.file.ref = file
-#rootLogger.appenderRef.console.ref = console
+rootLogger.appenderRef.console.ref = console
 
 #logger.camel-core.name = org.apache.camel
 #logger.camel-core.level = TRACE
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java
index f25221f..2d594bd 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java
@@ -191,10 +191,6 @@ public abstract class ScheduledPollEndpoint extends DefaultEndpoint {
         }
     }
 
-    public long getDefaultDelay() {
-        return (getDelay() == -1) ? DEFAULT_DELAY : getDelay();
-    }
-
     @Override
     protected void doStart() throws Exception {
         super.doStart();
@@ -244,6 +240,13 @@ public abstract class ScheduledPollEndpoint extends DefaultEndpoint {
         this.delay = delay;
     }
 
+    /**
+     * Gets the default delay.
+     */
+    public long getDefaultDelay() {
+        return DEFAULT_DELAY;
+    }
+
     public TimeUnit getTimeUnit() {
         return timeUnit;
     }