2022-07-31 09:11:46 +00:00
|
|
|
import pytest
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
import os
|
|
|
|
from kazoo.client import KazooClient
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
CONFIG_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs")
|
|
|
|
|
|
|
|
node1 = cluster.add_instance(
|
|
|
|
"node1", main_configs=["configs/enable_keeper1.xml"], stay_alive=True
|
|
|
|
)
|
|
|
|
|
|
|
|
node2 = cluster.add_instance(
|
|
|
|
"node2", main_configs=["configs/enable_keeper2.xml"], stay_alive=True
|
|
|
|
)
|
|
|
|
|
2022-07-31 09:24:53 +00:00
|
|
|
|
2022-07-31 09:11:46 +00:00
|
|
|
def get_fake_zk(node, timeout=30.0):
|
|
|
|
_fake_zk_instance = KazooClient(
|
|
|
|
hosts=cluster.get_instance_ip(node.name) + ":9181", timeout=timeout
|
|
|
|
)
|
|
|
|
_fake_zk_instance.start()
|
|
|
|
return _fake_zk_instance
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2022-07-31 09:24:53 +00:00
|
|
|
|
2022-07-31 09:11:46 +00:00
|
|
|
def test_snapshot_on_exit(started_cluster):
|
2022-07-31 09:24:53 +00:00
|
|
|
zk_conn = get_fake_zk(node1)
|
2022-07-31 09:11:46 +00:00
|
|
|
|
|
|
|
zk_conn.create("/some_path", b"some_data")
|
|
|
|
|
|
|
|
node1.stop_clickhouse()
|
|
|
|
assert node1.contains_in_log("Created persistent snapshot")
|
|
|
|
|
|
|
|
node1.start_clickhouse()
|
|
|
|
assert node1.contains_in_log("Loaded snapshot")
|
|
|
|
|
|
|
|
node2.stop_clickhouse()
|
|
|
|
assert not node2.contains_in_log("Created persistent snapshot")
|
|
|
|
|
|
|
|
node2.start_clickhouse()
|
|
|
|
assert node2.contains_in_log("No existing snapshots")
|