activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1084009 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2401Test.java
Date Mon, 21 Mar 2011 22:50:02 GMT
Author: tabish
Date: Mon Mar 21 22:50:02 2011
New Revision: 1084009

URL: http://svn.apache.org/viewvc?rev=1084009&view=rev
Log:
Clean up the test a bit and adds some additional time to account for slower machines.  

Removes System.out and replaces with logging.

Modified:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2401Test.java

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2401Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2401Test.java?rev=1084009&r1=1084008&r2=1084009&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2401Test.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ2401Test.java Mon
Mar 21 22:50:02 2011
@@ -37,12 +37,14 @@ import org.apache.activemq.broker.Broker
 import org.apache.activemq.broker.region.policy.PolicyEntry;
 import org.apache.activemq.broker.region.policy.PolicyMap;
 import org.apache.activemq.broker.region.policy.VMPendingQueueMessageStoragePolicy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import junit.framework.TestCase;
 
 /**
  * An AMQ-2401 Test
- * 
+ *
  */
 public class AMQ2401Test extends TestCase implements MessageListener{
     BrokerService broker;
@@ -52,6 +54,8 @@ public class AMQ2401Test extends TestCas
     private static final int PRODUCER_COUNT = 1;
     private static final int LOG_INTERVAL = 10;
 
+    private static final Logger LOG = LoggerFactory.getLogger(AMQ2401Test.class);
+
     private ArrayList<Service> services = new ArrayList<Service>(CONSUMER_COUNT
+ PRODUCER_COUNT);
     int count = 0;
     CountDownLatch latch;
@@ -87,7 +91,7 @@ public class AMQ2401Test extends TestCas
         try {
 
             latch = new CountDownLatch(SEND_COUNT);
-            
+
             for(int i = 0; i < CONSUMER_COUNT; i++)
             {
                 TestConsumer consumer = new TestConsumer();
@@ -100,7 +104,7 @@ public class AMQ2401Test extends TestCas
                 producer.start();
                 services.add(producer);
             }
-            waitForMessageReceipt(3000);
+            waitForMessageReceipt(TimeUnit.SECONDS.toMillis(30));
 
         } finally {
             if (p != null) {
@@ -113,37 +117,38 @@ public class AMQ2401Test extends TestCas
         }
 
     }
-    
+
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
      */
     public void onMessage(Message message) {
         latch.countDown();
         if (++count % LOG_INTERVAL == 0) {
-            System.out.println("Received message " + count);
+            LOG.debug("Received message " + count);
         }
         try {
-            Thread.currentThread().sleep(1);
+            Thread.sleep(1);
         } catch (InterruptedException e) {
             Thread.currentThread().interrupt();
         }
-        
+
     }
 
     /**
      * @throws InterruptedException
      * @throws TimeoutException
-     * 
+     *
      */
     private void waitForMessageReceipt(long timeout) throws InterruptedException, TimeoutException
{
-        // TODO Auto-generated method stub
         if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
-            throw new TimeoutException("Consumner didn't receive messages");
+            throw new TimeoutException(String.format(
+                "Consumner didn't receive expected # of messages, %d of %d received.",
+                latch.getCount(), SEND_COUNT ));
         }
     }
-    
+
     private interface Service {
         public void start() throws Exception;
 
@@ -177,7 +182,7 @@ public class AMQ2401Test extends TestCas
             for (int i = 1; i <= count; i++) {
                 try {
                     if( (i% LOG_INTERVAL)==0 ) {
-                        System.out.println("Sending: " + i);
+                        LOG.debug("Sending: " + i);
                     }
                     message = session.createBytesMessage();
                     message.writeBytes(new byte[1024]);
@@ -197,12 +202,10 @@ public class AMQ2401Test extends TestCas
         }
     }
 
-    
     private class TestConsumer implements Runnable, Service {
         ActiveMQConnection connection;
         Session session;
         MessageConsumer consumer;
-        Thread thread;
 
         TestConsumer() throws Exception {
             factory.setOptimizeAcknowledge(false);
@@ -227,7 +230,7 @@ public class AMQ2401Test extends TestCas
 
         /*
          * (non-Javadoc)
-         * 
+         *
          * @see java.lang.Runnable#run()
          */
         public void run() {
@@ -238,8 +241,6 @@ public class AMQ2401Test extends TestCas
                     e.printStackTrace();
                 }
             }
-
         }
-
     }
 }



Mime
View raw message