2019-08-01 17:03:34 +00:00
|
|
|
import pytest
|
2019-08-01 17:43:10 +00:00
|
|
|
from helpers.client import QueryRuntimeException
|
2020-09-16 04:26:10 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
2019-08-01 17:03:34 +00:00
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
2022-03-22 16:39:58 +00:00
|
|
|
node1 = cluster.add_instance(
|
|
|
|
"node1", main_configs=["configs/notleader.xml"], with_zookeeper=True
|
|
|
|
)
|
|
|
|
node2 = cluster.add_instance(
|
|
|
|
"node2", main_configs=["configs/notleaderignorecase.xml"], with_zookeeper=True
|
|
|
|
)
|
|
|
|
node3 = cluster.add_instance("node3", with_zookeeper=True)
|
2019-08-01 17:03:34 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2019-08-01 17:03:34 +00:00
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
2019-08-01 17:43:10 +00:00
|
|
|
for i, node in enumerate((node1, node2)):
|
2019-08-01 17:03:34 +00:00
|
|
|
node.query(
|
2022-03-22 16:39:58 +00:00
|
|
|
"""
|
2019-08-01 17:03:34 +00:00
|
|
|
CREATE TABLE test_table(date Date, id UInt32, dummy UInt32)
|
|
|
|
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_table', '{}')
|
|
|
|
PARTITION BY date ORDER BY id
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
i
|
|
|
|
)
|
2019-08-01 17:03:34 +00:00
|
|
|
)
|
|
|
|
|
2019-08-01 17:43:10 +00:00
|
|
|
with pytest.raises(QueryRuntimeException):
|
|
|
|
node3.query(
|
2022-03-22 16:39:58 +00:00
|
|
|
"""
|
2019-08-01 17:43:10 +00:00
|
|
|
CREATE TABLE test_table(date Date, id UInt32, dummy UInt32)
|
|
|
|
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_table', '{}')
|
|
|
|
PARTITION BY date ORDER BY id SETTINGS replicated_can_become_leader=0sad
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
3
|
|
|
|
)
|
2019-08-01 17:43:10 +00:00
|
|
|
)
|
|
|
|
|
2019-08-01 17:03:34 +00:00
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_can_become_leader(start_cluster):
|
2022-03-22 16:39:58 +00:00
|
|
|
assert (
|
|
|
|
node1.query(
|
|
|
|
"select can_become_leader from system.replicas where table = 'test_table'"
|
|
|
|
)
|
|
|
|
== "0\n"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
node2.query(
|
|
|
|
"select can_become_leader from system.replicas where table = 'test_table'"
|
|
|
|
)
|
|
|
|
== "0\n"
|
|
|
|
)
|