servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r794649 - in /servicemix/components/engines/servicemix-camel/trunk: ./ src/test/java/org/apache/servicemix/camel/ src/test/resources/org/apache/servicemix/camel/su9-src/
Date Thu, 16 Jul 2009 12:20:05 GMT
Author: gertv
Date: Thu Jul 16 12:20:05 2009
New Revision: 794649

URL: http://svn.apache.org/viewvc?rev=794649&view=rev
Log:
SMXCOMP-587: additional unit tests for servicemix-camel stream caching in error handlers/dlc

Modified:
    servicemix/components/engines/servicemix-camel/trunk/pom.xml
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithErrorHandledTrueSpringDSLTest.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithFaultHandledTrueSpringDSLTest.java
    servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/su9-src/camel-context.xml

Modified: servicemix/components/engines/servicemix-camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/pom.xml?rev=794649&r1=794648&r2=794649&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/pom.xml (original)
+++ servicemix/components/engines/servicemix-camel/trunk/pom.xml Thu Jul 16 12:20:05 2009
@@ -38,7 +38,7 @@
 
   <properties>
     <previous.releases>3.1.2,3.2,3.2.1,3.2.2,3.2.3,2008.01</previous.releases>
-    <camel-version>1.6.0</camel-version>
+    <camel-version>1.6.2-SNAPSHOT</camel-version>
     <servicemix-version>3.3</servicemix-version>
     <servicemix-shared-version>2009.02-SNAPSHOT</servicemix-shared-version>
     <servicemix.osgi.import>      

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithErrorHandledTrueSpringDSLTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithErrorHandledTrueSpringDSLTest.java?rev=794649&r1=794648&r2=794649&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithErrorHandledTrueSpringDSLTest.java
(original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithErrorHandledTrueSpringDSLTest.java
Thu Jul 16 12:20:05 2009
@@ -16,18 +16,26 @@
  */
 package org.apache.servicemix.camel;
 
+import java.io.ByteArrayInputStream;
 import java.util.List;
 
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
 import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
 
 import org.apache.camel.processor.DeadLetterChannel;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
 import org.apache.servicemix.MessageExchangeListener;
 import org.apache.servicemix.client.ServiceMixClient;
 import org.apache.servicemix.components.util.ComponentSupport;
 import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.helper.MessageUtil;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.tck.ReceiverComponent;
 import org.springframework.util.Assert;
 
@@ -41,25 +49,50 @@
     private ReceiverComponent receiver;
     private ReceiverComponent deadLetter;
 
+    private static final String MESSAGE = "<just><a>test</a></just>";
+    private static final Level LOG_LEVEL = Logger.getLogger("org.apache.servicemix").getEffectiveLevel();
+    
     @Override
     protected void setUp() throws Exception {
         receiver = new ReceiverComponent() {
             public void onMessageExchange(MessageExchange exchange) throws MessagingException
{
-                Object value = getInMessage(exchange).getProperty(DeadLetterChannel.CAUGHT_EXCEPTION_HEADER);
+                NormalizedMessage inMessage = getInMessage(exchange);
+                Object value = inMessage.getProperty(DeadLetterChannel.CAUGHT_EXCEPTION_HEADER);
                 Assert.notNull(value, DeadLetterChannel.CAUGHT_EXCEPTION_HEADER + " property
not set");
+                try {
+                    MessageUtil.enableContentRereadability(inMessage);
+                    String message = new SourceTransformer().contentToString(inMessage);
+                    Assert.isTrue(message.contains(MESSAGE));
+                } catch (Exception e) {
+                    throw new MessagingException(e);
+                }
+                
                 super.onMessageExchange(exchange);
             }
         };
         deadLetter = new ReceiverComponent();
 
         super.setUp();
+
+        // change the log level to avoid the conversion to DOMSource 
+        Logger.getLogger("org.apache.servicemix").setLevel(Level.ERROR);
     }
 
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+
+        // restore the original log level
+        Logger.getLogger("org.apache.servicemix").setLevel(LOG_LEVEL);
+    }
+    
     public void testErrorHandledByExceptionClause() throws Exception {
         ServiceMixClient smxClient = getServicemixClient();
         MessageExchange[] exchanges = new MessageExchange[] {smxClient.createInOnlyExchange(),
smxClient.createRobustInOnlyExchange()};
         for (MessageExchange exchange : exchanges) {
             exchange.setService(TEST_SERVICE);
+            Source content = new StreamSource(new ByteArrayInputStream(MESSAGE.getBytes()));
+            exchange.getMessage("in").setContent(content);
 
             smxClient.send(exchange);
 
@@ -89,6 +122,13 @@
     protected static class ReturnNullPointerExceptionErrorComponent extends ComponentSupport
implements MessageExchangeListener {
         public void onMessageExchange(MessageExchange exchange) throws MessagingException
{
             if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+                // read the in message content before returning to ensure that the 
+                // Camel DeadLetterChannel caches the stream correctly prior to re-delivery
+                try {
+                    new SourceTransformer().contentToString(exchange.getMessage("in"));
+                } catch (Exception e) {
+                    throw new MessagingException(e);
+                }
                 fail(exchange, new NullPointerException());
             }
         }

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithFaultHandledTrueSpringDSLTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithFaultHandledTrueSpringDSLTest.java?rev=794649&r1=794648&r2=794649&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithFaultHandledTrueSpringDSLTest.java
(original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOnlyWithFaultHandledTrueSpringDSLTest.java
Thu Jul 16 12:20:05 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.servicemix.camel;
 
+import java.io.ByteArrayInputStream;
 import java.util.List;
 
 import javax.jbi.messaging.ExchangeStatus;
@@ -23,15 +24,21 @@
 import javax.jbi.messaging.InOnly;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
 import javax.jbi.messaging.RobustInOnly;
 import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
 
-import org.apache.camel.converter.jaxp.StringSource;
 import org.apache.camel.processor.DeadLetterChannel;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
 import org.apache.servicemix.MessageExchangeListener;
 import org.apache.servicemix.client.ServiceMixClient;
 import org.apache.servicemix.components.util.ComponentSupport;
 import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.helper.MessageUtil;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.tck.ReceiverComponent;
 import org.springframework.util.Assert;
 
@@ -45,24 +52,49 @@
     private ReceiverComponent receiver;
     private ReceiverComponent deadLetter;
 
+    private static final String MESSAGE = "<just><a>test</a></just>";
+    private static final Level LOG_LEVEL = Logger.getLogger("org.apache.servicemix").getEffectiveLevel();
+    
     @Override
     protected void setUp() throws Exception {
         receiver = new ReceiverComponent() {
             public void onMessageExchange(MessageExchange exchange) throws MessagingException
{
-                Object value = getInMessage(exchange).getProperty(DeadLetterChannel.CAUGHT_EXCEPTION_HEADER);
+                NormalizedMessage inMessage = getInMessage(exchange);
+                Object value = inMessage.getProperty(DeadLetterChannel.CAUGHT_EXCEPTION_HEADER);
                 Assert.notNull(value, DeadLetterChannel.CAUGHT_EXCEPTION_HEADER + " property
not set");
+                try {
+                    MessageUtil.enableContentRereadability(inMessage);
+                    String message = new SourceTransformer().contentToString(inMessage);
+                    Assert.isTrue(message.contains(MESSAGE));
+                } catch (Exception e) {
+                    throw new MessagingException(e);
+                }
+                
                 super.onMessageExchange(exchange);
             }
         };
         deadLetter = new ReceiverComponent();
 
         super.setUp();
+
+        // change the log level to avoid the conversion to DOMSource 
+        Logger.getLogger("org.apache.servicemix").setLevel(Level.ERROR);
     }
 
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+
+        // restore the original log level
+        Logger.getLogger("org.apache.servicemix").setLevel(LOG_LEVEL);
+    }
+    
     public void testInOnlyWithFaultHandledByExceptionClause() throws Exception {
         ServiceMixClient smxClient = getServicemixClient();
         InOnly exchange = smxClient.createInOnlyExchange();
         exchange.setEndpoint(jbiContainer.getRegistry().getEndpointsForService(TEST_SERVICE)[0]);
+        Source content = new StreamSource(new ByteArrayInputStream(MESSAGE.getBytes()));
+        exchange.getMessage("in").setContent(content);
 
         smxClient.send(exchange);
 
@@ -78,6 +110,8 @@
         ServiceMixClient smxClient = getServicemixClient();
         RobustInOnly exchange = smxClient.createRobustInOnlyExchange();
         exchange.setEndpoint(jbiContainer.getRegistry().getEndpointsForService(TEST_SERVICE)[0]);
+        Source content = new StreamSource(new ByteArrayInputStream(MESSAGE.getBytes()));
+        exchange.getMessage("in").setContent(content);
 
         smxClient.send(exchange);
 
@@ -105,8 +139,16 @@
     protected static class ReturnFaultComponent extends ComponentSupport implements MessageExchangeListener
{
         public void onMessageExchange(MessageExchange exchange) throws MessagingException
{
             if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+                // read the in message content before returning to ensure that the 
+                // Camel DeadLetterChannel caches the stream correctly prior to re-delivery
+                try {
+                    new SourceTransformer().contentToString(exchange.getMessage("in"));
+                } catch (Exception e) {
+                    throw new MessagingException(e);
+                }
+
                 Fault fault = exchange.createFault();
-                fault.setContent(new StringSource("<fault/>"));
+                fault.setContent(new StreamSource(new ByteArrayInputStream("<fault/>".getBytes())));
                 fail(exchange, fault);
             }
         }

Modified: servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/su9-src/camel-context.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/su9-src/camel-context.xml?rev=794649&r1=794648&r2=794649&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/su9-src/camel-context.xml
(original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/resources/org/apache/servicemix/camel/su9-src/camel-context.xml
Thu Jul 16 12:20:05 2009
@@ -28,14 +28,19 @@
   <camelContext  xmlns="http://activemq.apache.org/camel/schema/spring">
     <route errorHandlerRef="deadLetterErrorHandler">
       <from uri="jbi:service:urn:test:fault-handled-true"/>
+      <interceptor ref="handleFaultProcessor">
+        <to uri="jbi:service:urn:test:faulty-service"/>
+      </interceptor>
       <onException>
         <!-- Catch exception from in-only/robust-in-only message exchange. -->
         <exception>org.apache.servicemix.jbi.exception.FaultException</exception>
-        <redeliveryPolicy maximumRedeliveries="0"/>
+        <interceptor ref="handleFaultProcessor2">
+          <to uri="jbi:service:urn:test:receiver-service"/>
+        </interceptor>
         <handled>
           <constant>true</constant>
         </handled>
-        <to uri="jbi:service:urn:test:receiver-service"/>
+        <redeliveryPolicy maximumRedeliveries="0"/>
       </onException>
       <onException>
         <!-- This clause is needed for testing since the test client still
@@ -46,27 +51,36 @@
              TODO remove this when ServiceMix 3.3.1 is released.
              -->
         <exception>org.apache.servicemix.jbi.FaultException</exception>
-        <redeliveryPolicy maximumRedeliveries="0"/>
+        <interceptor ref="handleFaultProcessor3">
+          <to uri="jbi:service:urn:test:receiver-service"/>
+        </interceptor>
         <handled>
           <constant>true</constant>
         </handled>
-        <to uri="jbi:service:urn:test:receiver-service"/>
+        <redeliveryPolicy maximumRedeliveries="0"/>
       </onException>     
-      <handleFault/> 
-      <to uri="jbi:service:urn:test:faulty-service"/>
     </route>
   </camelContext>
 
   <bean id="deadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
-    <property name="defaultDeadLetterEndpointUri" value="jbi:service:urn:test:deadLetter-service"/>
+    <property name="logger" ref="logger" />
+    <property name="defaultDeadLetterEndpointUri" value="log:dlc?showBody=false,log:dlc"/>
     <property name="redeliveryPolicy" ref="redeliveryPolicyConfig" />
   </bean>
     
   <bean id="redeliveryPolicyConfig" class="org.apache.camel.processor.RedeliveryPolicy">
-    <property name="maximumRedeliveries" value="3" />
+    <property name="maximumRedeliveries" value="0" />
     <property name="initialRedeliveryDelay" value="2000" />
     <property name="useExponentialBackOff" value="true" />
     <property name="backOffMultiplier" value="2" />
   </bean>
 
+  <bean id="logger" class="org.apache.camel.processor.Logger" />
+
+  <bean id="handleFaultProcessor" class="org.apache.camel.processor.HandleFaultProcessor"
/>
+
+  <bean id="handleFaultProcessor2" class="org.apache.camel.processor.HandleFaultProcessor"
/>
+
+  <bean id="handleFaultProcessor3" class="org.apache.camel.processor.HandleFaultProcessor"
/>
+
 </beans>



Mime
View raw message