ClickHouse/tests/integration/test_named_collections/test.py

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

201 lines
5.3 KiB
Python
Raw Normal View History

2022-11-16 17:27:13 +00:00
import logging
import pytest
import os
2022-11-17 14:33:06 +00:00
import time
2022-11-16 17:27:13 +00:00
from helpers.cluster import ClickHouseCluster
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
NAMED_COLLECTIONS_CONFIG = os.path.join(
SCRIPT_DIR, "./configs/config.d/named_collections.xml"
)
@pytest.fixture(scope="module")
def cluster():
try:
cluster = ClickHouseCluster(__file__)
cluster.add_instance(
"node",
main_configs=[
"configs/config.d/named_collections.xml",
],
2022-11-17 14:33:06 +00:00
user_configs=[
"configs/users.d/users.xml",
],
2022-11-16 17:27:13 +00:00
stay_alive=True,
)
logging.info("Starting cluster...")
cluster.start()
logging.info("Cluster started")
yield cluster
finally:
cluster.shutdown()
2022-11-17 14:33:06 +00:00
def replace_config(node, old, new):
node.replace_in_config(
"/etc/clickhouse-server/config.d/named_collections.xml",
old,
new,
)
2022-11-16 17:27:13 +00:00
def test_config_reload(cluster):
node = cluster.instances["node"]
assert (
"collection1" == node.query("select name from system.named_collections").strip()
)
assert (
"['key1']"
== node.query(
"select mapKeys(collection) from system.named_collections where name = 'collection1'"
).strip()
)
assert (
"value1"
== node.query(
"select collection['key1'] from system.named_collections where name = 'collection1'"
).strip()
)
2022-11-17 14:33:06 +00:00
replace_config(node, "value1", "value2")
2022-11-16 17:27:13 +00:00
node.query("SYSTEM RELOAD CONFIG")
assert (
"['key1']"
== node.query(
"select mapKeys(collection) from system.named_collections where name = 'collection1'"
).strip()
)
assert (
"value2"
== node.query(
"select collection['key1'] from system.named_collections where name = 'collection1'"
).strip()
)
2022-11-17 14:33:06 +00:00
def test_sql_commands(cluster):
2022-11-16 17:27:13 +00:00
node = cluster.instances["node"]
assert "1" == node.query("select count() from system.named_collections").strip()
node.query("CREATE NAMED COLLECTION collection2 AS key1=1, key2='value2'")
def check_created():
assert (
"collection1\ncollection2"
== node.query("select name from system.named_collections").strip()
)
assert (
"['key1','key2']"
== node.query(
"select mapKeys(collection) from system.named_collections where name = 'collection2'"
).strip()
)
assert (
"1"
== node.query(
"select collection['key1'] from system.named_collections where name = 'collection2'"
).strip()
)
assert (
"value2"
== node.query(
"select collection['key2'] from system.named_collections where name = 'collection2'"
).strip()
)
check_created()
node.restart_clickhouse()
check_created()
2022-11-17 14:33:06 +00:00
node.query("ALTER NAMED COLLECTION collection2 SET key1=4, key3='value3'")
def check_altered():
assert (
"['key1','key2','key3']"
== node.query(
"select mapKeys(collection) from system.named_collections where name = 'collection2'"
).strip()
)
assert (
"4"
== node.query(
"select collection['key1'] from system.named_collections where name = 'collection2'"
).strip()
)
assert (
"value3"
== node.query(
"select collection['key3'] from system.named_collections where name = 'collection2'"
).strip()
)
2022-11-17 15:01:42 +00:00
check_altered()
2022-11-17 14:33:06 +00:00
node.restart_clickhouse()
2022-11-17 15:01:42 +00:00
check_altered()
2022-11-17 14:33:06 +00:00
node.query("ALTER NAMED COLLECTION collection2 DELETE key2")
def check_deleted():
assert (
"['key1','key3']"
== node.query(
"select mapKeys(collection) from system.named_collections where name = 'collection2'"
).strip()
)
2022-11-17 15:01:42 +00:00
check_deleted()
2022-11-17 14:33:06 +00:00
node.restart_clickhouse()
2022-11-17 15:01:42 +00:00
check_deleted()
2022-11-17 14:33:06 +00:00
2022-11-17 15:01:42 +00:00
node.query(
"ALTER NAMED COLLECTION collection2 SET key3=3, key4='value4' DELETE key1"
)
2022-11-17 14:33:06 +00:00
def check_altered_and_deleted():
assert (
"['key3','key4']"
== node.query(
"select mapKeys(collection) from system.named_collections where name = 'collection2'"
).strip()
)
assert (
"3"
== node.query(
"select collection['key3'] from system.named_collections where name = 'collection2'"
).strip()
)
2022-11-17 15:01:42 +00:00
2022-11-17 14:33:06 +00:00
assert (
"value4"
== node.query(
"select collection['key4'] from system.named_collections where name = 'collection2'"
).strip()
)
2022-11-17 15:01:42 +00:00
check_altered_and_deleted()
2022-11-17 14:33:06 +00:00
node.restart_clickhouse()
2022-11-17 15:01:42 +00:00
check_altered_and_deleted()
2022-11-17 14:33:06 +00:00
2022-11-16 17:27:13 +00:00
node.query("DROP NAMED COLLECTION collection2")
def check_dropped():
assert "1" == node.query("select count() from system.named_collections").strip()
assert (
"collection1"
== node.query("select name from system.named_collections").strip()
)
check_dropped()
node.restart_clickhouse()
check_dropped()