activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r359856 - in /incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq: JmsMultipleClientsTestSupport.java broker/QueueSubscriptionTest.java util/MessageList.java
Date Thu, 29 Dec 2005 17:26:39 GMT
Author: jstrachan
Date: Thu Dec 29 09:26:35 2005
New Revision: 359856

URL: http://svn.apache.org/viewcvs?rev=359856&view=rev
Log:
tidied up the test cases a bit

Modified:
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JmsMultipleClientsTestSupport.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/QueueSubscriptionTest.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/MessageList.java

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JmsMultipleClientsTestSupport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JmsMultipleClientsTestSupport.java?rev=359856&r1=359855&r2=359856&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JmsMultipleClientsTestSupport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JmsMultipleClientsTestSupport.java
Thu Dec 29 09:26:35 2005
@@ -90,7 +90,7 @@
             // Wait for all producers to finish sending
             synchronized (producerLock) {
                 while (producerLock.get() != 0) {
-                    producerLock.wait();
+                    producerLock.wait(2000);
                 }
             }
 
@@ -169,16 +169,16 @@
     protected TopicSubscriber createDurableSubscriber(Connection conn, Destination dest,
String name) throws Exception {
         conn.setClientID(name);
         connections.add(conn);
+        conn.start();
 
         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
         final TopicSubscriber consumer = sess.createDurableSubscriber((javax.jms.Topic)dest,
name);
-        conn.start();
 
         return consumer;
     }
 
-    protected void waitForAllMessagesToBeReceived(int timeout) throws Exception {
-        //Thread.sleep(timeout);
+    protected void waitForAllMessagesToBeReceived(int messageCount) throws Exception {
+        allMessagesList.waitForMessagesToArrive(messageCount);
     }
 
     protected ActiveMQDestination createDestination() throws JMSException {
@@ -233,7 +233,7 @@
 
     protected void assertConsumerReceivedXMessages(MessageConsumer consumer, int msgCount)
{
         MessageList messageList = (MessageList)consumers.get(consumer);
-        messageList.assertMessagesReceived(msgCount);
+        messageList.assertMessagesReceivedNoWait(msgCount);
     }
 
     protected void assertEachConsumerReceivedAtLeastXMessages(int msgCount) {
@@ -255,7 +255,7 @@
     }
 
     protected void assertTotalMessagesReceived(int msgCount) {
-        allMessagesList.assertMessagesReceived(msgCount);
+        allMessagesList.assertMessagesReceivedNoWait(msgCount);
         
         // now lets count the individual messages received 
         int totalMsg = 0;

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/QueueSubscriptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/QueueSubscriptionTest.java?rev=359856&r1=359855&r2=359856&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/QueueSubscriptionTest.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/QueueSubscriptionTest.java
Thu Dec 29 09:26:35 2005
@@ -137,11 +137,11 @@
         startConsumers(consumerFactory, dest);
 
         // Wait for consumers to setup
-        Thread.sleep(500);
+        Thread.sleep(1000);
 
         startProducers(dest, messageCount);
 
         // Wait for messages to be received. Make it proportional to the messages delivered.
-        waitForAllMessagesToBeReceived((producerCount * messageCount) / 2000);
+        waitForAllMessagesToBeReceived(messageCount * producerCount);
     }
 }

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/MessageList.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/MessageList.java?rev=359856&r1=359855&r2=359856&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/MessageList.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/MessageList.java
Thu Dec 29 09:26:35 2005
@@ -43,6 +43,7 @@
     private Object semaphore;
     private boolean verbose;
     private MessageListener parent;
+    private long maximumDuration = 15000L;
 
     public MessageList() {
         this(new Object());
@@ -134,6 +135,10 @@
                 if (hasReceivedMessages(messageCount)) {
                     break;
                 }
+                long duration = System.currentTimeMillis() - start;
+                if (duration > maximumDuration ) {
+                    break;
+                }
                 synchronized (semaphore) {
                     semaphore.wait(4000);
                 }
@@ -144,28 +149,43 @@
         }
         long end = System.currentTimeMillis() - start;
 
-        System.out.println("End of wait for " + end + " millis");
+        System.out.println("End of wait for " + end + " millis and received: " + getMessageCount()
+ " messages");
     }
 
     /**
      * Performs a testing assertion that the correct number of messages have
-     * been received
+     * been received without waiting
+     * 
+     * @param messageCount
+     */
+    public void assertMessagesReceivedNoWait(int messageCount) {
+        assertEquals("expected number of messages when received", messageCount, getMessageCount());
+    }
+    
+    /**
+     * Performs a testing assertion that the correct number of messages have
+     * been received waiting for the messages to arrive up to a fixed amount of time.
      * 
      * @param messageCount
      */
     public void assertMessagesReceived(int messageCount) {
         waitForMessagesToArrive(messageCount);
 
-        assertEquals("expected number of messages when received: " + getMessages(), messageCount,
getMessageCount());
+        assertMessagesReceivedNoWait(messageCount);
     }
 
+    /**
+     * Asserts that there are at least the given number of messages received without waiting.
+     */
     public void assertAtLeastMessagesReceived(int messageCount) {
-        waitForMessagesToArrive(messageCount);
-
         int actual = getMessageCount();
         assertTrue("at least: " + messageCount + " messages received. Actual: " + actual,
actual >= messageCount);
     }
 
+    /**
+     * Asserts that there are at most the number of messages received without waiting
+     * @param messageCount
+     */
     public void assertAtMostMessagesReceived(int messageCount) {
         int actual = getMessageCount();
         assertTrue("at most: " + messageCount + " messages received. Actual: " + actual,
actual <= messageCount);



Mime
View raw message