diff options
| author | Aidan Skinner <aidan@apache.org> | 2009-07-01 13:59:05 +0000 |
|---|---|---|
| committer | Aidan Skinner <aidan@apache.org> | 2009-07-01 13:59:05 +0000 |
| commit | a2298c0209ea44b9d5e92c1de2f3020f941b80fc (patch) | |
| tree | 7fd8460ace564530514557b08c0b1daa024be327 /qpid/java | |
| parent | 1c5601630dbac0540f96a9bcddb78c830f00ce11 (diff) | |
| download | qpid-python-a2298c0209ea44b9d5e92c1de2f3020f941b80fc.tar.gz | |
Author: Martin Ritchie <ritchiem@apache.org>
QPID-1037 : Added new test with updates to QTC to provide better generic send methods
Signed-off-by: Aidan Skinner <aidan@apache.org>
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@790171 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
| -rw-r--r-- | qpid/java/systests/src/main/java/org/apache/qpid/server/queue/DeepQueueConsumeWithSelector.java | 162 | ||||
| -rw-r--r-- | qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java | 32 |
2 files changed, 192 insertions, 2 deletions
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/DeepQueueConsumeWithSelector.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/DeepQueueConsumeWithSelector.java new file mode 100644 index 0000000000..dfb5cde247 --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/DeepQueueConsumeWithSelector.java @@ -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); + } + + } +} diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java index 72d0e2c5fc..892b80896c 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java @@ -673,25 +673,53 @@ public class QpidTestCase extends TestCase 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(); |
