You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2012/11/22 15:13:59 UTC

svn commit: r1412555 - /servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/LogThrowableInExecutorTest.java

Author: gertv
Date: Thu Nov 22 14:13:58 2012
New Revision: 1412555

URL: http://svn.apache.org/viewvc?rev=1412555&view=rev
Log:
SM-2166: Intermittent test failure in LogThrowableInExecutorTest

Modified:
    servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/LogThrowableInExecutorTest.java

Modified: servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/LogThrowableInExecutorTest.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/LogThrowableInExecutorTest.java?rev=1412555&r1=1412554&r2=1412555&view=diff
==============================================================================
--- servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/LogThrowableInExecutorTest.java (original)
+++ servicemix/utils/trunk/src/test/java/org/apache/servicemix/executors/impl/LogThrowableInExecutorTest.java Thu Nov 22 14:13:58 2012
@@ -22,11 +22,10 @@ import org.apache.log4j.Logger;
 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 @@ public class LogThrowableInExecutorTest 
     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 class LogThrowableInExecutorTest 
             }
         });
 
-        // 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));
 
     }