camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r935198 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/java/org/apache/camel/processor/ camel-core/src/test/java/org/apache/camel/impl/ components/camel-spring/src/test/java/org/apache/camel/spring/i...
Date Sat, 17 Apr 2010 16:21:01 GMT
Author: davsclaus
Date: Sat Apr 17 16:21:00 2010
New Revision: 935198

URL: http://svn.apache.org/viewvc?rev=935198&view=rev
Log:
CAMEL-2635: Improved validation of routes on startup to check if they have output.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/RouteMustHaveOutputOnExceptionTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Throttler.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithLocalOnExceptionTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=935198&r1=935197&r2=935198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Sat
Apr 17 16:21:00 2010
@@ -227,7 +227,6 @@ public abstract class ProcessorDefinitio
             }
         }
 
-
         if (log.isTraceEnabled()) {
             log.trace(defn + " wrapped in Channel: " + channel);
         }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java?rev=935198&r1=935197&r2=935198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
Sat Apr 17 16:21:00 2010
@@ -169,4 +169,33 @@ public final class ProcessorDefinitionHe
         }
     }
 
+    /**
+     * Is there any outputs in the given list.
+     * <p/>
+     * Is used for check if the route output has any real outputs (non abstracts)
+     *
+     * @param outputs           the outputs
+     * @param excludeAbstract   whether or not to exclude abstract outputs (e.g. skip onException
etc.)
+     * @return <tt>true</tt> if has outputs, otherwise <tt>false</tt>
is returned
+     */
+    @SuppressWarnings("unchecked")
+    public static boolean hasOutputs(List<ProcessorDefinition> outputs, boolean excludeAbstract)
{
+        if (outputs == null || outputs.isEmpty()) {
+            return false;
+        }
+        if (!excludeAbstract) {
+            return !outputs.isEmpty();
+        }
+        for (ProcessorDefinition output : outputs) {
+            if (output instanceof TransactedDefinition || output instanceof PolicyDefinition)
{
+                // special for those as they wrap entire output, so we should just check
its output
+                return hasOutputs(output.getOutputs(), excludeAbstract);
+            }
+            if (!output.isAbstract()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java?rev=935198&r1=935197&r2=935198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java Sat Apr
17 16:21:00 2010
@@ -717,7 +717,7 @@ public class RouteDefinition extends Pro
         }
 
         // validate route has output processors
-        if (outputs.isEmpty()) {
+        if (!ProcessorDefinitionHelper.hasOutputs(outputs, true)) {
             RouteDefinition route = routeContext.getRoute();
             String at = fromType.toString();
             Exception cause = new IllegalArgumentException("Route " + route.getId() + " has
no output processors."

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Throttler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Throttler.java?rev=935198&r1=935197&r2=935198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Throttler.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Throttler.java Sat Apr
17 16:21:00 2010
@@ -25,7 +25,7 @@ import org.apache.camel.Processor;
  * to a processor within a specific time period. <p/> This pattern can be
  * extremely useful if you have some external system which meters access; such
  * as only allowing 100 requests per second; or if huge load can cause a
- * particular systme to malfunction or to reduce its throughput you might want
+ * particular system to malfunction or to reduce its throughput you might want
  * to introduce some throttling.
  * 
  * @version $Revision$

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/RouteMustHaveOutputOnExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/RouteMustHaveOutputOnExceptionTest.java?rev=935198&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/RouteMustHaveOutputOnExceptionTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/RouteMustHaveOutputOnExceptionTest.java
Sat Apr 17 16:21:00 2010
@@ -0,0 +1,78 @@
+/**
+ * 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.impl;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class RouteMustHaveOutputOnExceptionTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testValid() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .onException(Exception.class)
+                        .maximumRedeliveries(2)
+                        .backOffMultiplier(1.5)
+                        .handled(true)
+                        .delay(1000)
+                            .log("Halting for some time")
+                            .to("mock:halt")
+                        .end()
+                    .end()
+                    .to("mock:result");
+            }
+        });
+        context.start();
+    }
+
+    public void testInValid() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .onException(Exception.class)
+                        .maximumRedeliveries(2)
+                        .backOffMultiplier(1.5)
+                        .handled(true)
+                        .delay(1000)
+                            .log("Halting for some time")
+                            .to("mock:halt")
+                        // end missing
+                    .end()
+                    .to("mock:result");
+            }
+        });
+        try {
+            context.start();
+            fail("Should have thrown an exception");
+        } catch (FailedToCreateRouteException e) {
+            // expected
+        }
+    }
+
+}

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

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

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest.java?rev=935198&r1=935197&r2=935198&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest.java
Sat Apr 17 16:21:00 2010
@@ -35,7 +35,10 @@ public class TransactionalClientDataSour
 
                 from("file://target/transacted/fail?moveFailed=../failed")
                     .transacted()
-                    .onException(IllegalArgumentException.class).handled(false).to("mock:error")
+                    .onException(IllegalArgumentException.class)
+                        .handled(false)
+                        .to("mock:error")
+                    .end()
                     .setBody(constant("Tiger in Action")).beanRef("bookService")
                     .setBody(constant("Donkey in Action")).beanRef("bookService");
             }

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithLocalOnExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithLocalOnExceptionTest.java?rev=935198&r1=935197&r2=935198&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithLocalOnExceptionTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithLocalOnExceptionTest.java
Sat Apr 17 16:21:00 2010
@@ -30,14 +30,20 @@ public class TransactionalClientDataSour
                 from("direct:okay")
                     .transacted()
                     // use local on exception
-                    .onException(IllegalArgumentException.class).handled(false).to("mock:error")
+                    .onException(IllegalArgumentException.class)
+                        .handled(false)
+                        .to("mock:error")
+                    .end()
                     .setBody(constant("Tiger in Action")).beanRef("bookService")
                     .setBody(constant("Elephant in Action")).beanRef("bookService");
 
                 from("direct:fail")
                     .transacted()
                     // use local on exception
-                    .onException(IllegalArgumentException.class).handled(false).to("mock:error")
+                    .onException(IllegalArgumentException.class)
+                        .handled(false)
+                        .to("mock:error")
+                    .end()
                     .setBody(constant("Tiger in Action")).beanRef("bookService")
                     .setBody(constant("Donkey in Action")).beanRef("bookService");
             }



Mime
View raw message