Skip to content
Browse files

SM-2166: Intermittent test failure in LogThrowableInExecutorTest

git-svn-id: https://svn.apache.org/repos/asf/servicemix/utils/trunk@1412555 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 3f7c453 commit 36b3a05a5a52da9e60cdbb7cf01d6513f422678f @gertv gertv committed Nov 22, 2012
Showing with 9 additions and 10 deletions.
  1. +9 −10 src/test/java/org/apache/servicemix/executors/impl/LogThrowableInExecutorTest.java
View
19 src/test/java/org/apache/servicemix/executors/impl/LogThrowableInExecutorTest.java
@@ -22,11 +22,10 @@
import org.apache.log4j.spi.LoggingEvent;
import org.apache.servicemix.executors.Executor;
import org.apache.servicemix.executors.ExecutorFactory;
-import org.apache.servicemix.executors.impl.ExecutorFactoryImpl;
-import org.apache.servicemix.executors.impl.ExecutorImpl;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.TimeUnit;
/**
* Test case to ensure that Executor will always log throwables from the executed Runnable (SM-1847)
@@ -36,13 +35,13 @@
private static final String MESSAGE = "I'm a bad Runnable throwing errors at people";
public void testThrowableLogged() throws InterruptedException {
- final List<LoggingEvent> events = new LinkedList<LoggingEvent>();
+ final BlockingQueue<LoggingEvent> events = new LinkedBlockingDeque<LoggingEvent>();
// unit tests use LOG4J as the backend for SLF4J so add the appender to LOG4J
Logger.getLogger(ExecutorImpl.class).addAppender(new AppenderSkeleton() {
@Override
protected void append(LoggingEvent event) {
- events.add(event);
+ events.offer(event);
}
@Override
@@ -64,12 +63,12 @@ public void run() {
}
});
- // let's wait to make sure the runnable is done
- Thread.sleep(500);
+ LoggingEvent event = events.poll(10, TimeUnit.SECONDS);
- assertEquals("Should have logged 1 message", 1, events.size());
+
+ assertNotNull("Should have logged a message", event);
assertTrue("Exception message should have been logged",
- events.get(0).getThrowableStrRep()[0].contains(MESSAGE));
+ event.getThrowableStrRep()[0].contains(MESSAGE));
}

0 comments on commit 36b3a05

Please sign in to comment.
Something went wrong with that request. Please try again.