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 2012/01/24 10:31:52 UTC

svn commit: r1235186 - in /camel/trunk/camel-core/src/test/java/org/apache/camel/impl: PendingExchangesShutdownGracefulTest.java PendingExchangesTwoRouteShutdownGracefulTest.java

Author: davsclaus
Date: Tue Jan 24 09:31:52 2012
New Revision: 1235186

URL: http://svn.apache.org/viewvc?rev=1235186&view=rev
Log:
Fixed test

Modified:
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/PendingExchangesShutdownGracefulTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/PendingExchangesTwoRouteShutdownGracefulTest.java

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/PendingExchangesShutdownGracefulTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/PendingExchangesShutdownGracefulTest.java?rev=1235186&r1=1235185&r2=1235186&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/PendingExchangesShutdownGracefulTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/PendingExchangesShutdownGracefulTest.java Tue Jan 24 09:31:52 2012
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.impl;
 
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
@@ -27,9 +30,10 @@ import org.apache.camel.builder.RouteBui
 public class PendingExchangesShutdownGracefulTest extends ContextTestSupport {
 
     private static String foo = "";
+    private static CountDownLatch latch = new CountDownLatch(1);
 
     public void testShutdownGraceful() throws Exception {
-        getMockEndpoint("mock:foo").expectedMessageCount(1);
+        getMockEndpoint("mock:foo").expectedMinimumMessageCount(1);
 
         template.sendBody("seda:foo", "A");
         template.sendBody("seda:foo", "B");
@@ -40,11 +44,11 @@ public class PendingExchangesShutdownGra
         assertMockEndpointsSatisfied();
 
         // now stop the route before its complete
-        foo = foo + "stop";
+        latch.await(10, TimeUnit.SECONDS);
         context.stop();
 
         // it should wait as there was 1 inflight exchange and 4 pending messages left
-        assertEquals("Should graceful shutdown", "stopABCDE", foo);
+        assertEquals("Should graceful shutdown", "ABCDE", foo);
     }
 
     @Override
@@ -52,9 +56,10 @@ public class PendingExchangesShutdownGra
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("seda:foo").to("mock:foo").delay(1000).process(new Processor() {
+                from("seda:foo").to("mock:foo").delay(500).process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
                         foo = foo + exchange.getIn().getBody(String.class);
+                        latch.countDown();
                     }
                 });
             }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/PendingExchangesTwoRouteShutdownGracefulTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/PendingExchangesTwoRouteShutdownGracefulTest.java?rev=1235186&r1=1235185&r2=1235186&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/PendingExchangesTwoRouteShutdownGracefulTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/PendingExchangesTwoRouteShutdownGracefulTest.java Tue Jan 24 09:31:52 2012
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.impl;
 
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
@@ -28,6 +31,7 @@ public class PendingExchangesTwoRouteShu
 
     private static String foo = "";
     private static String bar = "";
+    private static CountDownLatch latch = new CountDownLatch(2);
 
     public void testShutdownGraceful() throws Exception {
         getMockEndpoint("mock:foo").expectedMinimumMessageCount(1);
@@ -47,14 +51,12 @@ public class PendingExchangesTwoRouteShu
 
         assertMockEndpointsSatisfied();
 
-        // now stop the route before its complete
-        foo = foo + "stop";
-        bar = bar + "stop";
+        latch.await(10, TimeUnit.SECONDS);
         context.stop();
 
         // it should wait as there were 2 inflight exchanges and 8 pending messages left
-        assertEquals("Should graceful shutdown", "stopABCDE", foo);
-        assertEquals("Should graceful shutdown", "stopABCDE", bar);
+        assertEquals("Should graceful shutdown", "ABCDE", foo);
+        assertEquals("Should graceful shutdown", "ABCDE", bar);
     }
 
     @Override
@@ -65,12 +67,14 @@ public class PendingExchangesTwoRouteShu
                 from("seda:foo").to("mock:foo").delay(1000).process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
                         foo = foo + exchange.getIn().getBody(String.class);
+                        latch.countDown();
                     }
                 });
 
                 from("seda:bar").to("mock:bar").delay(500).process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
                         bar = bar + exchange.getIn().getBody(String.class);
+                        latch.countDown();
                     }
                 });
             }