ClickHouse/tests/integration/test_truncate_database/test_distributed.py

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

52 lines
1.6 KiB
Python
Raw Normal View History

2023-08-11 03:58:19 +00:00
import pytest
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance(
2024-08-27 10:42:47 +00:00
"node1", with_zookeeper=True, main_configs=["configs/distributed_servers.xml"]
2023-08-11 03:58:19 +00:00
)
node2 = cluster.add_instance(
"node2", with_zookeeper=True, main_configs=["configs/distributed_servers.xml"]
)
2024-08-27 14:20:31 +00:00
2024-08-27 10:42:47 +00:00
def fill_nodes(nodes):
for node in nodes:
node.query(
"""
DROP DATABASE IF EXISTS test;
CREATE DATABASE test;
CREATE TABLE test.local_table(id UInt32, val String) ENGINE = MergeTree ORDER BY id;
CREATE TABLE test.distributed(id UInt32, val String) ENGINE = Distributed(test_cluster, test, local_table);
INSERT INTO test.local_table VALUES ({pos}, '{replica}');
""".format(
pos=node.name[4:], replica=node.name
)
)
2023-08-11 03:58:19 +00:00
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_truncate_database_distributed(started_cluster):
2024-08-27 10:42:47 +00:00
fill_nodes([node1, node2])
2023-08-11 03:58:19 +00:00
query1 = "SELECT count() FROM test.distributed WHERE (id, val) IN ((1, 'node1'), (2, 'a'), (3, 'b'))"
query2 = "SELECT sum((id, val) IN ((1, 'node1'), (2, 'a'), (3, 'b'))) FROM test.distributed"
assert node1.query(query1) == "1\n"
assert node1.query(query2) == "1\n"
assert node2.query(query1) == "1\n"
assert node2.query(query2) == "1\n"
assert node2.query("SHOW DATABASES LIKE 'test'") == "test\n"
node1.query("TRUNCATE DATABASE test ON CLUSTER test_cluster SYNC")
assert node2.query("SHOW TABLES FROM test") == ""