summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2007-12-14 10:40:37 +0000
committerMartin Ritchie <ritchiem@apache.org>2007-12-14 10:40:37 +0000
commit4be5cdedef3802a08664d609e2647be6b6d86732 (patch)
treef686112bc77555769b43ce27e0c13b336f9cf6ff
parentc0183ff1edda5e30a97649d49083e39484560a69 (diff)
downloadqpid-python-4be5cdedef3802a08664d609e2647be6b6d86732.tar.gz
QPID-707 : Added new test to check message count on broker as messages are consumed to ensure that an ack is sent at 5000 mgs. Added acks on message consumer closure.
Augmented VMTestCase to have helper methods for accessing broker statistics. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2.1.1@604151 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQSession.java30
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java15
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java21
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java140
4 files changed, 175 insertions, 31 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
index a052b48426..5a8f163bee 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
@@ -106,7 +106,6 @@ import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -245,7 +244,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
*/
private Map<AMQShortString, BasicMessageConsumer> _consumers =
new ConcurrentHashMap<AMQShortString, BasicMessageConsumer>();
-
+
/**
* Contains a list of consumers which have been removed but which might still have
* messages to acknowledge, eg in client ack or transacted modes
@@ -655,10 +654,10 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
lastTag = next;
}
}
-
+
if (_transacted)
{
- // Do the above, but for consumers which have been de-registered since the
+ // Do the above, but for consumers which have been de-registered since the
// last commit
for (int i = 0; i < _removedConsumers.size(); i++)
{
@@ -809,7 +808,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
checkValidDestination(destination);
- return createConsumerImpl(destination, prefetch, prefetch, noLocal, exclusive, selector, null, false, false);
+ return createConsumerImpl(destination, prefetch, prefetch / 2, noLocal, exclusive, selector, null, false, false);
}
public MessageConsumer createConsumer(Destination destination, int prefetchHigh, int prefetchLow, boolean noLocal,
@@ -825,7 +824,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
{
checkValidDestination(destination);
- return createConsumerImpl(destination, prefetch, prefetch, noLocal, exclusive, selector, rawSelector, false, false);
+ return createConsumerImpl(destination, prefetch, prefetch / 2, noLocal, exclusive, selector, rawSelector, false, false);
}
public MessageConsumer createConsumer(Destination destination, int prefetchHigh, int prefetchLow, boolean noLocal,
@@ -1714,10 +1713,9 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
_destinationConsumerCount.remove(dest);
}
}
-
-
- // Consumers that are closed in a transaction must be stored
- // so that messages they have received can be acknowledged on commit
+
+ // Consumers that are closed in a transaction must be stored
+ // so that messages they have received can be acknowledged on commit
if (_transacted)
{
_removedConsumers.add(consumer);
@@ -2609,17 +2607,13 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
return _messageDeliveryLock;
}
- /**
- * Signifies that the session has pending sends to commit.
- */
+ /** Signifies that the session has pending sends to commit. */
public void markDirty()
{
_dirty = true;
}
- /**
- * Signifies that the session has no pending sends to commit.
- */
+ /** Signifies that the session has no pending sends to commit. */
public void markClean()
{
_dirty = false;
@@ -2628,6 +2622,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
/**
* Check to see if failover has occured since the last call to markClean(commit or rollback).
+ *
* @return boolean true if failover has occured.
*/
public boolean hasFailedOver()
@@ -2637,6 +2632,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
/**
* Check to see if any message have been sent in this transaction and have not been commited.
+ *
* @return boolean true if a message has been sent but not commited
*/
public boolean isDirty()
@@ -2728,7 +2724,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi
}
}
-
+
for (int i = 0; i < _removedConsumers.size(); i++)
{
// Sends acknowledgement to server
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
index 44c10afcf5..26f04ad945 100644
--- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
+++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
@@ -253,6 +253,10 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
switch (_acknowledgeMode)
{
+ case Session.DUPS_OK_ACKNOWLEDGE:
+ _logger.info("Recording tag for acking on close:" + msg.getDeliveryTag());
+ _receivedDeliveryTags.add(msg.getDeliveryTag());
+ break;
case Session.CLIENT_ACKNOWLEDGE:
_unacknowledgedDeliveryTags.add(msg.getDeliveryTag());
@@ -543,6 +547,13 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
_logger.info("Closing consumer:" + debugIdentity());
}
+ switch (_acknowledgeMode)
+ {
+ case Session.DUPS_OK_ACKNOWLEDGE:
+ acknowledgeLastDelivered();
+ break;
+ }
+
synchronized (_connection.getFailoverMutex())
{
if (!_closed.getAndSet(true))
@@ -776,7 +787,8 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
_dups_ok_acknowledge_send = true;
}
- if (_outstanding <= _prefetchLow)
+ //Can't use <= as _prefetchHigh may equal _prefetchLow so no acking would occur.
+ if (_outstanding < _prefetchLow)
{
_dups_ok_acknowledge_send = false;
}
@@ -786,6 +798,7 @@ public class BasicMessageConsumer extends Closeable implements MessageConsumer
if (!_session.isInRecovery())
{
_session.acknowledgeMessage(msg.getDeliveryTag(), true);
+ _outstanding = 0;
}
}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java b/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java
index 9629f87d46..624d9c9f3d 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java
@@ -20,27 +20,16 @@
*/
package org.apache.qpid.test;
-import junit.extensions.TestSetup;
-
-import junit.framework.Test;
import junit.framework.TestCase;
-
import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
import org.apache.qpid.server.registry.ApplicationRegistry;
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
import javax.naming.Context;
import javax.naming.spi.InitialContextFactory;
-
import java.util.HashMap;
import java.util.Hashtable;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
public class VMTestCase extends TestCase
@@ -89,7 +78,7 @@ public class VMTestCase extends TestCase
}
env.put("connectionfactory.connection", "amqp://guest:guest@" + _clientID + _virtualhost + "?brokerlist='"
- + _brokerlist + "'");
+ + _brokerlist + "'");
for (Map.Entry<String, String> c : _connections.entrySet())
{
@@ -121,6 +110,12 @@ public class VMTestCase extends TestCase
super.tearDown();
}
+ public int getMessageCount(String queueName)
+ {
+ return ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(_virtualhost.substring(1))
+ .getQueueRegistry().getQueue(new AMQShortString(queueName)).getMessageCount();
+ }
+
public void testDummyinVMTestCase()
{
// keep maven happy
diff --git a/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java b/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java
new file mode 100644
index 0000000000..200f4f3956
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java
@@ -0,0 +1,140 @@
+package org.apache.qpid.test.client;
+
+import org.apache.qpid.test.VMTestCase;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.NamingException;
+import java.util.concurrent.CountDownLatch;/*
+ *
+ * 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.
+ *
+ */
+
+public class DupsOkTest extends VMTestCase
+{
+
+ private Queue _queue;
+ private static final int MSG_COUNT = 9999;
+ private CountDownLatch _awaitCompletion = new CountDownLatch(1);
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ _queue = (Queue) _context.lookup("queue");
+
+ //CreateQueue
+ ((ConnectionFactory) _context.lookup("connection")).createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(_queue).close();
+
+ //Create Producer put some messages on the queue
+ Connection producerConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
+
+ producerConnection.start();
+
+ Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = producerSession.createProducer(_queue);
+
+ for (int count = 1; count <= MSG_COUNT; count++)
+ {
+ Message msg = producerSession.createTextMessage("Message " + count);
+ msg.setIntProperty("count", count);
+ producer.send(msg);
+ }
+
+ producerConnection.close();
+ }
+
+ public void testDupsOK() throws NamingException, JMSException, InterruptedException
+ {
+ //Create Client
+ Connection clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
+
+ clientConnection.start();
+
+ Session clientSession = clientConnection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+
+ MessageConsumer consumer = clientSession.createConsumer(_queue);
+
+ consumer.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message message)
+ {
+ if (message == null)
+ {
+ fail("Should not get null messages");
+ }
+
+ if (message instanceof TextMessage)
+ {
+ try
+ {
+ if (message.getIntProperty("count") == 5000)
+ {
+ assertEquals("The queue should have 4999 msgs left", 4999, getMessageCount(_queue.getQueueName()));
+ }
+
+ if (message.getIntProperty("count") == 9999)
+ {
+ assertEquals("The queue should have 0 msgs left", 0, getMessageCount(_queue.getQueueName()));
+
+ //This is the last message so release test.
+ _awaitCompletion.countDown();
+ }
+
+ }
+ catch (JMSException e)
+ {
+ fail("Unable to get int property 'count'");
+ }
+ }
+ else
+ {
+ fail("");
+ }
+ }
+ });
+
+ try
+ {
+ _awaitCompletion.await();
+ }
+ catch (InterruptedException e)
+ {
+ fail("Unable to wait for test completion");
+ throw e;
+ }
+
+// consumer.close();
+
+ clientConnection.close();
+
+ assertEquals("The queue should have 0 msgs left", 0, getMessageCount(_queue.getQueueName()));
+ }
+
+
+}