You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2010/04/21 11:32:54 UTC

svn commit: r936226 - in /servicemix/smx4/features/trunk: ./ camel/servicemix-camel/ camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/ camel/servicemix-camel/src/...

Author: gertv
Date: Wed Apr 21 09:32:54 2010
New Revision: 936226

URL: http://svn.apache.org/viewvc?rev=936226&view=rev
Log:
SMX4-519: Allow configuring Camel NMR endpoint to bypass thread pool for handling exchanges

Added:
    servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/AbstractComponentTest.java
    servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/ShouldRunSynchronouslyTest.java
    servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/SimpleNmrTest.java
    servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/resources/log4j.properties
Modified:
    servicemix/smx4/features/trunk/camel/servicemix-camel/pom.xml
    servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixBinding.java
    servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java
    servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java
    servicemix/smx4/features/trunk/pom.xml

Modified: servicemix/smx4/features/trunk/camel/servicemix-camel/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/pom.xml?rev=936226&r1=936225&r2=936226&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/pom.xml (original)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/pom.xml Wed Apr 21 09:32:54 2010
@@ -33,6 +33,10 @@
     <version>4.3.0-SNAPSHOT</version>
     <name>Apache ServiceMix Camel Component</name>
 
+    <properties>
+      <excluded.tests/>
+    </properties>
+
     <dependencies>
         <dependency>
             <groupId>org.apache.servicemix.nmr</groupId>
@@ -166,6 +170,20 @@
         <version>${woodstox.version}</version>
         <scope>test</scope>
       </dependency>
+
+      <dependency>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-core</artifactId>
+        <version>${camel.version}</version>
+        <type>test-jar</type>
+        <scope>test</scope>
+      </dependency>
+      
+      <dependency>
+        <groupId>log4j</groupId>
+        <artifactId>log4j</artifactId>
+        <scope>test</scope>
+      </dependency>
     </dependencies>
 
     <build>
@@ -208,6 +226,9 @@
                             <value>com.ctc.wstx.stax.WstxOutputFactory</value>
                         </property>
                     </systemProperties>
+                    <excludes>
+                      <exclude>${excluded.tests}</exclude>
+                    </excludes>
                 </configuration>
             </plugin>
             <plugin>
@@ -250,5 +271,20 @@
          </plugins>
     </build>
 
+    <!-- Workaround for SMX4-518: test fails on MacOS + JDK 1.6 -->
+    <profiles>
+      <profile>
+        <id>mac-jdk6-exclude-tests</id>
+        <activation>
+          <jdk>1.6</jdk>
+          <os>
+            <family>mac</family>
+          </os>
+        </activation>
+        <properties>
+          <excluded.tests>**/WSSecurityTest.*</excluded.tests>
+        </properties>
+      </profile>
+    </profiles>
 
 </project>

Modified: servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixBinding.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixBinding.java?rev=936226&r1=936225&r2=936226&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixBinding.java (original)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixBinding.java Wed Apr 21 09:32:54 2010
@@ -22,7 +22,6 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.activation.DataHandler;
-import javax.jbi.messaging.MessagingException;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
@@ -41,7 +40,7 @@ public class ServiceMixBinding {
     public static final String NMR_EXCHANGE = "nmrExchange";
     public static final String NMR_OPERATION = "nmrOperation";
     
-    public void copyCamelMessageToNmrMessage(org.apache.servicemix.nmr.api.Message nmrMessage, Message camelMessage) throws MessagingException {
+    public void copyCamelMessageToNmrMessage(org.apache.servicemix.nmr.api.Message nmrMessage, Message camelMessage) {
         nmrMessage.setBody(camelMessage.getBody());
         nmrMessage.getHeaders().clear();
         addNmrHeaders(nmrMessage, camelMessage);
@@ -57,8 +56,7 @@ public class ServiceMixBinding {
         addCamelAttachments(nmrMessage, camelMessage);        
     }
     
-    public org.apache.servicemix.nmr.api.Exchange populateNmrExchangeFromCamelExchange(Exchange camelExchange, Channel client) 
-    	throws MessagingException {
+    public org.apache.servicemix.nmr.api.Exchange populateNmrExchangeFromCamelExchange(Exchange camelExchange, Channel client)  {
     	org.apache.servicemix.nmr.api.Exchange e = client.createExchange(
                 Pattern.fromWsdlUri(camelExchange.getPattern().getWsdlUri()));
     	e.getProperties().putAll(camelExchange.getProperties());

Modified: servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java?rev=936226&r1=936225&r2=936226&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java (original)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixConsumer.java Wed Apr 21 09:32:54 2010
@@ -19,10 +19,10 @@ package org.apache.servicemix.camel.nmr;
 import java.util.Map;
 
 import org.apache.camel.Consumer;
-import org.apache.camel.ExchangePattern;
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultConsumer;
 import org.apache.servicemix.nmr.api.Channel;
+import org.apache.servicemix.nmr.api.Endpoint;
 import org.apache.servicemix.nmr.api.Exchange;
 import org.apache.servicemix.nmr.api.Status;
 import org.apache.servicemix.nmr.api.service.ServiceHelper;
@@ -53,9 +53,10 @@ public class ServiceMixConsumer extends 
     }
 
     private Map<String,?> createEndpointMap() {
-        return ServiceHelper.createMap(org.apache.servicemix.nmr.api.Endpoint.NAME,
-        				               getEndpoint().getEndpointName());
-
+        Map<String, Object> result = ServiceHelper.createMap(Endpoint.NAME,
+                                                             getEndpoint().getEndpointName());
+        result.put(Endpoint.CHANNEL_SYNC_DELIVERY, getEndpoint().isSynchronous());
+        return result;
     }
 
     public void setChannel(Channel channel) {

Modified: servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java?rev=936226&r1=936225&r2=936226&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java (original)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java Wed Apr 21 09:32:54 2010
@@ -16,6 +16,8 @@
  */
 package org.apache.servicemix.camel.nmr;
 
+import java.util.Map;
+
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -30,12 +32,20 @@ import org.apache.camel.Processor;
  */
 public class ServiceMixEndpoint extends DefaultEndpoint {
 
+    private static final String SYNCHRONOUS = "synchronous";
+
     private String endpointName;
+    private boolean synchronous;
 
     public ServiceMixEndpoint(ServiceMixComponent component, String uri, String endpointName) {
         super(uri, component);
         this.endpointName = endpointName;
     }
+    @Override
+
+    public void configureProperties(Map<String, Object> options) {
+        synchronous = Boolean.valueOf((String) options.remove(SYNCHRONOUS));
+    }
 
     public ServiceMixComponent getComponent() {
         return (ServiceMixComponent)super.getComponent();
@@ -45,6 +55,10 @@ public class ServiceMixEndpoint extends 
         return true;
     }
 
+    public boolean isSynchronous() {
+        return synchronous;
+    }
+
     public Producer createProducer() throws Exception {
         return new ServiceMixProducer(this);
     }

Added: servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/AbstractComponentTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/AbstractComponentTest.java?rev=936226&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/AbstractComponentTest.java (added)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/AbstractComponentTest.java Wed Apr 21 09:32:54 2010
@@ -0,0 +1,65 @@
+/*
+ * 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.servicemix.camel.nmr;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.servicemix.nmr.api.Channel;
+import org.apache.servicemix.nmr.core.ServiceMix;
+
+/**
+ * Abstract base class for building NMR component unit tests
+ * - the NMR component is available with URI prefix nmr:
+ * - a client channel to the NMR can be obtained with the {@link #getChannel()} method
+ */
+public abstract class AbstractComponentTest extends ContextTestSupport {
+
+    private ServiceMix nmr;
+    private ServiceMixComponent component;
+    private Channel channel;
+
+    @Override
+    protected void setUp() throws Exception {
+        nmr = new ServiceMix();
+        nmr.init();
+
+        component = new ServiceMixComponent();
+        component.setNmr(nmr);
+
+        super.setUp();
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        registry.bind("nmr", component);
+        return registry;
+    }
+
+    /**
+     * Get a client channel to access the NMR used for testing
+     *
+     * @return the client channel
+     */
+    protected Channel getChannel() {
+        if (channel == null) {
+            channel = nmr.createChannel();
+        }
+
+        return channel;
+    }
+}

Added: servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/ShouldRunSynchronouslyTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/ShouldRunSynchronouslyTest.java?rev=936226&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/ShouldRunSynchronouslyTest.java (added)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/ShouldRunSynchronouslyTest.java Wed Apr 21 09:32:54 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.servicemix.camel.nmr;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * Test case for the ?synchronous=true setting on a camel consumer endpoint
+ */
+public class ShouldRunSynchronouslyTest extends AbstractComponentTest {
+
+    private static final String HANDLED_BY_THREAD = "HandledByThread";
+
+    public void testProcessingOnSameThread() throws InterruptedException {
+        MockEndpoint mock = getMockEndpoint("mock:simple");
+        mock.expectedBodiesReceived("Simple message body");
+
+        template.sendBody("direct:simple", "Simple message body");
+
+        assertMockEndpointsSatisfied();
+
+        Thread thread = mock.getExchanges().get(0).getProperty(HANDLED_BY_THREAD, Thread.class);
+        assertNotNull(thread);
+        assertEquals("No thread context switching should have occurred",
+                     Thread.currentThread(), thread);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+
+            @Override
+            public void configure() throws Exception {
+                from("direct:simple").to("nmr:simple");
+                from("nmr:simple?synchronous=true").process(new Processor() {
+
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.setProperty(HANDLED_BY_THREAD, Thread.currentThread());
+                    }
+
+                }).to("mock:simple");
+            }
+        };
+    }
+}
\ No newline at end of file

Added: servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/SimpleNmrTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/SimpleNmrTest.java?rev=936226&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/SimpleNmrTest.java (added)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/SimpleNmrTest.java Wed Apr 21 09:32:54 2010
@@ -0,0 +1,48 @@
+/*
+ * 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.servicemix.camel.nmr;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * A very basic NMR test, just testing if the Exchange can flow through the NMR
+ * from one Camel route to the next one
+ */
+public class SimpleNmrTest extends AbstractComponentTest {
+
+    public void testSimpleExchange() throws InterruptedException {
+        MockEndpoint mock = getMockEndpoint("mock:simple");
+        mock.expectedBodiesReceived("Simple message body");
+
+        template.sendBody("direct:simple", "Simple message body");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+
+            @Override
+            public void configure() throws Exception {
+                from("direct:simple").to("nmr:simple");
+                from("nmr:simple").to("mock:simple");
+            }
+        };
+    }
+}

Added: servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/resources/log4j.properties?rev=936226&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/resources/log4j.properties (added)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/resources/log4j.properties Wed Apr 21 09:32:54 2010
@@ -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.
+#
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=DEBUG, out
+
+# CONSOLE appender not used by default
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.out.file=target/servicemix-test.log
+log4j.appender.out.append=true

Modified: servicemix/smx4/features/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/pom.xml?rev=936226&r1=936225&r2=936226&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/pom.xml (original)
+++ servicemix/smx4/features/trunk/pom.xml Wed Apr 21 09:32:54 2010
@@ -188,7 +188,7 @@
       <servicemix3.version>3.3</servicemix3.version>
       <servicemix-utils.version>1.3.0-SNAPSHOT</servicemix-utils.version>
       <servicemix.legal.version>1.0</servicemix.legal.version>
-      <servicemix.nmr.version>1.1.0-SNAPSHOT</servicemix.nmr.version>
+      <servicemix.nmr.version>1.3.0-SNAPSHOT</servicemix.nmr.version>
       <servicemix.specs.version>1.4.0</servicemix.specs.version>
 
       <servicemix-shared-version>2010.01</servicemix-shared-version>