On Thu, Aug 11, 2011 at 12:07 PM, jason.parr <jason.p...@usa.net> 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/management/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 = whenDone(5).to("activemq:queue:foo").create();



> In all the NotifyBuilder examples I've seen the notify conditions are either
> 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:
>
>    NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
>    boolean matches = notify.create().matches(10, TimeUnit.SECONDS);
>    Thread.sleep(1000);
>    // Now assert on browsable queues
>
> But having that sleep makes the test nondeterministic in my opinion - what
> happens if a full GC during test makes it run slower etc. I really dont like
> 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 with
> NotifyBuilder when it is given rubbish, eg:
>
>  NotifyBuilder notify = new NotifyBuilder(context)
>      .from("{{this-does-not-exist}}").whenDone(1).create();
>
>
> Code of failing test due to timeout:
> ------------------------------------------
>
> /**
>  * Test for {@link RadialRouteBuilder}
>  */
> public class RadialRouteBuilderTestCase extends CamelTestSupport {
>
>  private JndiRegistry registry;
>
>  @Test
>  public void testCompleteRoute() throws Exception {
>
>    // Test has completed when all expected trades have hit external
> endpoints
>    NotifyBuilder notify = new NotifyBuilder(context)
>      .from("{{url.radial-trades}}").whenDone(4)
>      .from("{{url.dead-letter}}").whenDone(1).create();
>
>    // Fail on timeout after 10 seconds
>    boolean matches = notify.create().matches(10, TimeUnit.SECONDS);
>    assertTrue("Expected four trade messages to be produced and one dead
> letter message", matches);
>
>
>    // Never get here
>
>    BrowsableEndpoint radialTradesEP =
> context.getEndpoint("{{url.radial-trades}}", BrowsableEndpoint.class);
>    assertEquals("Radial Trade Messages", 4,
> radialTradesEP.getExchanges().size());
>
>    BrowsableEndpoint deadLetterEP =
> context.getEndpoint("{{url.dead-letter}}", BrowsableEndpoint.class);
>    assertEquals("Dead Letter Messages", 1,
> deadLetterEP.getExchanges().size());
>  }
>
>  @Override
>  protected RouteBuilder createRouteBuilder() throws Exception {
>    return new RadialRouteBuilder() {
>      @Override
>      public void configure() {
>        super.configure();
>        //Play trades into route's jms queues via an embedded jms broker
>
> from("file:src/test/data/radial-route-builder-test-case?noop=true&include=bond_msg.*")
>          .to("{{url.tradebus-bond-trades}}");
>
> from("file:src/test/data/radial-route-builder-test-case?noop=true&include=future_msg.*")
>          .to("{{url.tradebus-future-trades}}");
>      }
>    };
>  }
>
>  @Override
>  protected CamelContext createCamelContext() throws Exception {
>    CamelContext context = super.createCamelContext();
>
>    //Configure active mq to use embedded broker
>    context.addComponent("activemq",
> activeMQComponent("vm://localhost?broker.persistent=false"));
>
>    // Load test specific properties
>    PropertiesComponent properties =
> context.getComponent("properties",PropertiesComponent.class);
>    properties.setLocations(new String[]{
>      "file:config/config-dev.properties",
>      "file:src/test/config/config-test.properties"});
>
>    // Setup spring beans
>    RadialBondTradeEventProcessor bondTEP = new
> RadialBondTradeEventProcessor();
>    bondTEP.setTradeCache(new BasicTradeCache<BondTrade>());
>    registry.bind("bondTradeEventProcessor", bondTEP);
>    RadialFutureTradeEventProcessor futureTEP = new
> RadialFutureTradeEventProcessor();
>    futureTEP.setTradeCache(new BasicTradeCache<FutureTrade>());
>    registry.bind("futureTradeEventProcessor", futureTEP);
>
>    return context;
>  }
>
>  @Override
>  protected JndiRegistry createRegistry() throws Exception {
>    // Store registry so can register spring beans later
>    registry = super.createRegistry();
>    return registry;    //To change body of overridden methods use File |
> Settings | File Templates.
>  }
> }
>
>
>
>
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/NotifyBuilder-condition-fails-to-match-on-an-out-activemq-endpoint-tp4689038p4689038.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



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

Reply via email to