Return-Path: Delivered-To: apmail-geronimo-activemq-commits-archive@www.apache.org Received: (qmail 10994 invoked from network); 15 Mar 2006 15:16:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 15 Mar 2006 15:16:21 -0000 Received: (qmail 47341 invoked by uid 500); 15 Mar 2006 15:16:08 -0000 Delivered-To: apmail-geronimo-activemq-commits-archive@geronimo.apache.org Received: (qmail 47322 invoked by uid 500); 15 Mar 2006 15:16:08 -0000 Mailing-List: contact activemq-commits-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-commits@geronimo.apache.org Received: (qmail 47313 invoked by uid 99); 15 Mar 2006 15:16:07 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Mar 2006 07:16:07 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 15 Mar 2006 07:16:07 -0800 Received: (qmail 9958 invoked by uid 65534); 15 Mar 2006 15:15:32 -0000 Message-ID: <20060315151532.9955.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r386092 - /incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/LargeStreamletTest.java Date: Wed, 15 Mar 2006 15:15:31 -0000 To: activemq-commits@geronimo.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: chirino Date: Wed Mar 15 07:15:29 2006 New Revision: 386092 URL: http://svn.apache.org/viewcvs?rev=386092&view=rev Log: Be more carefull about how long we wait for the test to timeout Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/LargeStreamletTest.java Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/LargeStreamletTest.java URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/LargeStreamletTest.java?rev=386092&r1=386091&r2=386092&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/LargeStreamletTest.java (original) +++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/LargeStreamletTest.java Wed Mar 15 07:15:29 2006 @@ -25,10 +25,8 @@ import junit.framework.Assert; import junit.framework.TestCase; - -import org.apache.activemq.ActiveMQConnection; -import org.apache.activemq.ActiveMQConnectionFactory; import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean; +import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger; /** * @author rnewson @@ -41,9 +39,9 @@ private static final int MESSAGE_COUNT = 1024*1024; - private int totalRead; + private AtomicInteger totalRead = new AtomicInteger(); - private int totalWritten; + private AtomicInteger totalWritten = new AtomicInteger(); private AtomicBoolean stopThreads = new AtomicBoolean(false); @@ -66,7 +64,7 @@ final Thread readerThread = new Thread(new Runnable() { public void run() { - totalRead = 0; + totalRead.set(0); try { final InputStream inputStream = connection .createInputStream(destination); @@ -75,7 +73,7 @@ final byte[] buf = new byte[BUFFER_SIZE]; while (!stopThreads.get() && (read = inputStream.read(buf)) != -1) { - totalRead += read; + totalRead.addAndGet(read); } } finally { inputStream.close(); @@ -93,7 +91,7 @@ final Thread writerThread = new Thread(new Runnable() { public void run() { - totalWritten = 0; + totalWritten.set(0); int count = MESSAGE_COUNT; try { final OutputStream outputStream = connection @@ -103,7 +101,7 @@ new Random().nextBytes(buf); while (count > 0 && !stopThreads.get()) { outputStream.write(buf); - totalWritten += buf.length; + totalWritten.addAndGet(buf.length); count--; } } finally { @@ -122,8 +120,19 @@ readerThread.start(); writerThread.start(); - writerThread.join(60 * 1000); - readerThread.join(60 * 1000); + + // Wait till reader is has finished receiving all the messages or he has stopped + // receiving messages. + Thread.sleep(1000); + int lastRead = totalRead.get(); + while( readerThread.isAlive() ) { + readerThread.join(1000); + // No progress?? then stop waiting.. + if( lastRead == totalRead.get() ) { + break; + } + lastRead = totalRead.get(); + } stopThreads.set(true); @@ -131,7 +140,7 @@ assertTrue("Should not have received a writer exception", writerException == null); Assert.assertEquals("Not all messages accounted for", - totalWritten, totalRead); + totalWritten.get(), totalRead.get()); } finally { session.close();