Esempio n. 1
0
class AMQPCase(BaseTestCase):
    "Test AMQP messaging"

    def setUp(self):
        BaseTestCase.setUp(self)
        self.manager_oid = str(uuid.uuid1())
        self.manager = None
        self.node = None
        parameters = pika.ConnectionParameters('localhost')
        connection = pika.BlockingConnection(parameters)
        channel = connection.channel()
        channel.exchange_declare(exchange=options.rpc_exchange, 
                                 exchange_type='topic')
        channel.exchange_declare(exchange=options.reports_exchange, 
                                 exchange_type='topic')
        channel.queue_declare(queue=options.reports_queue)

        channel.queue_bind(queue=options.reports_queue, 
                           exchange=options.reports_exchange,
                           routing_key='#')
        
    def tearDown(self):
        parameters = pika.ConnectionParameters('localhost')
        connection = pika.BlockingConnection(parameters)
        channel = connection.channel()
        channel.queue_unbind(queue=options.reports_queue, 
                             exchange=options.reports_exchange,
                             routing_key='#')
        channel.exchange_delete(exchange=options.rpc_exchange)
        channel.exchange_delete(exchange=options.reports_exchange)
        channel.queue_delete(queue=options.reports_queue)

        BaseTestCase.tearDown(self)
        
    def set_manager(self, *args, **kw):
        kw['oid'] = self.manager_oid
        kw['io_loop']  = self.io_loop
        self.manager = ManagerAMQPClient(*args, **kw)
        self.manager.connect()

    def set_node(self, *args, **kw):
        kw['oid'] = self.node_oid
        kw['io_loop']  = self.io_loop
        self.node = NodeAMQPClient(*args, **kw)
        self.node.connect()

    def entity_from_json(self, json_str):
        "Return Entity instance for given json str"
        return Entity.from_json(json_str)
Esempio n. 2
0
 def set_manager(self, *args, **kw):
     kw['oid'] = self.manager_oid
     kw['io_loop']  = self.io_loop
     self.manager = ManagerAMQPClient(*args, **kw)
     self.manager.connect()