Esempio n. 1
0
    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)
Esempio n. 2
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()))
Esempio n. 3
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()))
Esempio n. 4
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)