Author: davsclaus
Date: Sat Oct 11 03:17:50 2008
New Revision: 703643
URL: http://svn.apache.org/viewvc?rev=703643&view=rev
Log:
CAMEL-960: fixed boolean not used
CAMEL-901: added unit test for looking into this rare issue
polished code and fixed wrong wrapping of exceptions
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue901Test.java
(with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.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/util/ObjectHelper.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?rev=703643&r1=703642&r2=703643&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
Sat Oct 11 03:17:50 2008
@@ -35,6 +35,7 @@
String AGGREGATED_COUNT = "org.apache.camel.Exchange.AggregatedCount";
String EXCEPTION_HANDLED_PROPERTY = "CamelExceptionHandled";
+
/**
* Returns the [EMAIL PROTECTED] ExchangePattern} (MEP) of this exchange.
*
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java?rev=703643&r1=703642&r2=703643&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java
Sat Oct 11 03:17:50 2008
@@ -48,7 +48,7 @@
@XmlElement(name = "exception")
private List<String> exceptions = new ArrayList<String>();
- @XmlElement(name = "redeliveryPolicy", required = false)
+ @XmlElement(name = "redeliveryPolicy", required = false)
private RedeliveryPolicyType redeliveryPolicy;
@XmlElementRef
private List<ProcessorType<?>> outputs = new ArrayList<ProcessorType<?>>();
@@ -121,7 +121,7 @@
//-------------------------------------------------------------------------
public ExceptionType handled(boolean cond) {
ConstantLanguage constant = new ConstantLanguage();
- return handled(constant.createPredicate("true"));
+ return handled(constant.createPredicate(Boolean.toString(cond)));
}
public ExceptionType handled(Predicate cond) {
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?rev=703643&r1=703642&r2=703643&view=diff
==============================================================================
---
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
Sat Oct 11 03:17:50 2008
@@ -86,7 +86,7 @@
@Override
public String toString() {
- return "DeadLetterChannel[" + output + ", " + deadLetter + ", " +
redeliveryPolicy + "]";
+ return "DeadLetterChannel[" + output + ", " + deadLetter + "]";
}
public boolean process(Exchange exchange, final AsyncCallback callback) {
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=703643&r1=703642&r2=703643&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
Sat Oct 11 03:17:50 2008
@@ -604,7 +604,7 @@
try {
return type.newInstance();
} catch (InstantiationException e) {
- throw new RuntimeCamelException(e.getCause());
+ throw new RuntimeCamelException(e);
} catch (IllegalAccessException e) {
throw new RuntimeCamelException(e);
}
@@ -618,7 +618,7 @@
Object value = actualType.newInstance();
return cast(expectedType, value);
} catch (InstantiationException e) {
- throw new RuntimeCamelException(e.getCause());
+ throw new RuntimeCamelException();
} catch (IllegalAccessException e) {
throw new RuntimeCamelException(e);
}
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue901Test.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue901Test.java?rev=703643&view=auto
==============================================================================
---
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue901Test.java
(added)
+++
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue901Test.java
Sat Oct 11 03:17:50 2008
@@ -0,0 +1,102 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Unit test to verify that error handling using thread() pool also works as
expected.
+ */
+public class BelasThreadErrorHandlerIssue901Test extends ContextTestSupport {
+ private static final transient Log LOG =
LogFactory.getLog(BelasThreadErrorHandlerIssue901Test.class);
+ private String msg1 = "Message Intended For Processor #1",
+ msg2 = "Message Intended For Processor #2",
+ msg3 = "Message Intended For Processor #3";
+ private int callCounter1 = 0, callCounter2 = 0, callCounter3 = 0;
+ private int redelivery = 1;
+
+ protected void setUp() throws Exception {
+ disableJMX();
+ super.setUp();
+ }
+
+ public void testThreadErrorHandlerLogging() throws Exception {
+ MockEndpoint handled = getMockEndpoint("mock:handled");
+
+ template.sendBody("seda:errorTest", msg1);
+
+ handled.expectedMessageCount(1);
+ handled.expectedBodiesReceived(msg3);
+
+ // TODO: Enable this when looking into this issue
+ //Thread.sleep(3000);
+
+ assertMockEndpointsSatisfied();
+
+ assertEquals(1, callCounter1);
+ assertEquals(1, callCounter2);
+ assertEquals(1 + redelivery, callCounter3); // Only this should be
more then 1
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ //getContext().addInterceptStrategy(new Tracer());
+
errorHandler(deadLetterChannel("mock:handled").maximumRedeliveries(redelivery));
+
+ from("seda:errorTest")
+ // TODO: When using thread there is a multi threading /
concurreny issue in Camel
+ // hard to debug as it tend only to surface when unit test
is running really fast
+ // (no break points)
+
+ //.thread(5).maxSize(5)
+ // Processor #1
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ callCounter1++;
+ LOG.debug("Processor #1 Received A " +
exchange.getIn().getBody());
+ exchange.getOut().setBody(msg2);
+ }
+ })
+ // Processor #2
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ callCounter2++;
+ LOG.debug("Processor #2 Received A " +
exchange.getIn().getBody());
+ exchange.getOut().setBody(msg3);
+ }
+ })
+ // Processor #3
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ //Thread.sleep(100);
+ callCounter3++;
+ LOG.debug("Processor #3 Received A " +
exchange.getIn().getBody());
+ throw new Exception("Forced exception by unit
test");
+ }
+ });
+ }
+ };
+ }
+
+}
Propchange:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue901Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue901Test.java
------------------------------------------------------------------------------
svn:keywords = Rev Date