From b008c49bd9c8c6281be6cd3e36ca24b253625887 Mon Sep 17 00:00:00 2001 From: bharatnc Date: Sat, 5 Dec 2020 13:36:21 -0800 Subject: [PATCH] DDlWorkerQueueTable - add integration test --- .../test_system_ddl_worker_queue/__init__.py | 0 .../configs/config.d/clusters.xml | 93 +++++++++++++++++++ .../configs/config.d/ddl.xml | 8 ++ .../configs/config.d/macro.xml | 5 + .../configs/config.d/query_log.xml | 14 +++ .../config.d/zookeeper_session_timeout.xml | 7 ++ .../configs/users.d/query_log.xml | 8 ++ .../configs/users.d/restricted_user.xml | 16 ++++ .../test_system_ddl_worker_queue/test.py | 64 +++++++++++++ 9 files changed, 215 insertions(+) create mode 100644 tests/integration/test_system_ddl_worker_queue/__init__.py create mode 100644 tests/integration/test_system_ddl_worker_queue/configs/config.d/clusters.xml create mode 100644 tests/integration/test_system_ddl_worker_queue/configs/config.d/ddl.xml create mode 100644 tests/integration/test_system_ddl_worker_queue/configs/config.d/macro.xml create mode 100644 tests/integration/test_system_ddl_worker_queue/configs/config.d/query_log.xml create mode 100644 tests/integration/test_system_ddl_worker_queue/configs/config.d/zookeeper_session_timeout.xml create mode 100644 tests/integration/test_system_ddl_worker_queue/configs/users.d/query_log.xml create mode 100644 tests/integration/test_system_ddl_worker_queue/configs/users.d/restricted_user.xml create mode 100644 tests/integration/test_system_ddl_worker_queue/test.py diff --git a/tests/integration/test_system_ddl_worker_queue/__init__.py b/tests/integration/test_system_ddl_worker_queue/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/integration/test_system_ddl_worker_queue/configs/config.d/clusters.xml b/tests/integration/test_system_ddl_worker_queue/configs/config.d/clusters.xml new file mode 100644 index 00000000000..9a8dde66756 --- /dev/null +++ b/tests/integration/test_system_ddl_worker_queue/configs/config.d/clusters.xml @@ -0,0 +1,93 @@ + + + + + + + true + + ch1 + 9000 + + + ch2 + 9000 + + + + true + + ch3 + 9000 + + + ch4 + 9000 + + + + + + + + true + + ch1 + 9000 + default + + + ch2 + 9000 + test2 + + + + true + + ch3 + 9000 + default + + + ch4 + 9000 + test2 + + + + + + + + false + + ch1 + 9000 + + + + false + + ch2 + 9000 + + + + false + + ch3 + 9000 + + + + false + + ch4 + 9000 + + + + + + diff --git a/tests/integration/test_system_ddl_worker_queue/configs/config.d/ddl.xml b/tests/integration/test_system_ddl_worker_queue/configs/config.d/ddl.xml new file mode 100644 index 00000000000..1f11ae24dc0 --- /dev/null +++ b/tests/integration/test_system_ddl_worker_queue/configs/config.d/ddl.xml @@ -0,0 +1,8 @@ + + + /clickhouse/task_queue/ddl + 10 + 3600 + 5 + + diff --git a/tests/integration/test_system_ddl_worker_queue/configs/config.d/macro.xml b/tests/integration/test_system_ddl_worker_queue/configs/config.d/macro.xml new file mode 100644 index 00000000000..b7bc11da782 --- /dev/null +++ b/tests/integration/test_system_ddl_worker_queue/configs/config.d/macro.xml @@ -0,0 +1,5 @@ + + + cluster_no_replicas + + diff --git a/tests/integration/test_system_ddl_worker_queue/configs/config.d/query_log.xml b/tests/integration/test_system_ddl_worker_queue/configs/config.d/query_log.xml new file mode 100644 index 00000000000..7f57bb1eb85 --- /dev/null +++ b/tests/integration/test_system_ddl_worker_queue/configs/config.d/query_log.xml @@ -0,0 +1,14 @@ + + + + + system + query_log
+ + + 1000 +
+
diff --git a/tests/integration/test_system_ddl_worker_queue/configs/config.d/zookeeper_session_timeout.xml b/tests/integration/test_system_ddl_worker_queue/configs/config.d/zookeeper_session_timeout.xml new file mode 100644 index 00000000000..6af9cc8cc99 --- /dev/null +++ b/tests/integration/test_system_ddl_worker_queue/configs/config.d/zookeeper_session_timeout.xml @@ -0,0 +1,7 @@ + + + + 3000 + + + diff --git a/tests/integration/test_system_ddl_worker_queue/configs/users.d/query_log.xml b/tests/integration/test_system_ddl_worker_queue/configs/users.d/query_log.xml new file mode 100644 index 00000000000..0f389295bec --- /dev/null +++ b/tests/integration/test_system_ddl_worker_queue/configs/users.d/query_log.xml @@ -0,0 +1,8 @@ + + + + + 1 + + + diff --git a/tests/integration/test_system_ddl_worker_queue/configs/users.d/restricted_user.xml b/tests/integration/test_system_ddl_worker_queue/configs/users.d/restricted_user.xml new file mode 100644 index 00000000000..5b6084eea7b --- /dev/null +++ b/tests/integration/test_system_ddl_worker_queue/configs/users.d/restricted_user.xml @@ -0,0 +1,16 @@ + + + + + default + default + + ::/0 + + + + db1 + + + + diff --git a/tests/integration/test_system_ddl_worker_queue/test.py b/tests/integration/test_system_ddl_worker_queue/test.py new file mode 100644 index 00000000000..fb017b8bfdf --- /dev/null +++ b/tests/integration/test_system_ddl_worker_queue/test.py @@ -0,0 +1,64 @@ +import os +import sys +import time +from contextlib import contextmanager + +import pytest + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +# just import cluster setup from test_didstributed_ddl to avoid code duplication +from test_distributed_ddl.cluster import ClickHouseClusterWithDDLHelpers + + +@pytest.fixture(scope="module", params=["configs"]) +def test_cluster(request): + cluster = ClickHouseClusterWithDDLHelpers(__file__, request.param) + + try: + cluster.prepare() + + yield cluster + + instance = cluster.instances['ch1'] + cluster.ddl_check_query(instance, "DROP DATABASE test ON CLUSTER 'cluster'") + + # Check query log to ensure that DDL queries are not executed twice + time.sleep(1.5) + for instance in list(cluster.instances.values()): + cluster.ddl_check_there_are_no_dublicates(instance) + + cluster.pm_random_drops.heal_all() + + finally: + cluster.shutdown() + + +def test_ddl_worker_queue_table_entries(test_cluster): + instance = test_cluster.instances['ch2'] + test_cluster.ddl_check_query(instance, "DROP TABLE IF EXISTS merge ON CLUSTER '{cluster}'") + + test_cluster.ddl_check_query(instance, """ +CREATE TABLE IF NOT EXISTS merge ON CLUSTER '{cluster}' (p Date, i Int32) +ENGINE = MergeTree(p, p, 1) +""") + for i in range(0, 4, 2): + k = (i / 2) * 2 + test_cluster.instances['ch{}'.format(i + 1)].query("INSERT INTO merge (i) VALUES ({})({})".format(k, k + 1)) + time.sleep(5) + test_cluster.ddl_check_query(instance, "ALTER TABLE merge ON CLUSTER '{cluster}' DETACH PARTITION 197002") + + # query the ddl_worker_queue table to ensure that the columns are populated as expected + expected_finished_nodes = ['ch1:9000', 'ch3:9000', 'ch2:9000', 'ch4:9000'] + for exp in expected_finished_nodes: + assert exp in instance.query("SELECT finished FROM system.ddl_worker_queue WHERE name='query-0000000000'") + assert exp not in instance.query("SELECT active FROM system.ddl_worker_queue WHERE name='query-0000000000'") + + test_cluster.ddl_check_query(instance, "DROP TABLE merge ON CLUSTER '{cluster}'") + + +if __name__ == '__main__': + with contextmanager(test_cluster)() as ctx_cluster: + for name, instance in list(ctx_cluster.instances.items()): + print(name, instance.ip_address) + input("Cluster created, press any key to destroy...")