camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1154933 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/java/org/apache/camel/processor/interceptor/ camel-core/src/test/java/org/apache/camel/processor/interceptor/ components/camel-spring/src/test/...
Date Mon, 08 Aug 2011 11:53:01 GMT
Author: davsclaus
Date: Mon Aug  8 11:53:01 2011
New Revision: 1154933

URL: http://svn.apache.org/viewvc?rev=1154933&view=rev
Log:
CAMEL-4314: When tracing is enabled force ids on all the nodes to be assigned.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceInitIdOnAllNodesTest.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.xml
  (contents, props changed)
      - copied, changed from r1154890, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopafter.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java?rev=1154933&r1=1154932&r2=1154933&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
Mon Aug  8 11:53:01 2011
@@ -30,8 +30,6 @@ import org.apache.camel.util.ObjectHelpe
  * <p/>
  * Utility methods to help preparing {@link RouteDefinition} before they are added to
  * {@link org.apache.camel.CamelContext}.
- *
- * @version 
  */
 public final class RouteDefinitionHelper {
 
@@ -357,4 +355,26 @@ public final class RouteDefinitionHelper
         }
     }
 
+    /**
+     * Force assigning ids to the give node and all its children (recursively).
+     * <p/>
+     * This is needed when doing tracing or the likes, where each node should have its id
assigned
+     * so the tracing can pin point exactly.
+     *
+     * @param context the camel context
+     * @param processor the node
+     */
+    @SuppressWarnings("unchecked")
+    public static void forceAssignIds(CamelContext context, ProcessorDefinition processor)
{
+        // force id on the child
+        processor.idOrCreate(context.getNodeIdFactory());
+
+        List<ProcessorDefinition> children = processor.getOutputs();
+        if (children != null && !children.isEmpty()) {
+            for (ProcessorDefinition child : children) {
+                forceAssignIds(context, child);
+            }
+        }
+    }
+
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java?rev=1154933&r1=1154932&r2=1154933&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java
Mon Aug  8 11:53:01 2011
@@ -25,6 +25,7 @@ import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.Service;
 import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.RouteDefinitionHelper;
 import org.apache.camel.processor.CamelLogger;
 import org.apache.camel.spi.ExchangeFormatter;
 import org.apache.camel.spi.InterceptStrategy;
@@ -104,7 +105,7 @@ public class Tracer implements Intercept
                                                  Processor target, Processor nextTarget)
throws Exception {
         // Force the creation of an id, otherwise the id is not available when the trace
formatter is
         // outputting trace information
-        definition.idOrCreate(context.getNodeIdFactory());
+        RouteDefinitionHelper.forceAssignIds(context, definition);
         return getTraceInterceptorFactory().createTraceInterceptor(definition, target, formatter,
this);
     }
 

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceInitIdOnAllNodesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceInitIdOnAllNodesTest.java?rev=1154933&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceInitIdOnAllNodesTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceInitIdOnAllNodesTest.java
Mon Aug  8 11:53:01 2011
@@ -0,0 +1,97 @@
+/**
+ * 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.interceptor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ChoiceDefinition;
+import org.apache.camel.model.LogDefinition;
+import org.apache.camel.model.OtherwiseDefinition;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.WhenDefinition;
+
+/**
+ * Tests that when tracing is enabled the ids of all the nodes is forced assigned
+ * to ensure the tracer outputs node id for each node in the tracing messages.
+ */
+public class TraceInitIdOnAllNodesTest extends ContextTestSupport {
+
+    public void testInitIdsOnAllNodes() throws Exception {
+        getMockEndpoint("mock:camel").expectedBodiesReceived("Hello Camel");
+        getMockEndpoint("mock:other").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:end").expectedMessageCount(2);
+
+        template.sendBody("direct:start", "Hello Camel");
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        RouteDefinition route = context.getRouteDefinitions().get(0);
+        assertNotNull(route);
+
+        ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
+        assertEquals("choice1", choice.getId());
+
+        WhenDefinition when = (WhenDefinition) choice.getOutputs().get(0);
+        assertEquals("when1", when.getId());
+
+        LogDefinition log1 = (LogDefinition) when.getOutputs().get(0);
+        assertEquals("log1", log1.getId());
+
+        ToDefinition to1 = (ToDefinition) when.getOutputs().get(1);
+        assertEquals("camel", to1.getId());
+
+        OtherwiseDefinition other = (OtherwiseDefinition) choice.getOutputs().get(1);
+        assertEquals("otherwise1", other.getId());
+
+        LogDefinition log2 = (LogDefinition) other.getOutputs().get(0);
+        assertEquals("log2", log2.getId());
+
+        ToDefinition to2 = (ToDefinition) other.getOutputs().get(1);
+        assertEquals("to1", to2.getId());
+
+        ToDefinition to3 = (ToDefinition) other.getOutputs().get(2);
+        assertEquals("foo", to3.getId());
+
+        ToDefinition to4 = (ToDefinition) route.getOutputs().get(1);
+        assertEquals("end", to4.getId());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // when tracing is enabled, then the ids is force assigned
+                context.setTracing(true);
+
+                from("direct:start")
+                    .choice()
+                        .when(body().contains("Camel"))
+                            .log("A Camel message")
+                            .to("mock:camel").id("camel")
+                        .otherwise()
+                            .log("Some other kind of message")
+                            .to("mock:other") // should auto generate id
+                            .to("mock:foo").id("foo")
+                        .end()
+                    .to("mock:end").id("end");
+            }
+        };
+    }
+}

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.java?rev=1154933&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.java
Mon Aug  8 11:53:01 2011
@@ -0,0 +1,33 @@
+/**
+ * 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.spring.processor.tracing;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.processor.interceptor.TraceInitIdOnAllNodesTest;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+/**
+ *
+ */
+public class SpringTraceInitIdOnAllNodesTest extends TraceInitIdOnAllNodesTest {
+
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, "org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.xml");
+    }
+
+}

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.xml
(from r1154890, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopafter.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopafter.xml&r1=1154890&r2=1154933&rev=1154933&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopafter.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.xml
Mon Aug  8 11:53:01 2011
@@ -22,16 +22,23 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-    <!-- START SNIPPET: e1 -->
-    <camelContext xmlns="http://camel.apache.org/schema/spring">
-        <route>
-            <from uri="direct:start"/>
-            <aop afterUri="mock:after">
-                <transform><constant>Bye World</constant></transform>
-                <to uri="mock:result"/>
-            </aop>
-        </route>
-    </camelContext>
-    <!-- END SNIPPET: e1 -->
+  <camelContext xmlns="http://camel.apache.org/schema/spring" trace="true">
+    <route>
+      <from uri="direct:start"/>
+      <choice>
+        <when>
+          <simple>${body} contains 'Camel'</simple>
+          <log message="A Camel message"/>
+          <to uri="mock:camel" id="camel"/>
+        </when>
+        <otherwise>
+          <log message="Some other kind of message"/>
+          <to uri="mock:other"/>
+          <to uri="mock:foo" id="foo"/>
+        </otherwise>
+      </choice>
+      <to uri="mock:end" id="end"/>
+    </route>
+  </camelContext>
 
 </beans>

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/tracing/SpringTraceInitIdOnAllNodesTest.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message