Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6B112798C for ; Thu, 11 Aug 2011 14:50:24 +0000 (UTC) Received: (qmail 25363 invoked by uid 500); 11 Aug 2011 14:50:24 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 25225 invoked by uid 500); 11 Aug 2011 14:50:23 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 25213 invoked by uid 99); 11 Aug 2011 14:50:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2011 14:50:23 +0000 X-ASF-Spam-Status: No, hits=0.6 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of claus.ibsen@gmail.com designates 209.85.213.45 as permitted sender) Received: from [209.85.213.45] (HELO mail-yw0-f45.google.com) (209.85.213.45) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2011 14:50:19 +0000 Received: by ywf9 with SMTP id 9so1578321ywf.32 for ; Thu, 11 Aug 2011 07:49:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=ZDzVJINeiK9Seg+GhPteVvc95OUIL5TRrJ+LCq1VGHI=; b=AhXQRh7l+L+Bzpzgdj0/bsUisYiechs7N+g8FM1W6xZZTJgQrS5n44nwUroaCOodsU s9Nh0EojqxzgV6UbGVWTiCvdHsydRwc63ThSRzGtum05pkmxzOaHbmBqKGtNtbtXKysf 2ev9/kmMUWxYDFkvoiItLasBpEWneq9xU00PA= Received: by 10.100.114.12 with SMTP id m12mr4383792anc.80.1313074198192; Thu, 11 Aug 2011 07:49:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.34.5 with HTTP; Thu, 11 Aug 2011 07:49:38 -0700 (PDT) In-Reply-To: <1313057245953-4689038.post@n5.nabble.com> References: <1313057245953-4689038.post@n5.nabble.com> From: Claus Ibsen Date: Thu, 11 Aug 2011 16:49:38 +0200 Message-ID: Subject: Re: NotifyBuilder condition fails to match on an out/activemq endpoint To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Thu, Aug 11, 2011 at 12:07 PM, jason.parr wrote: > Is it possible to get NotifyBuilder to wait on message arrival at various > out/edge jms endpoints within a test? Surely this is what you want to do > most of the time?, ie check your end conditions. > When you say out/edge you mean when X number of messages has been *send* to this endpoint? We should be able to track that by keeping an eye on the ExchangeSentEvent notifications http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/m= anagement/event/ExchangeSentEvent.html So if you could do something like this. To say that notify when 5 exchange is done, and all the exchanges, was send to the given endpoint. NotifyBuilder notify =3D whenDone(5).to("activemq:queue:foo").create(); > In all the NotifyBuilder examples I've seen the notify conditions are eit= her > very general or on components that are at the start or mid route. > > In the test shown (at the end of this email) the properties > {{url.radial-trades}} & {{url.dead-letter}} are expanded to vm/activemq > queues. > > The NotifyBuilder's condition never fires and always times out. Now I can > get this working by adding a very general condition and a sleep: > > =A0 =A0NotifyBuilder notify =3D new NotifyBuilder(context).whenDone(5).cr= eate(); > =A0 =A0boolean matches =3D notify.create().matches(10, TimeUnit.SECONDS); > =A0 =A0Thread.sleep(1000); > =A0 =A0// Now assert on browsable queues > > But having that sleep makes the test nondeterministic in my opinion - wha= t > happens if a full GC during test makes it run slower etc. I really dont l= ike > the sleep! > > I've tried all of whenDone, whenReceived, whenComplete etc but condition > never fires when expression is on an out endpoint url. > > As an aside I noticed that property expansion does not fail/exception wit= h > NotifyBuilder when it is given rubbish, eg: > > =A0NotifyBuilder notify =3D new NotifyBuilder(context) > =A0 =A0 =A0.from("{{this-does-not-exist}}").whenDone(1).create(); > > > Code of failing test due to timeout: > ------------------------------------------ > > /** > =A0* Test for {@link RadialRouteBuilder} > =A0*/ > public class RadialRouteBuilderTestCase extends CamelTestSupport { > > =A0private JndiRegistry registry; > > =A0@Test > =A0public void testCompleteRoute() throws Exception { > > =A0 =A0// Test has completed when all expected trades have hit external > endpoints > =A0 =A0NotifyBuilder notify =3D new NotifyBuilder(context) > =A0 =A0 =A0.from("{{url.radial-trades}}").whenDone(4) > =A0 =A0 =A0.from("{{url.dead-letter}}").whenDone(1).create(); > > =A0 =A0// Fail on timeout after 10 seconds > =A0 =A0boolean matches =3D notify.create().matches(10, TimeUnit.SECONDS); > =A0 =A0assertTrue("Expected four trade messages to be produced and one de= ad > letter message", matches); > > > =A0 =A0// Never get here > > =A0 =A0BrowsableEndpoint radialTradesEP =3D > context.getEndpoint("{{url.radial-trades}}", BrowsableEndpoint.class); > =A0 =A0assertEquals("Radial Trade Messages", 4, > radialTradesEP.getExchanges().size()); > > =A0 =A0BrowsableEndpoint deadLetterEP =3D > context.getEndpoint("{{url.dead-letter}}", BrowsableEndpoint.class); > =A0 =A0assertEquals("Dead Letter Messages", 1, > deadLetterEP.getExchanges().size()); > =A0} > > =A0@Override > =A0protected RouteBuilder createRouteBuilder() throws Exception { > =A0 =A0return new RadialRouteBuilder() { > =A0 =A0 =A0@Override > =A0 =A0 =A0public void configure() { > =A0 =A0 =A0 =A0super.configure(); > =A0 =A0 =A0 =A0//Play trades into route's jms queues via an embedded jms = broker > > from("file:src/test/data/radial-route-builder-test-case?noop=3Dtrue&inclu= de=3Dbond_msg.*") > =A0 =A0 =A0 =A0 =A0.to("{{url.tradebus-bond-trades}}"); > > from("file:src/test/data/radial-route-builder-test-case?noop=3Dtrue&inclu= de=3Dfuture_msg.*") > =A0 =A0 =A0 =A0 =A0.to("{{url.tradebus-future-trades}}"); > =A0 =A0 =A0} > =A0 =A0}; > =A0} > > =A0@Override > =A0protected CamelContext createCamelContext() throws Exception { > =A0 =A0CamelContext context =3D super.createCamelContext(); > > =A0 =A0//Configure active mq to use embedded broker > =A0 =A0context.addComponent("activemq", > activeMQComponent("vm://localhost?broker.persistent=3Dfalse")); > > =A0 =A0// Load test specific properties > =A0 =A0PropertiesComponent properties =3D > context.getComponent("properties",PropertiesComponent.class); > =A0 =A0properties.setLocations(new String[]{ > =A0 =A0 =A0"file:config/config-dev.properties", > =A0 =A0 =A0"file:src/test/config/config-test.properties"}); > > =A0 =A0// Setup spring beans > =A0 =A0RadialBondTradeEventProcessor bondTEP =3D new > RadialBondTradeEventProcessor(); > =A0 =A0bondTEP.setTradeCache(new BasicTradeCache()); > =A0 =A0registry.bind("bondTradeEventProcessor", bondTEP); > =A0 =A0RadialFutureTradeEventProcessor futureTEP =3D new > RadialFutureTradeEventProcessor(); > =A0 =A0futureTEP.setTradeCache(new BasicTradeCache()); > =A0 =A0registry.bind("futureTradeEventProcessor", futureTEP); > > =A0 =A0return context; > =A0} > > =A0@Override > =A0protected JndiRegistry createRegistry() throws Exception { > =A0 =A0// Store registry so can register spring beans later > =A0 =A0registry =3D super.createRegistry(); > =A0 =A0return registry; =A0 =A0//To change body of overridden methods use= File | > Settings | File Templates. > =A0} > } > > > > > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/NotifyBui= lder-condition-fails-to-match-on-an-out-activemq-endpoint-tp4689038p4689038= .html > Sent from the Camel - Users mailing list archive at Nabble.com. > --=20 Claus Ibsen ----------------- FuseSource Email: cibsen@fusesource.com Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/