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/23 20:15:20 UTC

Why doesn't the stub component throw exceptions in tests

I am writing a test for my error handling. The route I am testing uses JMS
and therefore has URL properties that are not compatible with the direct
component. The way I have it set up is that I pass the following to the
Route Builder ("jms:queue:myqueue") and then it adds the additional URL
properties. In the test env I would like to be able to pass in something
like "direct:jmsInputChan" but this fails due to the URL properties not
working with direct.

Then I found stub. I can pass in "stub:blahblah" and get the route set up
and tested no problem. However, if I set a configuration to throw an
exception in the route I don't get the exception out. 

Here is what I mean... I am using ProducerTemplate.sendBody to send in a
message. If this channel is a "direct:xyz" and an exception is thrown the
exception is logged by Camel and then thrown out of sendBody which means I
can catch the exception in my test or have the test fail because of the
exception.

However, when the route starts with a stub and I cause the exception, Camel
logs the exception but it is NOT thrown out of sendBody. This makes it hard
to verify that the exception was not handled.

It seems that stub should behave similar to direct in this regard.



--
View this message in context: http://camel.465427.n5.nabble.com/Why-doesn-t-the-stub-component-throw-exceptions-in-tests-tp5733041.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Why doesn't the stub component throw exceptions in tests

Posted by dancerjohn <wi...@gmail.com>.
Ah, I see. It is the a-sync nature of stub that causes the difference. I will
look into how I can use stub and still get the exception thrown from the
produces (will look into receive).

Thanks



--
View this message in context: http://camel.465427.n5.nabble.com/Why-doesn-t-the-stub-component-throw-exceptions-in-tests-tp5733041p5733128.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Why doesn't the stub component throw exceptions in tests

Posted by Bilgin Ibryam <bi...@gmail.com>.
On 24 May 2013 16:15, Claus Ibsen <cl...@gmail.com> wrote:

> There is no bug on the seda consumer.


Claus, you are right as always, there is no bug.

I  was referring to line 196 from SedaConsumer [1]
If an exception happens during processing, it is logged and not propagated
back, but that is never the case, because the exception is always caught
and set to the exchange beforehand, so it is propagaed at line 194

Cheers
Bilgin


[1]
https://fisheye6.atlassian.com/browse/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java?hb=true#to196



> He sends a InOnly message.
> So the consumer can only "handle" the exception itself by logging it.
>
> If he does a InOut then the producer template will wait for the reply
> message, and because it failed with the exception, the reply message is the
> exception.
>
>
> On Fri, May 24, 2013 at 5:09 PM, Bilgin Ibryam <bi...@gmail.com> wrote:
>
> > Hi,
> >
> > can you try to set the exception on the exchange instead of throwing it?
> > If that's the case then I think there might a bug in SedaConsumer which
> > propagates back exceptions on the exchange but doesn't propagate thrown
> > exceptions.
> >
> > Bilgin
> >
> >
> > On 24 May 2013 12:31, dancerjohn <wi...@gmail.com> wrote:
> >
> > >
> > > I disagree... the javadoc for ProducerTemplate.sendBody() states
> "Notice:
> > > that if the processing of the exchange failed with an Exception it is
> > > thrown
> > > from this method as a CamelExecutionException with the caused exception
> > > wrapped.". So if an exception is thrown during processing sendBody
> should
> > > throw a CamelExecutionException.
> > >
> > > The point I am making is that when the channel is a direct channel this
> > > DOES
> > > happen. However, everything else being the same if the channel is a
> stub
> > > this DOES NOT happen. Therefore there is a difference in the components
> > > between direct and stub in this regard. This seems surprising.
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > >
> >
> http://camel.465427.n5.nabble.com/Why-doesn-t-the-stub-component-throw-exceptions-in-tests-tp5733041p5733083.html
> > > Sent from the Camel - Users mailing list archive at Nabble.com.
> > >
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> www.camelone.org: The open source integration conference.
>
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: Why doesn't the stub component throw exceptions in tests

Posted by Claus Ibsen <cl...@gmail.com>.
There is no bug on the seda consumer. He sends a InOnly message.
So the consumer can only "handle" the exception itself by logging it.

If he does a InOut then the producer template will wait for the reply
message, and because it failed with the exception, the reply message is the
exception.


On Fri, May 24, 2013 at 5:09 PM, Bilgin Ibryam <bi...@gmail.com> wrote:

> Hi,
>
> can you try to set the exception on the exchange instead of throwing it?
> If that's the case then I think there might a bug in SedaConsumer which
> propagates back exceptions on the exchange but doesn't propagate thrown
> exceptions.
>
> Bilgin
>
>
> On 24 May 2013 12:31, dancerjohn <wi...@gmail.com> wrote:
>
> >
> > I disagree... the javadoc for ProducerTemplate.sendBody() states "Notice:
> > that if the processing of the exchange failed with an Exception it is
> > thrown
> > from this method as a CamelExecutionException with the caused exception
> > wrapped.". So if an exception is thrown during processing sendBody should
> > throw a CamelExecutionException.
> >
> > The point I am making is that when the channel is a direct channel this
> > DOES
> > happen. However, everything else being the same if the channel is a stub
> > this DOES NOT happen. Therefore there is a difference in the components
> > between direct and stub in this regard. This seems surprising.
> >
> >
> >
> > --
> > View this message in context:
> >
> http://camel.465427.n5.nabble.com/Why-doesn-t-the-stub-component-throw-exceptions-in-tests-tp5733041p5733083.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Why doesn't the stub component throw exceptions in tests

Posted by Bilgin Ibryam <bi...@gmail.com>.
Hi,

can you try to set the exception on the exchange instead of throwing it?
If that's the case then I think there might a bug in SedaConsumer which
propagates back exceptions on the exchange but doesn't propagate thrown
exceptions.

Bilgin


On 24 May 2013 12:31, dancerjohn <wi...@gmail.com> wrote:

>
> I disagree... the javadoc for ProducerTemplate.sendBody() states "Notice:
> that if the processing of the exchange failed with an Exception it is
> thrown
> from this method as a CamelExecutionException with the caused exception
> wrapped.". So if an exception is thrown during processing sendBody should
> throw a CamelExecutionException.
>
> The point I am making is that when the channel is a direct channel this
> DOES
> happen. However, everything else being the same if the channel is a stub
> this DOES NOT happen. Therefore there is a difference in the components
> between direct and stub in this regard. This seems surprising.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Why-doesn-t-the-stub-component-throw-exceptions-in-tests-tp5733041p5733083.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Why doesn't the stub component throw exceptions in tests

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Study the EIPs and components again. And the difference between a direct
component vs a stub/seda (eg sync vs async) and the InOnly vs InOut.

And the send vs request methods on the producer template.

They all have an influence on what happens.


Also for testing purpose you may wanna take a look at
http://camel.apache.org/testing

For example about the notify builder




On Fri, May 24, 2013 at 1:31 PM, dancerjohn <wi...@gmail.com>wrote:

>
> I disagree... the javadoc for ProducerTemplate.sendBody() states "Notice:
> that if the processing of the exchange failed with an Exception it is
> thrown
> from this method as a CamelExecutionException with the caused exception
> wrapped.". So if an exception is thrown during processing sendBody should
> throw a CamelExecutionException.
>
> The point I am making is that when the channel is a direct channel this
> DOES
> happen. However, everything else being the same if the channel is a stub
> this DOES NOT happen. Therefore there is a difference in the components
> between direct and stub in this regard. This seems surprising.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Why-doesn-t-the-stub-component-throw-exceptions-in-tests-tp5733041p5733083.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Why doesn't the stub component throw exceptions in tests

Posted by dancerjohn <wi...@gmail.com>.
I disagree... the javadoc for ProducerTemplate.sendBody() states "Notice:
that if the processing of the exchange failed with an Exception it is thrown
from this method as a CamelExecutionException with the caused exception
wrapped.". So if an exception is thrown during processing sendBody should
throw a CamelExecutionException.

The point I am making is that when the channel is a direct channel this DOES
happen. However, everything else being the same if the channel is a stub
this DOES NOT happen. Therefore there is a difference in the components
between direct and stub in this regard. This seems surprising.



--
View this message in context: http://camel.465427.n5.nabble.com/Why-doesn-t-the-stub-component-throw-exceptions-in-tests-tp5733041p5733083.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Why doesn't the stub component throw exceptions in tests

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Read the javadoc API on the producer template and the methods you use,
eg sendBody vs requestBody.
eg its about InOnly vs InOut messaging style.

The eips
http://camel.apache.org/event-message.html
http://camel.apache.org/request-reply.html

On Thu, May 23, 2013 at 8:15 PM, dancerjohn <wi...@gmail.com> wrote:
> I am writing a test for my error handling. The route I am testing uses JMS
> and therefore has URL properties that are not compatible with the direct
> component. The way I have it set up is that I pass the following to the
> Route Builder ("jms:queue:myqueue") and then it adds the additional URL
> properties. In the test env I would like to be able to pass in something
> like "direct:jmsInputChan" but this fails due to the URL properties not
> working with direct.
>
> Then I found stub. I can pass in "stub:blahblah" and get the route set up
> and tested no problem. However, if I set a configuration to throw an
> exception in the route I don't get the exception out.
>
> Here is what I mean... I am using ProducerTemplate.sendBody to send in a
> message. If this channel is a "direct:xyz" and an exception is thrown the
> exception is logged by Camel and then thrown out of sendBody which means I
> can catch the exception in my test or have the test fail because of the
> exception.
>
> However, when the route starts with a stub and I cause the exception, Camel
> logs the exception but it is NOT thrown out of sendBody. This makes it hard
> to verify that the exception was not handled.
>
> It seems that stub should behave similar to direct in this regard.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Why-doesn-t-the-stub-component-throw-exceptions-in-tests-tp5733041.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen