Ejemplo n.º 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()
Ejemplo n.º 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]
        channel = yield self.messaging.new_channel(agent)

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

        self.assertIsInstance(client, messaging.MessagingClient)
        binding = channel.bind(agent.get_agent_id())
        yield binding.wait_created()

        d = self.cb_after(None, agent, 'on_message')
        channel.post(self._agent(0), m('something'))
        yield d

        self.assertEqual(1, len(agent.messages))
Ejemplo n.º 3
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))
Ejemplo n.º 4
0
    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.new_channel(self.web)
        pb = self.connection.bind(self.web.get_agent_id(), 'exchange')
        yield pb.wait_created()

        # setup our agent
        yield common.SimulationTest.setUp(self)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    def setUp(self):
        self.assert_not_skipped()
        # run rabbitmq
        yield self.run_rabbit()

        # get connection faking the web team listening
        self.server = net.RabbitMQ('127.0.0.1',
                                   self.rabbit.get_config()['port'])
        yield self.server.connect()
        self.web = StubAgent()
        self.connection = self.server.new_channel(self.web,
                                                  self.web.get_agent_id())
        yield self.connection.initiate()
        pb = self.connection.bind('exchange', self.web.get_agent_id())
        yield pb.wait_created()

        # setup our agent
        yield common.SimulationTest.setUp(self)
Ejemplo n.º 7
0
class TestWithRabbit(common.SimulationTest):

    timeout = 20

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

        # get connection faking the web team listening
        self.server = net.RabbitMQ('127.0.0.1',
                                   self.rabbit.get_config()['port'])
        yield self.server.connect()
        self.web = StubAgent()
        self.connection = self.server.new_channel(self.web,
                                                  self.web.get_agent_id())
        yield self.connection.initiate()
        pb = self.connection.bind('exchange', self.web.get_agent_id())
        yield pb.wait_created()

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

    @defer.inlineCallbacks
    def prolog(self):
        setup = format_block("""
        spawn_agency(start_host=False, \
                     'feat.agents.base.amqp.interface.IAMQPClientFactory')
        agency = _
        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 = first(self.driver.iter_agents('test-agent'))

    @defer.inlineCallbacks
    def tearDown(self):
        yield self.agent.terminate()
        yield self.wait_for_idle(80)
        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_agent_id())
        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()