[hornetq-commits] JBoss hornetq SVN: r8279 - trunk/tests/src/org/hornetq/tests/integration/jms/connection.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Nov 13 05:35:30 EST 2009


Author: ataylor
Date: 2009-11-13 05:35:30 -0500 (Fri, 13 Nov 2009)
New Revision: 8279

Modified:
   trunk/tests/src/org/hornetq/tests/integration/jms/connection/ExceptionListenerTest.java
Log:
fixed timing issue on test

Modified: trunk/tests/src/org/hornetq/tests/integration/jms/connection/ExceptionListenerTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/jms/connection/ExceptionListenerTest.java	2009-11-13 02:05:29 UTC (rev 8278)
+++ trunk/tests/src/org/hornetq/tests/integration/jms/connection/ExceptionListenerTest.java	2009-11-13 10:35:30 UTC (rev 8279)
@@ -31,6 +31,9 @@
 import org.hornetq.tests.integration.jms.server.management.NullInitialContext;
 import org.hornetq.tests.util.UnitTestCase;
 
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
 /**
  * 
  * A ExceptionListenerTest
@@ -98,24 +101,34 @@
    private class MyExceptionListener implements ExceptionListener
    {
       volatile int numCalls;
-      
+
+      private CountDownLatch latch;
+
+      public MyExceptionListener(CountDownLatch latch)
+      {
+         this.latch = latch;
+      }
+
       public synchronized void onException(JMSException arg0)
       {
          numCalls++;
+         latch.countDown();
       }      
    }
 
    public void testListenerCalledForOneConnection() throws Exception
    {
       Connection conn = cf.createConnection();
+      CountDownLatch latch = new CountDownLatch(1);
+      MyExceptionListener listener = new MyExceptionListener(latch);
       
-      MyExceptionListener listener = new MyExceptionListener();
-      
       conn.setExceptionListener(listener);
       
       ClientSessionInternal coreSession = (ClientSessionInternal)((HornetQConnection)conn).getInitialSession();
       
       coreSession.getConnection().fail(new HornetQException(HornetQException.INTERNAL_ERROR, "blah"));
+
+      latch.await(5, TimeUnit.SECONDS);
       
       assertEquals(1, listener.numCalls);
       
@@ -125,9 +138,10 @@
    public void testListenerCalledForOneConnectionAndSessions() throws Exception
    {
       Connection conn = cf.createConnection();
+
+      CountDownLatch latch = new CountDownLatch(1);
+      MyExceptionListener listener = new MyExceptionListener(latch);
       
-      MyExceptionListener listener = new MyExceptionListener();
-      
       conn.setExceptionListener(listener);
       
       Session sess1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -151,7 +165,8 @@
       coreSession2.getConnection().fail(new HornetQException(HornetQException.INTERNAL_ERROR, "blah"));
       
       coreSession3.getConnection().fail(new HornetQException(HornetQException.INTERNAL_ERROR, "blah"));
-      
+
+      latch.await(5, TimeUnit.SECONDS);
       //Listener should only be called once even if all sessions connections die
       assertEquals(1, listener.numCalls);    
       



More information about the hornetq-commits mailing list