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
diff --git a/src/test/java/org/apache/servicemix/executors/impl/LogThrowableInExecutorTest.java b/src/test/java/org/apache/servicemix/executors/impl/LogThrowableInExecutorTest.java
index b3f91e0..296f4e5 100644
--- a/src/test/java/org/apache/servicemix/executors/impl/LogThrowableInExecutorTest.java
+++ b/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 @@
             }
         });
 
-        // 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));
 
     }