camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen" <claus.ib...@gmail.com>
Subject Re: MockEndpoint - sleep for empty tests is flawed?
Date Thu, 18 Dec 2008 06:14:09 GMT
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/

Mime
View raw message