ClickHouse/tests/integration/test_keeper_client/test.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

219 lines
6.6 KiB
Python
Raw Normal View History

import pytest
from helpers.cluster import ClickHouseCluster
2023-07-26 05:57:16 +00:00
from helpers.test_tools import TSV
2023-09-16 00:03:46 +00:00
from helpers.keeper_utils import KeeperClient, KeeperException
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance(
"node",
main_configs=["configs/keeper_config.xml"],
with_zookeeper=True,
stay_alive=True,
)
2023-07-28 06:09:57 +00:00
@pytest.fixture(scope="module", autouse=True)
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
@pytest.fixture(scope="function")
def client(started_cluster):
with KeeperClient.from_cluster(cluster, "zoo1") as keeper_client:
yield keeper_client
2023-07-26 15:13:53 +00:00
def test_big_family(client: KeeperClient):
client.touch("/test_big_family")
client.touch("/test_big_family/1")
client.touch("/test_big_family/1/1")
client.touch("/test_big_family/1/2")
client.touch("/test_big_family/1/3")
client.touch("/test_big_family/1/4")
client.touch("/test_big_family/1/5")
client.touch("/test_big_family/2")
client.touch("/test_big_family/2/1")
client.touch("/test_big_family/2/2")
client.touch("/test_big_family/2/3")
response = client.find_big_family("/test_big_family")
assert response == TSV(
2023-07-26 05:57:16 +00:00
[
["/test_big_family/1", "5"],
["/test_big_family/2", "3"],
["/test_big_family/2/3", "0"],
["/test_big_family/2/2", "0"],
["/test_big_family/2/1", "0"],
["/test_big_family/1/5", "0"],
["/test_big_family/1/4", "0"],
["/test_big_family/1/3", "0"],
["/test_big_family/1/2", "0"],
["/test_big_family/1/1", "0"],
]
)
response = client.find_big_family("/test_big_family", 1)
2023-07-26 05:57:16 +00:00
assert response == TSV(
[
2023-07-26 05:57:16 +00:00
["/test_big_family/1", "5"],
]
)
2023-07-26 05:57:16 +00:00
def test_find_super_nodes(client: KeeperClient):
client.touch("/test_find_super_nodes")
client.touch("/test_find_super_nodes/1")
client.touch("/test_find_super_nodes/1/1")
client.touch("/test_find_super_nodes/1/2")
client.touch("/test_find_super_nodes/1/3")
client.touch("/test_find_super_nodes/1/4")
client.touch("/test_find_super_nodes/1/5")
client.touch("/test_find_super_nodes/2")
client.touch("/test_find_super_nodes/2/1")
client.touch("/test_find_super_nodes/2/2")
client.touch("/test_find_super_nodes/2/3")
client.touch("/test_find_super_nodes/2/4")
client.cd("/test_find_super_nodes")
response = client.find_super_nodes(4)
assert response == TSV(
2023-07-26 05:57:16 +00:00
[
["/test_find_super_nodes/1", "5"],
["/test_find_super_nodes/2", "4"],
]
)
def test_delete_stale_backups(client: KeeperClient):
client.touch("/clickhouse")
client.touch("/clickhouse/backups")
client.touch("/clickhouse/backups/1")
client.touch("/clickhouse/backups/1/stage")
client.touch("/clickhouse/backups/1/stage/alive123")
client.touch("/clickhouse/backups/2")
client.touch("/clickhouse/backups/2/stage")
client.touch("/clickhouse/backups/2/stage/dead123")
response = client.delete_stale_backups()
2023-07-26 05:57:16 +00:00
assert response == (
2023-07-28 06:34:05 +00:00
'Found backup "/clickhouse/backups/1", checking if it\'s active\n'
'Backup "/clickhouse/backups/1" is active, not going to delete\n'
'Found backup "/clickhouse/backups/2", checking if it\'s active\n'
'Backup "/clickhouse/backups/2" is not active, deleting it'
2023-07-26 05:57:16 +00:00
)
assert client.ls("/clickhouse/backups") == ["1"]
2023-07-26 05:57:16 +00:00
def test_base_commands(client: KeeperClient):
client.create("/test_create_zk_node1", "testvalue1")
client.create("/test_create_zk_node_2", "testvalue2")
assert client.get("/test_create_zk_node1") == "testvalue1"
client.create("/123", "1=2")
client.create("/123/321", "'foo;bar'")
assert client.get("/123") == "1=2"
assert client.get("/123/321") == "foo;bar"
2023-07-26 05:57:16 +00:00
def test_four_letter_word_commands(client: KeeperClient):
assert client.execute_query("ruok") == "imok"
2023-09-16 00:03:46 +00:00
def test_rm_with_version(client: KeeperClient):
node_path = "/test_rm_with_version_node"
client.create(node_path, "value")
assert client.get(node_path) == "value"
with pytest.raises(KeeperException) as ex:
client.rm(node_path, 1)
ex_as_str = str(ex)
assert "Coordination error: Bad version" in ex_as_str
assert node_path in ex_as_str
assert client.get(node_path) == "value"
client.rm(node_path, 0)
with pytest.raises(KeeperException) as ex:
client.get(node_path)
ex_as_str = str(ex)
assert "node doesn't exist" in ex_as_str
assert node_path in ex_as_str
def test_rm_without_version(client: KeeperClient):
node_path = "/test_rm_with_version_node"
client.create(node_path, "value")
assert client.get(node_path) == "value"
client.rm(node_path)
with pytest.raises(KeeperException) as ex:
client.get(node_path)
ex_as_str = str(ex)
assert "node doesn't exist" in ex_as_str
assert node_path in ex_as_str
2023-09-16 00:07:54 +00:00
def test_set_with_version(client: KeeperClient):
node_path = "/test_set_with_version_node"
client.create(node_path, "value")
assert client.get(node_path) == "value"
client.set(node_path, "value1", 0)
assert client.get(node_path) == "value1"
with pytest.raises(KeeperException) as ex:
client.set(node_path, "value2", 2)
ex_as_str = str(ex)
assert "Coordination error: Bad version" in ex_as_str
assert node_path in ex_as_str
assert client.get(node_path) == "value1"
client.set(node_path, "value2", 1)
assert client.get(node_path) == "value2"
def test_set_without_version(client: KeeperClient):
node_path = "/test_set_without_version_node"
client.create(node_path, "value")
assert client.get(node_path) == "value"
client.set(node_path, "value1")
assert client.get(node_path) == "value1"
client.set(node_path, "value2")
assert client.get(node_path) == "value2"
def test_quoted_argument_parsing(client: KeeperClient):
node_path = "/test_quoted_argument_parsing_node"
client.create(node_path, "value")
client.execute_query(f"set '{node_path}' 'value1 with some whitespace'")
assert client.get(node_path) == "value1 with some whitespace"
client.execute_query(f"set '{node_path}' 'value2 with some whitespace' 1")
assert client.get(node_path) == "value2 with some whitespace"
client.execute_query(f"set '{node_path}' \"value3 with some whitespace\"")
assert client.get(node_path) == "value3 with some whitespace"
client.execute_query(f"set '{node_path}' \"value4 with some whitespace\" 3")
2023-09-16 00:32:32 +00:00
assert client.get(node_path) == "value4 with some whitespace"