Back to index

rabbitmq-server  2.8.4
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
destinations.TestDurableSubscription Class Reference
Inheritance diagram for destinations.TestDurableSubscription:
Inheritance graph
[legend]
Collaboration diagram for destinations.TestDurableSubscription:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_durability
def test_share_subscription
def test_separate_ids
def test_durable_subscribe_no_id
def create_connection
def create_subscriber_connection
def setUp
def tearDown
def simple_test_send_rec
def assertListener
def assertListenerAfter

Public Attributes

 conn
 listener

Static Public Attributes

string ID = 'test.subscription'

Private Member Functions

def __subscribe
def __assert_receipt
def __assert_message

Detailed Description

Definition at line 325 of file destinations.py.


Member Function Documentation

def destinations.TestDurableSubscription.__assert_message (   self,
  msg,
  listener = None 
) [private]

Definition at line 347 of file destinations.py.

00347 
00348     def __assert_message(self, msg, listener=None):
00349         if not listener:
00350             listener = self.listener
00351 
00352         self.assertTrue(listener.await(5))
00353         self.assertEquals(1, len(listener.messages))
00354         self.assertEquals(msg, listener.messages[0]['message'])

Here is the caller graph for this function:

def destinations.TestDurableSubscription.__assert_receipt (   self,
  listener = None 
) [private]

Definition at line 340 of file destinations.py.

00340 
00341     def __assert_receipt(self, listener=None):
00342         if not listener:
00343             listener = self.listener
00344 
00345         self.assertTrue(listener.await(5))
00346         self.assertEquals(1, len(self.listener.receipts))

Here is the caller graph for this function:

def destinations.TestDurableSubscription.__subscribe (   self,
  dest,
  conn = None,
  id = None 
) [private]

Definition at line 329 of file destinations.py.

00329 
00330     def __subscribe(self, dest, conn=None, id=None):
00331         if not conn:
00332             conn = self.conn
00333         if not id:
00334             id = TestDurableSubscription.ID
00335 
00336         conn.subscribe(destination=dest,
00337                        headers    ={'persistent': 'true',
00338                                     'receipt': 1,
00339                                     'id': id})

Here is the caller graph for this function:

def base.BaseTest.assertListener (   self,
  errMsg,
  numMsgs = 0,
  numErrs = 0,
  numRcts = 0,
  timeout = 1 
) [inherited]

Definition at line 52 of file base.py.

00052 
00053    def assertListener(self, errMsg, numMsgs=0, numErrs=0, numRcts=0, timeout=1):
00054         if numMsgs + numErrs + numRcts > 0:
00055             self.assertTrue(self.listener.await(timeout), errMsg + " (#awaiting)")
00056         else:
00057             self.assertFalse(self.listener.await(timeout), errMsg + " (#awaiting)")
00058         self.assertEquals(numMsgs, len(self.listener.messages), errMsg + " (#messages)")
00059         self.assertEquals(numErrs, len(self.listener.errors), errMsg + " (#errors)")
00060         self.assertEquals(numRcts, len(self.listener.receipts), errMsg + " (#receipts)")

Here is the caller graph for this function:

def base.BaseTest.assertListenerAfter (   self,
  verb,
  errMsg = "",
  numMsgs = 0,
  numErrs = 0,
  numRcts = 0,
  timeout = 1 
) [inherited]

Definition at line 61 of file base.py.

00061 
00062    def assertListenerAfter(self, verb, errMsg="", numMsgs=0, numErrs=0, numRcts=0, timeout=1):
00063         num = numMsgs + numErrs + numRcts
00064         self.listener.reset(num if num>0 else 1)
00065         verb()
00066         self.assertListener(errMsg=errMsg, numMsgs=numMsgs, numErrs=numErrs, numRcts=numRcts, timeout=timeout)

Here is the call graph for this function:

Here is the caller graph for this function:

def base.BaseTest.create_connection (   self,
  version = None,
  heartbeat = None 
) [inherited]

Definition at line 9 of file base.py.

00009 
00010    def create_connection(self, version=None, heartbeat=None):
00011        conn = stomp.Connection(user="guest", passcode="guest",
00012                                version=version, heartbeat=heartbeat)
00013        conn.start()
00014        conn.connect()
00015        return conn

Here is the caller graph for this function:

def base.BaseTest.create_subscriber_connection (   self,
  dest 
) [inherited]

Definition at line 16 of file base.py.

00016 
00017    def create_subscriber_connection(self, dest):
00018        conn = self.create_connection()
00019        listener = WaitableListener()
00020        conn.set_listener('', listener)
00021        conn.subscribe(destination=dest, receipt="sub.receipt")
00022        listener.await()
00023        self.assertEquals(1, len(listener.receipts))
00024        listener.reset()
00025        return conn, listener

Here is the call graph for this function:

Here is the caller graph for this function:

def base.BaseTest.setUp (   self) [inherited]

Definition at line 26 of file base.py.

00026 
00027    def setUp(self):
00028         self.conn = self.create_connection()
00029         self.listener = WaitableListener()
00030         self.conn.set_listener('', self.listener)

def base.BaseTest.simple_test_send_rec (   self,
  dest,
  route = None 
) [inherited]

Definition at line 35 of file base.py.

00035 
00036    def simple_test_send_rec(self, dest, route = None):
00037         self.listener.reset()
00038 
00039         self.conn.subscribe(destination=dest)
00040         self.conn.send("foo", destination=dest)
00041 
00042         self.assertTrue(self.listener.await(), "Timeout, no message received")
00043 
00044         # assert no errors
00045         if len(self.listener.errors) > 0:
00046             self.fail(self.listener.errors[0]['message'])
00047 
00048         # check header content
00049         msg = self.listener.messages[0]
00050         self.assertEquals("foo", msg['message'])
00051         self.assertEquals(dest, msg['headers']['destination'])

Here is the caller graph for this function:

def base.BaseTest.tearDown (   self) [inherited]

Definition at line 31 of file base.py.

00031 
00032    def tearDown(self):
00033         if self.conn.is_connected():
00034             self.conn.stop()

Definition at line 355 of file destinations.py.

00355 
00356     def test_durability(self):
00357         d = '/topic/durable'
00358 
00359         self.__subscribe(d)
00360         self.__assert_receipt()
00361 
00362         # send first message without unsubscribing
00363         self.listener.reset(1)
00364         self.conn.send("first", destination=d)
00365         self.__assert_message("first")
00366 
00367         # now unsubscribe (disconnect only)
00368         self.conn.unsubscribe(id=TestDurableSubscription.ID)
00369 
00370         # send again
00371         self.listener.reset(1)
00372         self.conn.send("second", destination=d)
00373 
00374         # resubscribe and expect message
00375         self.__subscribe(d)
00376         self.__assert_message("second")
00377 
00378         # now unsubscribe (cancel)
00379         self.conn.unsubscribe(id=TestDurableSubscription.ID,
00380                               headers={'persistent': 'true'})
00381 
00382         # send again
00383         self.listener.reset(1)
00384         self.conn.send("third", destination=d)
00385 
00386         # resubscribe and expect no message
00387         self.__subscribe(d)
00388         self.assertTrue(self.listener.await(3))
00389         self.assertEquals(0, len(self.listener.messages))
00390         self.assertEquals(1, len(self.listener.receipts))

Here is the call graph for this function:

Definition at line 448 of file destinations.py.

00448 
00449     def test_durable_subscribe_no_id(self):
00450         d = '/topic/durable-invalid'
00451 
00452         self.conn.subscribe(destination=d, headers={'persistent':'true'}),
00453         self.listener.await(3)
00454         self.assertEquals(1, len(self.listener.errors))
00455         self.assertEquals("Missing Header", self.listener.errors[0]['headers']['message'])
00456 
00457 

Definition at line 415 of file destinations.py.

00415 
00416     def test_separate_ids(self):
00417         d = '/topic/durable-separate'
00418 
00419         conn2 = self.create_connection()
00420         listener2 = base.WaitableListener()
00421         conn2.set_listener('', listener2)
00422 
00423         try:
00424             # ensure durable subscription exists for each ID
00425             self.__subscribe(d)
00426             self.__assert_receipt()
00427             self.__subscribe(d, conn2, "other.id")
00428             self.__assert_receipt(listener2)
00429             self.conn.unsubscribe(id=TestDurableSubscription.ID)
00430             conn2.unsubscribe(id="other.id")
00431 
00432             self.listener.reset(101)
00433             listener2.reset(101) ## 100 messages and 1 receipt
00434 
00435             # send 100 messages
00436             for x in xrange(0, 100):
00437                 self.conn.send("msg" + str(x), destination=d)
00438 
00439             self.__subscribe(d)
00440             self.__subscribe(d, conn2, "other.id")
00441 
00442             for l in [self.listener, listener2]:
00443                 self.assertTrue(l.await(10))
00444                 self.assertEquals(100, len(l.messages))
00445 
00446         finally:
00447             conn2.stop()

Here is the call graph for this function:

Definition at line 391 of file destinations.py.

00391 
00392     def test_share_subscription(self):
00393         d = '/topic/durable-shared'
00394 
00395         conn2 = self.create_connection()
00396         conn2.set_listener('', self.listener)
00397 
00398         try:
00399             self.__subscribe(d)
00400             self.__assert_receipt()
00401             self.listener.reset(1)
00402             self.__subscribe(d, conn2)
00403             self.__assert_receipt()
00404 
00405             self.listener.reset(100)
00406 
00407             # send 100 messages
00408             for x in xrange(0, 100):
00409                 self.conn.send("msg" + str(x), destination=d)
00410 
00411             self.assertTrue(self.listener.await(5))
00412             self.assertEquals(100, len(self.listener.messages))
00413         finally:
00414             conn2.stop()

Here is the call graph for this function:


Member Data Documentation

base.BaseTest.conn [inherited]

Definition at line 27 of file base.py.

string destinations.TestDurableSubscription.ID = 'test.subscription' [static]

Definition at line 327 of file destinations.py.

Definition at line 28 of file base.py.


The documentation for this class was generated from the following file: