Back to index

rabbitmq-server  2.8.4
transactions.py
Go to the documentation of this file.
00001 import unittest
00002 import stomp
00003 import base
00004 import time
00005 
00006 class TestTransactions(base.BaseTest):
00007 
00008     def test_tx_commit(self):
00009         ''' Test TX with a COMMIT and ensure messages are delivered '''
00010         d = "/exchange/amq.fanout"
00011         tx = "test.tx"
00012 
00013         self.listener.reset()
00014         self.conn.subscribe(destination=d)
00015         self.conn.begin(transaction=tx)
00016         self.conn.send("hello!", destination=d, transaction=tx)
00017         self.conn.send("again!", destination=d)
00018 
00019         ## should see the second message
00020         self.assertTrue(self.listener.await(3))
00021         self.assertEquals(1, len(self.listener.messages))
00022         self.assertEquals("again!", self.listener.messages[0]['message'])
00023 
00024         ## now look for the first message
00025         self.listener.reset()
00026         self.conn.commit(transaction=tx)
00027         self.assertTrue(self.listener.await(3))
00028         self.assertEquals(1, len(self.listener.messages),
00029                           "Missing committed message")
00030         self.assertEquals("hello!", self.listener.messages[0]['message'])
00031 
00032     def test_tx_abort(self):
00033         ''' Test TX with an ABORT and ensure messages are discarded '''
00034         d = "/exchange/amq.fanout"
00035         tx = "test.tx"
00036 
00037         self.listener.reset()
00038         self.conn.subscribe(destination=d)
00039         self.conn.begin(transaction=tx)
00040         self.conn.send("hello!", destination=d, transaction=tx)
00041         self.conn.send("again!", destination=d)
00042 
00043         ## should see the second message
00044         self.assertTrue(self.listener.await(3))
00045         self.assertEquals(1, len(self.listener.messages))
00046         self.assertEquals("again!", self.listener.messages[0]['message'])
00047 
00048         ## now look for the first message to be discarded
00049         self.listener.reset()
00050         self.conn.abort(transaction=tx)
00051         self.assertFalse(self.listener.await(3))
00052         self.assertEquals(0, len(self.listener.messages),
00053                           "Unexpected committed message")
00054