2019-03-14 11:49:44 +00:00
|
|
|
import time
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
import pytest
|
2019-03-14 13:39:47 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
2019-03-14 11:49:44 +00:00
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
2022-03-22 16:39:58 +00:00
|
|
|
node1 = cluster.add_instance(
|
|
|
|
"node1",
|
|
|
|
main_configs=["configs/remote_servers.xml"],
|
|
|
|
with_zookeeper=True,
|
|
|
|
stay_alive=True,
|
|
|
|
)
|
2019-03-14 11:49:44 +00:00
|
|
|
|
2019-05-20 20:59:07 +00:00
|
|
|
|
2019-03-14 11:49:44 +00:00
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
node1.query(
|
2022-03-22 16:39:58 +00:00
|
|
|
"""
|
2019-03-14 11:49:44 +00:00
|
|
|
CREATE DATABASE test;
|
|
|
|
CREATE TABLE test_table(date Date, id UInt32)
|
|
|
|
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/replicated', 'node1') ORDER BY id PARTITION BY toYYYYMM(date);
|
2022-03-22 16:39:58 +00:00
|
|
|
"""
|
2019-05-20 20:59:07 +00:00
|
|
|
)
|
2019-03-14 11:49:44 +00:00
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
except Exception as ex:
|
2020-10-02 16:54:07 +00:00
|
|
|
print(ex)
|
2019-03-14 11:49:44 +00:00
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2019-05-20 20:59:07 +00:00
|
|
|
|
2019-03-14 11:49:44 +00:00
|
|
|
def drop_zk(zk):
|
|
|
|
zk.delete(path="/clickhouse", recursive=True)
|
|
|
|
|
2019-05-20 20:59:07 +00:00
|
|
|
|
2019-03-14 11:49:44 +00:00
|
|
|
def test_startup_without_zookeeper(start_cluster):
|
2022-03-22 16:39:58 +00:00
|
|
|
node1.query(
|
|
|
|
"INSERT INTO test_table VALUES ('2018-10-01', 1), ('2018-10-02', 2), ('2018-10-03', 3)"
|
|
|
|
)
|
2019-05-21 08:15:47 +00:00
|
|
|
assert node1.query("SELECT COUNT(*) from test_table") == "3\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
assert (
|
|
|
|
node1.query("SELECT is_readonly from system.replicas where table='test_table'")
|
|
|
|
== "0\n"
|
|
|
|
)
|
2019-03-14 11:49:44 +00:00
|
|
|
|
|
|
|
cluster.run_kazoo_commands_with_retries(drop_zk)
|
|
|
|
|
|
|
|
time.sleep(5)
|
2019-05-21 08:15:47 +00:00
|
|
|
assert node1.query("SELECT COUNT(*) from test_table") == "3\n"
|
2019-05-21 08:30:39 +00:00
|
|
|
with pytest.raises(Exception):
|
2022-03-22 16:39:58 +00:00
|
|
|
node1.query(
|
|
|
|
"INSERT INTO test_table VALUES ('2018-10-01', 1), ('2018-10-02', 2), ('2018-10-03', 3)"
|
|
|
|
)
|
2019-03-14 11:49:44 +00:00
|
|
|
|
2019-03-14 13:39:47 +00:00
|
|
|
node1.restart_clickhouse()
|
2019-03-14 11:49:44 +00:00
|
|
|
|
2019-05-21 08:15:47 +00:00
|
|
|
assert node1.query("SELECT COUNT(*) from test_table") == "3\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
assert (
|
|
|
|
node1.query("SELECT is_readonly from system.replicas where table='test_table'")
|
|
|
|
== "1\n"
|
|
|
|
)
|