camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jans...@apache.org
Subject svn commit: r709209 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/processor/ camel-core/src/test/java/org/apache/camel/builder/ camel-core/src/test/java/org/apache/camel/component/bean/ components/camel-spring/src/test/java/org/...
Date Thu, 30 Oct 2008 17:02:38 GMT
Author: janstey
Date: Thu Oct 30 10:02:37 2008
New Revision: 709209

URL: http://svn.apache.org/viewvc?rev=709209&view=rev
Log:
CAMEL-1036 - Adding Spring test case and improving some javadoc

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/CustomLog.java
  (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/MyExceptionThrowingProcessor.java
  (with props)
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/SpringExceptionBuilderWithRetryLoggingLevelSetTest.java
  (with props)
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderWithRetryLoggingLevelSetTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanPipelineTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java?rev=709209&r1=709208&r2=709209&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryPolicy.java
Thu Oct 30 10:02:37 2008
@@ -31,7 +31,7 @@
  * href="http://activemq.apache.org/camel/dead-letter-channel.html">Dead Letter
  * Channel</a>
  * <p>
- * The default values is:
+ * The default values are:
  * <ul>
  *   <li>maximumRedeliveries = 5</li>
  *   <li>delay = 1000L (the initial delay)</li>
@@ -40,6 +40,8 @@
  *   <li>useExponentialBackOff = false</li>
  *   <li>collisionAvoidanceFactor = 0.15d</li>
  *   <li>useCollisionAvoidance = false</li>
+ *   <li>retriesExhaustedLogLevel = LoggingLevel.ERROR</li>
+ *   <li>retryAttemptedLogLevel = LoggingLevel.ERROR</li>
  * </ul>
  * <p/>
  * Setting the maximumRedeliveries to a negative value such as -1 will then always redeliver
(unlimited).
@@ -343,6 +345,9 @@
         return randomNumberGenerator;
     }
 
+    /**
+     * Sets the logging level to use for log messages when retries have been exhausted.
+     */    
     public void setRetriesExhaustedLogLevel(LoggingLevel retriesExhaustedLogLevel) {
         this.retriesExhaustedLogLevel = retriesExhaustedLogLevel;        
     }
@@ -351,6 +356,9 @@
         return retriesExhaustedLogLevel;
     }
 
+    /**
+     * Sets the logging level to use for log messages when retries are attempted.
+     */    
     public void setRetryAttemptedLogLevel(LoggingLevel retryAttemptedLogLevel) {
         this.retryAttemptedLogLevel = retryAttemptedLogLevel;
     }

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/CustomLog.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/CustomLog.java?rev=709209&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/CustomLog.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/CustomLog.java
Thu Oct 30 10:02:37 2008
@@ -0,0 +1,90 @@
+/**
+ * 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.builder;
+
+import org.apache.commons.logging.Log;
+
+class CustomLog implements Log {
+
+    boolean loggedTrace = false;
+    boolean loggedFatal = false;
+
+    public boolean isDebugEnabled() {
+        return true;
+    }
+
+    public boolean isErrorEnabled() {
+        return true;
+    }
+
+    public boolean isFatalEnabled() {
+        return true;
+    }
+
+    public boolean isInfoEnabled() {
+        return true;
+    }
+
+    public boolean isTraceEnabled() {
+        return true;
+    }
+
+    public boolean isWarnEnabled() {
+        return true;
+    }
+
+    public void trace(Object message) {
+        loggedTrace = true;
+    }
+
+    public void trace(Object message, Throwable t) {
+        loggedTrace = true;
+    }
+
+    public void debug(Object message) {
+    }
+
+    public void debug(Object message, Throwable t) {
+    }
+
+    public void info(Object message) {
+    }
+
+    public void info(Object message, Throwable t) {
+    }
+
+    public void warn(Object message) {
+    }
+
+    public void warn(Object message, Throwable t) {
+    }
+
+    public void error(Object message) {
+    }
+
+    public void error(Object message, Throwable t) {
+
+    }
+
+    public void fatal(Object message) {
+        loggedFatal = true;
+    }
+
+    public void fatal(Object message, Throwable t) {
+        loggedFatal = true;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/CustomLog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderWithRetryLoggingLevelSetTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderWithRetryLoggingLevelSetTest.java?rev=709209&r1=709208&r2=709209&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderWithRetryLoggingLevelSetTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderWithRetryLoggingLevelSetTest.java
Thu Oct 30 10:02:37 2008
@@ -22,6 +22,8 @@
 import java.security.KeyException;
 import java.security.KeyManagementException;
 
+import javax.naming.Context;
+
 import org.apache.camel.CamelExchangeException;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
@@ -29,6 +31,8 @@
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.model.LoggingLevel;
+import org.apache.camel.spi.Registry;
+import org.apache.camel.util.jndi.JndiContext;
 import org.apache.commons.logging.Log;
 
 /**
@@ -39,14 +43,7 @@
     private static final String MESSAGE_INFO = "messageInfo";
     private static final String RESULT_QUEUE = "mock:result";
     private static final String ERROR_QUEUE = "mock:error";
-    private CustomLog logger;
-
-    @Override
-    protected void setUp() throws Exception {
-        logger = new CustomLog();
-        super.setUp();
-    }
-    
+   
     public void testExceptionIsLoggedWithCustomLogLevel() throws Exception {
         MockEndpoint result = getMockEndpoint(RESULT_QUEUE);
         result.expectedMessageCount(0);
@@ -62,10 +59,10 @@
             // expected
         }
 
-        MockEndpoint.assertIsSatisfied(result, mock);
-        assertTrue(logger.loggedTrace && logger.loggedFatal);
-    }
-
+        MockEndpoint.assertIsSatisfied(result, mock);        
+        assertTrue(getCustomLog().loggedTrace && getCustomLog().loggedFatal);
+    }   
+    
     public void testExceptionIsLoggedWithDefaultLevel() throws Exception {
         MockEndpoint result = getMockEndpoint(RESULT_QUEUE);
         result.expectedMessageCount(0);
@@ -82,13 +79,40 @@
         }
 
         MockEndpoint.assertIsSatisfied(result, mock);
-        assertTrue(!logger.loggedTrace && !logger.loggedFatal);
+        assertTrue(!getCustomLog().loggedTrace && !getCustomLog().loggedFatal);
+    }    
+
+    @Override
+    protected void setUp() throws Exception {
+        CustomLog logger = getCustomLog();
+        if (logger != null) {
+            // reinit state
+            logger.loggedFatal = false;
+            logger.loggedTrace = false;
+        }
+        super.setUp();
+    }   
+    
+    @Override
+    protected Context createJndiContext() throws Exception {
+        JndiContext answer = new JndiContext();
+        answer.bind("theCustomLog", new CustomLog());
+        answer.bind("myExceptionThrowingProcessor", new MyExceptionThrowingProcessor());
+        return answer;
     }    
     
+    private CustomLog getCustomLog() {
+        if (context != null) {
+            return context.getRegistry().lookup("theCustomLog", CustomLog.class);
+        } else {
+            return null;
+        }
+    }   
+    
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
-            public void configure() throws Exception {
-                errorHandler(deadLetterChannel().log(logger));
+            public void configure() throws Exception {             
+                errorHandler(deadLetterChannel().log(getCustomLog()));
                 
                 onException(NullPointerException.class)
                     .maximumRedeliveries(0)
@@ -108,97 +132,11 @@
                     .to(ERROR_QUEUE);
                 // END SNIPPET: exceptionBuilder1
 
-                from("direct:a").process(new Processor() {
-                    public void process(Exchange exchange) throws Exception {
-                        String s = exchange.getIn().getBody(String.class);
-                        if ("Hello NPE".equals(s)) {
-                            throw new NullPointerException();
-                        } else if ("Hello IO".equals(s)) {
-                            throw new ConnectException("Forced for testing - can not connect
to remote server");
-                        }
-                        exchange.getOut().setBody("Hello World");
-                    }
-                }).to("mock:result");
+                from("direct:a")
+                  .processRef("myExceptionThrowingProcessor").to("mock:result");
             }
         };
     }
-    
-    private class CustomLog implements Log {
-
-        boolean loggedTrace = false;
-        boolean loggedFatal = false;       
-        
-        public boolean isDebugEnabled() {
-            return true;
-        }
-
-        public boolean isErrorEnabled() {
-            return true;
-        }
-
-        public boolean isFatalEnabled() {
-            return true;
-        }
-
-        public boolean isInfoEnabled() {
-            return true;
-        }
-
-        public boolean isTraceEnabled() {
-            return true;
-        }
-
-        public boolean isWarnEnabled() {
-            return true;
-        }
-
-        public void trace(Object message) {
-            assertNotNull(message);
-            loggedTrace = true;            
-        }
-
-        public void trace(Object message, Throwable t) {
-            assertNotNull(t);
-            assertNotNull(message);
-            loggedTrace = true;            
-        }
-
-        public void debug(Object message) {
-        }
-
-        public void debug(Object message, Throwable t) {
-        }
-
-        public void info(Object message) {
-        }
-
-        public void info(Object message, Throwable t) {
-        }
-
-        public void warn(Object message) {
-        }
-
-        public void warn(Object message, Throwable t) {
-        }
-
-        public void error(Object message) {
-        }
-
-        public void error(Object message, Throwable t) {
-
-        }
-
-        public void fatal(Object message) {
-            assertNotNull(message);
-            loggedFatal = true;
-        }
-
-        public void fatal(Object message, Throwable t) {
-            assertNotNull(t);
-            assertNotNull(message);
-            loggedFatal = true;
-        }
-    }
 }
 
 

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/MyExceptionThrowingProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/MyExceptionThrowingProcessor.java?rev=709209&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/MyExceptionThrowingProcessor.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/MyExceptionThrowingProcessor.java
Thu Oct 30 10:02:37 2008
@@ -0,0 +1,35 @@
+/**
+ * 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.builder;
+
+import java.net.ConnectException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+class MyExceptionThrowingProcessor implements Processor {
+    public void process(Exchange exchange) throws Exception {
+        String s = exchange.getIn().getBody(String.class);
+        if ("Hello NPE".equals(s)) {
+            throw new NullPointerException();
+        } else if ("Hello IO".equals(s)) {
+            throw new ConnectException("Forced for testing - can not connect to remote server");
+        }
+        exchange.getOut().setBody("Hello World");
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/MyExceptionThrowingProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanPipelineTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanPipelineTest.java?rev=709209&r1=709208&r2=709209&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanPipelineTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanPipelineTest.java
Thu Oct 30 10:02:37 2008
@@ -28,7 +28,7 @@
 import org.apache.camel.util.jndi.JndiContext;
 
 /**
- * Unit test of bean can propogate headers in a pipleline
+ * Unit test of bean can propagate headers in a pipeline
  */
 public class BeanPipelineTest extends ContextTestSupport {
 

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/SpringExceptionBuilderWithRetryLoggingLevelSetTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/SpringExceptionBuilderWithRetryLoggingLevelSetTest.java?rev=709209&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/SpringExceptionBuilderWithRetryLoggingLevelSetTest.java
(added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/SpringExceptionBuilderWithRetryLoggingLevelSetTest.java
Thu Oct 30 10:02:37 2008
@@ -0,0 +1,30 @@
+/**
+ * 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.spring.processor.onexception;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.ExceptionBuilderWithRetryLoggingLevelSetTest;
+import org.apache.camel.component.mock.MockEndpoint;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringExceptionBuilderWithRetryLoggingLevelSetTest extends ExceptionBuilderWithRetryLoggingLevelSetTest
{
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, "/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml");
+    }
+}
\ No newline at end of file

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

Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml?rev=709209&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml
(added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml
Thu Oct 30 10:02:37 2008
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+    ">
+
+    <bean id="theCustomLog" class="org.apache.camel.builder.CustomLog" />
+
+    <bean id="theCustomLogger" class="org.apache.camel.processor.Logger">
+      <property name="log" ref="theCustomLog" />
+    </bean>
+
+    <bean id="myExceptionThrowingProcessor"
+      class="org.apache.camel.builder.MyExceptionThrowingProcessor" />
+
+    <bean id="dlc" class="org.apache.camel.builder.DeadLetterChannelBuilder">
+      <property name="logger" ref="theCustomLogger" />
+    </bean>
+
+    <!-- this is the camel context where we define the routes -->
+    <camelContext xmlns="http://activemq.apache.org/camel/schema/spring" errorHandlerRef="dlc">
+
+        <route>
+            <from uri="direct:a"/>
+
+            <!-- we must configure the on exception within the route, as opposed to Java
DSL where we can do this outside -->
+            <onException>
+                <exception>java.lang.NullPointerException</exception>
+                <redeliveryPolicy maximumRedeliveries="0"/>
+                <setHeader headerName="messageInfo">
+                  <constant>Damm a NPE</constant>
+                </setHeader>
+                <to uri="mock:error"/>
+            </onException>
+           <!-- START SNIPPET: e1 -->
+            <onException>
+                <exception>java.io.IOException</exception>
+                <redeliveryPolicy 
+                    initialRedeliveryDelay="1000"
+                    maximumRedeliveries="3"
+                    maximumRedeliveryDelay="10000"
+                    backOffMultiplier="1.0"
+                    useExponentialBackOff="true"
+                    retryAttemptedLogLevel="TRACE"
+                    retriesExhaustedLogLevel="FATAL"               
+                />
+                <setHeader headerName="messageInfo">
+                  <constant>Damm somekind of IO exception</constant>
+                </setHeader>
+                <to uri="mock:error"/>
+            </onException>
+            <!-- END SNIPPET: e1 -->
+                
+            <process ref="myExceptionThrowingProcessor"/>
+            <to uri="mock:result"/>
+        </route>
+
+    </camelContext>
+</beans>

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message