camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zregv...@apache.org
Subject camel git commit: CAMEL-11008: Consumer/Producer templates are no...
Date Tue, 14 Mar 2017 12:17:28 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x c82fd3bae -> 562794a7a


CAMEL-11008: Consumer/Producer templates are no...

...t stopped when auto-configured in Spring Boot

Adds `addService` for Consumer/Producer templates when configured from
Spring Boot this ensures that these are stopped on CamelContext shutdown


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/562794a7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/562794a7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/562794a7

Branch: refs/heads/camel-2.17.x
Commit: 562794a7a34843fd169edf19a1daf134c8418684
Parents: c82fd3b
Author: Zoran Regvart <zregvart@apache.org>
Authored: Mon Mar 13 23:42:12 2017 +0100
Committer: Zoran Regvart <zregvart@apache.org>
Committed: Tue Mar 14 13:16:44 2017 +0100

----------------------------------------------------------------------
 .../spring/boot/CamelAutoConfiguration.java     | 12 ++--
 .../CamelSpringBootTemplateShutdownTest.java    | 74 ++++++++++++++++++++
 2 files changed, 82 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/562794a7/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index 1385968..d8c3d36 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -100,8 +100,10 @@ public class CamelAutoConfiguration {
     // Camel handles the lifecycle of this bean
     @ConditionalOnMissingBean(ProducerTemplate.class)
     ProducerTemplate producerTemplate(CamelContext camelContext,
-                                      CamelConfigurationProperties config) {
-        return camelContext.createProducerTemplate(config.getProducerTemplateCacheSize());
+                                      CamelConfigurationProperties config) throws Exception
{
+        final ProducerTemplate producerTemplate = camelContext.createProducerTemplate(config.getProducerTemplateCacheSize());
+        camelContext.addService(producerTemplate);
+        return producerTemplate;
     }
 
     /**
@@ -111,8 +113,10 @@ public class CamelAutoConfiguration {
     // Camel handles the lifecycle of this bean
     @ConditionalOnMissingBean(ConsumerTemplate.class)
     ConsumerTemplate consumerTemplate(CamelContext camelContext,
-                                      CamelConfigurationProperties config) {
-        return camelContext.createConsumerTemplate(config.getConsumerTemplateCacheSize());
+                                      CamelConfigurationProperties config) throws Exception
{
+        final ConsumerTemplate consumerTemplate = camelContext.createConsumerTemplate(config.getConsumerTemplateCacheSize());
+        camelContext.addService(consumerTemplate);
+        return consumerTemplate;
     }
 
     // SpringCamelContext integration

http://git-wip-us.apache.org/repos/asf/camel/blob/562794a7/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelSpringBootTemplateShutdownTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelSpringBootTemplateShutdownTest.java
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelSpringBootTemplateShutdownTest.java
new file mode 100644
index 0000000..0b7b6e0
--- /dev/null
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelSpringBootTemplateShutdownTest.java
@@ -0,0 +1,74 @@
+/**
+ * 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.spring.boot;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.support.ServiceSupport;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.support.AbstractApplicationContext;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class CamelSpringBootTemplateShutdownTest {
+
+    CamelContext camelContext;
+
+    AbstractApplicationContext applicationContext;
+
+    ConsumerTemplate consumerTemplate;
+
+    ProducerTemplate producerTemplate;
+
+    @Before
+    public void setupApplicationContext() {
+        applicationContext = new AnnotationConfigApplicationContext(CamelAutoConfiguration.class);
+        camelContext = applicationContext.getBean(CamelContext.class);
+        consumerTemplate = applicationContext.getBean(ConsumerTemplate.class);
+        producerTemplate = applicationContext.getBean(ProducerTemplate.class);
+    }
+
+    @Test
+    public void shouldStopTemplatesWithCamelShutdown() throws Exception {
+        assertTrue(((ServiceSupport) consumerTemplate).isStarted());
+        assertTrue(((ServiceSupport) producerTemplate).isStarted());
+
+        camelContext.stop();
+
+        assertTrue(((ServiceSupport) camelContext).isStopped());
+        assertTrue(((ServiceSupport) consumerTemplate).isStopped());
+        assertTrue(((ServiceSupport) producerTemplate).isStopped());
+    }
+
+    @Test
+    public void shouldStopTemplatesWithApplicationContextShutdown() throws Exception {
+        assertTrue(((ServiceSupport) consumerTemplate).isStarted());
+        assertTrue(((ServiceSupport) producerTemplate).isStarted());
+
+        applicationContext.close();
+
+        assertFalse(applicationContext.isActive());
+        assertTrue(((ServiceSupport) camelContext).isStopped());
+        assertTrue(((ServiceSupport) consumerTemplate).isStopped());
+        assertTrue(((ServiceSupport) producerTemplate).isStopped());
+    }
+
+}
\ No newline at end of file


Mime
View raw message