You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by John <Jo...@ateb.com> on 2011/01/10 16:54:49 UTC

errorHandler when stopping routes in test

Hi,

I'm running 2.6-SNAPSHOT.

I have a route builder that sets up a number of routes. One of the routes is
a timer route.

For my unit tests, I would like to stop the timer route so that it doesn't
fire. Unfortunately when I stop the timer route, it appears to impact the
overall error handler.

An example of my route builder is:

            public void configure() throws Exception {
                errorHandler(deadLetterChannel("direct:emailSupport")
                    .maximumRedeliveries(2)
                    .redeliveryDelay(0));

                from("direct:emailSupport")
                    .routeId("smtpRoute")
                    .errorHandler(deadLetterChannel("log:dead?level=ERROR"))
                    .to("smtp://smtpServer");

               
from("timer://someTimer?delay=15000&fixedRate=true&period=5000")
                    .routeId("pollRoute")
                    .to("log:level=INFO");

                from("direct:start")
                    .routeId("TestRoute")
                    .to("seda:foo");
            }
        };

I am attempting to test the "TestRoute" and the error handler. In the test
itself, I intercept and throw an exception on the seda end point. I also
intercept the smtp endpoint with a mock. 

I expect the exceptions thrown on the seda endpoint to go through the error
handler and eventually hit the smtp endpoint when the retries are exhausted.

If I stop the "pollRoute" before running my test, I get an error:
    java.lang.IllegalStateException: SendProcessor has not been started:
sendTo(Endpoint[direct://emailSupport] InOnly)

Everything works as expected if I leave the timer route running.

If you have any ideas on what may be going on here, I'd appreciate it!

Thanks,

-john
-- 
View this message in context: http://camel.465427.n5.nabble.com/errorHandler-when-stopping-routes-in-test-tp3335015p3335015.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: errorHandler when stopping routes in test

Posted by Claus Ibsen <cl...@gmail.com>.
We'll revist this in Camel 3.0 where applying interceptors/error
handlers and the likes is more flexible and applied dynamic at
runtime.

The issue is the stop route causes side effect on the other adviced routes.

On Mon, Jan 10, 2011 at 4:54 PM, John <Jo...@ateb.com> wrote:
>
> Hi,
>
> I'm running 2.6-SNAPSHOT.
>
> I have a route builder that sets up a number of routes. One of the routes is
> a timer route.
>
> For my unit tests, I would like to stop the timer route so that it doesn't
> fire. Unfortunately when I stop the timer route, it appears to impact the
> overall error handler.
>
> An example of my route builder is:
>
>            public void configure() throws Exception {
>                errorHandler(deadLetterChannel("direct:emailSupport")
>                    .maximumRedeliveries(2)
>                    .redeliveryDelay(0));
>
>                from("direct:emailSupport")
>                    .routeId("smtpRoute")
>                    .errorHandler(deadLetterChannel("log:dead?level=ERROR"))
>                    .to("smtp://smtpServer");
>
>
> from("timer://someTimer?delay=15000&fixedRate=true&period=5000")
>                    .routeId("pollRoute")
>                    .to("log:level=INFO");
>
>                from("direct:start")
>                    .routeId("TestRoute")
>                    .to("seda:foo");
>            }
>        };
>
> I am attempting to test the "TestRoute" and the error handler. In the test
> itself, I intercept and throw an exception on the seda end point. I also
> intercept the smtp endpoint with a mock.
>
> I expect the exceptions thrown on the seda endpoint to go through the error
> handler and eventually hit the smtp endpoint when the retries are exhausted.
>
> If I stop the "pollRoute" before running my test, I get an error:
>    java.lang.IllegalStateException: SendProcessor has not been started:
> sendTo(Endpoint[direct://emailSupport] InOnly)
>
> Everything works as expected if I leave the timer route running.
>
> If you have any ideas on what may be going on here, I'd appreciate it!
>
> Thanks,
>
> -john
> --
> View this message in context: http://camel.465427.n5.nabble.com/errorHandler-when-stopping-routes-in-test-tp3335015p3335015.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: errorHandler when stopping routes in test

Posted by John <Jo...@ateb.com>.
I created the issue:

https://issues.apache.org/jira/browse/CAMEL-3534

Thanks,

-john
-- 
View this message in context: http://camel.465427.n5.nabble.com/errorHandler-when-stopping-routes-in-test-tp3335015p3338415.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: errorHandler when stopping routes in test

Posted by Willem Jiang <wi...@gmail.com>.
Hi John,

Please feel free to create a JIRA here[1] so we can trace it.

[1]https://issues.apache.org/jira/browse/CAMEL

Willem
On 1/11/11 9:16 PM, John wrote:
>
> I'm running the test via junit4. My test class extends CamelTestSupport.
>
> Below is the test itself, if that helps.
>
> Thanks!
>
> -john
>
>      @Test
>      public void testIssue() throws Exception {
>
>          RouteDefinition testRoute = context.getRouteDefinition("TestRoute");
>          testRoute.adviceWith(context, new RouteBuilder() {
>              @Override
>              public void configure() throws Exception {
>                  interceptSendToEndpoint("seda:*")
>                  .skipSendToOriginalEndpoint()
>                  .process(new Processor() {
>                      public void process(Exchange exchange) throws Exception
> {
>                          throw new Exception("Forced");
>                      }
>                  });
>              }
>          });
>
>          RouteDefinition smtpRoute = context.getRouteDefinition("smtpRoute");
>          smtpRoute.adviceWith(context, new RouteBuilder() {
>              @Override
>              public void configure() throws Exception
>              {
>                  interceptSendToEndpoint("smtp*")
>                      .skipSendToOriginalEndpoint()
>                      .to("mock:smtp");
>              }
>          });
>
>          getMockEndpoint("mock:smtp").expectedMessageCount(1);
>
>          RouteDefinition pollRoute = context.getRouteDefinition("pollRoute");
>          context.stopRoute(pollRoute.getId());
>
>          template.sendBody("direct:start", "Hello World");
>
>          assertMockEndpointsSatisfied();
>      }
>
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Re: errorHandler when stopping routes in test

Posted by John <Jo...@ateb.com>.
I'm running the test via junit4. My test class extends CamelTestSupport.

Below is the test itself, if that helps.

Thanks!

-john

    @Test
    public void testIssue() throws Exception {

        RouteDefinition testRoute = context.getRouteDefinition("TestRoute");
        testRoute.adviceWith(context, new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                interceptSendToEndpoint("seda:*")
                .skipSendToOriginalEndpoint()
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception
{
                        throw new Exception("Forced");
                    }
                });
            }
        });

        RouteDefinition smtpRoute = context.getRouteDefinition("smtpRoute");
        smtpRoute.adviceWith(context, new RouteBuilder() {
            @Override
            public void configure() throws Exception
            {
                interceptSendToEndpoint("smtp*")
                    .skipSendToOriginalEndpoint()
                    .to("mock:smtp");
            }
        });

        getMockEndpoint("mock:smtp").expectedMessageCount(1);

        RouteDefinition pollRoute = context.getRouteDefinition("pollRoute");
        context.stopRoute(pollRoute.getId());

        template.sendBody("direct:start", "Hello World");

        assertMockEndpointsSatisfied();
    }


-- 
View this message in context: http://camel.465427.n5.nabble.com/errorHandler-when-stopping-routes-in-test-tp3335015p3336443.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: errorHandler when stopping routes in test

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hmm, this is certainly odd... I will need to do a bit of digging around on
this...

BTW, How do you run this... (mainline Java, Spring/JUnit, some other
Container etc)...

Please let me know.

Cheers,

Ashwin...

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com
http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
-- 
View this message in context: http://camel.465427.n5.nabble.com/errorHandler-when-stopping-routes-in-test-tp3335015p3335739.html
Sent from the Camel - Users mailing list archive at Nabble.com.