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/03/16 12:58:03 UTC

[camel-spring-boot] branch master updated (e381e45 -> 8ec796b)

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

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git.


    from e381e45  Regen
     new aed02820 Fixed test after recent changes in camel-core
     new 0881d67  CAMEL-14642: camel-spring-boot - Using max duration and shutdown before should terminate scheduled thread quicker
     new 8ec796b  CAMEL-14642: camel-spring-boot - Using max duration and shutdown before should terminate scheduled thread quicker

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../boot/CamelSpringBootApplicationListener.java   | 88 ++++++++++++++++++----
 .../boot/CamelSpringBootTemplateShutdownTest.java  |  4 +-
 .../spring/boot/StartupShutdownOrderTest.java      |  6 +-
 .../SupervisingRouteControllerRestartTest.java     |  8 +-
 .../boot/SupervisingRouteControllerTest.java       |  8 +-
 .../spring/boot/zlast/MixedJavaDslAndXmlTest.java  |  2 +-
 6 files changed, 87 insertions(+), 29 deletions(-)


[camel-spring-boot] 01/03: Fixed test after recent changes in camel-core

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit aed028204d0ceeca06c7df76793e1baf9d6793f9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 16 13:35:29 2020 +0100

    Fixed test after recent changes in camel-core
---
 .../camel/spring/boot/CamelSpringBootTemplateShutdownTest.java    | 4 ++--
 .../org/apache/camel/spring/boot/StartupShutdownOrderTest.java    | 6 +++---
 .../camel/spring/boot/SupervisingRouteControllerRestartTest.java  | 8 ++++----
 .../apache/camel/spring/boot/SupervisingRouteControllerTest.java  | 8 ++++----
 .../apache/camel/spring/boot/zlast/MixedJavaDslAndXmlTest.java    | 2 +-
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelSpringBootTemplateShutdownTest.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelSpringBootTemplateShutdownTest.java
index 3ec20e1..90e2ea1 100644
--- a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelSpringBootTemplateShutdownTest.java
+++ b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelSpringBootTemplateShutdownTest.java
@@ -60,7 +60,7 @@ public class CamelSpringBootTemplateShutdownTest {
 
         camelContext.stop();
 
-        assertTrue(((ServiceSupport) camelContext).isStopped());
+        assertTrue(camelContext.isStopped());
         assertTrue(((ServiceSupport) consumerTemplate).isStopped());
         assertTrue(((ServiceSupport) producerTemplate).isStopped());
         assertTrue(((ServiceSupport) fluentProducerTemplate).isStopped());
@@ -75,7 +75,7 @@ public class CamelSpringBootTemplateShutdownTest {
         applicationContext.close();
 
         assertFalse(applicationContext.isActive());
-        assertTrue(((ServiceSupport) camelContext).isStopped());
+        assertTrue(camelContext.isStopped());
         assertTrue(((ServiceSupport) consumerTemplate).isStopped());
         assertTrue(((ServiceSupport) producerTemplate).isStopped());
         assertTrue(((ServiceSupport) fluentProducerTemplate).isStopped());
diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/StartupShutdownOrderTest.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/StartupShutdownOrderTest.java
index d705ec6..1a2bcad 100644
--- a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/StartupShutdownOrderTest.java
+++ b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/StartupShutdownOrderTest.java
@@ -213,7 +213,7 @@ public class StartupShutdownOrderTest {
         final ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
             CamelAutoConfiguration.class, Beans.class);
 
-        final ServiceSupport camelContext = (ServiceSupport) context.getBean(CamelContext.class);
+        final CamelContext camelContext = context.getBean(CamelContext.class);
         final Map<String, TestState> testStates = context.getBeansOfType(TestState.class);
 
         assertThat(camelContext.isStarted()).as("Camel context should be started").isTrue();
@@ -224,8 +224,8 @@ public class StartupShutdownOrderTest {
         testStates.values().stream().forEach(TestState::assertValid);
     }
 
-    static ServiceSupport camel(final ApplicationContext context) {
-        return (ServiceSupport) context.getBean(CamelContext.class);
+    static CamelContext camel(final ApplicationContext context) {
+        return context.getBean(CamelContext.class);
     }
 
     static boolean camelIsStarted(final ApplicationContext context) {
diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java
index a4257c4..d620de9 100644
--- a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java
+++ b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerRestartTest.java
@@ -118,18 +118,18 @@ public class SupervisingRouteControllerRestartTest {
                 public void configure() throws Exception {
                     getContext().addComponent("dummy", new DummyComponent());
 
-                    from("timer:foo?period=5s")
+                    from("timer:foo?period=5000")
                         .id("foo")
                         .startupOrder(2)
                         .to("mock:foo");
-                    from("timer:bar?period=5s")
+                    from("timer:bar?period=5000")
                         .id("bar")
                         .startupOrder(1)
                         .to("mock:bar");
-                    from("scheduler:unmanaged?initialDelay=5s")
+                    from("scheduler:unmanaged?initialDelay=5000")
                         .id("scheduler-unmanaged")
                         .to("mock:scheduler-unmanaged");
-                    from("timer:no-autostartup?period=5s")
+                    from("timer:no-autostartup?period=5000")
                         .id("timer-no-autostartup")
                         .autoStartup(false)
                         .to("mock:timer-no-autostartup");
diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerTest.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerTest.java
index ca366de..8c8dc37 100644
--- a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerTest.java
+++ b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SupervisingRouteControllerTest.java
@@ -114,18 +114,18 @@ public class SupervisingRouteControllerTest {
             return new RouteBuilder() {
                 @Override
                 public void configure() throws Exception {
-                    from("timer:foo?period=5s")
+                    from("timer:foo?period=5000")
                         .id("foo")
                         .startupOrder(2)
                         .to("mock:foo");
-                    from("timer:bar?period=5s")
+                    from("timer:bar?period=5000")
                         .id("bar")
                         .startupOrder(1)
                         .to("mock:bar");
-                    from("scheduler:unmanaged?initialDelay=5s")
+                    from("scheduler:unmanaged?initialDelay=5000")
                         .id("scheduler-unmanaged")
                         .to("mock:scheduler-unmanaged");
-                    from("timer:no-autostartup?period=5s")
+                    from("timer:no-autostartup?period=5000")
                         .id("timer-no-autostartup")
                         .autoStartup(false)
                         .to("mock:timer-no-autostartup");
diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/zlast/MixedJavaDslAndXmlTest.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/zlast/MixedJavaDslAndXmlTest.java
index 54be1c4..06239ad 100644
--- a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/zlast/MixedJavaDslAndXmlTest.java
+++ b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/zlast/MixedJavaDslAndXmlTest.java
@@ -52,7 +52,7 @@ public class MixedJavaDslAndXmlTest {
             return new RouteBuilder() {
                 @Override
                 public void configure() throws Exception {
-                    from("timer:project?period=1s").id("java").setBody().constant("Hello World from Java Route")
+                    from("timer:project?period=1000").id("java").setBody().constant("Hello World from Java Route")
                         .log(">>> ${body}");
                 }
             };


[camel-spring-boot] 02/03: CAMEL-14642: camel-spring-boot - Using max duration and shutdown before should terminate scheduled thread quicker

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0881d6716809bc967fff1d2b438437a90a2bbbb1
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 16 13:38:29 2020 +0100

    CAMEL-14642: camel-spring-boot - Using max duration and shutdown before should terminate scheduled thread quicker
---
 .../boot/CamelSpringBootApplicationListener.java   | 34 ++++++++++++++++++++--
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationListener.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationListener.java
index 58ace8a..9942705 100644
--- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationListener.java
+++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationListener.java
@@ -20,19 +20,23 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.StartupListener;
 import org.apache.camel.main.MainDurationEventNotifier;
+import org.apache.camel.main.MainLifecycleStrategy;
 import org.apache.camel.main.RoutesCollector;
 import org.apache.camel.main.RoutesConfigurer;
 import org.apache.camel.spi.CamelEvent;
 import org.apache.camel.spi.CamelEvent.Type;
 import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.support.EventNotifierSupport;
+import org.apache.camel.support.LifecycleStrategySupport;
 import org.apache.camel.support.service.ServiceHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -227,7 +231,15 @@ public class CamelSpringBootApplicationListener implements ApplicationListener<C
                 latch.countDown();
             }
         };
-        executorService.schedule(task, seconds, TimeUnit.SECONDS);
+
+        final ScheduledFuture future = executorService.schedule(task, seconds, TimeUnit.SECONDS);
+        camelContext.addLifecycleStrategy(new LifecycleStrategySupport() {
+            @Override
+            public void onContextStop(CamelContext context) {
+                // we are stopping then cancel the task so we can shutdown quicker
+                future.cancel(true);
+            }
+        });
     }
 
     private void terminateApplicationContext(final ConfigurableApplicationContext applicationContext, final CamelContext camelContext, int seconds) {
@@ -237,7 +249,15 @@ public class CamelSpringBootApplicationListener implements ApplicationListener<C
             // we need to run a daemon thread to stop ourselves so this thread pool can be stopped nice also
             new Thread(applicationContext::close).start();
         };
-        executorService.schedule(task, seconds, TimeUnit.SECONDS);
+
+        final ScheduledFuture future = executorService.schedule(task, seconds, TimeUnit.SECONDS);
+        camelContext.addLifecycleStrategy(new LifecycleStrategySupport() {
+            @Override
+            public void onContextStop(CamelContext context) {
+                // we are stopping then cancel the task so we can shutdown quicker
+                future.cancel(true);
+            }
+        });
     }
 
     private void terminateApplicationContext(final ConfigurableApplicationContext applicationContext, final CamelContext camelContext, final CountDownLatch latch) {
@@ -252,7 +272,15 @@ public class CamelSpringBootApplicationListener implements ApplicationListener<C
                 // ignore
             }
         };
-        executorService.submit(task);
+
+        final Future future = executorService.submit(task);
+        camelContext.addLifecycleStrategy(new LifecycleStrategySupport() {
+            @Override
+            public void onContextStop(CamelContext context) {
+                // we are stopping then cancel the task so we can shutdown quicker
+                future.cancel(true);
+            }
+        });
     }
 
 }


[camel-spring-boot] 03/03: CAMEL-14642: camel-spring-boot - Using max duration and shutdown before should terminate scheduled thread quicker

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8ec796b7e3cc0064677ff23b3b4e16d080232c7e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 16 13:57:50 2020 +0100

    CAMEL-14642: camel-spring-boot - Using max duration and shutdown before should terminate scheduled thread quicker
---
 .../boot/CamelSpringBootApplicationListener.java   | 60 ++++++++++++++++------
 1 file changed, 45 insertions(+), 15 deletions(-)

diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationListener.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationListener.java
index 9942705..8f6c5d0 100644
--- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationListener.java
+++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationListener.java
@@ -220,16 +220,24 @@ public class CamelSpringBootApplicationListener implements ApplicationListener<C
 
     private void terminateMainControllerAfter(final CamelContext camelContext, int seconds, final AtomicBoolean completed, final CountDownLatch latch) {
         ScheduledExecutorService executorService = camelContext.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "CamelSpringBootTerminateTask");
+
+        final AtomicBoolean running = new AtomicBoolean();
         Runnable task = () -> {
-            LOG.info("CamelSpringBoot triggering shutdown of the JVM.");
-            try {
-                camelContext.stop();
-            } catch (Throwable e) {
-                LOG.warn("Error during stopping CamelContext", e);
-            } finally {
-                completed.set(true);
-                latch.countDown();
-            }
+            // need to spin up as separate thread so we can terminate this thread pool without problems
+            Runnable stop = () -> {
+                running.set(true);
+                LOG.info("CamelSpringBoot triggering shutdown of the JVM.");
+                try {
+                    camelContext.stop();
+                } catch (Throwable e) {
+                    LOG.warn("Error during stopping CamelContext", e);
+                } finally {
+                    completed.set(true);
+                    latch.countDown();
+                }
+                running.set(false);
+            };
+            new Thread(stop, "CamelSpringBootTerminateTaskWorker").start();
         };
 
         final ScheduledFuture future = executorService.schedule(task, seconds, TimeUnit.SECONDS);
@@ -237,17 +245,27 @@ public class CamelSpringBootApplicationListener implements ApplicationListener<C
             @Override
             public void onContextStop(CamelContext context) {
                 // we are stopping then cancel the task so we can shutdown quicker
-                future.cancel(true);
+                if (!running.get()) {
+                    future.cancel(true);
+                }
             }
         });
     }
 
     private void terminateApplicationContext(final ConfigurableApplicationContext applicationContext, final CamelContext camelContext, int seconds) {
         ScheduledExecutorService executorService = camelContext.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "CamelSpringBootTerminateTask");
+
+        final AtomicBoolean running = new AtomicBoolean();
         Runnable task = () -> {
-            LOG.info("CamelSpringBoot triggering shutdown of the JVM.");
-            // we need to run a daemon thread to stop ourselves so this thread pool can be stopped nice also
-            new Thread(applicationContext::close).start();
+            // need to spin up as separate thread so we can terminate this thread pool without problems
+            Runnable stop = () -> {
+                running.set(true);
+                LOG.info("CamelSpringBoot triggering shutdown of the JVM.");
+                // we need to run a daemon thread to stop ourselves so this thread pool can be stopped nice also
+                new Thread(applicationContext::close).start();
+                running.set(false);
+            };
+            new Thread(stop, "CamelSpringBootTerminateTaskWorker").start();
         };
 
         final ScheduledFuture future = executorService.schedule(task, seconds, TimeUnit.SECONDS);
@@ -255,22 +273,29 @@ public class CamelSpringBootApplicationListener implements ApplicationListener<C
             @Override
             public void onContextStop(CamelContext context) {
                 // we are stopping then cancel the task so we can shutdown quicker
-                future.cancel(true);
+                if (!running.get()) {
+                    future.cancel(true);
+                }
             }
         });
     }
 
     private void terminateApplicationContext(final ConfigurableApplicationContext applicationContext, final CamelContext camelContext, final CountDownLatch latch) {
         ExecutorService executorService = camelContext.getExecutorServiceManager().newSingleThreadExecutor(this, "CamelSpringBootTerminateTask");
+
+        final AtomicBoolean running = new AtomicBoolean();
         Runnable task = () -> {
             try {
                 latch.await();
+                // only mark as running after the latch
+                running.set(true);
                 LOG.info("CamelSpringBoot triggering shutdown of the JVM.");
                 // we need to run a daemon thread to stop ourselves so this thread pool can be stopped nice also
                 new Thread(applicationContext::close).start();
             } catch (Throwable e) {
                 // ignore
             }
+            running.set(false);
         };
 
         final Future future = executorService.submit(task);
@@ -278,7 +303,12 @@ public class CamelSpringBootApplicationListener implements ApplicationListener<C
             @Override
             public void onContextStop(CamelContext context) {
                 // we are stopping then cancel the task so we can shutdown quicker
-                future.cancel(true);
+                if (!running.get()) {
+                    future.cancel(true);
+                } else {
+                    // trigger shutdown
+                    latch.countDown();
+                }
             }
         });
     }