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 B4002DCBB for ; Thu, 13 Dec 2012 16:32:23 +0000 (UTC) Received: (qmail 92598 invoked by uid 500); 13 Dec 2012 16:32:23 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 92436 invoked by uid 500); 13 Dec 2012 16:32: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 92421 invoked by uid 99); 13 Dec 2012 16:32:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Dec 2012 16:32:22 +0000 X-ASF-Spam-Status: No, hits=2.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [62.179.121.48] (HELO fep28.mx.upcmail.net) (62.179.121.48) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Dec 2012 16:32:16 +0000 Received: from edge01.upcmail.net ([192.168.13.236]) by viefep28-int.chello.at (InterMail vM.8.01.05.05 201-2260-151-110-20120111) with ESMTP id <20121213163151.WLRP29590.viefep28-int.chello.at@edge01.upcmail.net> for ; Thu, 13 Dec 2012 17:31:51 +0100 Received: from [10.0.0.6] ([46.126.159.149]) by edge01.upcmail.net with edge id b4Xj1k01V3DhZoW014XqsJ; Thu, 13 Dec 2012 17:31:51 +0100 X-SourceIP: 46.126.159.149 X-Authenticated-Sender: babak.vahdat@swissonline.ch User-Agent: Microsoft-MacOutlook/14.14.0.111121 Date: Thu, 13 Dec 2012 17:31:41 +0100 Subject: Re: mock.expectedMessageCount(0) resulting in a false positive From: Babak Vahdat To: Message-ID: Thread-Topic: mock.expectedMessageCount(0) resulting in a false positive In-Reply-To: <1355403106152-5724031.post@n5.nabble.com> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Am 13.12.12 13:51 schrieb "camel.user2.ch" unter : >Hi Babak, > >Thanks a lot for your reply, it confirms what I suspected from looking >through the source. I can see that when you setExpectedMessageCount(0), >there is no countdown latch, resulting in the mock being asserted on >pretty >much straight away. That's correct. > >I don't really like the MockEndpoint.setSleepForEmptyTest() idea as it's >pretty much analogous to sticking an arbitrary Thread.sleep() into the >code. This is just a matter of personal taste. > >The NotifyBuilder example seems to work a lot nicer however, thanks a lot >for your suggestion. I now have: > > // wait for the message to pass through the route before running >the >assertions. > // JMS msgs are processed asynchronously creating a race condition >for the test. > NotifyBuilder notify = new >NotifyBuilder(context).whenDone(1).create(); > notify.matches(500, TimeUnit.MILLISECONDS); > > sftpMockEndpoint.assertIsSatisfied(); > >And this is working as expected. > >I'm a little surprised that there is not much mention of this potential >race >condition when using the Camel testing framework - neither within the >online >documentation nor within the Camel in Action book. It seems to be a pretty >big omission within what is otherwise an excellent and well documented >framework. Check the page 295 with an example where it says: QUOTE_BEGIN "Then you sleep a bit to let the routing complete." QUOTE_END In general count with this whenever you make use of a polling consumer: http://camel.apache.org/polling-consumer.html Also another way of doing this is the usage of a java.util.concurrent.CountDownLatch through which you can make sure that you do assert on something *after* some conditions have been already fulfilled for sure. If you look at the Camel's own unit tests you will find pretty much of this pattern as well. Greetings from the domain "ch" as well... :-) Babak > >Thanks for your help. >John > > > >-- >View this message in context: >http://camel.465427.n5.nabble.com/mock-expectedMessageCount-0-resulting-in >-a-false-positive-tp5723952p5724031.html >Sent from the Camel - Users mailing list archive at Nabble.com.