camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1292836 - 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/
Date Thu, 23 Feb 2012 16:02:03 GMT
Author: davsclaus
Date: Thu Feb 23 16:02:03 2012
New Revision: 1292836

URL: http://svn.apache.org/viewvc?rev=1292836&view=rev
Log:
Added test based on user forum issue

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceAutoStartupFalseTest.java
      - copied, changed from r1292765, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceTest.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFailOverLoadBalanceAutoStartupFalseTest.java
      - copied, changed from r1292765, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFailOverLoadBalanceTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/FailOverLoadBalanceAutoStartupFalseTest.xml
      - copied, changed from r1292765, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/failOverLoadBalance.xml

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceAutoStartupFalseTest.java
(from r1292765, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceAutoStartupFalseTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceAutoStartupFalseTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceTest.java&r1=1292765&r2=1292836&rev=1292836&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceAutoStartupFalseTest.java
Thu Feb 23 16:02:03 2012
@@ -17,91 +17,34 @@
 package org.apache.camel.processor;
 
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 
-import static org.apache.camel.component.mock.MockEndpoint.expectsMessageCount;
-
-public class FailOverLoadBalanceTest extends ContextTestSupport {
+public class FailOverLoadBalanceAutoStartupFalseTest extends ContextTestSupport {
+    
+    public void testFailover() throws Exception {
+        getMockEndpoint("mock:x").expectedMessageCount(1);
+        getMockEndpoint("mock:y").expectedMessageCount(1);
+        getMockEndpoint("mock:z").expectedMessageCount(1);
 
-    protected MockEndpoint x;
-    protected MockEndpoint y;
-    protected MockEndpoint z;
+        context.startRoute("foo");
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+        template.sendBody("direct:start", "Hello World");
 
-        x = getMockEndpoint("mock:x");
-        y = getMockEndpoint("mock:y");
-        z = getMockEndpoint("mock:z");
-    }
-    
-    public static class MyException extends Exception {
-        private static final long serialVersionUID = 1L;
-    }
-    
-    public static class MyAnotherException extends Exception {
-        private static final long serialVersionUID = 1L;
-    }
-    
-    public static class MyExceptionProcessor implements Processor {        
-        public void process(Exchange exchange) throws Exception {
-            throw new MyException();            
-        }        
-    }
-    
-    public static class MyAnotherExceptionProcessor implements Processor {
-        public void process(Exchange exchange) throws Exception {
-            throw new MyAnotherException();            
-        }
+        assertMockEndpointsSatisfied();
     }
 
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from("direct:exception").loadBalance()
-                    // catch all the exception here
-                    .failover().to("direct:x", "direct:y", "direct:z");
-                
-                from("direct:customerException").loadBalance()
-                    .failover(MyException.class).to("direct:x", "direct:y", "direct:z");
-                
-                from("direct:x").process(new MyExceptionProcessor()).to("mock:x");
-                
-                from("direct:y").process(new MyAnotherExceptionProcessor()).to("mock:y");
+                from("direct:start").routeId("foo").noAutoStartup()
+                    .loadBalance().failover(3, true, true)
+                        .to("direct:x", "direct:y", "direct:z");
                 
+                from("direct:x").to("mock:x").throwException(new IllegalArgumentException("Forced"));
+                from("direct:y").to("mock:y").throwException(new IllegalArgumentException("Also
Forced"));
                 from("direct:z").to("mock:z");
-                
             }
         };
     }
 
-    public void testThrowable() throws Exception {
-        String body = "<one/>";
-        expectsMessageCount(0, x, y);
-        z.expectedBodiesReceived(body);
-        sendMessage("direct:exception", "bar", body);
-        assertMockEndpointsSatisfied();
-    }
-    
-    public void testMyException() throws Exception {
-        String body = "<two/>";
-        expectsMessageCount(0, x, y, z);
-        try {
-            sendMessage("direct:customerException", "bar", body);
-            fail("There should get the MyAnotherException");
-        } catch (RuntimeCamelException ex) {
-            // expect the exception here
-            assertTrue("The cause should be MyAnotherException", ex.getCause() instanceof
MyAnotherException);
-        }
-        assertMockEndpointsSatisfied();
-    }
-
-    protected void sendMessage(final String endpoint, final Object headerValue, final Object
body) throws Exception {
-        template.sendBodyAndHeader(endpoint, body, "foo", headerValue);
-    }
 }

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFailOverLoadBalanceAutoStartupFalseTest.java
(from r1292765, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFailOverLoadBalanceTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFailOverLoadBalanceAutoStartupFalseTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFailOverLoadBalanceAutoStartupFalseTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFailOverLoadBalanceTest.java&r1=1292765&r2=1292836&rev=1292836&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFailOverLoadBalanceTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFailOverLoadBalanceAutoStartupFalseTest.java
Thu Feb 23 16:02:03 2012
@@ -14,18 +14,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.spring.processor;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.processor.FailOverLoadBalanceTest;
+import org.apache.camel.processor.FailOverLoadBalanceAutoStartupFalseTest;
 
 import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 
-public class SpringFailOverLoadBalanceTest extends FailOverLoadBalanceTest {
+public class SpringFailOverLoadBalanceAutoStartupFalseTest extends FailOverLoadBalanceAutoStartupFalseTest
{
     
     protected CamelContext createCamelContext() throws Exception {
-        return createSpringCamelContext(this, "org/apache/camel/spring/processor/failOverLoadBalance.xml");
+        return createSpringCamelContext(this, "org/apache/camel/spring/processor/FailOverLoadBalanceAutoStartupFalseTest.xml");
     }
 
 }

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/FailOverLoadBalanceAutoStartupFalseTest.xml
(from r1292765, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/failOverLoadBalance.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/FailOverLoadBalanceAutoStartupFalseTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/FailOverLoadBalanceAutoStartupFalseTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/failOverLoadBalance.xml&r1=1292765&r2=1292836&rev=1292836&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/failOverLoadBalance.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/FailOverLoadBalanceAutoStartupFalseTest.xml
Thu Feb 23 16:02:03 2012
@@ -22,50 +22,41 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-
-  <!-- START SNIPPET: example -->
-
   <camelContext xmlns="http://camel.apache.org/schema/spring">
-    <route errorHandlerRef="noErrorHandler">
-      <from uri="direct:exception"/>
-      <loadBalance>
-          <failover/>
-          <to uri="direct:x"/>
-          <to uri="direct:y"/>
-          <to uri="direct:z"/>
-      </loadBalance>      
-    </route>    
-    <route errorHandlerRef="noErrorHandler">
-      <from uri="direct:customerException"/>
-      <loadBalance>
-          <failover>
-              <exception>org.apache.camel.processor.FailOverLoadBalanceTest$MyException</exception>
-          </failover>
-          <to uri="direct:x"/>
-          <to uri="direct:y"/>
-          <to uri="direct:z"/>
+
+    <route id="foo" autoStartup="false">
+      <from uri="direct:start"/>
+      <loadBalance inheritErrorHandler="true">
+        <failover maximumFailoverAttempts="3" roundRobin="true"/>
+        <to uri="direct:x"/>
+        <to uri="direct:y"/>
+        <to uri="direct:z"/>
       </loadBalance>
     </route>
-    <route errorHandlerRef="noErrorHandler">
-       <from uri="direct:x"/>
-       <process ref="myExceptionProcessor"/>
-       <to uri="mock:x"/>
+    
+    <route>
+      <from uri="direct:x"/>
+      <to uri="mock:x"/>
+      <throwException ref="forced"/>
+    </route>
+    <route>
+      <from uri="direct:y"/>
+      <to uri="mock:y"/>
+      <throwException ref="alsoForced"/>
     </route>
-    <route errorHandlerRef="noErrorHandler">
-       <from uri="direct:y"/>
-       <process ref="myAnotherExceptionProcessor"/>
-       <to uri="mock:y"/>
-    </route>    
-    <route errorHandlerRef="noErrorHandler">
-       <from uri="direct:z"/>       
-       <to uri="mock:z"/>
-    </route>    
+    <route>
+      <from uri="direct:z"/>
+      <to uri="mock:z"/>
+    </route>
+
   </camelContext>
   
-  <bean id="noErrorHandler" class="org.apache.camel.builder.NoErrorHandlerBuilder"/>
-  <bean id="myExceptionProcessor" class="org.apache.camel.processor.FailOverLoadBalanceTest$MyExceptionProcessor"/>
-  <bean id="myAnotherExceptionProcessor" class="org.apache.camel.processor.FailOverLoadBalanceTest$MyAnotherExceptionProcessor"/>
-  
-  <!-- END SNIPPET: example -->
+  <bean id="forced" class="java.lang.IllegalArgumentException">
+    <constructor-arg index="0" value="Forced"/>
+  </bean>
+
+  <bean id="alsoForced" class="java.lang.IllegalArgumentException">
+    <constructor-arg index="0" value="Also Forced"/>
+  </bean>
 
 </beans>



Mime
View raw message