2022-08-27 16:33:04 +00:00
|
|
|
import logging
|
|
|
|
import pytest
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
from helpers.network import PartitionManager
|
|
|
|
from helpers.client import QueryRuntimeException
|
|
|
|
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
node = cluster.add_instance(
|
2022-08-28 18:05:39 +00:00
|
|
|
"node",
|
|
|
|
main_configs=[
|
|
|
|
"configs/config.d/minio.xml",
|
|
|
|
],
|
2023-07-04 10:42:27 +00:00
|
|
|
user_configs=[
|
|
|
|
"configs/users.d/users.xml",
|
|
|
|
],
|
2022-08-28 18:05:39 +00:00
|
|
|
with_minio=True,
|
2022-08-27 16:33:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
settings = {
|
2022-08-28 18:05:39 +00:00
|
|
|
"s3_max_connections": "1",
|
|
|
|
"max_insert_threads": "1",
|
|
|
|
"s3_truncate_on_insert": "1",
|
|
|
|
"s3_min_upload_part_size": "33554432",
|
|
|
|
}
|
2022-08-27 16:33:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
logging.info("Starting cluster...")
|
|
|
|
cluster.start()
|
|
|
|
logging.info("Cluster started")
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
logging.info("Stopping cluster")
|
|
|
|
cluster.shutdown()
|
|
|
|
logging.info("Cluster stopped")
|
|
|
|
|
|
|
|
|
|
|
|
def test_s3_table_functions(started_cluster):
|
|
|
|
"""
|
|
|
|
Simple test to check s3 table function functionalities
|
|
|
|
"""
|
|
|
|
node.query(
|
|
|
|
"""
|
|
|
|
INSERT INTO FUNCTION s3
|
|
|
|
(
|
2023-07-04 10:42:27 +00:00
|
|
|
nc_s3,
|
2022-08-27 16:33:04 +00:00
|
|
|
filename = 'test_file.tsv.gz',
|
|
|
|
format = 'TSV',
|
|
|
|
structure = 'number UInt64',
|
|
|
|
compression_method = 'gz'
|
|
|
|
)
|
|
|
|
SELECT * FROM numbers(1000000)
|
|
|
|
""",
|
|
|
|
settings=settings,
|
|
|
|
)
|
2022-08-28 18:05:39 +00:00
|
|
|
|
|
|
|
assert (
|
2022-08-27 16:33:04 +00:00
|
|
|
node.query(
|
2022-08-28 18:05:39 +00:00
|
|
|
"""
|
2022-08-27 16:33:04 +00:00
|
|
|
SELECT count(*) FROM s3
|
|
|
|
(
|
2023-07-04 10:42:27 +00:00
|
|
|
nc_s3,
|
2022-08-27 16:33:04 +00:00
|
|
|
filename = 'test_file.tsv.gz',
|
|
|
|
format = 'TSV',
|
|
|
|
structure = 'number UInt64',
|
|
|
|
compression_method = 'gz'
|
|
|
|
);
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
== "1000000\n"
|
|
|
|
)
|
|
|
|
|
2022-08-28 18:05:39 +00:00
|
|
|
|
2022-08-27 16:33:04 +00:00
|
|
|
def test_s3_table_functions_timeouts(started_cluster):
|
|
|
|
"""
|
2022-08-28 18:05:39 +00:00
|
|
|
Test with timeout limit of 1200ms.
|
2022-08-27 16:33:04 +00:00
|
|
|
This should raise an Exception and pass.
|
2022-08-28 18:05:39 +00:00
|
|
|
"""
|
2024-03-03 13:22:40 +00:00
|
|
|
|
2022-08-27 16:33:04 +00:00
|
|
|
with PartitionManager() as pm:
|
|
|
|
pm.add_network_delay(node, 1200)
|
|
|
|
|
|
|
|
with pytest.raises(QueryRuntimeException):
|
|
|
|
node.query(
|
2022-08-28 18:05:39 +00:00
|
|
|
"""
|
2022-08-27 16:33:04 +00:00
|
|
|
INSERT INTO FUNCTION s3
|
|
|
|
(
|
2023-07-04 10:42:27 +00:00
|
|
|
nc_s3,
|
2022-08-27 16:33:04 +00:00
|
|
|
filename = 'test_file.tsv.gz',
|
|
|
|
format = 'TSV',
|
|
|
|
structure = 'number UInt64',
|
|
|
|
compression_method = 'gz'
|
|
|
|
)
|
|
|
|
SELECT * FROM numbers(1000000)
|
|
|
|
""",
|
2022-08-28 18:05:39 +00:00
|
|
|
settings=settings,
|
2022-08-27 16:33:04 +00:00
|
|
|
)
|