camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r674115 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ components/camel-spring/src/main/java/org/apache/camel/spring/ components/camel-spring/src/main/java/org/apache/camel/spring/spi/ components/camel-spring...
Date Fri, 04 Jul 2008 20:26:49 GMT
Author: davsclaus
Date: Fri Jul  4 13:26:49 2008
New Revision: 674115

URL: http://svn.apache.org/viewvc?rev=674115&view=rev
Log:
CAMEL-663: Improved builder methods for Java DSL. Added missing builder method for the new
option on DLC. 

Added:
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithDefaultErrorHandlerTest.java
  (contents, props changed)
      - copied, changed from r674068, activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java?rev=674115&r1=674114&r2=674115&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
Fri Jul  4 13:26:49 2008
@@ -91,6 +91,11 @@
         return this;
     }
 
+    public DeadLetterChannelBuilder maximumRedeliveryDelay(long maximumRedeliveryDelay) {
+        getRedeliveryPolicy().maximumRedeliveryDelay(maximumRedeliveryDelay);
+        return this;
+    }
+
     public DeadLetterChannelBuilder useCollisionAvoidance() {
         getRedeliveryPolicy().useCollisionAvoidance();
         return this;

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java?rev=674115&r1=674114&r2=674115&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java
Fri Jul  4 13:26:49 2008
@@ -17,8 +17,13 @@
 package org.apache.camel.spring;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.processor.RedeliveryPolicy;
+import org.apache.camel.spi.Policy;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.DeadLetterChannelBuilder;
 import org.apache.camel.spring.spi.TransactionInterceptor;
+import org.apache.camel.spring.spi.TransactionErrorHandlerBuilder;
+import org.apache.camel.spring.spi.SpringTransactionPolicy;
 
 import org.springframework.context.ApplicationContext;
 import org.springframework.transaction.support.TransactionTemplate;
@@ -97,4 +102,17 @@
     public void setApplicationContext(ApplicationContext applicationContext) {
         this.applicationContext = applicationContext;
     }
+
+    /**
+     * Creates a transaction error handler.
+     *
+     * @param policy   using this transaction policy (eg: required, supports, ...)
+     * @return the created error handler
+     */
+    public TransactionErrorHandlerBuilder transactionErrorHandler(SpringTransactionPolicy
policy) {
+        TransactionErrorHandlerBuilder answer = new TransactionErrorHandlerBuilder();
+        answer.setTransactionTemplate(policy.getTemplate());
+        return answer;
+    }
+
 }

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java?rev=674115&r1=674114&r2=674115&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java
Fri Jul  4 13:26:49 2008
@@ -73,4 +73,42 @@
     public void afterPropertiesSet() throws Exception {
         ObjectHelper.notNull(transactionTemplate, "transactionTemplate");
     }
+
+    // Builder methods
+    // -------------------------------------------------------------------------
+    public TransactionErrorHandlerBuilder backOffMultiplier(double backOffMultiplier) {
+        getRedeliveryPolicy().backOffMultiplier(backOffMultiplier);
+        return this;
+    }
+
+    public TransactionErrorHandlerBuilder collisionAvoidancePercent(short collisionAvoidancePercent)
{
+        getRedeliveryPolicy().collisionAvoidancePercent(collisionAvoidancePercent);
+        return this;
+    }
+
+    public TransactionErrorHandlerBuilder initialRedeliveryDelay(long initialRedeliveryDelay)
{
+        getRedeliveryPolicy().initialRedeliveryDelay(initialRedeliveryDelay);
+        return this;
+    }
+
+    public TransactionErrorHandlerBuilder maximumRedeliveries(int maximumRedeliveries) {
+        getRedeliveryPolicy().maximumRedeliveries(maximumRedeliveries);
+        return this;
+    }
+
+    public TransactionErrorHandlerBuilder maximumRedeliveryDelay(long maximumRedeliveryDelay)
{
+        getRedeliveryPolicy().maximumRedeliveryDelay(maximumRedeliveryDelay);
+        return this;
+    }
+
+    public TransactionErrorHandlerBuilder useCollisionAvoidance() {
+        getRedeliveryPolicy().useCollisionAvoidance();
+        return this;
+    }
+
+    public TransactionErrorHandlerBuilder useExponentialBackOff() {
+        getRedeliveryPolicy().useExponentialBackOff();
+        return this;
+    }
+
 }

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java?rev=674115&r1=674114&r2=674115&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java
Fri Jul  4 13:26:49 2008
@@ -78,6 +78,7 @@
 
         transactionTemplate.execute(new TransactionCallbackWithoutResult() {
             protected void doInTransactionWithoutResult(TransactionStatus status) {
+                // TODO: The delay is in some cases never triggered - see CAMEL-663
                 if (redeliveryPolicy != null && redeliveryData.previousRollback)
{
                     // lets delay
                     redeliveryData.redeliveryDelay = redeliveryPolicy.sleep(redeliveryData.redeliveryDelay);

Modified: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java?rev=674115&r1=674114&r2=674115&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java
Fri Jul  4 13:26:49 2008
@@ -19,9 +19,9 @@
 import javax.sql.DataSource;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.SpringRouteBuilder;
 import org.apache.camel.spring.SpringTestSupport;
 import org.apache.camel.spring.spi.SpringTransactionPolicy;
-import org.apache.camel.spi.Policy;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.transaction.support.TransactionTemplate;
@@ -31,7 +31,8 @@
  */
 public class TransactionalClientDataSourceTest extends SpringTestSupport {
 
-    private JdbcTemplate jdbc;
+    protected JdbcTemplate jdbc;
+    protected boolean useTransactionErrorHandler = true;
 
     protected ClassPathXmlApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext(
@@ -73,6 +74,7 @@
     // END SNIPPET: e3
 
     // START SNIPPET: e4
+
     public void testTransactionRollback() throws Exception {
         template.sendBody("direct:fail", "Hello World");
 
@@ -82,13 +84,29 @@
     // END SNIPPET: e4
 
     protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
+        // START SNIPPET: e1
+        // Notice that we use the SpringRouteBuilder that has a few more features than
+        // the standard RouteBuilder
+        return new SpringRouteBuilder() {
             public void configure() throws Exception {
                 // START SNIPPET: e1
                 // setup the transaction policy
                 TransactionTemplate tt = context.getRegistry()
                     .lookup("PROPAGATION_REQUIRED", TransactionTemplate.class);
-                Policy required = new SpringTransactionPolicy(tt);
+                SpringTransactionPolicy required = new SpringTransactionPolicy(tt);
+
+                // use this error handler instead of DeadLetterChannel that is the default
+                // Notice: transactionErrorHandler is in SpringRouteBuilder
+                if (useTransactionErrorHandler) {
+                    // useTransactionErrorHandler is only used for unit testing to reuse
code
+                    // for doing a 2nd test without this transaction error handler, so ignore
+                    // this. For spring based transaction, end users is encured to use the
+                    // transaction error handler instead of the default DeadLetterChannel.
+                    errorHandler(transactionErrorHandler(required).
+                        // notice that the builder has builder methods for chained configuration
+                        maximumRedeliveries(3).
+                        initialRedeliveryDelay(5 * 1000L));
+                }
                 // END SNIPPET: e1
 
                 // START SNIPPET: e2

Copied: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithDefaultErrorHandlerTest.java
(from r674068, activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithDefaultErrorHandlerTest.java?p2=activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithDefaultErrorHandlerTest.java&p1=activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java&r1=674068&r2=674115&rev=674115&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithDefaultErrorHandlerTest.java
Fri Jul  4 13:26:49 2008
@@ -19,91 +19,23 @@
 import javax.sql.DataSource;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.SpringRouteBuilder;
 import org.apache.camel.spring.SpringTestSupport;
 import org.apache.camel.spring.spi.SpringTransactionPolicy;
-import org.apache.camel.spi.Policy;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.transaction.support.TransactionTemplate;
 
 /**
- * Unit test to demonstrate the transactional client pattern.
+ * Using the default error handler = DeadLetterChannel to unit test that this works out of
the box
+ * also, that Camel doesn't break.
  */
-public class TransactionalClientDataSourceTest extends SpringTestSupport {
-
-    private JdbcTemplate jdbc;
-
-    protected ClassPathXmlApplicationContext createApplicationContext() {
-        return new ClassPathXmlApplicationContext(
-            "/org/apache/camel/spring/interceptor/transactionalClientDataSource.xml");
-    }
-
-    protected int getExpectedRouteCount() {
-        return 0;
-    }
+public class TransactionalClientDataSourceWithDefaultErrorHandlerTest extends TransactionalClientDataSourceTest
{
 
     @Override
     protected void setUp() throws Exception {
-        this.disableJMX();
         super.setUp();
-
-        // START SNIPPET: e5
-        // create database and insert dummy data
-        final DataSource ds = getMandatoryBean(DataSource.class, "dataSource");
-        jdbc = new JdbcTemplate(ds);
-        jdbc.execute("create table books (title varchar(50))");
-        jdbc.update("insert into books (title) values (?)", new Object[] {"Camel in Action"});
-        // END SNIPPET: e5
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        jdbc.execute("drop table books");
-        this.enableJMX();
-    }
-
-    // START SNIPPET: e3
-    public void testTransactionSuccess() throws Exception {
-        template.sendBody("direct:okay", "Hello World");
-
-        int count = jdbc.queryForInt("select count(*) from books");
-        assertEquals("Number of books", 3, count);
-    }
-    // END SNIPPET: e3
-
-    // START SNIPPET: e4
-    public void testTransactionRollback() throws Exception {
-        template.sendBody("direct:fail", "Hello World");
-
-        int count = jdbc.queryForInt("select count(*) from books");
-        assertEquals("Number of books", 1, count);
+        useTransactionErrorHandler = false;
     }
-    // END SNIPPET: e4
-
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            public void configure() throws Exception {
-                // START SNIPPET: e1
-                // setup the transaction policy
-                TransactionTemplate tt = context.getRegistry()
-                    .lookup("PROPAGATION_REQUIRED", TransactionTemplate.class);
-                Policy required = new SpringTransactionPolicy(tt);
-                // END SNIPPET: e1
-
-                // START SNIPPET: e2
-                // set the required policy for this route
-                from("direct:okay").policy(required).
-                    setBody(constant("Tiger in Action")).beanRef("bookService").
-                    setBody(constant("Elephant in Action")).beanRef("bookService");
-
-                // set the required policy for this route
-                from("direct:fail").policy(required).
-                    setBody(constant("Tiger in Action")).beanRef("bookService").
-                    setBody(constant("Donkey in Action")).beanRef("bookService");
-                // END SNIPPET: e2
-            }
-        };
-    }
-
-}
+    
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithDefaultErrorHandlerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithDefaultErrorHandlerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message