[hornetq-commits] JBoss hornetq SVN: r8285 - trunk/tests/src/org/hornetq/tests/integration/jms/server/management.

do-not-reply at jboss.org do-not-reply at jboss.org
Sat Nov 14 04:11:04 EST 2009


Author: timfox
Date: 2009-11-14 04:11:04 -0500 (Sat, 14 Nov 2009)
New Revision: 8285

Modified:
   trunk/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControl2Test.java
Log:
fixed timing issue in test

Modified: trunk/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControl2Test.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControl2Test.java	2009-11-14 05:58:59 UTC (rev 8284)
+++ trunk/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControl2Test.java	2009-11-14 09:11:04 UTC (rev 8285)
@@ -62,9 +62,9 @@
    // Attributes ----------------------------------------------------
 
    private HornetQServer server;
-   
+
    JMSServerManagerImpl serverManager;
-   
+
    private InVMContext context;
 
    // Static --------------------------------------------------------
@@ -147,13 +147,13 @@
    {
       return ManagementControlHelper.createJMSServerControl(mbeanServer);
    }
-   
+
    protected void tearDown() throws Exception
    {
       serverManager = null;
-      
+
       server = null;
-      
+
       super.tearDown();
    }
 
@@ -174,23 +174,18 @@
 
          String[] connectionIDs = control.listConnectionIDs();
          assertEquals(1, connectionIDs.length);
-       
+
          ConnectionFactory cf2 = JMSUtil.createFactory(connectorFactory, CONNECTION_TTL, PING_PERIOD);
          Connection connection2 = cf2.createConnection();
          assertEquals(2, control.listConnectionIDs().length);
 
          connection.close();
-         Thread.sleep(2 * CONNECTION_TTL);
+         
+         waitForConnectionIDs(1, control);
 
-         connectionIDs = control.listConnectionIDs();
-         assertEquals("got " + Arrays.asList(connectionIDs), 1, connectionIDs.length);
-
-         assertEquals(1, control.listConnectionIDs().length);
-
          connection2.close();
-         Thread.sleep(2 * CONNECTION_TTL);
-
-         assertEquals(0, control.listConnectionIDs().length);
+         
+         waitForConnectionIDs(0, control);
       }
       finally
       {
@@ -198,7 +193,7 @@
          {
             serverManager.stop();
          }
-         
+
          if (server != null)
          {
             server.stop();
@@ -206,6 +201,26 @@
       }
    }
 
+   private void waitForConnectionIDs(final int num, final JMSServerControl control) throws Exception
+   {
+      final long timeout = 10000;
+      long start = System.currentTimeMillis();
+      while (true)
+      {
+         if (control.listConnectionIDs().length == num)
+         {
+            return;
+         }
+
+         if (System.currentTimeMillis() - start > timeout)
+         {
+            throw new IllegalStateException("Timed out waiting for number of connections");
+         }
+
+         Thread.sleep(10);
+      }
+   }
+
    private void doListSessions(String acceptorFactory, String connectorFactory) throws Exception
    {
       try
@@ -231,7 +246,7 @@
 
          connection.close();
 
-         Thread.sleep(2 * CONNECTION_TTL);
+         waitForConnectionIDs(0, control);
 
          assertEquals(0, control.listConnectionIDs().length);
       }
@@ -241,8 +256,7 @@
          {
             serverManager.stop();
          }
-         
-         
+
          if (server != null)
          {
             server.stop();
@@ -270,12 +284,12 @@
          {
             System.out.println(remoteAddress);
          }
-         
+
          connection.close();
 
-         Thread.sleep(2 * CONNECTION_TTL);
+         waitForConnectionIDs(0, control);
 
-         remoteAddresses = control.listRemoteAddresses();         
+         remoteAddresses = control.listRemoteAddresses();
          assertEquals("got " + Arrays.asList(remoteAddresses), 0, remoteAddresses.length);
       }
       finally
@@ -284,8 +298,7 @@
          {
             serverManager.stop();
          }
-         
-         
+
          if (server != null)
          {
             server.stop();
@@ -327,10 +340,10 @@
          boolean gotException = exceptionLatch.await(2 * CONNECTION_TTL, TimeUnit.MILLISECONDS);
          assertTrue("did not received the expected JMSException", gotException);
 
-         remoteAddresses = control.listRemoteAddresses();         
+         remoteAddresses = control.listRemoteAddresses();
          assertEquals("got " + Arrays.asList(remoteAddresses), 0, remoteAddresses.length);
          assertEquals(0, server.getConnectionCount());
-         
+
          connection.close();
       }
       finally
@@ -339,7 +352,7 @@
          {
             serverManager.stop();
          }
-         
+
          if (server != null)
          {
             server.stop();
@@ -383,7 +396,7 @@
 
          assertEquals(1, control.listRemoteAddresses().length);
          assertEquals(1, server.getConnectionCount());
-         
+
          connection.close();
 
       }
@@ -393,7 +406,7 @@
          {
             serverManager.stop();
          }
-         
+
          if (server != null)
          {
             server.stop();



More information about the hornetq-commits mailing list