Back to index

rabbitmq-server  2.8.4
Public Member Functions | Public Attributes
ack.TestAck Class Reference
Inheritance diagram for ack.TestAck:
Inheritance graph
[legend]
Collaboration diagram for ack.TestAck:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_ack_client
def test_ack_client_individual
def test_ack_client_tx
def test_topic_prefetch
def test_nack
def test_nack_multi
def create_connection
def create_subscriber_connection
def setUp
def tearDown
def simple_test_send_rec
def assertListener
def assertListenerAfter

Public Attributes

 conn
 listener

Detailed Description

Definition at line 6 of file ack.py.


Member Function Documentation

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 8 of file ack.py.

00008 
00009     def test_ack_client(self):
00010         d = "/queue/ack-test"
00011 
00012         # subscribe and send message
00013         self.listener.reset(2) ## expecting 2 messages
00014         self.conn.subscribe(destination=d, ack='client',
00015                             headers={'prefetch-count': '10'})
00016         self.conn.send("test1", destination=d)
00017         self.conn.send("test2", destination=d)
00018         self.assertTrue(self.listener.await(4), "initial message not received")
00019         self.assertEquals(2, len(self.listener.messages))
00020 
00021         # disconnect with no ack
00022         self.conn.disconnect()
00023 
00024         # now reconnect
00025         conn2 = self.create_connection()
00026         try:
00027             listener2 = base.WaitableListener()
00028             listener2.reset(2)
00029             conn2.set_listener('', listener2)
00030             conn2.subscribe(destination=d, ack='client',
00031                             headers={'prefetch-count': '10'})
00032             self.assertTrue(listener2.await(), "message not received again")
00033             self.assertEquals(2, len(listener2.messages))
00034 
00035             # now ack only the last message - expecting cumulative behaviour
00036             mid = listener2.messages[1]['headers']['message-id']
00037             conn2.ack({'message-id':mid})
00038         finally:
00039             conn2.stop()
00040 
00041         # now reconnect again, shouldn't see the message
00042         conn3 = self.create_connection()
00043         try:
00044             listener3 = base.WaitableListener()
00045             conn3.set_listener('', listener3)
00046             conn3.subscribe(destination=d)
00047             self.assertFalse(listener3.await(3),
00048                              "unexpected message. ACK not working?")
00049         finally:
00050             conn3.stop()

Here is the call graph for this function:

Definition at line 51 of file ack.py.

00051 
00052     def test_ack_client_individual(self):
00053         d = "/queue/ack-test-individual"
00054 
00055         # subscribe and send message
00056         self.listener.reset(2) ## expecting 2 messages
00057         self.conn.subscribe(destination=d, ack='client-individual',
00058                             headers={'prefetch-count': '10'})
00059         self.conn.send("test1", destination=d)
00060         self.conn.send("test2", destination=d)
00061         self.assertTrue(self.listener.await(4), "Both initial messages not received")
00062         self.assertEquals(2, len(self.listener.messages))
00063 
00064         # disconnect without acks
00065         self.conn.disconnect()
00066 
00067         # now reconnect
00068         conn2 = self.create_connection()
00069         try:
00070             listener2 = base.WaitableListener()
00071             listener2.reset(2) ## expect 2 messages
00072             conn2.set_listener('', listener2)
00073             conn2.subscribe(destination=d, ack='client-individual',
00074                             headers={'prefetch-count': '10'})
00075             self.assertTrue(listener2.await(2.5), "Did not receive 2 messages")
00076             self.assertEquals(2, len(listener2.messages), "Not exactly 2 messages received")
00077 
00078             # now ack only the 'test2' message - expecting individual behaviour
00079             nummsgs = len(listener2.messages)
00080             mid = None
00081             for ind in range(nummsgs):
00082                 if listener2.messages[ind]['message']=="test2":
00083                     mid = listener2.messages[ind]['headers']['message-id']
00084                     self.assertEquals(1, ind, 'Expecting test2 to be second message')
00085                     break
00086             self.assertTrue(mid, "Did not find test2 message id.")
00087             conn2.ack({'message-id':mid})
00088         finally:
00089             conn2.stop()
00090 
00091         # now reconnect again, shouldn't see the message
00092         conn3 = self.create_connection()
00093         try:
00094             listener3 = base.WaitableListener()
00095             listener3.reset(2) ## expecting a single message, but wait for two
00096             conn3.set_listener('', listener3)
00097             conn3.subscribe(destination=d)
00098             self.assertFalse(listener3.await(2.5),
00099                              "Expected to see only one message. ACK not working?")
00100             self.assertEquals(1, len(listener3.messages), "Expecting exactly one message")
00101             self.assertEquals("test1", listener3.messages[0]['message'], "Unexpected message remains")
00102         finally:
00103             conn3.stop()

Here is the call graph for this function:

Definition at line 104 of file ack.py.

00104 
00105     def test_ack_client_tx(self):
00106         d = "/queue/ack-test-tx"
00107 
00108         # subscribe and send message
00109         self.listener.reset()
00110         self.conn.subscribe(destination=d, ack='client')
00111         self.conn.send("test", destination=d)
00112         self.assertTrue(self.listener.await(3), "initial message not received")
00113         self.assertEquals(1, len(self.listener.messages))
00114 
00115         # disconnect with no ack
00116         self.conn.disconnect()
00117 
00118         # now reconnect
00119         conn2 = self.create_connection()
00120         try:
00121             tx = "abc"
00122             listener2 = base.WaitableListener()
00123             conn2.set_listener('', listener2)
00124             conn2.begin(transaction=tx)
00125             conn2.subscribe(destination=d, ack='client')
00126             self.assertTrue(listener2.await(), "message not received again")
00127             self.assertEquals(1, len(listener2.messages))
00128 
00129             # now ack
00130             mid = listener2.messages[0]['headers']['message-id']
00131             conn2.ack({'message-id':mid, 'transaction':tx})
00132 
00133             #now commit
00134             conn2.commit(transaction=tx)
00135         finally:
00136             conn2.stop()
00137 
00138         # now reconnect again, shouldn't see the message
00139         conn3 = self.create_connection()
00140         try:
00141             listener3 = base.WaitableListener()
00142             conn3.set_listener('', listener3)
00143             conn3.subscribe(destination=d)
00144             self.assertFalse(listener3.await(3),
00145                              "unexpected message. TX ACK not working?")
00146         finally:
00147             conn3.stop()

Here is the call graph for this function:

def ack.TestAck.test_nack (   self)

Definition at line 163 of file ack.py.

00163 
00164     def test_nack(self):
00165         d = "/queue/nack-test"
00166 
00167         #subscribe and send
00168         self.conn.subscribe(destination=d, ack='client-individual')
00169         self.conn.send("nack-test", destination=d)
00170 
00171         self.assertTrue(self.listener.await(), "Not received message")
00172         message_id = self.listener.messages[0]['headers']['message-id']
00173         self.listener.reset()
00174 
00175         self.conn.send_frame("NACK", {"message-id" : message_id})
00176         self.assertTrue(self.listener.await(), "Not received message after NACK")
00177         message_id = self.listener.messages[0]['headers']['message-id']
00178         self.conn.ack({'message-id' : message_id})

Definition at line 179 of file ack.py.

00179 
00180     def test_nack_multi(self):
00181         d = "/queue/nack-multi"
00182 
00183         self.listener.reset(2)
00184 
00185         #subscribe and send
00186         self.conn.subscribe(destination=d, ack='client',
00187                             headers = {'prefetch-count' : '10'})
00188         self.conn.send("nack-test1", destination=d)
00189         self.conn.send("nack-test2", destination=d)
00190 
00191         self.assertTrue(self.listener.await(), "Not received messages")
00192         message_id = self.listener.messages[1]['headers']['message-id']
00193         self.listener.reset(2)
00194 
00195         self.conn.send_frame("NACK", {"message-id" : message_id})
00196         self.assertTrue(self.listener.await(), "Not received message again")
00197         message_id = self.listener.messages[1]['headers']['message-id']
00198         self.conn.ack({'message-id' : message_id})

Definition at line 148 of file ack.py.

00148 
00149     def test_topic_prefetch(self):
00150         d = "/topic/prefetch-test"
00151 
00152         # subscribe and send message
00153         self.listener.reset(6) ## expect 6 messages
00154         self.conn.subscribe(destination=d, ack='client',
00155                             headers={'prefetch-count': '5'})
00156 
00157         for x in range(10):
00158             self.conn.send("test" + str(x), destination=d)
00159 
00160         self.assertFalse(self.listener.await(3),
00161                          "Should not have been able to see 6 messages")
00162         self.assertEquals(5, len(self.listener.messages))


Member Data Documentation

base.BaseTest.conn [inherited]

Definition at line 27 of file base.py.

Definition at line 28 of file base.py.


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