Author: bvahdat
Date: Wed Oct 3 05:07:05 2012
New Revision: 1393291
URL: http://svn.apache.org/viewvc?rev=1393291&view=rev
Log:
Fixed the test failure with NPE on the CI-Server. The usage of static variables
was the cause of this in case the second test method would be run as the first
one in which case both beforeThreadName & afterThreadName would be null. Also
afterThreadName should be correctly volatile as we set it's value async but
read it inside the main thread.
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadsCorePoolTest.java
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadsCorePoolTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadsCorePoolTest.java?rev=1393291&r1=1393290&r2=1393291&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadsCorePoolTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadsCorePoolTest.java
Wed Oct 3 05:07:05 2012
@@ -26,8 +26,8 @@ import org.apache.camel.builder.RouteBui
*/
public class ThreadsCorePoolTest extends ContextTestSupport {
- private static String beforeThreadName;
- private static String afterThreadName;
+ private String beforeThreadName;
+ private volatile String afterThreadName;
public void testThreadsCorePool() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(1);
@@ -36,6 +36,8 @@ public class ThreadsCorePoolTest extends
assertMockEndpointsSatisfied();
+ assertNotNull("The main thread name should be already properly set!",
beforeThreadName);
+ assertNotNull("The camel thread name should be already properly set!",
afterThreadName);
assertFalse("Should use different threads",
beforeThreadName.equalsIgnoreCase(afterThreadName));
}
@@ -46,6 +48,8 @@ public class ThreadsCorePoolTest extends
assertMockEndpointsSatisfied();
+ assertNotNull("The main thread name should be already properly set!",
beforeThreadName);
+ assertNotNull("The camel thread name should be already properly set!",
afterThreadName);
assertFalse("Should use different threads",
beforeThreadName.equalsIgnoreCase(afterThreadName));
}
@@ -74,8 +78,18 @@ public class ThreadsCorePoolTest extends
.to("mock:result");
from("direct:foo")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ beforeThreadName =
Thread.currentThread().getName();
+ }
+ })
// using the builder style
.threads().poolSize(5)
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ afterThreadName = Thread.currentThread().getName();
+ }
+ })
.to("mock:result");
}
};