Author: bvahdat Date: Mon Jan 28 21:32:16 2013 New Revision: 1439646 URL: http://svn.apache.org/viewvc?rev=1439646&view=rev Log: Merged revisions 1439643 via svnmerge from https://svn.apache.org/repos/asf/camel/branches/camel-2.10.x
................ r1439643 | bvahdat | 2013-01-28 22:30:14 +0100 (Mo, 28 Jan 2013) | 9 lines Merged revisions 1439639 via svnmerge from https://svn.apache.org/repos/asf/camel/trunk ........ r1439639 | bvahdat | 2013-01-28 22:28:01 +0100 (Mo, 28 Jan 2013) | 1 line Fixed the broken test on the CI-Server. ........ ................ Modified: camel/branches/camel-2.9.x/ (props changed) camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateTimeoutTest.java Propchange: camel/branches/camel-2.9.x/ ------------------------------------------------------------------------------ Merged /camel/trunk:r1439639 Merged /camel/branches/camel-2.10.x:r1439643 Propchange: camel/branches/camel-2.9.x/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateTimeoutTest.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateTimeoutTest.java?rev=1439646&r1=1439645&r2=1439646&view=diff ============================================================================== --- camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateTimeoutTest.java (original) +++ camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateTimeoutTest.java Mon Jan 28 21:32:16 2013 @@ -16,7 +16,6 @@ */ package org.apache.camel.processor.aggregator; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.apache.camel.ContextTestSupport; @@ -26,11 +25,15 @@ import org.apache.camel.component.mock.M import org.apache.camel.processor.aggregate.TimeoutAwareAggregationStrategy; /** - * @version + * @version */ public class AggregateTimeoutTest extends ContextTestSupport { - private static final AtomicInteger INVOKED = new AtomicInteger(); + private final AtomicInteger INVOKED = new AtomicInteger(); + private volatile Exchange receivedExchange; + private volatile int receivedIndex; + private volatile int receivedTotal; + private volatile long receivedTimeout; public void testAggregateTimeout() throws Exception { MockEndpoint mock = getMockEndpoint("mock:aggregated"); @@ -39,7 +42,7 @@ public class AggregateTimeoutTest extend template.sendBodyAndHeader("direct:start", "A", "id", 123); template.sendBodyAndHeader("direct:start", "B", "id", 123); - // wait 3 seconds + // wait 3 seconds so that the timeout kicks in Thread.sleep(3000); mock.assertIsSatisfied(); @@ -47,18 +50,24 @@ public class AggregateTimeoutTest extend // should invoke the timeout method assertEquals(1, INVOKED.get()); - // now send 3 which does not timeout + assertNotNull(receivedExchange); + assertEquals("A+B", receivedExchange.getIn().getBody()); + assertEquals(-1, receivedIndex); + assertEquals(-1, receivedTotal); + assertEquals(2000, receivedTimeout); + mock.reset(); - mock.expectedBodiesReceived("C+D+E"); + mock.expectedBodiesReceived("A+B+C"); + // now send 3 exchanges which shouldn't trigger the timeout anymore template.sendBodyAndHeader("direct:start", "A", "id", 123); template.sendBodyAndHeader("direct:start", "B", "id", 123); template.sendBodyAndHeader("direct:start", "C", "id", 123); // should complete before timeout - mock.await(1500, TimeUnit.MILLISECONDS); + mock.assertIsSatisfied(1500); - // should not invoke the timeout method + // should have not invoked the timeout method anymore assertEquals(1, INVOKED.get()); } @@ -78,16 +87,18 @@ public class AggregateTimeoutTest extend }; } - private static class MyAggregationStrategy implements TimeoutAwareAggregationStrategy { + private class MyAggregationStrategy implements TimeoutAwareAggregationStrategy { public void timeout(Exchange oldExchange, int index, int total, long timeout) { INVOKED.incrementAndGet(); - assertEquals(2000, timeout); - assertEquals(-1, total); - assertEquals(-1, index); - assertNotNull(oldExchange); - assertEquals("AB", oldExchange.getIn().getBody()); + // we can't assert on the expected values here as the contract of this method doesn't + // allow to throw any Throwable here (including AssertionFailedError) so that we assert + // about the expected values directly inside the test method itself + receivedExchange = oldExchange; + receivedIndex = index; + receivedTotal = total; + receivedTimeout = timeout; } public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { @@ -96,7 +107,7 @@ public class AggregateTimeoutTest extend } String body = oldExchange.getIn().getBody(String.class); - oldExchange.getIn().setBody(body + newExchange.getIn().getBody(String.class)); + oldExchange.getIn().setBody(body + "+" + newExchange.getIn().getBody(String.class)); return oldExchange; } }
