コード例 #1
0
ファイル: tests.py プロジェクト: hujunfei/samsa
    def test_initial_configuration(self, cw):
        nodes = ['0', '1', '2', '5']

        with mock.patch('samsa.brokers.DataWatch'):
            brokers = BrokerMap(self.cluster)
            brokers._configure(nodes)
        self.assertEqual(len(brokers), len(nodes))
        self.assertEqual(brokers.keys(), map(int, nodes))
        self.assertTrue(all(isinstance(value, Broker) for value
            in brokers.values()))
コード例 #2
0
ファイル: tests.py プロジェクト: NorthIsUp/samsa
    def test_update_configuration(self):
        nodes = ['0', '1']
        self.cluster.zookeeper.get_children.return_value = nodes
        brokers = BrokerMap(self.cluster)
        self.assertEqual(len(brokers), len(nodes))

        broker = brokers.get(1)

        # Emulate a broker entering the pool.
        nodes = ['0', '1', '2']
        self.cluster.zookeeper.get_children.return_value = nodes
        brokers._configure(event=mock.Mock())
        self.assertEqual(len(brokers), len(nodes))

        self.assertIs(broker, brokers.get(1))
        self.assertFalse(broker.is_dead)

        # Emulate a broker leaving the pool.
        nodes = ['0', '2']
        self.cluster.zookeeper.get_children.return_value = nodes
        brokers._configure(event=mock.Mock())
        self.assertEqual(len(brokers), len(nodes))

        self.assertTrue(broker.is_dead)
        with self.assertRaises(KeyError):
            brokers.get(1)
コード例 #3
0
ファイル: tests.py プロジェクト: NorthIsUp/samsa
    def test_initial_configuration(self):
        nodes = ['0', '1', '2', '5']
        self.cluster.zookeeper.get_children.return_value = nodes

        brokers = BrokerMap(self.cluster)
        self.assertEqual(len(brokers), len(nodes))
        self.assertEqual(brokers.keys(), map(int, nodes))
        self.assertTrue(all(isinstance(value, Broker) for value
            in brokers.values()))

        self.assertEqual(self.cluster.zookeeper.get_children.call_count, 1)
コード例 #4
0
ファイル: cluster.py プロジェクト: KevinGetandGive/samsa
    def __init__(self, zookeeper, handler=None):
        if not zookeeper.connected:
            raise Exception("Zookeeper must be connected before use.")

        self.zookeeper = zookeeper

        if not handler:
            handler = ThreadingHandler()
        self.handler = handler

        self.brokers = BrokerMap(self)
        self.topics = TopicMap(self)
コード例 #5
0
    def test_initial_configuration(self, cw):
        nodes = ['0', '1', '2', '5']

        with mock.patch('samsa.brokers.DataWatch'):
            brokers = BrokerMap(self.cluster)
            brokers._configure(nodes)
        self.assertEqual(len(brokers), len(nodes))
        self.assertEqual(brokers.keys(), map(int, nodes))
        self.assertTrue(
            all(isinstance(value, Broker) for value in brokers.values()))
コード例 #6
0
    def test_update_configuration(self, w1, w2):
        nodes = ['0', '1']
        brokers = BrokerMap(self.cluster)
        brokers._configure(nodes)
        self.assertEqual(len(brokers), len(nodes))

        broker = brokers.get(1)

        # Emulate a broker entering the pool.
        nodes = ['0', '1', '2']
        self.cluster.zookeeper.get_children.return_value = nodes
        brokers._configure(nodes)
        self.assertEqual(len(brokers), len(nodes))

        self.assertIs(broker, brokers.get(1))
        self.assertFalse(broker.is_dead)

        # Emulate a broker leaving the pool.
        nodes = ['0', '2']
        brokers._configure(nodes)
        self.assertEqual(len(brokers), len(nodes))

        self.assertTrue(broker.is_dead)
        with self.assertRaises(KeyError):
            brokers.get(1)
コード例 #7
0
    def test_configuration_no_node(self, cw):
        cw.side_effect = NoNodeException

        with self.assertRaises(ImproperlyConfiguredError):
            BrokerMap(self.cluster)
コード例 #8
0
ファイル: tests.py プロジェクト: NorthIsUp/samsa
    def test_configuration_no_node(self):
        self.cluster.zookeeper.get_children.side_effect = NoNodeException

        brokers = BrokerMap(self.cluster)
        with self.assertRaises(ImproperlyConfiguredError):
            brokers.get(0)