You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2012/01/11 02:20:22 UTC

svn commit: r1229846 - in /camel/branches/camel-2.9.x/camel-core/src: main/java/org/apache/camel/component/seda/ test/java/org/apache/camel/component/seda/

Author: hadrian
Date: Wed Jan 11 01:20:22 2012
New Revision: 1229846

URL: http://svn.apache.org/viewvc?rev=1229846&view=rev
Log:
CAMEL-4882. Remove timed out Exchanges from seda queue

Modified:
    camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaProducer.java
    camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutDisabledTest.java
    camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutTest.java

Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaProducer.java?rev=1229846&r1=1229845&r2=1229846&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaProducer.java (original)
+++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaProducer.java Wed Jan 11 01:20:22 2012
@@ -129,6 +129,8 @@ public class SedaProducer extends Defaul
                     exchange.setException(new ExchangeTimedOutException(exchange, timeout));
                     // count down to indicate timeout
                     latch.countDown();
+                    // remove   timed out Exchange from queue
+                    queue.remove(copy);
                 }
             } else {
                 if (log.isTraceEnabled()) {

Modified: camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutDisabledTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutDisabledTest.java?rev=1229846&r1=1229845&r2=1229846&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutDisabledTest.java (original)
+++ camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutDisabledTest.java Wed Jan 11 01:20:22 2012
@@ -27,10 +27,10 @@ import org.apache.camel.builder.RouteBui
  */
 public class SedaTimeoutDisabledTest extends ContextTestSupport {
 
-    public void testSedaNoTineout() throws Exception {
+    public void testSedaNoTimeout() throws Exception {
         Future<String> out = template.asyncRequestBody("seda:foo?timeout=0", "World", String.class);
-        // use 60 sec failsafe in case something hangs
-        assertEquals("Bye World", out.get(60, TimeUnit.SECONDS));
+        // use 5 sec failsafe in case something hangs
+        assertEquals("Bye World", out.get(5, TimeUnit.SECONDS));
     }
 
     @Override
@@ -38,7 +38,7 @@ public class SedaTimeoutDisabledTest ext
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("seda:foo").to("mock:before").delay(2000).transform(body().prepend("Bye ")).to("mock:result");
+                from("seda:foo").to("mock:before").delay(500).transform(body().prepend("Bye ")).to("mock:result");
             }
         };
     }

Modified: camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutTest.java?rev=1229846&r1=1229845&r2=1229846&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutTest.java (original)
+++ camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutTest.java Wed Jan 11 01:20:22 2012
@@ -28,29 +28,44 @@ import org.apache.camel.builder.RouteBui
  * @version 
  */
 public class SedaTimeoutTest extends ContextTestSupport {
+    private int timeout = 100;
 
-    public void testSedaNoTineout() throws Exception {
+    public void testSedaNoTimeout() throws Exception {
         Future<String> out = template.asyncRequestBody("seda:foo", "World", String.class);
         assertEquals("Bye World", out.get());
     }
 
-    public void testSedaTineout() throws Exception {
-        Future<String> out = template.asyncRequestBody("seda:foo?timeout=100", "World", String.class);
+    public void testSedaTimeout() throws Exception {
+        Future<String> out = template.asyncRequestBody("seda:foo?timeout=" + timeout, "World", String.class);
         try {
             out.get();
             fail("Should have thrown an exception");
         } catch (ExecutionException e) {
             assertIsInstanceOf(CamelExecutionException.class, e.getCause());
             assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause().getCause());
+
+            SedaEndpoint se = (SedaEndpoint)context.getRoute("seda").getEndpoint();
+            assertNotNull("Consumer endpoint cannot be null", se);
+            assertEquals("Timeout Exchanges should be removed from queue", 0, se.getCurrentQueueSize());
         }
     }
 
+    public void testSedaTimeoutWithStoppedRoute() throws Exception {
+        context.stopRoute("seda");
+        timeout = 500;
+        testSedaTimeout();
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("seda:foo").to("mock:before").delay(250).transform(body().prepend("Bye ")).to("mock:result");
+                from("seda:foo").routeId("seda")
+                    .to("mock:before")
+                    .delay(250)
+                    .transform(body().prepend("Bye "))
+                    .to("mock:result");
             }
         };
     }