ClickHouse/tests/integration/test_s3_table_functions/test.py

103 lines
2.4 KiB
Python
Raw Normal View History

import logging
2024-09-27 10:19:39 +00:00
import pytest
2024-09-27 10:19:39 +00:00
from helpers.client import QueryRuntimeException
from helpers.cluster import ClickHouseCluster
from helpers.network import PartitionManager
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,
)
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",
}
@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,
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 (
node.query(
2022-08-28 18:05:39 +00:00
"""
SELECT count(*) FROM s3
(
2023-07-04 10:42:27 +00:00
nc_s3,
filename = 'test_file.tsv.gz',
format = 'TSV',
structure = 'number UInt64',
compression_method = 'gz'
);
"""
)
== "1000000\n"
)
2022-08-28 18:05:39 +00:00
def test_s3_table_functions_timeouts(started_cluster):
"""
2022-08-28 18:05:39 +00:00
Test with timeout limit of 1200ms.
This should raise an Exception and pass.
2022-08-28 18:05:39 +00:00
"""
2024-03-03 13:22:40 +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
"""
INSERT INTO FUNCTION s3
(
2023-07-04 10:42:27 +00:00
nc_s3,
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,
)