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

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


The following commit(s) were added to refs/heads/camel-3.0.x by this push:
     new 631afbb  CAMEL-14449: camel-main: duration properties are ignored
631afbb is described below

commit 631afbb980d5e2bd7f9544d59ce87239a18e5dbe
Author: lburgazzoli <[email protected]>
AuthorDate: Tue Jan 28 11:05:03 2020 +0100

    CAMEL-14449: camel-main: duration properties are ignored
---
 .../java/org/apache/camel/main/BaseMainSupport.java  | 18 +++++++++---------
 .../test/java/org/apache/camel/main/MainTest.java    | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 04929ed..d8935f1 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -511,15 +511,6 @@ public abstract class BaseMainSupport extends 
ServiceSupport {
             pc.setOverrideProperties(overrideProperties);
         }
 
-        if (mainConfigurationProperties.getDurationMaxMessages() > 0 || 
mainConfigurationProperties.getDurationMaxIdleSeconds() > 0) {
-            // register lifecycle so we can trigger to shutdown the JVM when 
maximum number of messages has been processed
-            EventNotifier notifier = new 
MainDurationEventNotifier(camelContext, 
mainConfigurationProperties.getDurationMaxMessages(),
-                    mainConfigurationProperties.getDurationMaxIdleSeconds(), 
completed, latch, true);
-            // register our event notifier
-            ServiceHelper.startService(notifier);
-            camelContext.getManagementStrategy().addEventNotifier(notifier);
-        }
-
         // gathers the properties (key=value) that was auto-configured
         final Map<String, String> autoConfiguredProperties = new 
LinkedHashMap<>();
 
@@ -563,6 +554,15 @@ public abstract class BaseMainSupport extends 
ServiceSupport {
             });
         }
 
+        if (mainConfigurationProperties.getDurationMaxMessages() > 0 || 
mainConfigurationProperties.getDurationMaxIdleSeconds() > 0) {
+            // register lifecycle so we can trigger to shutdown the JVM when 
maximum number of messages has been processed
+            EventNotifier notifier = new 
MainDurationEventNotifier(camelContext, 
mainConfigurationProperties.getDurationMaxMessages(),
+                mainConfigurationProperties.getDurationMaxIdleSeconds(), 
completed, latch, true);
+            // register our event notifier
+            ServiceHelper.startService(notifier);
+            camelContext.getManagementStrategy().addEventNotifier(notifier);
+        }
+
         // try to load the route builders
         loadRouteBuilders(camelContext);
         // then configure and add the routes
diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainTest.java 
b/core/camel-main/src/test/java/org/apache/camel/main/MainTest.java
index b5e95ae..550f506 100644
--- a/core/camel-main/src/test/java/org/apache/camel/main/MainTest.java
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainTest.java
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.main;
 
+import java.util.Properties;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.ManagementStrategy;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -116,6 +119,23 @@ public class MainTest extends Assert {
         main.stop();
     }
 
+    @Test
+    public void testLifecycleConfiguration() throws Exception {
+        Properties properties = new Properties();
+        properties.setProperty("camel.main.duration-max-messages", "1");
+
+        Main main = new Main();
+        main.setOverrideProperties(properties);
+        main.start();
+
+        CamelContext camelContext = main.getCamelContext();
+        ManagementStrategy strategy = camelContext.getManagementStrategy();
+
+        assertTrue(strategy.getEventNotifiers().stream().anyMatch(n -> n 
instanceof MainDurationEventNotifier));
+
+        main.stop();
+    }
+
     public static class MyRouteBuilder extends RouteBuilder {
         @Override
         public void configure() throws Exception {

Reply via email to