activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r532029 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ main/java/org/apache/camel/component/mock/ main/java/org/apache/camel/processor/ test/java/org/apache/camel/processor/
Date Tue, 24 Apr 2007 17:58:17 GMT
Author: jstrachan
Date: Tue Apr 24 10:58:16 2007
New Revision: 532029

URL: http://svn.apache.org/viewvc?view=rev&rev=532029
Log:
disabled the nasty stack traces for the unit tests by default

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Logger.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.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?view=diff&rev=532029&r1=532028&r2=532029
==============================================================================
--- 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
Tue Apr 24 10:58:16 2007
@@ -23,6 +23,10 @@
 import org.apache.camel.processor.DeadLetterChannel;
 import org.apache.camel.processor.RecipientList;
 import org.apache.camel.processor.RedeliveryPolicy;
+import org.apache.camel.processor.Logger;
+import org.apache.camel.processor.LoggingLevel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * A builder of a <a href="http://activemq.apache.org/camel/dead-letter-channel.html">Dead
Letter Channel</a>
@@ -35,6 +39,7 @@
     private Processor<E> defaultDeadLetterEndpoint;
     private Expression<E> defaultDeadLetterEndpointExpression;
     private String defaultDeadLetterEndpointUri = "log:org.apache.camel.DeadLetterChannel:error";
+    private Logger<E> logger = DeadLetterChannel.createDefaultLogger();
 
     public DeadLetterChannelBuilder() {
     }
@@ -55,7 +60,7 @@
 
     public Processor<E> createErrorHandler(Processor<E> processor) throws Exception
{
         Processor<E> deadLetter = getDeadLetterFactory().createProcessor();
-        return new DeadLetterChannel<E>(processor, deadLetter, getRedeliveryPolicy());
+        return new DeadLetterChannel<E>(processor, deadLetter, getRedeliveryPolicy(),
getLogger());
     }
 
     // Builder methods
@@ -90,6 +95,44 @@
         return this;
     }
 
+    /**
+     * Sets the logger used for caught exceptions
+     */
+    public DeadLetterChannelBuilder<E> logger(Logger<E> logger) {
+        setLogger(logger);
+        return this;
+    }
+
+    /**
+     * Sets the logging level of exceptions caught
+     */
+    public DeadLetterChannelBuilder<E> loggingLevel(LoggingLevel level) {
+        getLogger().setLevel(level);
+        return this;
+    }
+
+    /**
+     * Sets the log used for caught exceptions
+     */
+    public DeadLetterChannelBuilder<E> log(Log log) {
+        getLogger().setLog(log);
+        return this;
+    }
+
+    /**
+     * Sets the log used for caught exceptions
+     */
+    public DeadLetterChannelBuilder<E> log(String log) {
+        return log(LogFactory.getLog(log));
+    }
+
+    /**
+     * Sets the log used for caught exceptions
+     */
+    public DeadLetterChannelBuilder<E> log(Class log) {
+        return log(LogFactory.getLog(log));
+    }
+
     // Properties
     //-------------------------------------------------------------------------
     public RedeliveryPolicy getRedeliveryPolicy() {
@@ -162,5 +205,13 @@
      */
     public void setDefaultDeadLetterEndpointUri(String defaultDeadLetterEndpointUri) {
         this.defaultDeadLetterEndpointUri = defaultDeadLetterEndpointUri;
+    }
+
+    public Logger<E> getLogger() {
+        return logger;
+    }
+
+    public void setLogger(Logger<E> logger) {
+        this.logger = logger;
     }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java?view=diff&rev=532029&r1=532028&r2=532029
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
Tue Apr 24 10:58:16 2007
@@ -99,9 +99,7 @@
      */
     protected void applyAssertionOn(MockEndpoint endpoint, int index, E exchange) {
         for (Predicate<E> predicate : predicates) {
-            if (!predicate.matches(exchange)) {
-                endpoint.fail("Message " + index + " failed Predicate " + predicate + " with
" + exchange);
-            }
+            predicate.assertMatches(endpoint.getEndpointUri() + " ", exchange);
         }
     }
 
@@ -114,7 +112,6 @@
         public PredicateValueBuilder(Expression<E> expression) {
             super(expression);
         }
-
 
         protected Predicate<E> onNewPredicate(Predicate<E> predicate) {
             addPredicate(predicate);

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java?view=diff&rev=532029&r1=532028&r2=532029
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
Tue Apr 24 10:58:16 2007
@@ -40,15 +40,21 @@
     private Processor<E> output;
     private Processor<E> deadLetter;
     private RedeliveryPolicy redeliveryPolicy;
+    private Logger<E> logger;
+
+    public static <E extends Exchange> Logger<E> createDefaultLogger() {
+        return new Logger<E>(log, LoggingLevel.ERROR);
+    }
 
     public DeadLetterChannel(Processor<E> output, Processor<E> deadLetter) {
-        this(output, deadLetter, new RedeliveryPolicy());
+        this(output, deadLetter, new RedeliveryPolicy(), DeadLetterChannel.<E>createDefaultLogger());
     }
 
-    public DeadLetterChannel(Processor<E> output, Processor<E> deadLetter, RedeliveryPolicy
redeliveryPolicy) {
+    public DeadLetterChannel(Processor<E> output, Processor<E> deadLetter, RedeliveryPolicy
redeliveryPolicy, Logger<E> logger) {
         this.deadLetter = deadLetter;
         this.output = output;
         this.redeliveryPolicy = redeliveryPolicy;
+        this.logger = logger;
     }
 
     @Override
@@ -72,7 +78,7 @@
                 return;
             }
             catch (RuntimeException e) {
-                log.error("On delivery attempt: " + redeliveryCounter + " caught: " + e,
e);
+                logger.log("On delivery attempt: " + redeliveryCounter + " caught: " + e,
e);
             }
             redeliveryCounter = incrementRedeliveryCounter(exchange);
         }
@@ -110,6 +116,16 @@
         this.redeliveryPolicy = redeliveryPolicy;
     }
 
+    public Logger<E> getLogger() {
+        return logger;
+    }
+
+    /**
+     * Sets the logger strategy; which {@link Log} to use and which {@link LoggingLevel}
to use
+     */
+    public void setLogger(Logger<E> logger) {
+        this.logger = logger;
+    }
 
     // Implementation methods
     //-------------------------------------------------------------------------

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Logger.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Logger.java?view=diff&rev=532029&r1=532028&r2=532029
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Logger.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Logger.java Tue
Apr 24 10:58:16 2007
@@ -87,6 +87,80 @@
         }
     }
 
+    public void log(String message) {
+        switch (level) {
+            case DEBUG:
+                if (log.isDebugEnabled()) {
+                    log.debug(message);
+                }
+                break;
+            case ERROR:
+                if (log.isErrorEnabled()) {
+                    log.error(message);
+                }
+                break;
+            case FATAL:
+                if (log.isFatalEnabled()) {
+                    log.fatal(message);
+                }
+                break;
+            case INFO:
+                if (log.isInfoEnabled()) {
+                    log.debug(message);
+                }
+                break;
+            case TRACE:
+                if (log.isTraceEnabled()) {
+                    log.trace(message);
+                }
+                break;
+            case WARN:
+                if (log.isWarnEnabled()) {
+                    log.warn(message);
+                }
+                break;
+            default:
+                log.error("Unknown level: " + level + " when trying to log exchange: " +
message);
+        }
+    }
+
+    public void log(String message, Throwable exception) {
+        switch (level) {
+            case DEBUG:
+                if (log.isDebugEnabled()) {
+                    log.debug(message, exception);
+                }
+                break;
+            case ERROR:
+                if (log.isErrorEnabled()) {
+                    log.error(message, exception);
+                }
+                break;
+            case FATAL:
+                if (log.isFatalEnabled()) {
+                    log.fatal(message, exception);
+                }
+                break;
+            case INFO:
+                if (log.isInfoEnabled()) {
+                    log.debug(message, exception);
+                }
+                break;
+            case TRACE:
+                if (log.isTraceEnabled()) {
+                    log.trace(message, exception);
+                }
+                break;
+            case WARN:
+                if (log.isWarnEnabled()) {
+                    log.warn(message, exception);
+                }
+                break;
+            default:
+                log.error("Unknown level: " + level + " when trying to log exchange: " +
message, exception);
+        }
+    }
+
     protected Object logMessage(E exchange) {
         return exchange;
     }
@@ -97,5 +171,13 @@
 
     public void setLog(Log log) {
         this.log = log;
+    }
+
+    public LoggingLevel getLevel() {
+        return level;
+    }
+
+    public void setLevel(LoggingLevel level) {
+        this.level = level;
     }
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java?view=diff&rev=532029&r1=532028&r2=532029
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java
Tue Apr 24 10:58:16 2007
@@ -85,8 +85,10 @@
 
         return new RouteBuilder<Exchange>() {
             public void configure() {
-                from("direct:start").errorHandler(deadLetterChannel("mock:failed").maximumRedeliveries(2).initialRedeliveryDelay(1))
-                        .process(processor);
+                from("direct:start").errorHandler(deadLetterChannel("mock:failed")
+                        .maximumRedeliveries(2).initialRedeliveryDelay(1).loggingLevel(LoggingLevel.DEBUG)
+
+                ).process(processor);
 
                 /*  TODO - currently process().to() results in two separate operations which
have their own error handler
 



Mime
View raw message