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 2008/09/07 18:55:40 UTC

svn commit: r692897 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/model/ test/java/org/apache/camel/issues/ test/java/org/apache/camel/processor/

Author: davsclaus
Date: Sun Sep  7 09:55:39 2008
New Revision: 692897

URL: http://svn.apache.org/viewvc?rev=692897&view=rev
Log:
CAMEL-794: Refined ThreadType for two issues
- configured children should also inherit route builder
- direct setting errorHandler on ThreadType is not supported as it does not work as end-users might expect when they build the route using the fluent builders.

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MultiErrorHandlerInRouteTest.java   (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadSetErrorHandlerTest.java   (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThreadType.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue794Test.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThreadType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThreadType.java?rev=692897&r1=692896&r2=692897&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThreadType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThreadType.java Sun Sep  7 09:55:39 2008
@@ -29,6 +29,7 @@
 import javax.xml.bind.annotation.XmlTransient;
 
 import org.apache.camel.Processor;
+import org.apache.camel.builder.ErrorHandlerBuilder;
 import org.apache.camel.processor.Pipeline;
 import org.apache.camel.processor.ThreadProcessor;
 import org.apache.camel.spi.RouteContext;
@@ -98,7 +99,6 @@
 
     @Override
     public Processor createProcessor(RouteContext routeContext) throws Exception {
-
         ThreadProcessor thread = new ThreadProcessor();
         thread.setExecutor(executor);
         if (coreSize != null) {
@@ -122,18 +122,29 @@
         thread.setThreadGroup(threadGroup);
 
         // TODO: see if we can avoid creating so many nested pipelines
-
         ArrayList<Processor> pipe = new ArrayList<Processor>(2);
         pipe.add(thread);
         pipe.add(createOutputsProcessor(routeContext, outputs));
         return new Pipeline(pipe);
     }
 
-    ///////////////////////////////////////////////////////////////////
-    //
-    // Fluent Methods
-    //
-    ///////////////////////////////////////////////////////////////////
+    @Override
+    protected void configureChild(ProcessorType output) {
+        super.configureChild(output);
+        if (isInheritErrorHandler()) {
+            output.setErrorHandlerBuilder(getErrorHandlerBuilder());
+        }
+    }
+
+    // Fluent methods
+    // -----------------------------------------------------------------------
+    @Override
+    public ProcessorType errorHandler(ErrorHandlerBuilder errorHandlerBuilder) {
+        // do not support setting error handling on thread type as its confusing and will not be used
+        throw new IllegalArgumentException("Setting errorHandler on ThreadType is not supported."
+            + " Instead set the errorHandler on the parent.");
+    }
+
     public ThreadType coreSize(int coreSize) {
         setCoreSize(coreSize);
         return this;

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue794Test.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue794Test.java?rev=692897&r1=692896&r2=692897&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue794Test.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue794Test.java Sun Sep  7 09:55:39 2008
@@ -65,30 +65,6 @@
         assertEquals(3, counter); // One call + 2 re-deliveries
     }
 
-    public void xtestThreadErrorHandlerRedeliveryAfterThread() throws Exception {
-        // TODO: Fix me
-        counter = 0;
-
-        // We expect the exchange here after 1 delivery and 2 re-deliveries
-        MockEndpoint mock = getMockEndpoint("mock:deafultAfterThread");
-        mock.expectedMessageCount(1);
-        mock.message(0).header("org.apache.camel.Redelivered").isEqualTo(Boolean.TRUE);
-        mock.message(0).header("org.apache.camel.RedeliveryCounter").isEqualTo(2);
-
-        template.sendBody("direct:inAfterThread", "Hello World");
-
-        mock.assertIsSatisfied();
-    }
-
-    public void xtestThreadErrorHandlerCallAfterThread() throws Exception {
-        // TODO: Fix me
-        counter = 0;
-
-        template.sendBody("direct:inAfterThread", "Hello World");
-
-        assertEquals(3, counter); // One call + 2 re-deliveries
-    }
-
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
@@ -111,16 +87,6 @@
                             throw new Exception("Forced exception by unit test");
                         }
                     });
-
-                from("direct:inAfterThread")
-                    .thread(2)
-                    .errorHandler(deadLetterChannel("mock:afterThread").maximumRedeliveries(2))
-                    .process(new Processor() {
-                        public void process(Exchange exchange) throws Exception {
-                            counter++;
-                            throw new Exception("Forced exception by unit test");
-                        }
-                    });
             }
         };
     }

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MultiErrorHandlerInRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MultiErrorHandlerInRouteTest.java?rev=692897&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MultiErrorHandlerInRouteTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MultiErrorHandlerInRouteTest.java Sun Sep  7 09:55:39 2008
@@ -0,0 +1,102 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * Unit test with multi route specific error handlers
+ */
+public class MultiErrorHandlerInRouteTest extends ContextTestSupport {
+    private MyProcessor outer = new MyProcessor();
+    private MyProcessor inner = new MyProcessor();
+
+    public void testNoErrors() throws Exception {
+        outer.setName("Claus");
+        inner.setName("James");
+
+        MockEndpoint mock = getMockEndpoint("mock:end");
+        mock.expectedHeaderReceived("name", "James");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisifed();
+    }
+
+    public void testOuterError() throws Exception {
+        outer.setName("Error");
+        inner.setName("James");
+
+        MockEndpoint mock = getMockEndpoint("mock:outer");
+        mock.expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisifed();
+    }
+
+    public void testInnerError() throws Exception {
+        outer.setName("Claus");
+        inner.setName("Error");
+
+        MockEndpoint mock = getMockEndpoint("mock:inner");
+        mock.expectedHeaderReceived("name", "Claus");
+        mock.expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisifed();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:start")
+                    .errorHandler(deadLetterChannel("mock:outer").maximumRedeliveries(1))
+                    .process(outer)
+                    .to("direct:outer");
+
+               from("direct:outer")
+                    .errorHandler(deadLetterChannel("mock:inner").maximumRedeliveries(2))
+                    .process(inner)
+                    .to("mock:end");
+            }
+        };
+    }
+
+    private class MyProcessor implements Processor {
+
+        private String name;
+
+        public void process(Exchange exchange) throws Exception {
+            if (name.equals("Error")) {
+                throw new IllegalArgumentException("Forced exception by unit test");
+            }
+            exchange.getIn().setHeader("name", name);
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
+    
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MultiErrorHandlerInRouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MultiErrorHandlerInRouteTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadSetErrorHandlerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadSetErrorHandlerTest.java?rev=692897&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadSetErrorHandlerTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadSetErrorHandlerTest.java Sun Sep  7 09:55:39 2008
@@ -0,0 +1,45 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Unit test that verifies that thread does not allow add a error handler
+ * as it will not kick in as expected by end-users.
+ */
+public class ThreadSetErrorHandlerTest extends ContextTestSupport {
+
+    public void testNotAllowed() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                public void configure() throws Exception {
+                    from("direct:start")
+                        .thread(2)
+                        // add error handler on thread is not allowed instead set on the parent (from)
+                        .errorHandler(deadLetterChannel("mock:error"))
+                        .to("mock:end");
+                }
+            });
+            fail("Should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // ok
+        }
+    }
+
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadSetErrorHandlerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadSetErrorHandlerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date