Index: components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortTest.java =================================================================== --- components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortTest.java (revision 15875) +++ components/camel-rss/src/test/java/org/apache/camel/component/rss/RssEntrySortTest.java (working copy) @@ -38,6 +38,7 @@ MockEndpoint mock = getMockEndpoint("mock:sorted"); mock.expectsAscending(ExpressionBuilder.beanExpression("myBean", "getPubDate")); mock.expectedMessageCount(10); + mock.setResultWaitTime(15000L); mock.assertIsSatisfied(); } Index: components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntrySortTest.java =================================================================== --- components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntrySortTest.java (revision 15875) +++ components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntrySortTest.java (working copy) @@ -39,6 +39,7 @@ MockEndpoint mock = getMockEndpoint("mock:sorted"); mock.expectsAscending(ExpressionBuilder.beanExpression("myBean", "getPubDate")); mock.expectedMessageCount(10); + mock.setResultWaitTime(15000L); mock.assertIsSatisfied(); } Index: camel-core/src/test/java/org/apache/camel/processor/ConvertBodyTest.java =================================================================== --- camel-core/src/test/java/org/apache/camel/processor/ConvertBodyTest.java (revision 15875) +++ camel-core/src/test/java/org/apache/camel/processor/ConvertBodyTest.java (working copy) @@ -88,7 +88,7 @@ public void testConvertToStringCharsetFail() throws Exception { - String body = "Hellö Wörld"; + String body = "Hell\u00F6 W\u00F6rld"; MockEndpoint result = getMockEndpoint("mock:result"); Index: camel-core/src/test/java/org/apache/camel/builder/ValueBuilderTest.java =================================================================== --- camel-core/src/test/java/org/apache/camel/builder/ValueBuilderTest.java (revision 15875) +++ camel-core/src/test/java/org/apache/camel/builder/ValueBuilderTest.java (working copy) @@ -88,6 +88,13 @@ // send in a false test mock.reset(); + mock.message(0).body().matches(new Expression() { + public T evaluate(Exchange exchange, Class type) { + String body = exchange.getIn().getBody(String.class); + Boolean answer = body.contains("Camel"); + return type.cast(answer); + } + }); template.sendBody("direct:start", "Hello World"); mock.assertIsNotSatisfied(); } Index: camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java =================================================================== --- camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java (revision 15875) +++ camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java (working copy) @@ -37,6 +37,9 @@ public void testConsumeFileOnly() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); + // Default wait time of 10 sec is not quite long enough on slow + // machines. + mock.setResultWaitTime(15000L); mock.expectedBodiesReceivedInAnyOrder("Hello World", "Bye World"); assertMockEndpointsSatisfied(); Index: camel-core/src/test/java/org/apache/camel/component/timer/TimerWithTimeOptionTest.java =================================================================== --- camel-core/src/test/java/org/apache/camel/component/timer/TimerWithTimeOptionTest.java (revision 15875) +++ camel-core/src/test/java/org/apache/camel/component/timer/TimerWithTimeOptionTest.java (working copy) @@ -75,7 +75,7 @@ assertMockEndpointsSatisfied(); } - public void testFiredInFutureWithTPatternFixedReat() throws Exception { + public void testFiredInFutureWithTPatternFixedRate() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { Index: camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java =================================================================== --- camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java (revision 15875) +++ camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java (working copy) @@ -109,7 +109,7 @@ MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); resultEndpoint.expectedMessageCount(5); - resultEndpoint.assertIsNotSatisfied(); + resultEndpoint.assertIsSatisfied(); } public void testExpectationsAfterMessagesArriveFail() throws Exception { @@ -176,8 +176,6 @@ resultEndpoint.expectedHeaderReceived("number", 123); sendHeader("number", 123); resultEndpoint.assertIsSatisfied(); - - resultEndpoint.assertIsNotSatisfied(); } public void testExpressionExpectationOfHeader() throws InterruptedException { Index: camel-core/src/test/java/org/apache/camel/management/ManagedThrottlerTest.java =================================================================== --- camel-core/src/test/java/org/apache/camel/management/ManagedThrottlerTest.java (revision 15875) +++ camel-core/src/test/java/org/apache/camel/management/ManagedThrottlerTest.java (working copy) @@ -42,7 +42,11 @@ public void testManageThrottler() throws Exception { getMockEndpoint("mock:result").expectedMessageCount(10); - // send in 10 messages + // Send in a first batch of 10 messages and check that the endpoint + // gets them. We'll check the total time of the second and third + // batches as it seems that there is some time required to prime + // things, which can vary significantly... particularly on slower + // machines. for (int i = 0; i < 10; i++) { template.sendBody("direct:start", "Message " + i); } @@ -57,16 +61,24 @@ // use route to get the total time ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=routes,name=\"route1\""); + + // reset the counters + mbeanServer.invoke(routeName, "reset", null, null); + + // send in 10 messages + for (int i = 0; i < 10; i++) { + template.sendBody("direct:start", "Message " + i); + } + Long completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted"); assertEquals(10, completed.longValue()); Long timePeriod = (Long) mbeanServer.getAttribute(throttlerName, "TimePeriodMillis"); assertEquals(1000, timePeriod.longValue()); - Long last = (Long) mbeanServer.getAttribute(routeName, "LastProcessingTime"); Long total = (Long) mbeanServer.getAttribute(routeName, "TotalProcessingTime"); - assertTrue("Should take at most 2.5 sec: was " + total, total < 2500); + assertTrue("Should take at most 1.5 sec: was " + total, total < 1500); // change the throttler using JMX mbeanServer.setAttribute(throttlerName, new Attribute("MaximumRequestsPerPeriod", (long) 2)); Index: camel-core/src/test/java/org/apache/camel/management/ManagedTimerTest.java =================================================================== --- camel-core/src/test/java/org/apache/camel/management/ManagedTimerTest.java (revision 15875) +++ camel-core/src/test/java/org/apache/camel/management/ManagedTimerTest.java (working copy) @@ -67,6 +67,12 @@ mbeanServer.invoke(on, "stop", null, null); mbeanServer.invoke(on, "start", null, null); + // Take the time to check the service is started to help avoid + // sporadic failure on slower machines. + String state = (String) mbeanServer.getAttribute(on, "State"); + assertEquals("Should be started", + org.apache.camel.ServiceStatus.Started.name(), state); + // start and we should be done in at most 3 second mock.expectedMinimumMessageCount(3); mock.setResultWaitTime(3900); Index: camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java =================================================================== --- camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java (revision 15875) +++ camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java (working copy) @@ -253,12 +253,18 @@ * Validates that the assertions fail on this endpoint */ public void assertIsNotSatisfied() throws InterruptedException { + boolean failed = false; try { assertIsSatisfied(); - fail("Expected assertion failure!"); + // did not throw expected error... fail! + failed = true; } catch (AssertionError e) { LOG.info("Caught expected failure: " + e); } + if (failed) { + // fail() throws the AssertionError to indicate the test failed. + fail("Expected assertion failure but test succeeded!"); + } } /** @@ -268,12 +274,18 @@ * should wait for the test to be true */ public void assertIsNotSatisfied(long timeoutForEmptyEndpoints) throws InterruptedException { + boolean failed = false; try { assertIsSatisfied(timeoutForEmptyEndpoints); - fail("Expected assertion failure!"); + // did not throw expected error... fail! + failed = true; } catch (AssertionError e) { LOG.info("Caught expected failure: " + e); } + if (failed) { + // fail() throws the AssertionError to indicate the test failed. + fail("Expected assertion failure but test succeeded!"); + } } /**