camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: NotifyBuilder and MockEndpoint message count
Date Sat, 22 Jan 2011 08:43:45 GMT
On Fri, Jan 21, 2011 at 3:59 PM, David Tombs <cyan.spam@gmail.com> wrote:
> Hello all,
>
> While using the great testing utilities that camel provides, I have
> noticed that NotifyBuilder and MockEndpoint provide options for a
> minimum message received count (expectedMinimumMessageCount) and an
> exact message received count (expectedMessageCount). However, as far
> as I can tell from experience and glancing at the source code, the
> exact versions are not reliable because the object will only delay
> until the expected count is reached, then immedaitely return.
>
> For example, consider the following sequence:
> 1) [test-thread] mock.expectedMessageCount(1)
> 2) [test-thread] mock.assertIsSatisfied()
> 3) [msg-thread] message 1 comes in
> 4) [test-thread] mock.assertIsSatisfied() wakes up an returns
> 5) [msg-thread] message 2 comes in
>
> Of course, (4) and (5) can be in either order, so it's a race
> condition: assertIsSatisfied() can return true or false.
>

The mock endpoint works as expected. You indicate that you expect 1
message and the assertion triggers when this occurs.

If then a 2nd message arrives after the trigger, that's not something
you "out of the blue" can signal back to the unit test class.

What you are looking for is to say that I expect 1 message to arrive,
and there should not arrive a 2nd message thereafter within a period
of X time.

So we should maybe improve the mock endpoint to have the notion of
specifying such a time expectation?
Maybe a DSL in the likes of:

expectedMessageCount(1).noMessagesMustArriveAfter(1).second()

Obviously that will have Camel to wait for 1 sec to know whether or
not any other messages arrived after the expectation occurred.

There is a ticket in JIRA to improve this with the notion of
time/schedule so you can also say that I expect this message to arrive
within 2 seconds after this event occurred. Or I expect the messages
to arrive with at least 25 milli seconds apart. And so on.
https://issues.apache.org/jira/browse/CAMEL-2630

> Am I right about this? If so, is there any way to avoid the race condition?
>

You can always check the number of exchanges on a mock endpoint using its API

int size = mock.getExchanges().size();


> Thanks in advance,
> David
>
> --
> Wise men _still_ seek Him.
>



-- 
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/

Mime
View raw message