2019-04-08 05:13:16 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
|
|
|
|
node1 = cluster.add_instance('node1', main_configs=['configs/remote_servers.xml'])
|
|
|
|
node2 = cluster.add_instance('node2', main_configs=['configs/remote_servers.xml'])
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
for node in (node1, node2):
|
|
|
|
node.query('''CREATE TABLE local_table(id UInt32, val String) ENGINE = MergeTree ORDER BY id;''')
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
node1.query(
|
|
|
|
'''CREATE TABLE distributed_table(id UInt32, val String) ENGINE = Distributed(test_cluster, default, local_table, id);''')
|
2019-04-08 05:13:16 +00:00
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_start_and_stop_replica_send(started_cluster):
|
2019-04-22 15:11:16 +00:00
|
|
|
node1.query("SYSTEM STOP DISTRIBUTED SENDS distributed_table;")
|
2019-04-08 05:13:16 +00:00
|
|
|
|
|
|
|
node1.query("INSERT INTO distributed_table VALUES (0, 'node1')")
|
|
|
|
node1.query("INSERT INTO distributed_table VALUES (1, 'node2')")
|
|
|
|
|
2019-06-17 08:25:06 +00:00
|
|
|
# Write only to this node when stop distributed sends
|
2019-04-08 05:13:16 +00:00
|
|
|
assert node1.query("SELECT COUNT() FROM distributed_table").rstrip() == '1'
|
|
|
|
|
2019-04-22 15:11:16 +00:00
|
|
|
node1.query("SYSTEM START DISTRIBUTED SENDS distributed_table;")
|
2019-05-10 04:19:02 +00:00
|
|
|
node1.query("SYSTEM FLUSH DISTRIBUTED distributed_table;")
|
2019-04-08 05:13:16 +00:00
|
|
|
assert node1.query("SELECT COUNT() FROM distributed_table").rstrip() == '2'
|