ClickHouse/tests/integration/test_always_fetch_merged/test.py
2020-04-20 18:17:34 +03:00

64 lines
1.9 KiB
Python

import pytest
import time
from helpers.cluster import ClickHouseCluster
from helpers.test_tools import assert_eq_with_retry
cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance('node1', with_zookeeper=True)
node2 = cluster.add_instance('node2', with_zookeeper=True)
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_replica_always_download(started_cluster):
node1.query("""
CREATE TABLE test_table(
key UInt64,
value String
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_table/replicated', '1')
ORDER BY tuple()
""")
node2.query("""
CREATE TABLE test_table(
key UInt64,
value String
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_table/replicated', '2')
ORDER BY tuple()
SETTINGS always_fetch_merged_part=1
""")
# Stop merges on single node
node1.query("SYSTEM STOP MERGES")
for i in range(0, 10):
node1.query("INSERT INTO test_table VALUES ({}, '{}')".format(i, i))
assert node1.query("SELECT COUNT() FROM test_table") == "10\n"
assert_eq_with_retry(node2, "SELECT COUNT() FROM test_table", "10\n")
time.sleep(3)
# Nothing is merged
assert node1.query("SELECT COUNT() FROM system.parts WHERE table = 'test_table' and active=1") == "10\n"
assert node2.query("SELECT COUNT() FROM system.parts WHERE table = 'test_table' and active=1") == "10\n"
node1.query("SYSTEM START MERGES")
time.sleep(3)
node1_parts = node1.query("SELECT COUNT() FROM system.parts WHERE table = 'test_table' and active=1").strip()
node2_parts = node2.query("SELECT COUNT() FROM system.parts WHERE table = 'test_table' and active=1").strip()
assert int(node1_parts) < 10 # something merged
assert int(node2_parts) < 10