You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dancerjohn <wi...@gmail.com> on 2013/05/24 14:45:08 UTC
Using MockEndpoint to throw an Exception not propated
I am attempting to use a MockEndpoint to drive Exception testing. I have
configured the MockEndpoint as follows:
mockEndpoint.whenAnyExchangeReceived(new Processor(){
public void process(Exchange ago0) throws Exception{
System.out.println("here");
throw new RuntimeException("blah");
}
});
When I run my test I see the "here" on the console / log but I don't see any
error messages related to the Exception. I believe this route is currently
using the DefaultErrorHandler (bit complicated because the test hits
multiple routes in multiple contexts) as I do not have any error handlers
configured. I have some onException logic in place which I am trying to
exercise but those are not being hit either.
If instead I use adviceWith to throw the same exception at the same point
(intercepting on same URI to which the MockEndpoint is linked) it works as
expected (Exception is thrown and logged by Camel).
Why is the Exception not being propagated out of MockEndpoint?
--
View this message in context: http://camel.465427.n5.nabble.com/Using-MockEndpoint-to-throw-an-Exception-not-propated-tp5733088.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Using MockEndpoint to throw an Exception not propated
Posted by dancerjohn <wi...@gmail.com>.
This is what my test looks like
@EndpointInject(uri="mock:coreEndpoint", context="coreContext")
MockEndpoint mockEndpoint;
@Produce(uri="direct:jmsInputQueue")
ProducerTemplate producerTemplate;
@Test
public void test(){
mockEndpoint.whenAnyExchangeReceived(new Processor(){
public void process(Exchange ago0) throws Exception{
System.out.println("here");
throw new RuntimeException("blah");
}
producerTemplate.sendBody("blahblah");
// do verification here that my error handler handled and logged the
exception
});
}
All logging is routed to the Console. When I run the above, I see the
logging from my route and the "here" in the console but I do not see the
exception (nor the stack trace) logged. This should be logged either by the
default error handler or my onException handling.
If instead of using the MockEndpoint.whenAnyExchangeReceived I use
adviceWith on the route and throw a RuntimeException I see the exception on
the console (via the logger) and am able to verify that my onException
handled the exception due to the logging.
The route design is as follows (using all direct components)...
Context 1:
from("direct:input")... to("direct:input2");
from("direct:input2)... to("context2:coreChannel");
Context 2:
from("direct:coreChannel").log(...).to("mock:mockEndpoint");
--
View this message in context: http://camel.465427.n5.nabble.com/Using-MockEndpoint-to-throw-an-Exception-not-propated-tp5733088p5733129.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Using MockEndpoint to throw an Exception not propated
Posted by Christian Posta <ch...@gmail.com>.
Thanks Christoph :)
I had 2 seconds to hack it up before i boarded a plane.
If you run it, exception will bubble up. Was looking for some dialog with
dancerjohn about his usecase and how his might be different and where the
exception might be caught and/or subsumed.
On Fri, May 24, 2013 at 7:42 AM, Christoph Emmersberger <
cemmersb@googlemail.com> wrote:
> Hi Christian,
>
> first of all, it would be really helpful if you could provide some more
> information.
>
> Secondly, as far as I can see from the sample code, you are directly
> writing to System out "here". However, I do not see any expected behavior
> for your RuntimeException. Are you catching this exception somewhere? In
> case you do so, please take care about your logging configuration, i.e.
> directing your output to the console rather than towards any file, ...
>
> - Christoph
>
> On May 24, 2013, at 4:18 PM, Christian Posta wrote:
>
> > K.. let's start with this, which works... how is your route different?
> >
> >
> https://github.com/christian-posta/camel-sandbox/blob/master/one-off/src/test/java/posta/TestMockExceptions.java
> >
> >
> >
> >
> > On Fri, May 24, 2013 at 5:45 AM, dancerjohn <winddancerjohn@gmail.com
> >wrote:
> >
> >> I am attempting to use a MockEndpoint to drive Exception testing. I have
> >> configured the MockEndpoint as follows:
> >>
> >> mockEndpoint.whenAnyExchangeReceived(new Processor(){
> >>
> >> public void process(Exchange ago0) throws Exception{
> >> System.out.println("here");
> >> throw new RuntimeException("blah");
> >> }
> >> });
> >>
> >> When I run my test I see the "here" on the console / log but I don't see
> >> any
> >> error messages related to the Exception. I believe this route is
> currently
> >> using the DefaultErrorHandler (bit complicated because the test hits
> >> multiple routes in multiple contexts) as I do not have any error
> handlers
> >> configured. I have some onException logic in place which I am trying to
> >> exercise but those are not being hit either.
> >>
> >> If instead I use adviceWith to throw the same exception at the same
> point
> >> (intercepting on same URI to which the MockEndpoint is linked) it works
> as
> >> expected (Exception is thrown and logged by Camel).
> >>
> >> Why is the Exception not being propagated out of MockEndpoint?
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://camel.465427.n5.nabble.com/Using-MockEndpoint-to-throw-an-Exception-not-propated-tp5733088.html
> >> Sent from the Camel - Users mailing list archive at Nabble.com.
> >>
> >
> >
> >
> > --
> > *Christian Posta*
> > http://www.christianposta.com/blog
> > twitter: @christianposta
>
>
--
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta
Re: Using MockEndpoint to throw an Exception not propated
Posted by Christoph Emmersberger <ce...@googlemail.com>.
Hi Christian,
first of all, it would be really helpful if you could provide some more information.
Secondly, as far as I can see from the sample code, you are directly writing to System out "here". However, I do not see any expected behavior for your RuntimeException. Are you catching this exception somewhere? In case you do so, please take care about your logging configuration, i.e. directing your output to the console rather than towards any file, ...
- Christoph
On May 24, 2013, at 4:18 PM, Christian Posta wrote:
> K.. let's start with this, which works... how is your route different?
>
> https://github.com/christian-posta/camel-sandbox/blob/master/one-off/src/test/java/posta/TestMockExceptions.java
>
>
>
>
> On Fri, May 24, 2013 at 5:45 AM, dancerjohn <wi...@gmail.com>wrote:
>
>> I am attempting to use a MockEndpoint to drive Exception testing. I have
>> configured the MockEndpoint as follows:
>>
>> mockEndpoint.whenAnyExchangeReceived(new Processor(){
>>
>> public void process(Exchange ago0) throws Exception{
>> System.out.println("here");
>> throw new RuntimeException("blah");
>> }
>> });
>>
>> When I run my test I see the "here" on the console / log but I don't see
>> any
>> error messages related to the Exception. I believe this route is currently
>> using the DefaultErrorHandler (bit complicated because the test hits
>> multiple routes in multiple contexts) as I do not have any error handlers
>> configured. I have some onException logic in place which I am trying to
>> exercise but those are not being hit either.
>>
>> If instead I use adviceWith to throw the same exception at the same point
>> (intercepting on same URI to which the MockEndpoint is linked) it works as
>> expected (Exception is thrown and logged by Camel).
>>
>> Why is the Exception not being propagated out of MockEndpoint?
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Using-MockEndpoint-to-throw-an-Exception-not-propated-tp5733088.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> *Christian Posta*
> http://www.christianposta.com/blog
> twitter: @christianposta
Re: Using MockEndpoint to throw an Exception not propated
Posted by Christian Posta <ch...@gmail.com>.
K.. let's start with this, which works... how is your route different?
https://github.com/christian-posta/camel-sandbox/blob/master/one-off/src/test/java/posta/TestMockExceptions.java
On Fri, May 24, 2013 at 5:45 AM, dancerjohn <wi...@gmail.com>wrote:
> I am attempting to use a MockEndpoint to drive Exception testing. I have
> configured the MockEndpoint as follows:
>
> mockEndpoint.whenAnyExchangeReceived(new Processor(){
>
> public void process(Exchange ago0) throws Exception{
> System.out.println("here");
> throw new RuntimeException("blah");
> }
> });
>
> When I run my test I see the "here" on the console / log but I don't see
> any
> error messages related to the Exception. I believe this route is currently
> using the DefaultErrorHandler (bit complicated because the test hits
> multiple routes in multiple contexts) as I do not have any error handlers
> configured. I have some onException logic in place which I am trying to
> exercise but those are not being hit either.
>
> If instead I use adviceWith to throw the same exception at the same point
> (intercepting on same URI to which the MockEndpoint is linked) it works as
> expected (Exception is thrown and logged by Camel).
>
> Why is the Exception not being propagated out of MockEndpoint?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Using-MockEndpoint-to-throw-an-Exception-not-propated-tp5733088.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta