Ejemplo n.º 1
0
    def test_notifies_watchers_when_children_are_added(self):
        mock_zk = _mock_zk()

        mock_callback = Mock(name='monitor callback')

        def first_callback(*args, **kwargs):
            group.monitor(frozenset([Membership(1)]), mock_callback)

        group = ActiveKazooGroup(mock_zk, DEFAULT_PATH)
        group.monitor(callback=first_callback)

        members, _ = _happy_path(group, mock_zk, 1)

        mock_callback.assert_called_with(members)
Ejemplo n.º 2
0
    def test_notifies_watchers_when_children_are_added(self):
        mock_zk = _mock_zk()

        mock_callback = Mock(name="monitor callback")

        def first_callback(*args, **kwargs):
            group.monitor(frozenset([Membership(1)]), mock_callback)

        group = ActiveKazooGroup(mock_zk, DEFAULT_PATH)
        group.monitor(callback=first_callback)

        members, _ = _happy_path(group, mock_zk, 1)

        mock_callback.assert_called_with(members)
Ejemplo n.º 3
0
    def test_notifies_watchers_when_children_are_removed(self):
        mock_zk = _mock_zk()

        mock_callback = Mock(name='monitor callback')

        def devnull(*args, **kwargs):
            pass

        group = ActiveKazooGroup(mock_zk, DEFAULT_PATH)
        group.monitor(frozenset([]), mock_callback)

        members, completion_callback = _happy_path(group, mock_zk, 2)

        member_remaining, member_removed = list(members)
        znode_member_id = ActiveKazooGroup.id_to_znode(member_remaining.id)
        mock_get_children_result = Mock(name='mock get children async result')
        mock_get_children_result.get = Mock(return_value=[znode_member_id])

        completion_callback(mock_get_children_result)

        assert member_removed not in group._members

        mock_callback.assert_called_with(set([member_remaining]))
Ejemplo n.º 4
0
    def test_notifies_watchers_when_children_are_removed(self):
        mock_zk = _mock_zk()

        mock_callback = Mock(name="monitor callback")

        def devnull(*args, **kwargs):
            pass

        group = ActiveKazooGroup(mock_zk, DEFAULT_PATH)
        group.monitor(frozenset([]), mock_callback)

        members, completion_callback = _happy_path(group, mock_zk, 2)

        member_remaining, member_removed = list(members)
        znode_member_id = ActiveKazooGroup.id_to_znode(member_remaining.id)
        mock_get_children_result = Mock(name="mock get children async result")
        mock_get_children_result.get = Mock(return_value=[znode_member_id])

        completion_callback(mock_get_children_result)

        assert member_removed not in group._members

        mock_callback.assert_called_with(set([member_remaining]))