Skip to content

Commit

Permalink
SM-2166: Intermittent test failure in LogThrowableInExecutorTest
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/servicemix/utils/trunk@1412555 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
gertv committed Nov 22, 2012
1 parent 3f7c453 commit 36b3a05
Showing 1 changed file with 9 additions and 10 deletions.
Expand Up @@ -22,11 +22,10 @@
import org.apache.log4j.spi.LoggingEvent; import org.apache.log4j.spi.LoggingEvent;
import org.apache.servicemix.executors.Executor; import org.apache.servicemix.executors.Executor;
import org.apache.servicemix.executors.ExecutorFactory; 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.concurrent.BlockingQueue;
import java.util.List; 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) * Test case to ensure that Executor will always log throwables from the executed Runnable (SM-1847)
Expand All @@ -36,13 +35,13 @@ public class LogThrowableInExecutorTest extends TestCase {
private static final String MESSAGE = "I'm a bad Runnable throwing errors at people"; private static final String MESSAGE = "I'm a bad Runnable throwing errors at people";


public void testThrowableLogged() throws InterruptedException { 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 // unit tests use LOG4J as the backend for SLF4J so add the appender to LOG4J
Logger.getLogger(ExecutorImpl.class).addAppender(new AppenderSkeleton() { Logger.getLogger(ExecutorImpl.class).addAppender(new AppenderSkeleton() {
@Override @Override
protected void append(LoggingEvent event) { protected void append(LoggingEvent event) {
events.add(event); events.offer(event);
} }


@Override @Override
Expand All @@ -64,12 +63,12 @@ public void run() {
} }
}); });


// let's wait to make sure the runnable is done LoggingEvent event = events.poll(10, TimeUnit.SECONDS);
Thread.sleep(500);


assertEquals("Should have logged 1 message", 1, events.size());
assertNotNull("Should have logged a message", event);
assertTrue("Exception message should have been logged", assertTrue("Exception message should have been logged",
events.get(0).getThrowableStrRep()[0].contains(MESSAGE)); event.getThrowableStrRep()[0].contains(MESSAGE));


} }


Expand Down

0 comments on commit 36b3a05

Please sign in to comment.