From ebd03fbd77a97f7ca5f2f9ed178d803846e8d50e Mon Sep 17 00:00:00 2001 From: Bharat Nallan Chakravarthy Date: Thu, 26 Oct 2023 23:01:24 -0700 Subject: [PATCH] add a test --- .../test_system_logs_hostname/__init__.py | 0 .../configs/replicated_servers.xml | 34 +++++++++ .../test_replicated.py | 71 +++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 tests/integration/test_system_logs_hostname/__init__.py create mode 100644 tests/integration/test_system_logs_hostname/configs/replicated_servers.xml create mode 100644 tests/integration/test_system_logs_hostname/test_replicated.py diff --git a/tests/integration/test_system_logs_hostname/__init__.py b/tests/integration/test_system_logs_hostname/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/integration/test_system_logs_hostname/configs/replicated_servers.xml b/tests/integration/test_system_logs_hostname/configs/replicated_servers.xml new file mode 100644 index 00000000000..584edf41004 --- /dev/null +++ b/tests/integration/test_system_logs_hostname/configs/replicated_servers.xml @@ -0,0 +1,34 @@ + + + + + true + + node1 + 9000 + + + node2 + 9000 + + + node3 + 9000 + + + + + + system + query_log
+ toYYYYMM(event_date) + event_date + INTERVAL 30 DAY DELETE + + 100 + 8192 + 524288 + false +
+
diff --git a/tests/integration/test_system_logs_hostname/test_replicated.py b/tests/integration/test_system_logs_hostname/test_replicated.py new file mode 100644 index 00000000000..b9db6b03673 --- /dev/null +++ b/tests/integration/test_system_logs_hostname/test_replicated.py @@ -0,0 +1,71 @@ +import pytest +from helpers.cluster import ClickHouseCluster + + +def fill_nodes(nodes, shard): + for node in nodes: + node.query( + """ + CREATE DATABASE test; + + CREATE TABLE test.test_table(date Date, id UInt32) + ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/{shard}/replicated/test_table', '{replica}') ORDER BY id PARTITION BY toYYYYMM(date); + """.format( + shard=shard, replica=node.name + ) + ) + + +cluster = ClickHouseCluster(__file__) +node1 = cluster.add_instance( + "node1", with_zookeeper=True, main_configs=["configs/replicated_servers.xml"] +) +node2 = cluster.add_instance( + "node2", with_zookeeper=True, main_configs=["configs/replicated_servers.xml"] +) +node3 = cluster.add_instance( + "node3", with_zookeeper=True, main_configs=["configs/replicated_servers.xml"] +) + + +@pytest.fixture(scope="module") +def start_cluster(): + try: + cluster.start() + + fill_nodes([node1, node2, node3], 1) + + yield cluster + + except Exception as ex: + print(ex) + + finally: + cluster.shutdown() + + +def test_truncate_database_replicated(start_cluster): + node1.query("SELECT 1", query_id="query_node1") + node2.query("SELECT 1", query_id="query_node2") + node3.query("SELECT 1", query_id="query_node3") + node1.query("SYSTEM FLUSH LOGS") + node2.query("SYSTEM FLUSH LOGS") + node3.query("SYSTEM FLUSH LOGS") + assert ( + node1.query( + "SELECT hostname from system.query_log where query_id='query_node1' LIMIT 1" + ) + == "node1\n" + ) + assert ( + node2.query( + "SELECT hostname from system.query_log where query_id='query_node2' LIMIT 1" + ) + == "node2\n" + ) + assert ( + node3.query( + "SELECT hostname from system.query_log where query_id='query_node3' LIMIT 1" + ) + == "node3\n" + )