You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by martin11 <ma...@gmail.com> on 2013/02/10 15:41:15 UTC

disable timer for unit tests

Hello,

I use Camel ver. 2.10.1 and in production context I use timers (cca 10sec.)
to create an event on route.

I also create unit tests (extended from CamelSpringTestSupport) for my
production context to make tests on individual routes.
When I run my tests, timers expires and start new route. Because it is only
test, than I don`t have a connection to external endpoints (database, LDAP,
etc..) and it cause exceptions in log file. Of course it does not affect
result of my test, but logs are unobvious.

How can I disable timers inside production context when running unit tests?

Thanks for any advice!




--
View this message in context: http://camel.465427.n5.nabble.com/disable-timer-for-unit-tests-tp5727302.html
Sent from the Camel - Users mailing list archive at Nabble.com.

AW: disable timer for unit tests

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
One possibility is having a flag:

createRouteBuilder() {
   from(...).to(...); // standard routes
   if (inProduction) {
       from("timer:...").to(...);
   }
}

Or specify the timer in a special class which you dont start via Spring.

Not sure if the ControlBus could help (is just a pattern which comes to my
mind...)


Jan

-----Ursprüngliche Nachricht-----
Von: martin11 [mailto:mato.krajcir@gmail.com] 
Gesendet: Sonntag, 10. Februar 2013 15:41
An: users@camel.apache.org
Betreff: disable timer for unit tests

Hello,

I use Camel ver. 2.10.1 and in production context I use timers (cca 10sec.)
to create an event on route.

I also create unit tests (extended from CamelSpringTestSupport) for my
production context to make tests on individual routes.
When I run my tests, timers expires and start new route. Because it is only
test, than I don`t have a connection to external endpoints (database, LDAP,
etc..) and it cause exceptions in log file. Of course it does not affect
result of my test, but logs are unobvious.

How can I disable timers inside production context when running unit tests?

Thanks for any advice!




--
View this message in context:
http://camel.465427.n5.nabble.com/disable-timer-for-unit-tests-tp5727302.htm
l
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: disable timer for unit tests

Posted by martin11 <ma...@gmail.com>.
Thanks for good hints.

I did only two steps configuration it works fine ;-)
1. stop all timer routes in init method
2. and by adviceWith I replaced the FROM of affected routes

@Before
public void init() throws Exception {
    context.stopRoute("myRouteId");
    RouteDefinition route = context.getRouteDefinition("myRouteId");
    route.adviceWith(context, new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            replaceFromWith("direct:myRouteId");
        }
    });
}




--
View this message in context: http://camel.465427.n5.nabble.com/disable-timer-for-unit-tests-tp5727302p5727353.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: disable timer for unit tests

Posted by Claus Ibsen <cl...@gmail.com>.
On Sun, Feb 10, 2013 at 4:32 PM, Raul Kripalani <ra...@evosent.com> wrote:
> Hi,
>
> Identify the timer-based route with an explicit routeId:
>
> from("timer:...").routeId("timed-route")...
>
> And then stop it explicitly from your test code:
>
> context.stopRoute("timed-route");
>
> Alternatively, you could disable autostart for that route altogether, but
> then you have to start it manually for production usage.
>
> Or use a system property to control the behaviour per environment. See
> http://camel.apache.org/configuring-route-startup-ordering-and-autostartup.html.
>

Or use advice with
http://camel.apache.org/advicewith.html

And either remove the route, intercept from it and stop etc, or
replace the timer with another endpoint etc.
http://camel.apache.org/intercept


>
> Hope that helps,
> Raúl.
> On 10 Feb 2013 14:41, "martin11" <ma...@gmail.com> wrote:
>
> Hello,
>
> I use Camel ver. 2.10.1 and in production context I use timers (cca 10sec.)
> to create an event on route.
>
> I also create unit tests (extended from CamelSpringTestSupport) for my
> production context to make tests on individual routes.
> When I run my tests, timers expires and start new route. Because it is only
> test, than I don`t have a connection to external endpoints (database, LDAP,
> etc..) and it cause exceptions in log file. Of course it does not affect
> result of my test, but logs are unobvious.
>
> How can I disable timers inside production context when running unit tests?
>
> Thanks for any advice!
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/disable-timer-for-unit-tests-tp5727302.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
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: disable timer for unit tests

Posted by Raul Kripalani <ra...@evosent.com>.
Hi,

Identify the timer-based route with an explicit routeId:

from("timer:...").routeId("timed-route")...

And then stop it explicitly from your test code:

context.stopRoute("timed-route");

Alternatively, you could disable autostart for that route altogether, but
then you have to start it manually for production usage.

Or use a system property to control the behaviour per environment. See
http://camel.apache.org/configuring-route-startup-ordering-and-autostartup.html.


Hope that helps,
Raúl.
On 10 Feb 2013 14:41, "martin11" <ma...@gmail.com> wrote:

Hello,

I use Camel ver. 2.10.1 and in production context I use timers (cca 10sec.)
to create an event on route.

I also create unit tests (extended from CamelSpringTestSupport) for my
production context to make tests on individual routes.
When I run my tests, timers expires and start new route. Because it is only
test, than I don`t have a connection to external endpoints (database, LDAP,
etc..) and it cause exceptions in log file. Of course it does not affect
result of my test, but logs are unobvious.

How can I disable timers inside production context when running unit tests?

Thanks for any advice!




--
View this message in context:
http://camel.465427.n5.nabble.com/disable-timer-for-unit-tests-tp5727302.html
Sent from the Camel - Users mailing list archive at Nabble.com.