camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james.strac...@gmail.com>
Subject Re: MockEndpoint - sleep for empty tests is flawed?
Date Mon, 22 Dec 2008 12:28:34 GMT
Looks much neater :) Sorry for writing such crappy code in the first place :)

2008/12/18 Claus Ibsen <claus.ibsen@gmail.com>:
> I created a ticket for it
> https://issues.apache.org/activemq/browse/CAMEL-1196
>
> And attached a better patch. Runs fine now. all core tests passes.
>
> On Thu, Dec 18, 2008 at 6:46 AM, Claus Ibsen <claus.ibsen@gmail.com> wrote:
>> Hi
>>
>> Is there a flaw in MockEndpoint with sleep for empty tests?
>> For instance if I have this code I would expect it to wait 10 sec
>> before stopping, but it doesn't.
>>
>>    public void testManually() throws Exception {
>>        deleteDirectory("./target/exclusiveread");
>>        MockEndpoint mock = getMockEndpoint("mock:result");
>>        mock.setSleepForEmptyTest(10000);
>>        mock.expectedMessageCount(0);
>>
>>        mock.assertIsSatisfied();
>>    }
>>
>>
>> Fixing the code in MockEndpoint to this seems to fix it, and it's a
>> bit more readable, what it does
>>
>>
>>
>>
>>    public void assertIsSatisfied(long timeoutForEmptyEndpoints)
>> throws InterruptedException {
>>        LOG.info("Asserting: " + this + " is satisfied");
>>        if (expectedCount == 0) {
>>            if (timeoutForEmptyEndpoints > 0) {
>>                LOG.debug("Sleeping for: " + timeoutForEmptyEndpoints
>> + " millis to check there really are no messages received");
>>                Thread.sleep(timeoutForEmptyEndpoints);
>>            } else {
>>                waitForCompleteLatch();
>>            }
>>            assertEquals("Received message count", expectedCount,
>> getReceivedCounter());
>>        } else if (expectedCount > 0) {
>>            if (expectedCount != getReceivedCounter()) {
>>                waitForCompleteLatch();
>>            }
>>            assertEquals("Received message count", expectedCount,
>> getReceivedCounter());
>>        } else if (expectedMinimumCount > 0 && getReceivedCounter() <
>> expectedMinimumCount) {
>>            waitForCompleteLatch();
>>        }
>>
>>
>> Feedback from other riders is welcome ;)
>>
>> --
>>
>> /Claus Ibsen
>> Apache Camel Committer
>> Blog: http://davsclaus.blogspot.com/
>>
>
>
>
> --
>
> /Claus Ibsen
> Apache Camel Committer
> Blog: http://davsclaus.blogspot.com/
>



-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

Mime
View raw message