示例#1
0
class TestWithRabbit(common.SimulationTest):

    timeout = 20

    @defer.inlineCallbacks
    def setUp(self):
        # run rabbitmq
        yield self.run_rabbit()

        # get connection faking the web team listening
        self.server = messaging.Messaging('127.0.0.1',
                                          self.rabbit.get_config()['port'])
        self.web = StubAgent()
        self.connection = yield self.server.get_connection(self.web)
        pb = self.connection.personal_binding(self.web.get_queue_name(),
                                              'exchange')
        yield pb.created

        # setup our agent
        yield common.SimulationTest.setUp(self)

    @defer.inlineCallbacks
    def prolog(self):
        setup = format_block("""
        spawn_agency('feat.agents.base.amqp.interface.IAMQPClientFactory')
        agency = _
        agency.disable_protocol('setup-monitoring', 'Task')
        descriptor_factory('test-agent')
        agency.start_agent(_, host='127.0.0.1', port=%(port)s, \
                           exchange=%(exchange)s, \
                           exchange_type=%(type)s)
        """) % dict(port=self.rabbit.get_config()['port'],
                    exchange="'exchange'", type="'direct'")
        yield self.process(setup)
        self.agent = list(self.driver.iter_agents())[0]

    @defer.inlineCallbacks
    def tearDown(self):
        yield self.agent.terminate()
        yield self.wait_for_idle(10)
        yield self.server.disconnect()
        yield self.rabbit.terminate()
        yield common.SimulationTest.tearDown(self)

    @defer.inlineCallbacks
    def testWebGetsMessage(self):
        cb = self.cb_after(None, self.web, 'on_message')
        yield self.agent.get_agent().push_msg(message.BaseMessage(),
                                              self.web.get_queue_name())
        yield cb
        self.assertIsInstance(self.web.messages[0], message.BaseMessage)

    @defer.inlineCallbacks
    def run_rabbit(self):
        try:
            self.rabbit = rabbitmq.Process(self)
        except DependencyError as e:
            raise SkipTest(str(e))

        yield self.rabbit.restart()
示例#2
0
    def testCreatingBindingsOnReadyConnection(self):
        '''
        Checks that creating personal binding after the connection
        has been initialized works the same as during initialization
        time.
        '''
        agent = StubAgent()
        self.agents = [agent]
        connection = yield self.messaging.get_connection(agent)

        # wait for connection to be established
        client = yield connection._messaging.factory.add_connection_made_cb()

        self.assertIsInstance(client, messaging.MessagingClient)
        binding = connection.personal_binding(agent.get_queue_name())
        yield binding.created

        d = self.cb_after(None, agent, 'on_message')
        connection.publish(message=m('something'), **self._agent(0))
        yield d

        self.assertEqual(1, len(agent.messages))