2021-06-13 12:56:22 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
2021-08-16 14:50:07 +00:00
|
|
|
uuids = []
|
2021-06-13 12:56:22 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-06-13 12:56:22 +00:00
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def cluster():
|
|
|
|
try:
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
2022-03-22 16:39:58 +00:00
|
|
|
cluster.add_instance(
|
|
|
|
"node1", main_configs=["configs/storage_conf.xml"], with_nginx=True
|
|
|
|
)
|
|
|
|
cluster.add_instance(
|
|
|
|
"node2", main_configs=["configs/storage_conf_web.xml"], with_nginx=True
|
|
|
|
)
|
|
|
|
cluster.add_instance(
|
|
|
|
"node3", main_configs=["configs/storage_conf_web.xml"], with_nginx=True
|
|
|
|
)
|
2021-06-13 12:56:22 +00:00
|
|
|
cluster.start()
|
2021-08-16 14:50:07 +00:00
|
|
|
|
|
|
|
node1 = cluster.instances["node1"]
|
|
|
|
expected = ""
|
|
|
|
global uuids
|
|
|
|
for i in range(3):
|
2022-03-22 16:39:58 +00:00
|
|
|
node1.query(
|
|
|
|
""" CREATE TABLE data{} (id Int32) ENGINE = MergeTree() ORDER BY id SETTINGS storage_policy = 'def';""".format(
|
|
|
|
i
|
|
|
|
)
|
|
|
|
)
|
|
|
|
node1.query(
|
|
|
|
"INSERT INTO data{} SELECT number FROM numbers(500000 * {})".format(
|
|
|
|
i, i + 1
|
|
|
|
)
|
|
|
|
)
|
2021-08-16 14:50:07 +00:00
|
|
|
expected = node1.query("SELECT * FROM data{} ORDER BY id".format(i))
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
metadata_path = node1.query(
|
|
|
|
"SELECT data_paths FROM system.tables WHERE name='data{}'".format(i)
|
|
|
|
)
|
|
|
|
metadata_path = metadata_path[
|
|
|
|
metadata_path.find("/") : metadata_path.rfind("/") + 1
|
|
|
|
]
|
|
|
|
print(f"Metadata: {metadata_path}")
|
|
|
|
|
|
|
|
node1.exec_in_container(
|
|
|
|
[
|
|
|
|
"bash",
|
|
|
|
"-c",
|
|
|
|
"/usr/bin/clickhouse static-files-disk-uploader --test-mode --url http://nginx:80/test1 --metadata-path {}".format(
|
|
|
|
metadata_path
|
|
|
|
),
|
|
|
|
],
|
|
|
|
user="root",
|
|
|
|
)
|
|
|
|
parts = metadata_path.split("/")
|
2021-08-16 14:50:07 +00:00
|
|
|
uuids.append(parts[3])
|
2022-03-22 16:39:58 +00:00
|
|
|
print(f"UUID: {parts[3]}")
|
2021-08-16 14:50:07 +00:00
|
|
|
|
2021-06-13 12:56:22 +00:00
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
2021-11-11 10:19:49 +00:00
|
|
|
@pytest.mark.parametrize("node_name", ["node2"])
|
2021-10-29 08:40:21 +00:00
|
|
|
def test_usage(cluster, node_name):
|
2021-06-18 14:13:00 +00:00
|
|
|
node1 = cluster.instances["node1"]
|
2021-10-29 08:40:21 +00:00
|
|
|
node2 = cluster.instances[node_name]
|
2021-08-16 14:50:07 +00:00
|
|
|
global uuids
|
2022-03-22 16:39:58 +00:00
|
|
|
assert len(uuids) == 3
|
2021-06-19 11:26:48 +00:00
|
|
|
for i in range(3):
|
2022-03-22 16:39:58 +00:00
|
|
|
node2.query(
|
|
|
|
"""
|
2021-06-19 11:26:48 +00:00
|
|
|
ATTACH TABLE test{} UUID '{}'
|
|
|
|
(id Int32) ENGINE = MergeTree() ORDER BY id
|
|
|
|
SETTINGS storage_policy = 'web';
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
i, uuids[i], i, i
|
|
|
|
)
|
|
|
|
)
|
2021-06-19 11:26:48 +00:00
|
|
|
|
2021-10-29 08:40:21 +00:00
|
|
|
result = node2.query("SELECT * FROM test{} settings max_threads=20".format(i))
|
|
|
|
|
2021-06-19 11:26:48 +00:00
|
|
|
result = node2.query("SELECT count() FROM test{}".format(i))
|
2022-03-22 16:39:58 +00:00
|
|
|
assert int(result) == 500000 * (i + 1)
|
|
|
|
|
|
|
|
result = node2.query(
|
|
|
|
"SELECT id FROM test{} WHERE id % 56 = 3 ORDER BY id".format(i)
|
|
|
|
)
|
|
|
|
assert result == node1.query(
|
|
|
|
"SELECT id FROM data{} WHERE id % 56 = 3 ORDER BY id".format(i)
|
|
|
|
)
|
|
|
|
|
|
|
|
result = node2.query(
|
|
|
|
"SELECT id FROM test{} WHERE id > 789999 AND id < 999999 ORDER BY id".format(
|
|
|
|
i
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assert result == node1.query(
|
|
|
|
"SELECT id FROM data{} WHERE id > 789999 AND id < 999999 ORDER BY id".format(
|
|
|
|
i
|
|
|
|
)
|
|
|
|
)
|
2021-06-19 16:36:39 +00:00
|
|
|
|
2021-08-16 14:50:07 +00:00
|
|
|
node2.query("DROP TABLE test{}".format(i))
|
2021-06-19 11:26:48 +00:00
|
|
|
print(f"Ok {i}")
|
2021-08-16 14:50:07 +00:00
|
|
|
|
2021-08-23 11:26:54 +00:00
|
|
|
|
|
|
|
def test_incorrect_usage(cluster):
|
|
|
|
node1 = cluster.instances["node1"]
|
2021-08-24 07:29:50 +00:00
|
|
|
node2 = cluster.instances["node3"]
|
2021-08-23 11:26:54 +00:00
|
|
|
global uuids
|
2022-03-22 16:39:58 +00:00
|
|
|
node2.query(
|
|
|
|
"""
|
2021-08-23 11:26:54 +00:00
|
|
|
ATTACH TABLE test0 UUID '{}'
|
|
|
|
(id Int32) ENGINE = MergeTree() ORDER BY id
|
|
|
|
SETTINGS storage_policy = 'web';
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
uuids[0]
|
|
|
|
)
|
|
|
|
)
|
2021-08-23 11:26:54 +00:00
|
|
|
|
|
|
|
result = node2.query("SELECT count() FROM test0")
|
2022-03-22 16:39:58 +00:00
|
|
|
assert int(result) == 500000
|
2021-08-23 11:26:54 +00:00
|
|
|
|
|
|
|
result = node2.query_and_get_error("ALTER TABLE test0 ADD COLUMN col1 Int32 first")
|
2022-03-22 16:39:58 +00:00
|
|
|
assert "Table is read-only" in result
|
2021-08-23 11:26:54 +00:00
|
|
|
|
|
|
|
result = node2.query_and_get_error("TRUNCATE TABLE test0")
|
2022-03-22 16:39:58 +00:00
|
|
|
assert "Table is read-only" in result
|
2021-08-23 11:26:54 +00:00
|
|
|
|
|
|
|
node2.query("DROP TABLE test0")
|