ClickHouse/tests/integration/test_keeper_memory_soft_limit/test.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.6 KiB
Python
Raw Normal View History

2023-11-27 17:28:10 +00:00
#!/usr/bin/env python3
import random
import string
import pytest
from helpers.cluster import ClickHouseCluster
from helpers import keeper_utils
from kazoo.client import KazooClient, KazooState
from kazoo.exceptions import ConnectionLoss
2023-12-01 17:07:45 +00:00
cluster = ClickHouseCluster(__file__, keeper_config_dir="configs/")
2023-11-27 17:28:10 +00:00
# clickhouse itself will use external zookeeper
node = cluster.add_instance(
"node",
stay_alive=True,
with_zookeeper=True,
)
2023-11-27 21:03:05 +00:00
2023-11-27 17:28:10 +00:00
def random_string(length):
return "".join(random.choices(string.ascii_lowercase + string.digits, k=length))
2023-11-27 21:03:05 +00:00
2023-11-27 17:28:10 +00:00
def get_connection_zk(nodename, timeout=30.0):
_fake_zk_instance = KazooClient(
2023-12-01 17:07:45 +00:00
hosts=cluster.get_instance_ip(nodename) + ":2181", timeout=timeout
2023-11-27 17:28:10 +00:00
)
_fake_zk_instance.start()
return _fake_zk_instance
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
2023-11-27 21:03:05 +00:00
2023-11-27 17:28:10 +00:00
def test_soft_limit_create(started_cluster):
2023-12-01 17:07:45 +00:00
started_cluster.wait_zookeeper_to_start()
2023-11-27 17:28:10 +00:00
try:
2023-12-01 17:07:45 +00:00
node_zk = get_connection_zk("zoo1")
loop_time = 100000
2023-11-28 09:47:22 +00:00
node_zk.create("/test_soft_limit", b"abc")
2023-11-27 17:28:10 +00:00
for i in range(loop_time):
2023-11-28 09:47:22 +00:00
node_zk.create(
"/test_soft_limit/node_" + str(i), random_string(1000).encode()
2023-11-28 09:47:22 +00:00
)
2023-11-27 17:28:10 +00:00
except ConnectionLoss:
txn = node_zk.transaction()
for i in range(10):
txn.delete("/test_soft_limit/node_" + str(i))
2023-11-28 09:47:22 +00:00
txn.create("/test_soft_limit/node_1000001" + str(i), b"abcde")
2023-11-27 17:28:10 +00:00
txn.commit()
return
raise Exception("all records are inserted but no error occurs")