From commits-return-5594-apmail-activemq-commits-archive=activemq.apache.org@activemq.apache.org Mon Apr 02 13:43:26 2007 Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 20030 invoked from network); 2 Apr 2007 13:43:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Apr 2007 13:43:26 -0000 Received: (qmail 28669 invoked by uid 500); 2 Apr 2007 13:43:33 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 28623 invoked by uid 500); 2 Apr 2007 13:43:33 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 28614 invoked by uid 99); 2 Apr 2007 13:43:33 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Apr 2007 06:43:33 -0700 X-ASF-Spam-Status: No, hits=-98.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Apr 2007 06:43:24 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 756081A9838; Mon, 2 Apr 2007 06:43:04 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@activemq.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070402134304.756081A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 {