summaryrefslogtreecommitdiff
path: root/java/broker/src/test
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2011-11-11 10:16:47 +0000
committerRobert Gemmell <robbie@apache.org>2011-11-11 10:16:47 +0000
commita1f730067b3be09080327ac05312eeb6da47297b (patch)
tree067c28d9b775ca11c3409d56427dc926bc356323 /java/broker/src/test
parent9da016b7e810e054bb2b0cf21bf1ad5573c97d4b (diff)
downloadqpid-python-a1f730067b3be09080327ac05312eeb6da47297b.tar.gz
QPID-3592: ensure that the 'used credit' values are decremented when message transfer commands 'completed' following a message.stop command attempt to restore their credit (to no effect due to the 0 credit limit) when using 0-10 Window credit mode. Add unit test, and break CreditManager dependency on ServerMessages by passing the required size value rather than the message itself.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1200801 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/broker/src/test')
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/flow/WindowCreditManagerTest.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/java/broker/src/test/java/org/apache/qpid/server/flow/WindowCreditManagerTest.java b/java/broker/src/test/java/org/apache/qpid/server/flow/WindowCreditManagerTest.java
new file mode 100644
index 0000000000..61a9e0b446
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/flow/WindowCreditManagerTest.java
@@ -0,0 +1,63 @@
+package org.apache.qpid.server.flow;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class WindowCreditManagerTest extends QpidTestCase
+{
+ WindowCreditManager _creditManager;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _creditManager = new WindowCreditManager();
+ }
+
+ /**
+ * Tests that after the credit limit is cleared (e.g. from a message.stop command), credit is
+ * restored (e.g. from completed MessageTransfer) without increasing the available credit, and
+ * more credit is added, that the 'used' count is correct and the proper values for bytes
+ * and message credit are returned along with appropriate 'hasCredit' results (QPID-3592).
+ */
+ public void testRestoreCreditDecrementsUsedCountAfterCreditClear()
+ {
+ assertEquals("unexpected credit value", 0, _creditManager.getMessageCredit());
+ assertEquals("unexpected credit value", 0, _creditManager.getBytesCredit());
+
+ //give some message credit
+ _creditManager.addCredit(1, 0);
+ assertFalse("Manager should not 'haveCredit' due to having 0 bytes credit", _creditManager.hasCredit());
+ assertEquals("unexpected credit value", 1, _creditManager.getMessageCredit());
+ assertEquals("unexpected credit value", 0, _creditManager.getBytesCredit());
+
+ //give some bytes credit
+ _creditManager.addCredit(0, 1);
+ assertTrue("Manager should 'haveCredit'", _creditManager.hasCredit());
+ assertEquals("unexpected credit value", 1, _creditManager.getMessageCredit());
+ assertEquals("unexpected credit value", 1, _creditManager.getBytesCredit());
+
+ //use all the credit
+ _creditManager.useCreditForMessage(1);
+ assertEquals("unexpected credit value", 0, _creditManager.getBytesCredit());
+ assertEquals("unexpected credit value", 0, _creditManager.getMessageCredit());
+ assertFalse("Manager should not 'haveCredit'", _creditManager.hasCredit());
+
+ //clear credit out (eg from a message.stop command)
+ _creditManager.clearCredit();
+ assertEquals("unexpected credit value", 0, _creditManager.getBytesCredit());
+ assertEquals("unexpected credit value", 0, _creditManager.getMessageCredit());
+ assertFalse("Manager should not 'haveCredit'", _creditManager.hasCredit());
+
+ //restore credit (e.g the original message transfer command got completed)
+ //this should not increase credit, because it is now limited to 0
+ _creditManager.restoreCredit(1, 1);
+ assertEquals("unexpected credit value", 0, _creditManager.getBytesCredit());
+ assertEquals("unexpected credit value", 0, _creditManager.getMessageCredit());
+ assertFalse("Manager should not 'haveCredit'", _creditManager.hasCredit());
+
+ //give more credit to open the window again
+ _creditManager.addCredit(1, 1);
+ assertEquals("unexpected credit value", 1, _creditManager.getBytesCredit());
+ assertEquals("unexpected credit value", 1, _creditManager.getMessageCredit());
+ assertTrue("Manager should 'haveCredit'", _creditManager.hasCredit());
+ }
+}