activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r524780 - in /activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq: ./ broker/ network/
Date Mon, 02 Apr 2007 13:43:04 GMT
Author: chirino
Date: Mon Apr  2 06:43:03 2007
New Revision: 524780

URL: http://svn.apache.org/viewvc?view=rev&rev=524780
Log:
Tweaked some tests so that they are more resiliant against thread schedualing variations 

Modified:
    activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java
    activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTest.java
    activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/broker/RecoveryBrokerTest.java
    activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/network/DemandForwardingBridgeTest.java
    activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/network/ForwardingBridgeTest.java

Modified: activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java
URL: http://svn.apache.org/viewvc/activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java?view=diff&rev=524780&r1=524779&r2=524780
==============================================================================
--- activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java
(original)
+++ activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java
Mon Apr  2 06:43:03 2007
@@ -34,23 +34,34 @@
 
 public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
     
-    public void testUseURIToSetUseClientIDPrefixOnConnectionFactory() throws URISyntaxException,
JMSException {
+    private ActiveMQConnection connection;
+	private BrokerService broker;
+
+	public void testUseURIToSetUseClientIDPrefixOnConnectionFactory() throws URISyntaxException,
JMSException {
         ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?jms.clientIDPrefix=Cheese");
         assertEquals("Cheese", cf.getClientIDPrefix());
 
-        ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection();
-        try {
-            connection.start();
-
-            String clientID = connection.getClientID();
-            log.info("Got client ID: " + clientID);
-
-            assertTrue("should start with Cheese! but was: " + clientID, clientID.startsWith("Cheese"));
-        }
-        finally {
-            connection.close();
-        }
+        connection = (ActiveMQConnection) cf.createConnection();
+        connection.start();
+
+        String clientID = connection.getClientID();
+        log.info("Got client ID: " + clientID);
+
+        assertTrue("should start with Cheese! but was: " + clientID, clientID.startsWith("Cheese"));
     }
+	
+	protected void tearDown() throws Exception {
+		// Try our best to close any previously opend connection.
+		try {
+			connection.close();
+		} catch (Throwable ignore) {			
+		}
+		// Try our best to stop any previously started broker.
+		try {
+			broker.stop();
+		} catch (Throwable ignore) {			
+		}
+	}
     
     public void testUseURIToSetOptionsOnConnectionFactory() throws URISyntaxException, JMSException
{
         ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?jms.useAsyncSend=true");
@@ -73,26 +84,27 @@
         ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
         // Make sure the broker is not created until the connection is instantiated.
         assertNull( BrokerRegistry.getInstance().lookup("localhost") );        
-        Connection connection = cf.createConnection();
+        connection = (ActiveMQConnection) cf.createConnection();
         // This should create the connection.
         assertNotNull(connection);
         // Verify the broker was created.
         assertNotNull( BrokerRegistry.getInstance().lookup("localhost") );
+        
         connection.close();
+        
         // Verify the broker was destroyed.
         assertNull( BrokerRegistry.getInstance().lookup("localhost") );
     }
     
     public void testGetBrokerName() throws URISyntaxException, JMSException {
         ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
-        ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection();
+        connection = (ActiveMQConnection) cf.createConnection();
         connection.start();
         
         String brokerName = connection.getBrokerName();
         log.info("Got broker name: " + brokerName);
         
         assertNotNull("No broker name available!", brokerName);
-        connection.close();
     }
     
     public void testCreateTcpConnectionUsingAllocatedPort() throws Exception {
@@ -128,7 +140,7 @@
 
     protected void assertCreateConnection(String uri) throws Exception {
         // Start up a broker with a tcp connector.
-        BrokerService broker = new BrokerService();
+        broker = new BrokerService();
         broker.setPersistent(false);
         TransportConnector connector = broker.addConnector(uri);
         broker.start();
@@ -147,9 +159,8 @@
         
         // This should create the connection.
         ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(connectURI);
-        Connection connection = cf.createConnection();
+        connection = (ActiveMQConnection) cf.createConnection();
         assertNotNull(connection);
-        connection.close();
         
         broker.stop();
     }

Modified: activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTest.java
URL: http://svn.apache.org/viewvc/activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTest.java?view=diff&rev=524780&r1=524779&r2=524780
==============================================================================
--- activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTest.java
(original)
+++ activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTest.java
Mon Apr  2 06:43:03 2007
@@ -1309,6 +1309,9 @@
         connection2.send(sessionInfo2);
         connection2.send(consumerInfo2);
 
+        // Wait a little for messages to get delivered.
+        Thread.sleep(1000);
+        
         for( int i=0; i < 4; i++ ) {
             Message m1 = receiveMessage(connection1);
             Message m2 = receiveMessage(connection2);

Modified: activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/broker/RecoveryBrokerTest.java
URL: http://svn.apache.org/viewvc/activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/broker/RecoveryBrokerTest.java?view=diff&rev=524780&r1=524779&r2=524780
==============================================================================
--- activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/broker/RecoveryBrokerTest.java
(original)
+++ activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/broker/RecoveryBrokerTest.java
Mon Apr  2 06:43:03 2007
@@ -173,7 +173,7 @@
         // The we should get the messages.
         for( int i=0; i < 4 ; i++ ) {
             Message m2 = receiveMessage(connection2);
-            assertNotNull(m2);
+            assertNotNull("Message "+(i+1)+" is missing.", m2);
         }        
         assertNoMessagesLeft(connection2);
     }

Modified: activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/network/DemandForwardingBridgeTest.java
URL: http://svn.apache.org/viewvc/activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/network/DemandForwardingBridgeTest.java?view=diff&rev=524780&r1=524779&r2=524780
==============================================================================
--- activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/network/DemandForwardingBridgeTest.java
(original)
+++ activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/network/DemandForwardingBridgeTest.java
Mon Apr  2 06:43:03 2007
@@ -117,6 +117,14 @@
         ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);      
 
         connection2.send(consumerInfo);
         
+        // Give demand forwarding bridge a chance to finish forwarding the subscriptions.
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException ie) {
+            ie.printStackTrace();
+        }
+        
+        
         // Send the message to the local boker.
         connection1.send(createMessage(producerInfo, destination, deliveryMode));
         
@@ -130,14 +138,7 @@
         bridge = new DemandForwardingBridge(createTransport(), createRemoteTransport());
         bridge.setLocalBrokerName("local");
         bridge.setDispatchAsync(false);
-        bridge.start();
-        
-        // PATCH: Give demand forwarding bridge a chance to finish setting up
-        try {
-            Thread.sleep(1000);
-        } catch (InterruptedException ie) {
-            ie.printStackTrace();
-        }
+        bridge.start();        
     }
     
     protected void tearDown() throws Exception {

Modified: activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/network/ForwardingBridgeTest.java
URL: http://svn.apache.org/viewvc/activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/network/ForwardingBridgeTest.java?view=diff&rev=524780&r1=524779&r2=524780
==============================================================================
--- activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/network/ForwardingBridgeTest.java
(original)
+++ activemq/branches/activemq-4.1/activemq-core/src/test/java/org/apache/activemq/network/ForwardingBridgeTest.java
Mon Apr  2 06:43:03 2007
@@ -68,6 +68,13 @@
         ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);      
 
         connection2.send(consumerInfo);
         Thread.sleep(1000);
+        // Give forwarding bridge a chance to finish setting up
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException ie) {
+            ie.printStackTrace();
+        }
+        
         // Send the message to the local boker.
         connection1.send(createMessage(producerInfo, destination, deliveryMode));
         
@@ -82,14 +89,7 @@
         bridge = new ForwardingBridge(createTransport(), createRemoteTransport());
         bridge.setClientId("local-remote-bridge");
         bridge.setDispatchAsync(false);
-        bridge.start();
-        
-        // PATCH: Give forwarding bridge a chance to finish setting up
-        try {
-            Thread.sleep(1000);
-        } catch (InterruptedException ie) {
-            ie.printStackTrace();
-        }
+        bridge.start();        
     }
     
     protected void tearDown() throws Exception {



Mime
View raw message