def _queuemanager(self): """ Returns the configured L{QueueManager} instance to use. """ data_dir = os.path.join(os.getcwd(), 'data') if not os.path.exists(data_dir): os.makedirs(data_dir) configuration = {'qstore.sqlalchemy.url': 'sqlite:///data/coilmq.db'} engine = engine_from_config(configuration, 'qstore.sqlalchemy.') init_model(engine, drop=True) store = SAQueue() return QueueManager(store=store, subscriber_scheduler=FavorReliableSubscriberScheduler(), queue_scheduler=RandomQueueScheduler())
def _queuestore(self): """ Returns the configured L{QueueStore} instance to use. Can be overridden by subclasses that wish to change out any queue store parameters. @rtype: L{QueueStore} """ data_dir = os.path.join(os.getcwd(), 'data') if not os.path.exists(data_dir): os.makedirs(data_dir) configuration = {'qstore.sqlalchemy.url': 'sqlite:///data/coilmq.db'} engine = engine_from_config(configuration, 'qstore.sqlalchemy.') init_model(engine, drop=True) return SAQueue()
def setUp(self): engine = create_engine('sqlite:///:memory:', echo=True) init_model(engine) self.store = SAQueue()
class SAQueueTest(CommonQueueTest, unittest.TestCase): def setUp(self): engine = create_engine('sqlite:///:memory:', echo=True) init_model(engine) self.store = SAQueue() def tearDown(self): meta.Session.remove() def test_dequeue_order(self): """ Test the order that frames are returned by dequeue() method. """ dest = '/queue/foo' frame1 = Frame('MESSAGE', headers={'message-id': 'id-1'}, body='message-1') self.store.enqueue(dest, frame1) frame2 = Frame('MESSAGE', headers={'message-id': 'id-2'}, body='message-2') self.store.enqueue(dest, frame2) frame3 = Frame('MESSAGE', headers={'message-id': 'id-3'}, body='message-3') self.store.enqueue(dest, frame3) self.assertTrue(self.store.has_frames(dest)) self.assertEqual(self.store.size(dest), 3) # Perform some updates to change the expected order. sess = meta.Session() sess.execute(model.frames_table.update().where( model.frames_table.c.message_id == 'id-1').values( queued=datetime.datetime(2010, 1, 1))) sess.execute(model.frames_table.update().where( model.frames_table.c.message_id == 'id-2').values( queued=datetime.datetime(2009, 1, 1))) sess.execute(model.frames_table.update().where( model.frames_table.c.message_id == 'id-3').values( queued=datetime.datetime(2004, 1, 1))) sess.commit() rframe1 = self.store.dequeue(dest) assert frame3 == rframe1 rframe2 = self.store.dequeue(dest) assert frame2 == rframe2 rframe3 = self.store.dequeue(dest) assert frame1 == rframe3 assert self.store.has_frames(dest) == False assert self.store.size(dest) == 0
class SAQueueTest(unittest.TestCase, CommonQueueTestsMixin): def setUp(self): engine = create_engine('sqlite:///:memory:', echo=True) init_model(engine) self.store = SAQueue() def tearDown(self): print dir(meta.engine) meta.Session.remove() def test_dequeue_order(self): """ Test the order that frames are returned by dequeue() method. """ dest = '/queue/foo' frame1 = Frame('MESSAGE', headers={'message-id': 'id-1'}, body='message-1') self.store.enqueue(dest, frame1) frame2 = Frame('MESSAGE', headers={'message-id': 'id-2'}, body='message-2') self.store.enqueue(dest, frame2) frame3 = Frame('MESSAGE', headers={'message-id': 'id-3'}, body='message-3') self.store.enqueue(dest, frame3) assert self.store.has_frames(dest) == True assert self.store.size(dest) == 3 # Perform some updates to change the expected order. sess = meta.Session() sess.execute(model.frames_table.update().where(model.frames_table.c.message_id=='id-1').values(queued=datetime.datetime(2010, 01, 01))) sess.execute(model.frames_table.update().where(model.frames_table.c.message_id=='id-2').values(queued=datetime.datetime(2009, 01, 01))) sess.execute(model.frames_table.update().where(model.frames_table.c.message_id=='id-3').values(queued=datetime.datetime(2004, 01, 01))) sess.commit() rframe1 = self.store.dequeue(dest) assert frame3 == rframe1 rframe2 = self.store.dequeue(dest) assert frame2 == rframe2 rframe3 = self.store.dequeue(dest) assert frame1 == rframe3 assert self.store.has_frames(dest) == False assert self.store.size(dest) == 0
class SAQueueTest(CommonQueueTest, unittest.TestCase): def setUp(self): engine = create_engine("sqlite:///:memory:", echo=True) init_model(engine) self.store = SAQueue() def tearDown(self): meta.Session.remove() def test_dequeue_order(self): """ Test the order that frames are returned by dequeue() method. """ dest = "/queue/foo" frame1 = Frame("MESSAGE", headers={"message-id": "id-1"}, body="message-1") self.store.enqueue(dest, frame1) frame2 = Frame("MESSAGE", headers={"message-id": "id-2"}, body="message-2") self.store.enqueue(dest, frame2) frame3 = Frame("MESSAGE", headers={"message-id": "id-3"}, body="message-3") self.store.enqueue(dest, frame3) self.assertTrue(self.store.has_frames(dest)) self.assertEqual(self.store.size(dest), 3) # Perform some updates to change the expected order. sess = meta.Session() sess.execute( model.frames_table.update() .where(model.frames_table.c.message_id == "id-1") .values(queued=datetime.datetime(2010, 1, 1)) ) sess.execute( model.frames_table.update() .where(model.frames_table.c.message_id == "id-2") .values(queued=datetime.datetime(2009, 1, 1)) ) sess.execute( model.frames_table.update() .where(model.frames_table.c.message_id == "id-3") .values(queued=datetime.datetime(2004, 1, 1)) ) sess.commit() rframe1 = self.store.dequeue(dest) assert frame3 == rframe1 rframe2 = self.store.dequeue(dest) assert frame2 == rframe2 rframe3 = self.store.dequeue(dest) assert frame1 == rframe3 assert self.store.has_frames(dest) == False assert self.store.size(dest) == 0