You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ra...@apache.org on 2011/03/11 02:02:45 UTC

svn commit: r1080417 - /qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java

Author: rajith
Date: Fri Mar 11 01:02:44 2011
New Revision: 1080417

URL: http://svn.apache.org/viewvc?rev=1080417&view=rev
Log:
QPID-2732
Refactored the test a bit and added a test for default reliability modes for Topics and Queues.

Modified:
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java?rev=1080417&r1=1080416&r2=1080417&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java Fri Mar 11 01:02:44 2011
@@ -905,12 +905,13 @@ public class AddressBasedDestinationTest
     }
     
     /**
-     * Test Goals : 1. Tests if the client sets the correct accept mode for unreliable
+     * Test Goals : 1. Test if the client sets the correct accept mode for unreliable
      *                and at-least-once.
-     *             2. Tests if an exception is thrown if exactly-once is used.
-     *             3. Tests if an exception is thrown if at-least-once is used with topics.
+     *             2. Test default reliability modes for Queues and Topics.
+     *             3. Test if an exception is thrown if exactly-once is used.
+     *             4. Test if an exception is thrown if at-least-once is used with topics.
      * 
-     * Test Strategy: For goal #1
+     * Test Strategy: For goal #1 & #2
      *                For unreliable and at-least-once the test tries to receives messages
      *                in client_ack mode but does not ack the messages.
      *                It will then close the session, recreate a new session
@@ -919,61 +920,25 @@ public class AddressBasedDestinationTest
      *                For at-least-once the messages should be put back onto the queue.    
      * 
      */
+   
     public void testReliabilityOptions() throws Exception
     {
-        Session jmsSession = _connection.createSession(false,Session.CLIENT_ACKNOWLEDGE);
-        MessageConsumer cons;
-        MessageProducer prod;
-        
         String addr1 = "ADDR:testQueue1;{create: always, delete : receiver, link : {reliability : unreliable}}";
-        AMQDestination  dest = new AMQAnyDestination(addr1);
-        cons = jmsSession.createConsumer(dest);
-        prod = jmsSession.createProducer(dest);
-        
-        prod.send(jmsSession.createTextMessage("A"));
-        prod.send(jmsSession.createTextMessage("B"));
-        
-        // We are only receiving one message, but both messages should be taken off the queue.
-        Message msg = cons.receive(1000);
-        assertNotNull(msg);
-        assertEquals("A",((TextMessage)msg).getText());
-        
-        jmsSession.close();
-        jmsSession = _connection.createSession(false,Session.CLIENT_ACKNOWLEDGE);
-        long queueDepth = ((AMQSession) jmsSession).getQueueDepth(dest);        
-        assertEquals(0,queueDepth);        
-        cons.close();
-        prod.close();
+        acceptModeTest(addr1,0);
         
         String addr2 = "ADDR:testQueue2;{create: always, delete : receiver, link : {reliability : at-least-once}}";
-        dest = new AMQAnyDestination(addr2);
-        cons = jmsSession.createConsumer(dest);
-        prod = jmsSession.createProducer(dest);
-        
-        // We are receiving both messages but both should be put back into the queue
-        // bcos we don't ack them.
-        prod.send(jmsSession.createTextMessage("A"));
-        prod.send(jmsSession.createTextMessage("B"));
-        
-        msg = cons.receive(1000);
-        assertNotNull(msg);
-        assertEquals("A",((TextMessage)msg).getText());
-        
-        msg = cons.receive(1000);
-        assertNotNull(msg);
-        assertEquals("B",((TextMessage)msg).getText());
-        
-        jmsSession.close();
-        jmsSession = _connection.createSession(false,Session.CLIENT_ACKNOWLEDGE);
-        queueDepth = ((AMQSession) jmsSession).getQueueDepth(dest);
-        assertEquals(2,queueDepth); 
-        cons.close();
-        prod.close();
+        acceptModeTest(addr2,2);
+        
+        // Default accept-mode for topics
+        acceptModeTest("ADDR:amq.topic/test",0);        
+        
+        // Default accept-mode for queues
+        acceptModeTest("ADDR:testQueue1;{create: always}",2);
                
         String addr3 = "ADDR:testQueue2;{create: always, delete : receiver, link : {reliability : exactly-once}}";        
         try
         {
-            dest = new AMQAnyDestination(addr3);
+            AMQAnyDestination dest = new AMQAnyDestination(addr3);
             fail("An exception should be thrown indicating it's an unsupported type");
         }
         catch(Exception e)
@@ -984,8 +949,9 @@ public class AddressBasedDestinationTest
         String addr4 = "ADDR:amq.topic/test;{link : {reliability : at-least-once}}";        
         try
         {
-            dest = new AMQAnyDestination(addr4);
-            cons = jmsSession.createConsumer(dest);
+            AMQAnyDestination dest = new AMQAnyDestination(addr4);
+            Session ssn = _connection.createSession(false,Session.CLIENT_ACKNOWLEDGE);
+            MessageConsumer cons = ssn.createConsumer(dest);
             fail("An exception should be thrown indicating it's an unsupported combination");
         }
         catch(Exception e)
@@ -993,4 +959,34 @@ public class AddressBasedDestinationTest
             assertTrue(e.getCause().getMessage().contains("AT-LEAST-ONCE is not yet supported for Topics"));
         }
     }
+    
+    private void acceptModeTest(String address, int expectedQueueDepth) throws Exception
+    {
+        Session ssn = _connection.createSession(false,Session.CLIENT_ACKNOWLEDGE);
+        MessageConsumer cons;
+        MessageProducer prod;
+        
+        AMQDestination  dest = new AMQAnyDestination(address);
+        cons = ssn.createConsumer(dest);
+        prod = ssn.createProducer(dest);
+        
+        for (int i=0; i < expectedQueueDepth; i++)
+        {
+            prod.send(ssn.createTextMessage("Msg" + i));
+        }
+        
+        for (int i=0; i < expectedQueueDepth; i++)
+        {
+            Message msg = cons.receive(1000);
+            assertNotNull(msg);
+            assertEquals("Msg" + i,((TextMessage)msg).getText());
+        }
+        
+        ssn.close();
+        ssn = _connection.createSession(false,Session.CLIENT_ACKNOWLEDGE);
+        long queueDepth = ((AMQSession) ssn).getQueueDepth(dest);        
+        assertEquals(expectedQueueDepth,queueDepth);        
+        cons.close();
+        prod.close();        
+    }
 }



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org