How to use kazoo - 10 common examples

To help you get started, we’ve selected a few kazoo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github disqus / pgshovel / tests / integration.py View on Github external
def TemporaryZooKeeper():
    host = 'localhost:2181'
    path = 'pgshovel-test-%s' % (uuid.uuid1().hex,)

    zookeeper = KazooClient(host)
    zookeeper.start()
    zookeeper.create(path)
    zookeeper.stop()

    yield '/'.join((host, path))
github reddit / baseplate.py / tests / integration / live_data / writer_tests.py View on Github external
def setUp(self):
        self.zookeeper = KazooClient(hosts="%s:%d" % zookeeper_endpoint.address)
        self.zookeeper.start()

        try:
            self.zookeeper.delete(TEST_NODE_PATH)
        except NoNodeError:
            pass

        self.zookeeper.create(TEST_NODE_PATH, b"")
github wglass / lighthouse / tests / zookeeper_tests.py View on Github external
def test_report_down_no_such_node(self, mock_client):
        zk = ZookeeperDiscovery()
        zk.apply_config(
            {"hosts": ["zk01.int", "zk02.int"], "path": "/lighthouse"}
        )
        zk.connect()
        zk.connected.set()

        zk.client.delete.side_effect = exceptions.NoNodeError

        service = Mock(host="redis1")
        service.name = "webcache"

        zk.report_down(service, 6379)
github Nextdoor / ndserviceregistry / nd_service_registry / registration_tests.py View on Github external
def test_create_node_exists_error(self):
        self.zk.retry.side_effect = exceptions.NodeExistsError()
        self.reg._create_node()
        self.zk.retry.assert_called_once_with(
            self.zk.create,
            '/unittest/host:22',
            value=self.reg._encoded_data, ephemeral=False, makepath=False)
github zalando / patroni / tests / test_zookeeper.py View on Github external
def create(self, path, value=b"", acl=None, ephemeral=False, sequence=False, makepath=False):
        if not isinstance(path, six.string_types):
            raise TypeError("Invalid type for 'path' (string expected)")
        if not isinstance(value, (six.binary_type,)):
            raise TypeError("Invalid type for 'value' (must be a byte string)")
        if b'Exception' in value:
            raise Exception
        if path.endswith('/initialize') or path == '/service/test/optime/leader':
            raise Exception
        elif b'retry' in value or (b'exists' in value and self.exists):
            raise NodeExistsError
github disqus / pgshovel / tests / consumer / supervisor.py View on Github external
def test_supervisor_collision(application, database):
    setup_application(application, database)

    zookeeper = application.environment.zookeeper

    path = application.get_consumer_group_membership_path(consumer_group_identifier)

    zookeeper.ensure_path(path())
    zookeeper.create(path(consumer_identifier))
    with pytest.raises(NodeExistsError):
        supervisor = Supervisor(application, consumer_group_identifier, consumer_identifier, DummyHandler())
        supervisor.start()
        supervisor.result(5)
github twitter-archive / commons / tests / python / twitter / common / zookeeper / group / test_kazoo_group.py View on Github external
def listen(state):
      if state == KazooState.CONNECTED:
        started.set()
      return True
    tzk.add_listener(listen)
github python-zk / kazoo / kazoo / testing / harness.py View on Github external
def expire_session(self, event_factory):
        """Force ZK to expire a client session"""
        self.__break_connection(_SESSION_EXPIRED, KazooState.LOST,
                                event_factory)
github disqus / menagerie / tests / tests.py View on Github external
def state_watcher(state):
            if state is KazooState.LOST:
                self.assertTrue(getattr(self.holder, attribute))
                state_watcher.disconnects += 1