Author: ritchiem
Date: Fri Dec 14 02:40:37 2007
New Revision: 604151
URL: http://svn.apache.org/viewvc?rev=604151&view=rev
Log:
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.
Added:
incubator/qpid/branches/M2.1.1/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java
(with props)
Modified:
incubator/qpid/branches/M2.1.1/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
incubator/qpid/branches/M2.1.1/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
incubator/qpid/branches/M2.1.1/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java
Modified:
incubator/qpid/branches/M2.1.1/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1.1/java/client/src/main/java/org/apache/qpid/client/AMQSession.java?rev=604151&r1=604150&r2=604151&view=diff
==============================================================================
---
incubator/qpid/branches/M2.1.1/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
(original)
+++
incubator/qpid/branches/M2.1.1/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
Fri Dec 14 02:40:37 2007
@@ -106,7 +106,6 @@
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 @@
*/
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 @@
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 @@
{
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 @@
{
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 @@
_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 @@
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 @@
/**
* 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 @@
/**
* 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 @@
}
}
-
+
for (int i = 0; i < _removedConsumers.size(); i++)
{
// Sends acknowledgement to server
Modified:
incubator/qpid/branches/M2.1.1/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1.1/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java?rev=604151&r1=604150&r2=604151&view=diff
==============================================================================
---
incubator/qpid/branches/M2.1.1/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
(original)
+++
incubator/qpid/branches/M2.1.1/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
Fri Dec 14 02:40:37 2007
@@ -253,6 +253,10 @@
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 @@
_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 @@
_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 @@
if (!_session.isInRecovery())
{
_session.acknowledgeMessage(msg.getDeliveryTag(),
true);
+ _outstanding = 0;
}
}
Modified:
incubator/qpid/branches/M2.1.1/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1.1/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java?rev=604151&r1=604150&r2=604151&view=diff
==============================================================================
---
incubator/qpid/branches/M2.1.1/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java
(original)
+++
incubator/qpid/branches/M2.1.1/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java
Fri Dec 14 02:40:37 2007
@@ -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 @@
}
env.put("connectionfactory.connection", "amqp://guest:guest@" +
_clientID + _virtualhost + "?brokerlist='"
- + _brokerlist + "'");
+ + _brokerlist + "'");
for (Map.Entry<String, String> c : _connections.entrySet())
{
@@ -119,6 +108,12 @@
ApplicationRegistry.remove(1);
super.tearDown();
+ }
+
+ public int getMessageCount(String queueName)
+ {
+ return
ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(_virtualhost.substring(1))
+ .getQueueRegistry().getQueue(new
AMQShortString(queueName)).getMessageCount();
}
public void testDummyinVMTestCase()
Added:
incubator/qpid/branches/M2.1.1/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1.1/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java?rev=604151&view=auto
==============================================================================
---
incubator/qpid/branches/M2.1.1/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java
(added)
+++
incubator/qpid/branches/M2.1.1/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java
Fri Dec 14 02:40:37 2007
@@ -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()));
+ }
+
+
+}
Propchange:
incubator/qpid/branches/M2.1.1/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/qpid/branches/M2.1.1/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date