Author: aidan
Date: Wed Jul  1 13:59:05 2009
New Revision: 790171

URL: http://svn.apache.org/viewvc?rev=790171&view=rev
Log:
Author: Martin Ritchie <ritch...@apache.org>

QPID-1037 : Added new test with updates to QTC to provide better generic send 
methods

Signed-off-by: Aidan Skinner <ai...@apache.org>

Added:
    
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/DeepQueueConsumeWithSelector.java
Modified:
    
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java

Added: 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/DeepQueueConsumeWithSelector.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/DeepQueueConsumeWithSelector.java?rev=790171&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/DeepQueueConsumeWithSelector.java
 (added)
+++ 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/DeepQueueConsumeWithSelector.java
 Wed Jul  1 13:59:05 2009
@@ -0,0 +1,162 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.queue;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.client.AMQConnection;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.Session;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Test DeapQueueConsumerWithSelector
+ * Summary:
+ * Prior to M4 the broker had a different queue model which pre-processed the
+ * messages on the queue for any connecting subscription that had a selector.
+ *
+ * If the queue had a lot of data then this may take a long time to process
+ * to such an extent that the subscription creation may time out. During this
+ * pre-process phase the virtualhost would be come unresposive.
+ *
+ * Our solution was to allow the timeout to be adjusted QPID-1119, which 
allowed
+ * the subscription to connect but did not address the unresponsiveness.
+ *
+ * The new queue model introduced in M4 resolved this.
+ *
+ * This test is to validate that the new queueing model does indeed remove the
+ * long pre-processing phase and allow immediate subscription so that there is
+ * no unresponsive period.
+ *
+ * Test Strategy:
+ *
+ * Add 100k messages to the queue with a numberic header property that will
+ * allow later subscribers to use as in a selector.
+ *
+ * Connect the subscriber and time how long it takes to connect.
+ *
+ * Finally consume all the messages from the queue to clean up.
+ */
+public class DeepQueueConsumeWithSelector extends QpidTestCase implements 
MessageListener
+{
+    private static final String INDEX = "index";
+
+    private static final int MESSAGE_COUNT = 10000;
+    private static final int BATCH_SIZE = MESSAGE_COUNT / 10;
+
+    private CountDownLatch _receviedLatch = new CountDownLatch(MESSAGE_COUNT);
+
+    protected long SYNC_WRITE_TIMEOUT = 120000L;
+
+
+    public void setUp() throws Exception
+    {
+        //Set the syncWrite timeout to be just larger than the delay on the 
commitTran.
+        setSystemProperty("amqj.default_syncwrite_timeout", 
String.valueOf(SYNC_WRITE_TIMEOUT));
+
+        super.setUp();
+    }
+
+    public void test() throws Exception
+    {
+        // Create Connection
+        Connection connection = getConnection();
+        Session session = ((AMQConnection)connection).createSession(true, 
Session.SESSION_TRANSACTED, 100000);
+
+        Queue queue = (Queue) getInitialContext().lookup("queue");
+
+        // Validate that the destination exists
+        session.createConsumer(queue).close();
+
+        // Send Messages
+        sendMessage(session, queue, MESSAGE_COUNT, BATCH_SIZE);
+
+        session.close();
+
+        session = ((AMQConnection) connection).createSession(false, 
Session.AUTO_ACKNOWLEDGE);//, 100000);
+
+
+        // Setup Selector to perform a few calculations which will slow it down
+        String selector = "((\"" + INDEX + "\" % 1) = 0) AND ('" + INDEX + "' 
IS NOT NULL) AND ('" + INDEX + "' <> -1)";
+
+        // Setup timing
+        long start = System.nanoTime();
+
+        System.err.println("Create Consumer");
+        // Connect Consumer
+        MessageConsumer consumer = session.createConsumer(queue, selector);
+        consumer.setMessageListener(this);
+
+        // Validate timing details
+        long end = System.nanoTime();
+
+        System.err.println("Subscription time took:" + (end - start));
+
+        // Consume Messages
+        connection.start();
+
+
+
+        assertTrue("Messages took to long to be received 
:"+_receviedLatch.getCount(),
+                   _receviedLatch.await(SYNC_WRITE_TIMEOUT, 
TimeUnit.MILLISECONDS   ));
+
+    }
+
+    @Override
+    public Message createNextMessage(Session session, int msgCount) throws 
JMSException
+    {
+        Message message = session.createTextMessage("Message :" + msgCount);
+
+        message.setIntProperty(INDEX, msgCount);
+
+        if ((msgCount % BATCH_SIZE) == 0 )
+        {
+            System.err.println("Sent:"+msgCount);
+        }
+
+        return message;
+    }
+
+    public void onMessage(Message message)
+    {
+        _receviedLatch.countDown();
+        int msgCount = 0;
+        try
+        {
+            msgCount = message.getIntProperty(INDEX);
+        }
+        catch (JMSException e)
+        {
+            //ignore
+        }
+        if ((msgCount % BATCH_SIZE) == 0 )
+        {
+            System.err.println("Received:"+msgCount);            
+        }
+
+    }
+}

Modified: 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java?rev=790171&r1=790170&r2=790171&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
 (original)
+++ 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
 Wed Jul  1 13:59:05 2009
@@ -673,25 +673,53 @@
 
         revertSystemProperties();
     }
-
+    
     public List<Message> sendMessage(Session session, Destination destination,
                                      int count) throws Exception
     {
+       return sendMessage(session, destination, count, 0);
+    }
+
+    public List<Message> sendMessage(Session session, Destination destination,
+                                     int count,int batchSize) throws Exception
+    {
         List<Message> messages = new ArrayList<Message>(count);
         
         MessageProducer producer = session.createProducer(destination);
 
         for (int i = 0; i < count; i++)
         {
-            Message next = session.createMessage();
+            Message next = createNextMessage(session, i);
 
             producer.send(next);
 
+            if (session.getTransacted() && batchSize > 0)
+            {
+                if (i % batchSize == 0)
+                {
+                    session.commit();
+                }
+
+            }
+
             messages.add(next);
         }
+
+        // Ensure we commit the last messages
+        if (session.getTransacted() && (batchSize > 0) &&
+            (count / batchSize != 0))
+        {
+            session.commit();
+        }
+
         return messages;
     }
 
+    public Message createNextMessage(Session session, int msgCount) throws 
JMSException
+    {
+        return session.createMessage();
+    }
+
     public ConnectionURL getConnectionURL() throws NamingException
     {
         return getConnectionFactory().getConnectionURL();



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

Reply via email to