errorHandler when stopping routes in test

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

errorHandler when stopping routes in test

John
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
Reply | Threaded
Open this post in threaded view
|

Re: errorHandler when stopping routes in test

Ashwin Karpe
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
Red Hat
http://www.redhat.com

Blog:http://opensourceknowledge.blogspot.com
---------------------------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: errorHandler when stopping routes in test

John
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();
    }

Reply | Threaded
Open this post in threaded view
|

Re: errorHandler when stopping routes in test

Claus Ibsen-2
In reply to this post by John
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 <[hidden email]> 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: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Reply | Threaded
Open this post in threaded view
|

Re: errorHandler when stopping routes in test

Willem.Jiang
Administrator
In reply to this post by John
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
Reply | Threaded
Open this post in threaded view
|

Re: errorHandler when stopping routes in test

John
I created the issue:

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

Thanks,

-john