Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
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"")
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)
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)
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
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)
def listen(state):
if state == KazooState.CONNECTED:
started.set()
return True
tzk.add_listener(listen)
def expire_session(self, event_factory):
"""Force ZK to expire a client session"""
self.__break_connection(_SESSION_EXPIRED, KazooState.LOST,
event_factory)
def listener(state):
if state == KazooState.LOST:
session_expired.set()
def state_watcher(state):
if state is KazooState.LOST:
self.assertTrue(getattr(self.holder, attribute))
state_watcher.disconnects += 1