Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 079E695A4 for ; Thu, 29 Sep 2011 15:38:42 +0000 (UTC) Received: (qmail 84180 invoked by uid 500); 29 Sep 2011 15:38:42 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 84119 invoked by uid 500); 29 Sep 2011 15:38:41 -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 84107 invoked by uid 99); 29 Sep 2011 15:38:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Sep 2011 15:38:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Sep 2011 15:38:38 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 863702388847 for ; Thu, 29 Sep 2011 15:38:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1177338 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/SlowConnectionTest.java Date: Thu, 29 Sep 2011 15:38:15 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20110929153815.863702388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Thu Sep 29 15:38:15 2011 New Revision: 1177338 URL: http://svn.apache.org/viewvc?rev=1177338&view=rev Log: Make the test work without relying on a sleep statement to get the results needed. Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/SlowConnectionTest.java Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/SlowConnectionTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/SlowConnectionTest.java?rev=1177338&r1=1177337&r2=1177338&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/SlowConnectionTest.java (original) +++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/SlowConnectionTest.java Thu Sep 29 15:38:15 2011 @@ -26,50 +26,52 @@ import javax.net.ServerSocketFactory; import junit.framework.TestCase; import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.util.Wait; public class SlowConnectionTest extends TestCase { - + public void testSlowConnection() throws Exception { - + int timeout = 1000; URI tcpUri = new URI("tcp://localhost:61616?soTimeout=" + timeout + "&trace=true&connectionTimeout=" + timeout + "&wireFormat.maxInactivityDurationInitalDelay=" + timeout); - + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + tcpUri + ")"); final Connection connection = cf.createConnection(); - + MockBroker broker = new MockBroker(); broker.start(); - + new Thread(new Runnable() { public void run() { try { connection.start(); } catch (Throwable ignored) {} } }).start(); - - Thread.sleep(timeout * 5); - + int count = 0; - for (Thread thread : Thread.getAllStackTraces().keySet()) { - if (thread.getName().contains("ActiveMQ Transport")) { count++; } - } - + assertTrue("Transport count: " + count + ", expected <= 1", Wait.waitFor(new Wait.Condition(){ + public boolean isSatisified() throws Exception { + int count = 0; + for (Thread thread : Thread.getAllStackTraces().keySet()) { + if (thread.getName().contains("ActiveMQ Transport")) { count++; } + } + return count == 1; + }})); + broker.interrupt(); broker.join(); - - assertTrue("Transport count: " + count + ", expected <= 1", count <= 1); - } - + } + class MockBroker extends Thread { - + public void run() { - + List inProgress = new ArrayList(); ServerSocketFactory factory = ServerSocketFactory.getDefault(); ServerSocket ss = null; - + try { ss = factory.createServerSocket(61616); - + while (!interrupted()) { inProgress.add(ss.accept()); // eat socket } @@ -77,10 +79,10 @@ public class SlowConnectionTest extends e.printStackTrace(); } finally { try { ss.close(); } catch (IOException ignored) {} - for (Socket s : inProgress) { + for (Socket s : inProgress) { try { s.close(); } catch (IOException ignored) {} - } - } + } + } } } }