def test_create_fixed_address(self):
     self.assert_create_ok(FIXED_ADDRESS, 'fixed1', dict(prefix='fixed1'))
     msgr = self.messenger()
     address = self.router.addresses[0]+'/fixed1'
     msgr.subscribe(address)
     msgr.put(message(address=address, body='hello'))
     self.assertEqual('hello', msgr.fetch().body)
    def test_create_connector_waypoint(self):
        """Test creating waypoint, connector and fixedAddress
        Create a waypoint that leads out and back from a second router.
        """
        conf = Qdrouterd.Config([
            ('router', {'mode': 'standalone', 'routerId': 'wp-router'}),
            ('listener', {'port':self.get_port(), 'role':'normal'}),
            ('fixedAddress', {'prefix':'foo'})
        ])
        wp_router = self.qdrouterd('wp-router', conf)
        wp_router.wait_ready()

        # Configure the router
        for c in [
                (FIXED_ADDRESS, 'a1', {'prefix':'foo', 'phase':0, 'fanout':'single', 'bias':'spread'}),
                (FIXED_ADDRESS, 'a2', {'prefix':'foo', 'phase':1, 'fanout':'single', 'bias':'spread'}),
                (CONNECTOR, 'wp_connector', {'addr': '127.0.0.1', 'port':str(wp_router.ports[0]), 'saslMechanisms': 'ANONYMOUS', 'role': 'on-demand'}),
                (WAYPOINT, 'wp', {'address': 'foo', 'inPhase': 0, 'outPhase': 1, 'connector': 'wp_connector'})
        ]:
            self.assert_create_ok(*c)
        assert retry(lambda: self.router.is_connected, wp_router.ports[0])

        # Verify the entities
        id = 'connector/127.0.0.1:%s' % wp_router.ports[0]
        connector = self.node.read(identity=id)
        self.assertEqual(
            [connector.name, connector.addr, connector.port, connector.role],
            ['wp_connector', '127.0.0.1', str(wp_router.ports[0]), 'on-demand'])

        # Pause to allow the waypoint to settle down
        sleep(1)

        # Send a message through self.router, verify it goes via wp_router
        address=self.router.addresses[0]+"/foo"
        mr = self.messenger()
        mr.subscribe(address)
        messages = ['a', 'b', 'c']
        for m in messages:
            mr.put(message(address=address, body=m)); mr.send()

        # Check messages arrived
        self.assertEqual(messages, [mr.fetch().body for i in messages])

        # Check log files to verify that the messages went via wp_router
        # TODO aconway 2014-07-07: should be able to check this via management
        # stats instead.
        try:
            f = open('wp-router.log')
            self.assertEqual(6, len(re.findall(r'MESSAGE.*to=.*/foo', f.read())))
        finally:
            f.close()
Ejemplo n.º 3
0
 def test_create_config_address_pattern(self):
     self.assert_create_ok(CONFIG_ADDRESS, 'patternAddr', dict(pattern='a.*.b'))
     self.assert_read_ok(CONFIG_ADDRESS, 'patternAddr',
                         dict(prefix=None, pattern='a.*.b'))
     msgr = self.messenger()
     address = self.router.addresses[0]+'/a.HITHERE.b'
     msgr.subscribe(address)
     msgr.put(message(address=address, body='hello'))
     self.assertEqual('hello', msgr.fetch().body)
     msgr.stop()
     del msgr
     self.node.delete(CONFIG_ADDRESS, name='patternAddr')
     self.assertRaises(NotFoundStatus, self.node.read,
                       type=CONFIG_ADDRESS, name='patternAddr')
 def test_create_config_address_pattern(self):
     self.assert_create_ok(CONFIG_ADDRESS, 'patternAddr',
                           dict(pattern='a.*.b'))
     self.assert_read_ok(CONFIG_ADDRESS, 'patternAddr',
                         dict(prefix=None, pattern='a.*.b'))
     msgr = self.messenger()
     address = self.router.addresses[0] + '/a.HITHERE.b'
     msgr.subscribe(address)
     msgr.put(message(address=address, body='hello'))
     self.assertEqual('hello', msgr.fetch().body)
     msgr.stop()
     del msgr
     self.node.delete(CONFIG_ADDRESS, name='patternAddr')
     self.assertRaises(NotFoundStatus,
                       self.node.read,
                       type=CONFIG_ADDRESS,
                       name='patternAddr')
        def verify_equal_spread(self, send_addresses, receive_addresses):
            """Verify we send/receive to the queue the load was spread over the brokers.
            Send to each of the send_addresses in turn, subscribe to all of the receive_addresses.
            """
            msgr = self.messenger()
            for a in receive_addresses:
                msgr.subscribe(a)
            msgr.flush()
            n = 20  # Messages per broker
            r = ["x-%02d" % i for i in range(n * len(self.qpidds))]
            for b, a in zip(r, cycle(send_addresses)):
                msgr.put(message(address=a, body=b))
            msgr.flush()
            messages = sorted(msgr.fetch().body for i in r)
            msgr.flush()
            self.assertEqual(r, messages)

            qs = [q.management.getQueue(self.testq) for q in self.qpidds]
            enq = sum(q.msgTotalEnqueues for q in qs)
            deq = sum(q.msgTotalDequeues for q in qs)
            self.assertEquals((enq, deq), (len(r), len(r)))
            # Verify each broker handled a reasonable share of the messages.
            self.assert_fair([q.msgTotalEnqueues for q in qs])
        def verify_equal_spread(self, send_addresses, receive_addresses):
            """Verify we send/receive to the queue the load was spread over the brokers.
            Send to each of the send_addresses in turn, subscribe to all of the receive_addresses.
            """
            msgr = self.messenger()
            for a in receive_addresses:
                msgr.subscribe(a)
            msgr.flush()
            n = 20                  # Messages per broker
            r = ["x-%02d"%i for i in range(n*len(self.qpidds))]
            for b, a in zip(r, cycle(send_addresses)):
                msgr.put(message(address=a, body=b))
            msgr.flush()
            messages = sorted(msgr.fetch().body for i in r)
            msgr.flush()
            self.assertEqual(r, messages)

            qs = [q.management.getQueue(self.testq) for q in self.qpidds]
            enq = sum(q.msgTotalEnqueues for q in qs)
            deq = sum(q.msgTotalDequeues for q in qs)
            self.assertEquals((enq, deq), (len(r), len(r)))
            # Verify each broker handled a reasonable share of the messages.
            self.assert_fair([q.msgTotalEnqueues for q in qs])
    def test_create_connector_waypoint(self):
        """Test creating waypoint, connector and fixedAddress
        Create a waypoint that leads out and back from a second router.
        """
        conf = Qdrouterd.Config([('router', {
            'mode': 'standalone',
            'routerId': 'wp-router'
        }), ('listener', {
            'port': self.get_port(),
            'role': 'normal'
        }), ('fixedAddress', {
            'prefix': 'foo'
        })])
        wp_router = self.qdrouterd('wp-router', conf)
        wp_router.wait_ready()

        # Configure the router
        for c in [(FIXED_ADDRESS, 'a1', {
                'prefix': 'foo',
                'phase': 0,
                'fanout': 'single',
                'bias': 'spread'
        }),
                  (FIXED_ADDRESS, 'a2', {
                      'prefix': 'foo',
                      'phase': 1,
                      'fanout': 'single',
                      'bias': 'spread'
                  }),
                  (CONNECTOR, 'wp_connector', {
                      'addr': '127.0.0.1',
                      'port': str(wp_router.ports[0]),
                      'saslMechanisms': 'ANONYMOUS',
                      'role': 'on-demand'
                  }),
                  (WAYPOINT, 'wp', {
                      'address': 'foo',
                      'inPhase': 0,
                      'outPhase': 1,
                      'connector': 'wp_connector'
                  })]:
            self.assert_create_ok(*c)
        assert retry(lambda: self.router.is_connected, wp_router.ports[0])

        # Verify the entities
        id = 'connector/127.0.0.1:%s' % wp_router.ports[0]
        connector = self.node.read(identity=id)
        self.assertEqual([
            connector.name, connector.addr, connector.port, connector.role
        ], ['wp_connector', '127.0.0.1',
            str(wp_router.ports[0]), 'on-demand'])

        # Pause to allow the waypoint to settle down
        sleep(1)

        # Send a message through self.router, verify it goes via wp_router
        address = self.router.addresses[0] + "/foo"
        mr = self.messenger()
        mr.subscribe(address)
        messages = ['a', 'b', 'c']
        for m in messages:
            mr.put(message(address=address, body=m))
            mr.send()

        # Check messages arrived
        self.assertEqual(messages, [mr.fetch().body for i in messages])

        # Check log files to verify that the messages went via wp_router
        # TODO aconway 2014-07-07: should be able to check this via management
        # stats instead.
        try:
            f = open('wp-router.log')
            self.assertEqual(6, len(re.findall(r'MESSAGE.*to=.*/foo',
                                               f.read())))
        finally:
            f.close()