You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2015/10/05 15:16:28 UTC
qpid-jms git commit: QPIDJMS-112: refresh the credit after draining
it to reopen the consumers prefetch window
Repository: qpid-jms
Updated Branches:
refs/heads/master 5c538a065 -> 2a7e0e96d
QPIDJMS-112: refresh the credit after draining it to reopen the consumers prefetch window
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/2a7e0e96
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/2a7e0e96
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/2a7e0e96
Branch: refs/heads/master
Commit: 2a7e0e96dc8356fb0d0dc4db4b626d8b04ae3533
Parents: 5c538a0
Author: Robert Gemmell <ro...@apache.org>
Authored: Mon Oct 5 14:15:41 2015 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Mon Oct 5 14:15:41 2015 +0100
----------------------------------------------------------------------
.../org/apache/qpid/jms/JmsMessageConsumer.java | 18 ++++++++-----
.../MessageExpirationIntegrationTest.java | 2 ++
.../QueueBrowserIntegrationTest.java | 27 ++++++++++++--------
.../failover/FailoverIntegrationTest.java | 3 ++-
4 files changed, 32 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/2a7e0e96/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
index ba6c3df..a793fa7 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
@@ -296,13 +296,15 @@ public class JmsMessageConsumer implements MessageConsumer, JmsMessageAvailableC
// is redundant: zero-prefetch consumers already pull, and
// the rest block indefinitely on the local messageQueue.
pullForced = true;
- performPullIfRequired(timeout, true);
+ if(performPullIfRequired(timeout, true)) {
+ startConsumerResource();
+ // We refresh credit if it is a prefetching consumer, since the
+ // pull drained it. Processing acks can open the credit window, but
+ // not in all cases, and if we didn't get a message it would stay
+ // closed until future pulls were performed.
+ }
}
- // TODO: refresh credit if needed, since the above drains it.
- // Processing acks can currently reopen the credit window, but if we don't get a message
- // here then, it will stay closed for regular prefetching consumers.
- // Further receive calls will add and drain credit though.
} else if (envelope.getMessage() == null) {
//TODO: do we still need this now?
LOG.trace("{} no message was available for this consumer: {}", getConsumerId());
@@ -674,11 +676,15 @@ public class JmsMessageConsumer implements MessageConsumer, JmsMessageAvailableC
* The amount of time the pull request should remain valid.
* @param treatAsPullConsumer
* Treat the consumer as if it were a pull consumer, even if it isn't.
+ * @return true if a pull was performed, false if it was not.
*/
- protected void performPullIfRequired(long timeout, boolean treatAsPullConsumer) throws JMSException {
+ protected boolean performPullIfRequired(long timeout, boolean treatAsPullConsumer) throws JMSException {
if ((isPullConsumer() || treatAsPullConsumer) && messageQueue.isRunning() && messageQueue.isEmpty()) {
connection.pull(getConsumerId(), timeout);
+ return true;
}
+
+ return false;
}
private int getConfiguredPrefetch(JmsDestination destination, JmsPrefetchPolicy policy) {
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/2a7e0e96/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageExpirationIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageExpirationIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageExpirationIntegrationTest.java
index 89f210f..52ad5ff 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageExpirationIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageExpirationIntegrationTest.java
@@ -95,6 +95,8 @@ public class MessageExpirationIntegrationTest extends QpidJmsTestCase {
// Verify the other message is not there. Will drain to be sure there are no messages.
testPeer.expectLinkFlow(true, true, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_PREFETCH - 2)));
+ // Then reopen the credit window afterwards
+ testPeer.expectLinkFlow(false, false, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_PREFETCH)));
m = consumer.receive(10);
assertNull("Message should not have been received", m);
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/2a7e0e96/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/QueueBrowserIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/QueueBrowserIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/QueueBrowserIntegrationTest.java
index f0a567e..641a8bd 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/QueueBrowserIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/QueueBrowserIntegrationTest.java
@@ -117,10 +117,13 @@ public class QueueBrowserIntegrationTest extends QpidJmsTestCase {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("myQueue");
- // Expected the browser to create a consumer and send credit, then drain it.
+ // Expected the browser to create a consumer and send credit, then drain it when
+ // no message is there to satisfy an internal hasMoreElements check, then send more
+ // credit to reopen a window.
testPeer.expectQueueBrowserAttach();
testPeer.expectLinkFlow(false, false, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
testPeer.expectLinkFlow(true, true, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
+ testPeer.expectLinkFlow(false, false, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
testPeer.expectDetach(true, true, true);
QueueBrowser browser = session.createBrowser(queue);
@@ -128,7 +131,7 @@ public class QueueBrowserIntegrationTest extends QpidJmsTestCase {
assertNotNull(queueView);
try {
- assertNull(queueView.nextElement());
+ queueView.nextElement();
fail("Should have thrown an exception due to there being no more elements");
} catch (NoSuchElementException nsee) {
// expected
@@ -200,7 +203,7 @@ public class QueueBrowserIntegrationTest extends QpidJmsTestCase {
// at which point we send one, and a response flow to indicate the rest of the credit was drained.
testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, amqpValueNullContent,
1, true, true, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)), 1, true, false);
- // Expect processing the ack to open the credit window again.
+ // Expect the credit window to be opened again.
testPeer.expectLinkFlow(false, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
testPeer.expectDetach(true, true, true);
@@ -235,7 +238,7 @@ public class QueueBrowserIntegrationTest extends QpidJmsTestCase {
// at which point we send one, and a response flow to indicate the rest of the credit was drained.
testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, amqpValueNullContent,
1, true, true, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)), 1, true, false);
- // Expect processing the ack to open the credit window again.
+ // Expect the credit window to be opened again.
testPeer.expectLinkFlow(false, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
testPeer.expectDetach(true, true, true);
@@ -268,30 +271,32 @@ public class QueueBrowserIntegrationTest extends QpidJmsTestCase {
DescribedType amqpValueNullContent = new AmqpValueDescribedType(null);
+ // Expect the browser enumeration to create a underlying consumer
testPeer.expectQueueBrowserAttach();
+ // Expect initial credit to be sent
testPeer.expectLinkFlow(false, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
+ // Then expect it to drain it when no message arrives before hasMoreElements is called,
+ // at which point we send one, and a response flow to indicate the rest of the credit was drained.
testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, amqpValueNullContent,
1, true, true, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)), 1, true, false);
+ // Expect a non-draining flow to reopen the credit window again afterwards
+ testPeer.expectLinkFlow(false, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
- // First expect an unsettled 'declare' transfer to the txn coordinator, and
+ // Expect an unsettled 'declare' transfer to the txn coordinator, and
// reply with a declared disposition state containing the txnId.
Binary txnId = new Binary(new byte[]{ (byte) 1, (byte) 2, (byte) 3, (byte) 4});
TransferPayloadCompositeMatcher declareMatcher = new TransferPayloadCompositeMatcher();
declareMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(new Declare()));
testPeer.expectTransfer(declareMatcher, nullValue(), false, new Declared().setTxnId(txnId), true);
- // Expected the browser to create a consumer and send credit, once hasMoreElements
- // is called a message that is received should be delivered when the session is in
- // a transacted session, the browser should not participate and close when asked.
- testPeer.expectLinkFlow();
- testPeer.expectDetach(true, true, true);
-
QueueBrowser browser = session.createBrowser(queue);
Enumeration<?> queueView = browser.getEnumeration();
assertNotNull(queueView);
assertTrue(queueView.hasMoreElements());
// Browser should close without delay as it does not participate in the TX
+ testPeer.expectDetach(true, true, true);
+
browser.close();
testPeer.waitForAllHandlersToComplete(3000);
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/2a7e0e96/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverIntegrationTest.java
index abe63f6..a52cc79 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverIntegrationTest.java
@@ -619,8 +619,9 @@ public class FailoverIntegrationTest extends QpidJmsTestCase {
finalPeer.expectBegin();
finalPeer.expectBegin();
finalPeer.expectQueueBrowserAttach();
- finalPeer.expectLinkFlow();
+ finalPeer.expectLinkFlow(false, false, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
finalPeer.expectLinkFlow(true, true, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
+ finalPeer.expectLinkFlow(false, false, equalTo(UnsignedInteger.valueOf(JmsPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH)));
finalPeer.expectDetach(true, true, true);
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org