Test with no available replicas

This commit is contained in:
Igor Nikonov 2024-06-24 11:58:32 +00:00
parent 0b96f609ae
commit 3127177401
3 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<clickhouse>
<remote_servers>
<test_1_shard_1_replicas>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>initiator</host>
<port>9000</port>
</replica>
</shard>
</test_1_shard_1_replicas>
<test_1_shard_3_unavaliable_replicas>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>node1</host>
<port>9000</port>
</replica>
<replica>
<host>node2</host>
<port>9000</port>
</replica>
<replica>
<host>node3</host>
<port>9000</port>
</replica>
</shard>
</test_1_shard_3_unavaliable_replicas>
</remote_servers>
</clickhouse>

View File

@ -0,0 +1,49 @@
import pytest
from helpers.cluster import ClickHouseCluster
from helpers.client import QueryRuntimeException
cluster = ClickHouseCluster(__file__)
initiator = cluster.add_instance(
"initiator", main_configs=["configs/remote_servers.xml"], with_zookeeper=True
)
@pytest.fixture(scope="module")
def start_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def create_tables(cluster, table_name):
initiator.query(f"DROP TABLE IF EXISTS {table_name} SYNC")
initiator.query(
f"CREATE TABLE IF NOT EXISTS {table_name} (key Int64, value String) Engine=ReplicatedMergeTree('/test_parallel_replicas/shard1/{table_name}', 'r1') ORDER BY (key)"
)
# populate data
initiator.query(
f"INSERT INTO {table_name} SELECT number % 4, number FROM numbers(1000)"
)
@pytest.mark.parametrize("skip_unavailable_shards", [1, 0])
def test_skip_all_replicas(start_cluster, skip_unavailable_shards):
cluster_name = "test_1_shard_3_unavaliable_replicas"
table_name = "tt"
create_tables(cluster_name, table_name)
with pytest.raises(QueryRuntimeException):
initiator.query(
f"SELECT key, count() FROM {table_name} GROUP BY key ORDER BY key",
settings = {
"allow_experimental_parallel_reading_from_replicas": 2,
"max_parallel_replicas": 3,
"cluster_for_parallel_replicas": cluster_name,
"skip_unavailable_shards": skip_unavailable_shards,
}
)