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 2010/05/13 10:23:02 UTC

svn commit: r943841 - in /camel/trunk: camel-core/src/test/java/org/apache/camel/processor/ components/camel-spring/src/test/java/org/apache/camel/spring/processor/ components/camel-spring/src/test/resources/org/apache/camel/spring/processor/

Author: davsclaus
Date: Thu May 13 08:23:02 2010
New Revision: 943841

URL: http://svn.apache.org/viewvc?rev=943841&view=rev
Log:
For an example

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/EventNotifierExchangeSentExampleTest.java   (with props)
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyLoggingSentEventNotifer.java   (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEventNotifierExchangeSentExampleTest.java
      - copied, changed from r943830, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAOPBeforeTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/EventNotifierExchangeSentExampleTest.xml
      - copied, changed from r943830, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopafter.xml

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/EventNotifierExchangeSentExampleTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/EventNotifierExchangeSentExampleTest.java?rev=943841&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/EventNotifierExchangeSentExampleTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/EventNotifierExchangeSentExampleTest.java Thu May 13 08:23:02 2010
@@ -0,0 +1,62 @@
+/**
+ * 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.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+
+/**
+ * @version $Revision$
+ */
+public class EventNotifierExchangeSentExampleTest extends ContextTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        DefaultCamelContext context = (DefaultCamelContext) super.createCamelContext();
+
+        // START SNIPPET: e1
+        // add event notifier where we can log the times it took to process
+        // exchanges sent to an endpoint
+        context.getManagementStrategy().addEventNotifier(new MyLoggingSentEventNotifer());
+        // END SNIPPET: e1
+
+        return context;
+    }
+
+    public void testExchangeSent() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("direct:bar").to("mock:result");
+
+                from("direct:bar").delay(1000);
+            }
+        };
+    }
+
+}
\ No newline at end of file

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

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

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyLoggingSentEventNotifer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyLoggingSentEventNotifer.java?rev=943841&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyLoggingSentEventNotifer.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyLoggingSentEventNotifer.java Thu May 13 08:23:02 2010
@@ -0,0 +1,51 @@
+/**
+ * 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 java.util.EventObject;
+
+import org.apache.camel.management.EventNotifierSupport;
+import org.apache.camel.management.event.ExchangeSentEvent;
+
+/**
+ * @version $Revision$
+ */
+// START SNIPPET: e1
+public class MyLoggingSentEventNotifer extends EventNotifierSupport {
+
+    public void notify(EventObject event) throws Exception {
+        if (event instanceof ExchangeSentEvent) {
+            ExchangeSentEvent sent = (ExchangeSentEvent) event;
+            log.info("Took " + sent.getTimeTaken() + " millis to send to: " + sent.getEndpoint());
+        }
+    }
+
+    public boolean isEnabled(EventObject event) {
+        // we only want the sent events
+        return event instanceof ExchangeSentEvent;
+    }
+
+    protected void doStart() throws Exception {
+        // noop
+    }
+
+    protected void doStop() throws Exception {
+        // noop
+    }
+
+}
+// END SNIPPET: e1

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

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

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEventNotifierExchangeSentExampleTest.java (from r943830, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAOPBeforeTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEventNotifierExchangeSentExampleTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEventNotifierExchangeSentExampleTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAOPBeforeTest.java&r1=943830&r2=943841&rev=943841&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAOPBeforeTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEventNotifierExchangeSentExampleTest.java Thu May 13 08:23:02 2010
@@ -17,15 +17,16 @@
 package org.apache.camel.spring.processor;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.processor.AOPBeforeTest;
+import org.apache.camel.processor.EventNotifierExchangeSentExampleTest;
+
 import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 
 /**
  * @version $Revision$
  */
-public class SpringAOPBeforeTest extends AOPBeforeTest {
+public class SpringEventNotifierExchangeSentExampleTest extends EventNotifierExchangeSentExampleTest {
 
     protected CamelContext createCamelContext() throws Exception {
-        return createSpringCamelContext(this, "org/apache/camel/spring/processor/aopbefore.xml");
+        return createSpringCamelContext(this, "org/apache/camel/spring/processor/EventNotifierExchangeSentExampleTest.xml");
     }
 }
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/EventNotifierExchangeSentExampleTest.xml (from r943830, 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/EventNotifierExchangeSentExampleTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/EventNotifierExchangeSentExampleTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopafter.xml&r1=943830&r2=943841&rev=943841&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/EventNotifierExchangeSentExampleTest.xml Thu May 13 08:23:02 2010
@@ -23,14 +23,21 @@
     ">
 
     <!-- START SNIPPET: e1 -->
+    <bean id="myLoggingEventNotifier" class="org.apache.camel.processor.MyLoggingSentEventNotifer"/>
+
     <camelContext id="camel" 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>
+            <to uri="direct:bar"/>
+            <to uri="mock:result"/>
+        </route>
+
+        <route>
+            <from uri="direct:bar"/>
+            <delay><constant>1000</constant></delay>
         </route>
+
     </camelContext>
     <!-- END SNIPPET: e1 -->