summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2010-03-05 00:50:57 +0000
committerRafael H. Schloming <rhs@apache.org>2010-03-05 00:50:57 +0000
commit74d838068a2a24423c0c5af1e33b612e132291fb (patch)
tree27be2452ae9eee044eae2b1c83cb69a8c35c4fbc
parent19b32fed3cd3ef014b5684eb31d2f866e869b65b (diff)
downloadqpid-python-74d838068a2a24423c0c5af1e33b612e132291fb.tar.gz
made drain work on messages as well as content
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@919251 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--python/qpid/tests/messaging/__init__.py40
-rw-r--r--python/qpid/tests/messaging/endpoints.py18
-rw-r--r--python/qpid/tests/messaging/message.py18
3 files changed, 44 insertions, 32 deletions
diff --git a/python/qpid/tests/messaging/__init__.py b/python/qpid/tests/messaging/__init__.py
index eb8ff87391..e47f8cb119 100644
--- a/python/qpid/tests/messaging/__init__.py
+++ b/python/qpid/tests/messaging/__init__.py
@@ -71,15 +71,45 @@ class Base(Test):
assert msg.content == content, "expected %r, got %r" % (content, msg.content)
def drain(self, rcv, limit=None, timeout=0, expected=None):
- contents = []
+ messages = []
try:
- while limit is None or len(contents) < limit:
- contents.append(rcv.fetch(timeout=timeout).content)
+ while limit is None or len(messages) < limit:
+ messages.append(rcv.fetch(timeout=timeout))
except Empty:
pass
if expected is not None:
- assert expected == contents, "expected %s, got %s" % (expected, contents)
- return contents
+ self.assertEchos(expected, messages)
+ return messages
+
+ def diff(self, m1, m2):
+ result = {}
+ for attr in ("id", "subject", "user_id", "to", "reply_to",
+ "correlation_id", "durable", "priority", "ttl",
+ "properties", "content_type", "content"):
+ a1 = getattr(m1, attr)
+ a2 = getattr(m2, attr)
+ if a1 != a2:
+ result[attr] = (a1, a2)
+ return result
+
+ def assertEcho(self, msg, echo):
+ if not isinstance(msg, Message) or not isinstance(echo, Message):
+ if isinstance(msg, Message):
+ msg = msg.content
+ if isinstance(echo, Message):
+ echo = echo.content
+ assert msg == echo, "expected %s, got %s" % (msg, echo)
+ else:
+ delta = self.diff(msg, echo)
+ mttl, ettl = delta.pop("ttl", (0, 0))
+ assert mttl is not None and ettl is not None, "%s, %s" % (mttl, ettl)
+ assert mttl >= ettl, "%s, %s" % (mttl, ettl)
+ assert not delta, "expected %s, got %s, delta %s" % (msg, echo, delta)
+
+ def assertEchos(self, msgs, echoes):
+ assert len(msgs) == len(echoes), "%s, %s" % (msgs, echoes)
+ for m, e in zip(msgs, echoes):
+ self.assertEcho(m, e)
def assertEmpty(self, rcv):
contents = self.drain(rcv)
diff --git a/python/qpid/tests/messaging/endpoints.py b/python/qpid/tests/messaging/endpoints.py
index 6bc52d962d..049413206b 100644
--- a/python/qpid/tests/messaging/endpoints.py
+++ b/python/qpid/tests/messaging/endpoints.py
@@ -255,10 +255,10 @@ class SessionTests(Base):
if commit:
txssn.commit()
self.assertEmpty(rcv)
- assert contents == self.drain(copy_rcv)
+ self.drain(copy_rcv, expected=contents)
else:
txssn.rollback()
- assert contents == self.drain(rcv)
+ self.drain(rcv, expected=contents)
self.assertEmpty(copy_rcv)
self.ssn.acknowledge()
@@ -277,7 +277,7 @@ class SessionTests(Base):
if commit:
txssn.commit()
- assert contents == self.drain(rcv)
+ self.drain(rcv, expected=contents)
self.ssn.acknowledge()
else:
txssn.rollback()
@@ -298,17 +298,16 @@ class SessionTests(Base):
txrcv = txssn.receiver(TX_ACK_QC)
self.assertEmpty(txrcv)
contents = self.send(self.ssn, TX_ACK_QC, "txTestAck", 3)
- assert contents == self.drain(txrcv)
+ self.drain(txrcv, expected=contents)
if commit:
txssn.acknowledge()
else:
txssn.rollback()
- drained = self.drain(txrcv)
- assert contents == drained, "expected %s, got %s" % (contents, drained)
+ self.drain(txrcv, expected=contents)
txssn.acknowledge()
txssn.rollback()
- assert contents == self.drain(txrcv)
+ self.drain(txrcv, expected=contents)
txssn.commit() # commit without ack
self.assertEmpty(txrcv)
@@ -316,7 +315,7 @@ class SessionTests(Base):
txssn = self.conn.session(transactional=True)
txrcv = txssn.receiver(TX_ACK_QC)
- assert contents == self.drain(txrcv)
+ self.drain(txrcv, expected=contents)
txssn.acknowledge()
txssn.commit()
rcv = self.ssn.receiver(TX_ACK_QD)
@@ -838,8 +837,7 @@ class SenderTests(Base):
msgs = [self.content("asyncTest", i) for i in range(15)]
for m in msgs:
self.snd.send(m, sync=False)
- drained = self.drain(self.rcv, timeout=self.delay())
- assert msgs == drained, "expected %s, got %s" % (msgs, drained)
+ self.drain(self.rcv, timeout=self.delay(), expected=msgs)
self.ssn.acknowledge()
def testSendAsyncCapacity0(self):
diff --git a/python/qpid/tests/messaging/message.py b/python/qpid/tests/messaging/message.py
index 2f2acc13c3..654076588b 100644
--- a/python/qpid/tests/messaging/message.py
+++ b/python/qpid/tests/messaging/message.py
@@ -68,23 +68,7 @@ class MessageEchoTests(Base):
def check(self, msg):
self.snd.send(msg)
echo = self.rcv.fetch(0)
-
- assert msg.id == echo.id
- assert msg.subject == echo.subject
- assert msg.user_id == echo.user_id
- assert msg.to == echo.to
- assert msg.reply_to == echo.reply_to
- assert msg.correlation_id == echo.correlation_id
- assert msg.durable == echo.durable
- assert msg.priority == echo.priority
- if msg.ttl is None:
- assert echo.ttl is None
- else:
- assert msg.ttl >= echo.ttl
- assert msg.properties == echo.properties
- assert msg.content_type == echo.content_type
- assert msg.content == echo.content, "%s, %s" % (msg, echo)
-
+ self.assertEcho(msg, echo)
self.ssn.acknowledge(echo)
def testStringContent(self):