2020-05-12 23:24:39 +00:00
|
|
|
# pylint: disable=unused-argument
|
|
|
|
# pylint: disable=redefined-outer-name
|
|
|
|
# pylint: disable=line-too-long
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
|
|
|
|
n1 = cluster.add_instance('n1', main_configs=['configs/remote_servers.xml'])
|
|
|
|
n2 = cluster.add_instance('n2', main_configs=['configs/remote_servers.xml'])
|
|
|
|
|
|
|
|
@pytest.fixture(scope='module', autouse=True)
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2020-05-14 00:22:21 +00:00
|
|
|
def create_tables(**dist_settings):
|
2020-05-12 23:24:39 +00:00
|
|
|
n1.query('DROP TABLE IF EXISTS data')
|
|
|
|
n2.query('DROP TABLE IF EXISTS data')
|
|
|
|
n1.query('DROP TABLE IF EXISTS dist')
|
|
|
|
|
|
|
|
n1.query('CREATE TABLE data (key Int) Engine=Memory()')
|
|
|
|
n2.query('CREATE TABLE data (key Int) Engine=Memory()')
|
|
|
|
n1.query("""
|
|
|
|
CREATE TABLE dist AS data
|
|
|
|
Engine=Distributed(
|
|
|
|
integration_test_cluster,
|
|
|
|
currentDatabase(),
|
|
|
|
data,
|
|
|
|
rand()
|
|
|
|
)
|
2020-05-14 00:22:21 +00:00
|
|
|
""", settings=dist_settings)
|
2020-05-12 23:24:39 +00:00
|
|
|
|
|
|
|
def insert_data(**settings):
|
2020-05-14 00:22:21 +00:00
|
|
|
create_tables(**settings)
|
2020-05-12 23:24:39 +00:00
|
|
|
n1.query('INSERT INTO dist SELECT * FROM numbers(10)', settings=settings)
|
|
|
|
n1.query('SYSTEM FLUSH DISTRIBUTED dist')
|
|
|
|
|
|
|
|
def test_prefer_localhost_replica_1():
|
|
|
|
insert_data()
|
|
|
|
assert int(n1.query('SELECT count() FROM data')) == 10
|
|
|
|
assert int(n2.query('SELECT count() FROM data')) == 0
|
|
|
|
|
|
|
|
def test_prefer_localhost_replica_1_load_balancing_in_order():
|
|
|
|
insert_data(load_balancing='in_order')
|
|
|
|
assert int(n1.query('SELECT count() FROM data')) == 10
|
|
|
|
assert int(n2.query('SELECT count() FROM data')) == 0
|
|
|
|
|
2020-05-13 22:50:56 +00:00
|
|
|
def test_prefer_localhost_replica_0_load_balancing_nearest_hostname():
|
|
|
|
insert_data(load_balancing='nearest_hostname', prefer_localhost_replica=0)
|
|
|
|
assert int(n1.query('SELECT count() FROM data')) == 10
|
|
|
|
assert int(n2.query('SELECT count() FROM data')) == 0
|
|
|
|
|
2020-05-12 23:24:39 +00:00
|
|
|
def test_prefer_localhost_replica_0_load_balancing_in_order():
|
|
|
|
insert_data(load_balancing='in_order', prefer_localhost_replica=0)
|
|
|
|
assert int(n1.query('SELECT count() FROM data')) == 0
|
|
|
|
assert int(n2.query('SELECT count() FROM data')) == 10
|
|
|
|
|
|
|
|
def test_prefer_localhost_replica_0_load_balancing_in_order_sync():
|
|
|
|
insert_data(load_balancing='in_order', prefer_localhost_replica=0, insert_distributed_sync=1)
|
|
|
|
assert int(n1.query('SELECT count() FROM data')) == 0
|
|
|
|
assert int(n2.query('SELECT count() FROM data')) == 10
|