mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 17:41:59 +00:00
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
# 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()
|
|
|
|
def create_tables(**dist_settings):
|
|
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()
|
|
)
|
|
""", settings=dist_settings)
|
|
|
|
def insert_data(**settings):
|
|
create_tables(**settings)
|
|
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
|
|
|
|
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
|
|
|
|
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
|