~xianghui/ubuntu/trusty/oslo.messaging/icehouse-lp1521958

« back to all changes in this revision

Viewing changes to tests/test_rabbit.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2014-03-27 13:01:34 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140327130134-va1pxzs253r43n15
Tags: 1.3.0~a9-0ubuntu1
* New upstream release (LP: #1298970)
* debian/control:
  - Add python-oslotest as a build dependency.
  - Use python-oslosphinx instead of python-oslo.sphinx

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
        self._driver.listen(self._target)
109
109
        self.assertEqual(self._server_params[0], self.expected)
110
110
 
 
111
    def test_transport_url_listen_for_notification(self):
 
112
        self._driver.listen_for_notifications(
 
113
            [(messaging.Target(topic='topic'), 'info')])
 
114
        self.assertEqual(self._server_params[0], self.expected)
 
115
 
111
116
    def test_transport_url_send(self):
112
117
        self._driver.send(self._target, {}, {})
113
118
        self.assertEqual(self._server_params[0], self.expected)
603
608
 
604
609
 
605
610
TestReplyWireFormat.generate_scenarios()
 
611
 
 
612
 
 
613
class RpcKombuHATestCase(test_utils.BaseTestCase):
 
614
 
 
615
    def test_reconnect_order(self):
 
616
        brokers = ['host1', 'host2', 'host3', 'host4', 'host5']
 
617
        brokers_count = len(brokers)
 
618
 
 
619
        self.conf.rabbit_hosts = brokers
 
620
        self.conf.rabbit_max_retries = 1
 
621
 
 
622
        info = {'attempt': 0}
 
623
 
 
624
        def _connect(myself, params):
 
625
            # do as little work that is enough to pass connection attempt
 
626
            myself.connection = kombu.connection.BrokerConnection(**params)
 
627
            myself.connection_errors = myself.connection.connection_errors
 
628
 
 
629
            expected_broker = brokers[info['attempt'] % brokers_count]
 
630
            self.assertEqual(params['hostname'], expected_broker)
 
631
 
 
632
            info['attempt'] += 1
 
633
 
 
634
        # just make sure connection instantiation does not fail with an
 
635
        # exception
 
636
        self.stubs.Set(rabbit_driver.Connection, '_connect', _connect)
 
637
 
 
638
        # starting from the first broker in the list
 
639
        connection = rabbit_driver.Connection(self.conf)
 
640
 
 
641
        # now that we have connection object, revert to the real 'connect'
 
642
        # implementation
 
643
        self.stubs.UnsetAll()
 
644
 
 
645
        for i in range(len(brokers)):
 
646
            self.assertRaises(driver_common.RPCException, connection.reconnect)
 
647
 
 
648
        connection.close()