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 2022/10/25 13:01:29 UTC

[camel] branch main updated: CAMEL-18647: Java DSL - Set delay options from route templates in Delay EIP

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

davsclaus 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 b66a36ac0fc CAMEL-18647: Java DSL - Set delay options from route templates in Delay EIP
b66a36ac0fc is described below

commit b66a36ac0fc8836d4e28182380f540dd7442eab3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Oct 25 15:01:07 2022 +0200

    CAMEL-18647: Java DSL - Set delay options from route templates in Delay EIP
---
 .../org/apache/camel/model/DelayDefinition.java     | 21 +++++++++++++++++++++
 .../camel/processor/DelayerAsyncDelayedTest.java    | 20 ++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/DelayDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/DelayDefinition.java
index 995472ac7b2..fa1ed0f9204 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/DelayDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/DelayDefinition.java
@@ -99,6 +99,19 @@ public class DelayDefinition extends ExpressionNode implements ExecutorServiceAw
         return this;
     }
 
+    /**
+     * Whether or not the caller should run the task when it was rejected by the thread pool.
+     * <p/>
+     * Is by default <tt>true</tt>
+     *
+     * @param  callerRunsWhenRejected whether or not the caller should run
+     * @return                        the builder
+     */
+    public DelayDefinition callerRunsWhenRejected(String callerRunsWhenRejected) {
+        setCallerRunsWhenRejected(callerRunsWhenRejected);
+        return this;
+    }
+
     /**
      * Enables asynchronous delay which means the thread will <b>not</b> block while delaying.
      */
@@ -107,6 +120,14 @@ public class DelayDefinition extends ExpressionNode implements ExecutorServiceAw
         return this;
     }
 
+    /**
+     * Enables asynchronous delay which means the thread will <b>not</b> block while delaying.
+     */
+    public DelayDefinition asyncDelayed(String asyncDelayed) {
+        setAsyncDelayed(asyncDelayed);
+        return this;
+    }
+
     /**
      * Enables asynchronous delay which means the thread will <b>not</b> block while delaying.
      */
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/DelayerAsyncDelayedTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/DelayerAsyncDelayedTest.java
index b0b69f80947..db23a37f43a 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/DelayerAsyncDelayedTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/DelayerAsyncDelayedTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.processor;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -23,6 +24,13 @@ import org.junit.jupiter.api.Test;
 
 public class DelayerAsyncDelayedTest extends ContextTestSupport {
 
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.getPropertiesComponent().addInitialProperty("myAsync", "true");
+        return context;
+    }
+
     @Test
     public void testSendingMessageGetsDelayed() throws Exception {
         MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
@@ -51,6 +59,16 @@ public class DelayerAsyncDelayedTest extends ContextTestSupport {
         resultEndpoint.assertIsSatisfied();
     }
 
+    @Test
+    public void testDelayConstantPlaceholder() throws Exception {
+        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
+        resultEndpoint.expectedMessageCount(1);
+        // should at least take 1 sec to complete
+        resultEndpoint.setResultMinimumWaitTime(900);
+        template.sendBody("seda:c", "<hello>world!</hello>");
+        resultEndpoint.assertIsSatisfied();
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
@@ -62,6 +80,8 @@ public class DelayerAsyncDelayedTest extends ContextTestSupport {
                 // START SNIPPET: ex2
                 from("seda:b").delay(1000).asyncDelayed().to("mock:result");
                 // END SNIPPET: ex2
+
+                from("seda:c").delay(1000).asyncDelayed("{{myAsync}}").to("mock:result");
             }
         };
     }