camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Babak Vahdat <>
Subject Re: mock.expectedMessageCount(0) resulting in a false positive
Date Wed, 12 Dec 2012 15:08:42 GMT

Am 12.12.12 14:23 schrieb "" unter <>:

>I'm running an integration test using the CamelSpringJUnit4ClassRunner to
>test a route JMS -> Processor -> SFTP endpoint. In my test, I use a
>ProducerTemplate to fire a message to the JMS endpoint and mock the SFTP
>endpoint where I assert sftpMockEndpoint.setExpectedMessageCount(1). This
>all works fine.
>I've now written a test where I send an invalid message to the JMS queue.
>Normally this is caught by the processor which logs the message and stops
>any further processing. The SFTP endpoint should not receive a message in
>this case, so I've added:
>When I run this test and pass in a valid message (i.e. one that reaches
>SFTP endpoint), I'm still getting a positive result - the SFTP endpoint
>receives a message AND the setExpectedMessageCount(0) assertion passes.


If you don't want an explicit Thread.sleep() call inside your code then
you could make use of the MockEndpoint.setSleepForEmptyTest() API.


>I believe that because the JMS queue is asynchronous, the assertions are
>being fired before the message has passed along the route  - is this
>correct? E.g.:
>1. set mock expectation sftpMockEndpoint.expectedMessageCount(0);
>2. fire message to JMS queue. Starts an async process and return control
>test method
>3. test method runs sftpMockEndpoint.assertIsSatisfied(); which asserts
>the SFTP mock has received no messages. Assertion is correct.
>4. JMS messages continues to be processed and eventually makes it's way to
>the SFTP mock, which results in 1 message being received after the test
>assertions have been processed.
>Please could you confirm if this is the case and if there is anything I
>do to suspend processing of the assertions until the message has gone all
>the way through the route? I tried adding a
>sftpMockEndpoint.whenAnyExchangeReceived(new Processor() { // throw
>Exception }); to trigger a failure in the test whenever the SFTP mock
>received an Exchange but unfortunately the Exception gets swallowed up by
>the test framework.
>The only solution I have found is to add a Thread.sleep(100); before the
>test assertions (assertIsSatisfied) are processed, but this is ugly and I
>don't want arbitrary sleeps within my code.
>Any help would be greatly appreciated and apologies for the length of this
>post - I wanted to include as much information as possible but not post
>great swathes of unintelligible code.
>Thanks again,
>View this message in context:
>Sent from the Camel - Users mailing list archive at

View raw message