2021-08-04 13:19:42 +00:00
|
|
|
import pytest
|
|
|
|
from helpers.client import QueryRuntimeException
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
2022-01-23 16:31:09 +00:00
|
|
|
from ast import literal_eval
|
2021-08-04 13:19:42 +00:00
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
node1 = cluster.add_instance("node1", with_zookeeper=True)
|
|
|
|
node2 = cluster.add_instance("node2", with_zookeeper=True)
|
|
|
|
node3 = cluster.add_instance("node3", with_zookeeper=True)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-08-04 13:19:42 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
for i, node in enumerate((node1, node2, node3)):
|
|
|
|
node_name = "node" + str(i + 1)
|
|
|
|
node.query(
|
2022-03-22 16:39:58 +00:00
|
|
|
"""
|
2021-08-04 13:19:42 +00:00
|
|
|
CREATE TABLE test_table(date Date, id UInt32, dummy UInt32)
|
|
|
|
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_table', '{}')
|
|
|
|
PARTITION BY date ORDER BY id
|
|
|
|
""".format(
|
|
|
|
node_name
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_replica_is_active(start_cluster):
|
|
|
|
query_result = node1.query(
|
|
|
|
"select replica_is_active from system.replicas where table = 'test_table'"
|
|
|
|
)
|
2022-01-23 16:31:09 +00:00
|
|
|
assert literal_eval(query_result) == {"node1": 1, "node2": 1, "node3": 1}
|
2021-08-04 13:19:42 +00:00
|
|
|
|
|
|
|
node3.stop()
|
|
|
|
query_result = node1.query(
|
|
|
|
"select replica_is_active from system.replicas where table = 'test_table'"
|
|
|
|
)
|
2022-01-23 16:31:09 +00:00
|
|
|
assert literal_eval(query_result) == {"node1": 1, "node2": 1, "node3": 0}
|
2021-08-04 13:19:42 +00:00
|
|
|
|
|
|
|
node2.stop()
|
|
|
|
query_result = node1.query(
|
|
|
|
"select replica_is_active from system.replicas where table = 'test_table'"
|
|
|
|
)
|
2022-01-23 16:31:09 +00:00
|
|
|
assert literal_eval(query_result) == {"node1": 1, "node2": 0, "node3": 0}
|