camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r810364 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/processor/ThreadsProcessor.java test/java/org/apache/camel/issues/GertJBIIssueTest.java
Date Wed, 02 Sep 2009 05:53:42 GMT
Author: davsclaus
Date: Wed Sep  2 05:53:41 2009
New Revision: 810364

URL: http://svn.apache.org/viewvc?rev=810364&view=rev
Log:
added unit test based on some JBI simulate endpoint not exists problem

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/issues/GertJBIIssueTest.java   (with
props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ThreadsProcessor.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ThreadsProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ThreadsProcessor.java?rev=810364&r1=810363&r2=810364&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ThreadsProcessor.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/ThreadsProcessor.java
Wed Sep  2 05:53:41 2009
@@ -63,7 +63,7 @@
         // let it execute async and return the Future
         Callable<Exchange> task = createTask(output, copy);
 
-        // sumbit the task
+        // submit the task
         Future<Exchange> future = getExecutorService().submit(task);
 
         // compute if we should wait for task to complete or not

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/GertJBIIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/GertJBIIssueTest.java?rev=810364&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/issues/GertJBIIssueTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/issues/GertJBIIssueTest.java Wed
Sep  2 05:53:41 2009
@@ -0,0 +1,106 @@
+/**
+ * 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.issues;
+
+import java.util.concurrent.Future;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.WaitForTaskToComplete;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class GertJBIIssueTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testSimulateJBIEndpointNotExistWait() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(deadLetterChannel("mock:dlc").maximumRedeliveries(0).handled(false));
+
+                from("direct:start")
+                    // must wait for task to complete to know if there was an exception
+                    // as its in-only based
+                    .threads(2).waitForTaskToComplete(WaitForTaskToComplete.Always)
+                    .to("mock:done")
+                    .throwException(new IllegalArgumentException("Forced"));
+
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:done").expectedMessageCount(1);
+        getMockEndpoint("mock:dlc").expectedMessageCount(1);
+
+        try {
+            template.sendBody("direct:start", "Hello World");
+            fail("Should thrown exception");
+        } catch (Exception e) {
+            Exception cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+            assertEquals("Forced", cause.getMessage());
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testSimulateJBIEndpointNotExist() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(deadLetterChannel("mock:dlc").maximumRedeliveries(0).handled(false));
+
+                from("direct:start")
+                    // now we do not wait for task to complete but we get the future handle
+                    // so we can use that to wait for the task to complete and see if it
failed or not
+                    .threads(2)
+                    .to("mock:done")
+                    .throwException(new IllegalArgumentException("Forced"));
+
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:done").expectedMessageCount(1);
+        getMockEndpoint("mock:dlc").expectedMessageCount(1);
+
+        Exchange out = template.send("direct:start", new Processor() {
+                public void process(Exchange exchange) throws Exception {
+                    exchange.getIn().setBody("Hello World");
+                }
+            });
+
+        assertMockEndpointsSatisfied();
+
+        // we send in an in-only that was processed async. Then Camel provides the Future
handle in OUT
+        // that let us use it to check whether the task completed or failed (or even get
the result etc.)
+        Future<Exchange> future = out.getOut().getBody(Future.class);
+        Exchange task = future.get();
+        assertEquals("Should have failed", true, task.isFailed());
+
+        Exception cause = assertIsInstanceOf(IllegalArgumentException.class, task.getException());
+        assertEquals("Forced", cause.getMessage());
+    }
+
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/GertJBIIssueTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/GertJBIIssueTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message