Пример #1
0
class TestTidePool(mimic.MimicTestBase):
    """Don't test kazoo. Test the implementation of kazoo, though."""

    def setUp(self):
        super(TestTidePool, self).setUp()
        self.zk_session = FakeKazooClient()
        self.zk_session.start()
        self.tide_pool = TidePool(
            self.zk_session, 'bar', deferred_bind=True,
            connection_factory=FakeConnection
        )

    def test_bind_calls_DataWatch(self):
        self.mimic.replay_all()

        self.tide_pool.bind()

        self.assertTrue(
            self.tide_pool._data_watcher._watcher in
            self.zk_session._data_watchers['bar']
        )
        self.assertTrue(
            self.tide_pool._data_watcher._session_watcher in
            self.zk_session.state_listeners
        )

        self.tide_pool.unbind()

        self.assertTrue(
            self.tide_pool._data_watcher not in
            self.zk_session._data_watchers['bar']
        )

    def test_handle_znode_parent_change_calls_ChildrenWatch(self):
        # Stub out KazooClient
        self.mimic.stub_out_with_mock(self.zk_session, 'ChildrenWatch')

        self.zk_session.ChildrenWatch(
            self.tide_pool._znode_parent,
            func=self.tide_pool.set_hosts
        ).AndRaise(NoNodeError)

        self.mimic.replay_all()

        self.tide_pool._handle_znode_parent_change('herp,derp', {})
Пример #2
0
class TestTidePool(unittest.TestCase):
    """Don't test kazoo. Test the implementation of kazoo, though."""

    def setUp(self):
        super(TestTidePool, self).setUp()
        self.zk_session = FakeKazooClient()
        self.zk_session.start()
        self.tide_pool = TidePool(
            self.zk_session, 'bar', deferred_bind=True,
            connection_factory=FakeConnection
        )

    def test_bind_calls_DataWatch(self):
        self.tide_pool.bind()

        self.assertTrue(
            self.tide_pool._data_watcher._watcher in
            self.zk_session._data_watchers['bar']
        )
        self.assertTrue(
            self.tide_pool._data_watcher._session_watcher in
            self.zk_session.state_listeners
        )

        self.tide_pool.unbind()

        self.assertTrue(
            self.tide_pool._data_watcher not in
            self.zk_session._data_watchers['bar']
        )

    def test_handle_znode_parent_change_calls_ChildrenWatch(self):
        # Stub out KazooClient
        with patch.object(self.zk_session, 'ChildrenWatch') as mock_watch:
            mock_watch.side_effect = NoNodeError

            self.tide_pool._handle_znode_parent_change('herp,derp', {})

            mock_watch.assert_called_with(self.tide_pool._znode_parent,
                                          func=self.tide_pool.set_hosts)