summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qpid/cpp/src/qpid/broker/MessageHandlerImpl.cpp2
-rw-r--r--qpid/cpp/src/qpid/framing/SequenceNumberSet.cpp16
-rw-r--r--qpid/cpp/src/tests/SequenceNumberTest.cpp48
-rw-r--r--qpid/python/tests_0-10/message.py12
4 files changed, 70 insertions, 8 deletions
diff --git a/qpid/cpp/src/qpid/broker/MessageHandlerImpl.cpp b/qpid/cpp/src/qpid/broker/MessageHandlerImpl.cpp
index 87b23102e2..b12910893a 100644
--- a/qpid/cpp/src/qpid/broker/MessageHandlerImpl.cpp
+++ b/qpid/cpp/src/qpid/broker/MessageHandlerImpl.cpp
@@ -198,7 +198,7 @@ void MessageHandlerImpl::acquire(const SequenceNumberSet& transfers, u_int8_t /*
//TODO: implement mode
SequenceNumberSet results;
- RangedOperation op = boost::bind(&SemanticState::acquire, &state, _1, _2, results);
+ RangedOperation op = boost::bind(&SemanticState::acquire, &state, _1, _2, boost::ref(results));
transfers.processRanges(op);
results = results.condense();
getProxy().getMessage().acquired(results);
diff --git a/qpid/cpp/src/qpid/framing/SequenceNumberSet.cpp b/qpid/cpp/src/qpid/framing/SequenceNumberSet.cpp
index b769befeb7..afab9033e5 100644
--- a/qpid/cpp/src/qpid/framing/SequenceNumberSet.cpp
+++ b/qpid/cpp/src/qpid/framing/SequenceNumberSet.cpp
@@ -48,14 +48,20 @@ SequenceNumberSet SequenceNumberSet::condense() const
{
SequenceNumberSet result;
const_iterator last = end();
+ const_iterator start = end();
for (const_iterator i = begin(); i != end(); i++) {
- if (last == end()) {
- last = i;
+ if (start == end()) {
+ start = i;
} else if (*i - *last > 1) {
- result.push_back(*last);
- result.push_back(*i);
- last = end();
+ result.push_back(*start);
+ result.push_back(*last);
+ start = i;
}
+ last = i;
+ }
+ if (start != end()) {
+ result.push_back(*start);
+ result.push_back(*last);
}
return result;
}
diff --git a/qpid/cpp/src/tests/SequenceNumberTest.cpp b/qpid/cpp/src/tests/SequenceNumberTest.cpp
index 941eb9bf2e..d227b78323 100644
--- a/qpid/cpp/src/tests/SequenceNumberTest.cpp
+++ b/qpid/cpp/src/tests/SequenceNumberTest.cpp
@@ -22,6 +22,7 @@
#include "qpid_test_plugin.h"
#include <iostream>
#include "qpid/framing/SequenceNumber.h"
+#include "qpid/framing/SequenceNumberSet.h"
using namespace qpid::framing;
@@ -31,6 +32,9 @@ class SequenceNumberTest : public CppUnit::TestCase
CPPUNIT_TEST(testIncrementPostfix);
CPPUNIT_TEST(testIncrementPrefix);
CPPUNIT_TEST(testWrapAround);
+ CPPUNIT_TEST(testCondense);
+ CPPUNIT_TEST(testCondenseSingleRange);
+ CPPUNIT_TEST(testCondenseSingleItem);
CPPUNIT_TEST(testDifference);
CPPUNIT_TEST(testDifferenceWithWrapAround1);
CPPUNIT_TEST(testDifferenceWithWrapAround2);
@@ -112,6 +116,50 @@ class SequenceNumberTest : public CppUnit::TestCase
CPPUNIT_ASSERT(++a > b);
}
+ void testCondense()
+ {
+ SequenceNumberSet set;
+ for (uint i = 0; i < 6; i++) {
+ set.push_back(SequenceNumber(i));
+ }
+ set.push_back(SequenceNumber(7));
+ for (uint i = 9; i < 13; i++) {
+ set.push_back(SequenceNumber(i));
+ }
+ set.push_back(SequenceNumber(13));
+ SequenceNumberSet actual = set.condense();
+
+ SequenceNumberSet expected;
+ expected.addRange(SequenceNumber(0), SequenceNumber(5));
+ expected.addRange(SequenceNumber(7), SequenceNumber(7));
+ expected.addRange(SequenceNumber(9), SequenceNumber(13));
+ CPPUNIT_ASSERT_EQUAL(expected, actual);
+ }
+
+ void testCondenseSingleRange()
+ {
+ SequenceNumberSet set;
+ for (uint i = 0; i < 6; i++) {
+ set.push_back(SequenceNumber(i));
+ }
+ SequenceNumberSet actual = set.condense();
+
+ SequenceNumberSet expected;
+ expected.addRange(SequenceNumber(0), SequenceNumber(5));
+ CPPUNIT_ASSERT_EQUAL(expected, actual);
+ }
+
+ void testCondenseSingleItem()
+ {
+ SequenceNumberSet set;
+ set.push_back(SequenceNumber(1));
+ SequenceNumberSet actual = set.condense();
+
+ SequenceNumberSet expected;
+ expected.addRange(SequenceNumber(1), SequenceNumber(1));
+ CPPUNIT_ASSERT_EQUAL(expected, actual);
+ }
+
void testDifference()
{
SequenceNumber a;
diff --git a/qpid/python/tests_0-10/message.py b/qpid/python/tests_0-10/message.py
index 8212c7be67..0fcc38caa0 100644
--- a/qpid/python/tests_0-10/message.py
+++ b/qpid/python/tests_0-10/message.py
@@ -571,11 +571,19 @@ class MessageTests(TestBase):
self.subscribe(queue = "q", destination = "a", acquire_mode = 1, confirm_mode = 1)
msg = self.client.queue("a").get(timeout = 1)
- channel.message_acquire([msg.command_id, msg.command_id])
- msg.complete()
+ #message should still be on the queue:
+ self.assertEquals(1, channel.queue_query(queue = "q").message_count)
+ channel.message_acquire([msg.command_id, msg.command_id])
+ #check that we get notification (i.e. message_acquired)
+ response = channel.control_queue.get(timeout=1)
+ self.assertEquals(response.transfers, [msg.command_id, msg.command_id])
#message should have been removed from the queue:
self.assertEquals(0, channel.queue_query(queue = "q").message_count)
+ msg.complete()
+
+
+
def test_release(self):
"""