camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r935691 - in /camel/trunk/tests/camel-itest/src/test: java/org/apache/camel/itest/jetty/JettyJmsShutdownTest.java resources/log4j.properties resources/org/apache/camel/itest/jetty/JettyJmsShutdownTest-context.xml
Date Mon, 19 Apr 2010 18:06:29 GMT
Author: davsclaus
Date: Mon Apr 19 18:06:29 2010
New Revision: 935691

URL: http://svn.apache.org/viewvc?rev=935691&view=rev
Log:
Added unit test based on user forum issue.

Added:
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsShutdownTest.java
      - copied, changed from r935469, camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsTest.java
    camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsShutdownTest-context.xml
      - copied, changed from r935469, camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsTest-context.xml
Modified:
    camel/trunk/tests/camel-itest/src/test/resources/log4j.properties

Copied: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsShutdownTest.java
(from r935469, camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsShutdownTest.java?p2=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsShutdownTest.java&p1=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsTest.java&r1=935469&r2=935691&rev=935691&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsTest.java
(original)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsShutdownTest.java
Mon Apr 19 18:06:29 2010
@@ -16,52 +16,40 @@
  */
 package org.apache.camel.itest.jetty;
 
-import java.util.List;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 
+import junit.framework.Assert;
 import org.apache.camel.CamelContext;
-import org.apache.camel.EndpointInject;
-import org.apache.camel.Exchange;
 import org.apache.camel.ProducerTemplate;
-import org.apache.camel.component.mock.MockEndpoint;
-
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
 @ContextConfiguration
-public class JettyJmsTest extends AbstractJUnit4SpringContextTests {
+public class JettyJmsShutdownTest extends AbstractJUnit4SpringContextTests {
 
     @Autowired
     protected CamelContext camelContext;
 
-    @EndpointInject(uri = "mock:resultEndpoint")
-    protected MockEndpoint resultEndpoint;
+    @Autowired
+    protected ProducerTemplate template;
 
     @Test
-    public void testMocksAreValid() throws Exception {
-        assertNotNull(resultEndpoint);
-        resultEndpoint.reset();
-
-        ProducerTemplate template = camelContext.createProducerTemplate();
-        template.sendBodyAndHeader("jetty:http://localhost:9000/test", "Hello form Willem",
"Operation", "greetMe");
-
-        // Sleep a while and wait for the message whole processing
-        Thread.sleep(4000);
-        template.stop();
-
-        MockEndpoint.assertIsSatisfied(camelContext);
-        List<Exchange> list = resultEndpoint.getReceivedExchanges();
-        assertEquals("Should get one message", list.size(), 1);
-
-        for (Exchange exchange : list) {
-            Object result = exchange.getIn().getBody();
-            assertEquals("Should get the request", "Hello form Willem", result);
-            assertEquals("Should get the header", "greetMe", exchange.getIn().getHeader("Operation"));
-        }
+    public void testShutdown() throws Exception {
+        Future<String> reply1 = template.asyncRequestBody("jetty:http://localhost:9000/test",
"World", String.class);
+        Future<String> reply2 = template.asyncRequestBody("jetty:http://localhost:9000/test",
"Camel", String.class);
+        Future<String> reply3 = template.asyncRequestBody("jetty:http://localhost:9000/test",
"Tiger", String.class);
+
+        Thread.sleep(1000);
+
+        // shutdown while in progress
+        camelContext.stop();
+
+        Assert.assertEquals("Bye World", reply1.get(5, TimeUnit.SECONDS));
+        Assert.assertEquals("Bye Camel", reply2.get(5, TimeUnit.SECONDS));
+        Assert.assertEquals("Bye Tiger", reply3.get(5, TimeUnit.SECONDS));
     }
 
-}
+}
\ No newline at end of file

Modified: camel/trunk/tests/camel-itest/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/log4j.properties?rev=935691&r1=935690&r2=935691&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/log4j.properties (original)
+++ camel/trunk/tests/camel-itest/src/test/resources/log4j.properties Mon Apr 19 18:06:29
2010
@@ -29,8 +29,7 @@ log4j.logger.org.apache.activemq=WARN
 # CONSOLE appender not used by default
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
-#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
 
 # File appender
 log4j.appender.file=org.apache.log4j.FileAppender

Copied: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsShutdownTest-context.xml
(from r935469, camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsTest-context.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsShutdownTest-context.xml?p2=camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsShutdownTest-context.xml&p1=camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsTest-context.xml&r1=935469&r2=935691&rev=935691&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsTest-context.xml
(original)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsShutdownTest-context.xml
Mon Apr 19 18:06:29 2010
@@ -17,7 +17,6 @@
 -->
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
@@ -27,21 +26,25 @@
         <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
     </bean>
 
-    <bean id="setExchangePatternProcessor" class="org.apache.camel.itest.jetty.SetExchangePatternProcessor"/>
+    <camelContext xmlns="http://camel.apache.org/schema/spring">
 
-    <!-- START SNIPPET: example -->
-    <camelContext xmlns="http://camel.apache.org/schema/spring" trace="true">
-        <route>
+        <!-- defer shutdown to route the in progress exchanges -->
+        <route shutdownRoute="Defer">
             <from uri="jetty:http://localhost:9000/test"/>
-            <to uri="log:MyCategory?level=INFO"/>
-            <process ref="setExchangePatternProcessor"/>
-            <to uri="jms:responseQueue"/>
+            <to uri="jms:queue:foo"/>
         </route>
-        <route>
-            <from uri="jms:responseQueue"/>
-            <to uri="mock:resultEndpoint"/>
+
+        <!-- also defer this as we defer the other route -->
+        <route shutdownRoute="Defer">
+            <from uri="jms:queue:foo?concurrentConsumers=5"/>
+            <delay>
+                <constant>5000</constant>
+            </delay>
+            <transform>
+                <simple>Bye ${body}</simple>
+            </transform>
         </route>
+
     </camelContext>
-    <!-- END SNIPPET: example -->
 
 </beans>



Mime
View raw message