diff --git a/tests/integration/test_insert_into_distributed/configs/remote_servers.xml b/tests/integration/test_insert_into_distributed/configs/remote_servers.xml index 78e1640538b..07fd52751b7 100644 --- a/tests/integration/test_insert_into_distributed/configs/remote_servers.xml +++ b/tests/integration/test_insert_into_distributed/configs/remote_servers.xml @@ -41,14 +41,14 @@ - + shard1 9000 - - + + shard2 9000 diff --git a/tests/integration/test_insert_into_distributed/test.py b/tests/integration/test_insert_into_distributed/test.py index 987dd4ef97e..d54336a3027 100644 --- a/tests/integration/test_insert_into_distributed/test.py +++ b/tests/integration/test_insert_into_distributed/test.py @@ -1,6 +1,7 @@ import time import pytest +from helpers.client import QueryRuntimeException from helpers.cluster import ClickHouseCluster from helpers.network import PartitionManager from helpers.test_tools import TSV @@ -76,11 +77,19 @@ CREATE TABLE table_function (n UInt8, s String) ENGINE = MergeTree() ORDER BY n' CREATE TABLE table_function (n UInt8, s String) ENGINE = MergeTree() ORDER BY n''') node1.query(''' -CREATE TABLE distributed_one_replica (date Date, id UInt32) ENGINE = Distributed('shard_with_local_replica_internal_replication', 'default', 'single_replicated') +CREATE TABLE distributed_one_replica_internal_replication (date Date, id UInt32) ENGINE = Distributed('shard_with_local_replica_internal_replication', 'default', 'single_replicated') ''') node2.query(''' -CREATE TABLE distributed_one_replica (date Date, id UInt32) ENGINE = Distributed('shard_with_local_replica_internal_replication', 'default', 'single_replicated') +CREATE TABLE distributed_one_replica_internal_replication (date Date, id UInt32) ENGINE = Distributed('shard_with_local_replica_internal_replication', 'default', 'single_replicated') +''') + + node1.query(''' +CREATE TABLE distributed_one_replica_no_internal_replication (date Date, id UInt32) ENGINE = Distributed('shard_with_local_replica', 'default', 'single_replicated') +''') + + node2.query(''' +CREATE TABLE distributed_one_replica_no_internal_replication (date Date, id UInt32) ENGINE = Distributed('shard_with_local_replica', 'default', 'single_replicated') ''') node2.query(''' @@ -174,14 +183,45 @@ def test_inserts_local(started_cluster): assert instance.query("SELECT count(*) FROM local").strip() == '1' -def test_inserts_single_replica(started_cluster): +def test_inserts_single_replica_local_internal_replication(started_cluster): + with pytest.raises(QueryRuntimeException, match="Table default.single_replicated doesn't exist"): + node1.query( + "INSERT INTO distributed_one_replica_internal_replication VALUES ('2000-01-01', 1)", + settings={ + "insert_distributed_sync": "1", + "prefer_localhost_replica": "1", + # to make the test more deterministic + "load_balancing": "first_or_random", + }, + ) + assert node2.query("SELECT count(*) FROM single_replicated").strip() == '0' + + +def test_inserts_single_replica_internal_replication(started_cluster): node1.query( - "INSERT INTO distributed_one_replica VALUES ('2000-01-01', 1)", - settings={"insert_distributed_sync": "1", "prefer_localhost_replica": "0"}, + "INSERT INTO distributed_one_replica_internal_replication VALUES ('2000-01-01', 1)", + settings={ + "insert_distributed_sync": "1", + "prefer_localhost_replica": "0", + # to make the test more deterministic + "load_balancing": "first_or_random", + }, ) assert node2.query("SELECT count(*) FROM single_replicated").strip() == '1' +def test_inserts_single_replica_no_internal_replication(started_cluster): + with pytest.raises(QueryRuntimeException, match="Table default.single_replicated doesn't exist"): + node1.query( + "INSERT INTO distributed_one_replica_no_internal_replication VALUES ('2000-01-01', 1)", + settings={ + "insert_distributed_sync": "1", + "prefer_localhost_replica": "0", + }, + ) + assert node2.query("SELECT count(*) FROM single_replicated").strip() == '1' + + def test_prefer_localhost_replica(started_cluster): test_query = "SELECT * FROM distributed ORDER BY id"