2020-04-08 21:48:00 +00:00
|
|
|
import os
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
import pytest
|
2020-04-08 21:48:00 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
DICTIONARY_FILES = [
|
2022-03-22 16:39:58 +00:00
|
|
|
"configs/dictionaries/FileSourceConfig.xml",
|
|
|
|
"configs/dictionaries/ExecutableSourceConfig.xml",
|
|
|
|
"configs/dictionaries/source.csv",
|
|
|
|
"configs/dictionaries/HTTPSourceConfig.xml",
|
|
|
|
"configs/dictionaries/ClickHouseSourceConfig.xml",
|
2020-04-08 21:48:00 +00:00
|
|
|
]
|
|
|
|
|
2020-08-12 08:55:04 +00:00
|
|
|
cluster = ClickHouseCluster(__file__)
|
2022-03-22 16:39:58 +00:00
|
|
|
instance = cluster.add_instance("node", dictionaries=DICTIONARY_FILES)
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2020-04-08 21:48:00 +00:00
|
|
|
|
|
|
|
def prepare():
|
|
|
|
node = instance
|
|
|
|
path = "/source.csv"
|
|
|
|
|
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
2022-03-22 16:39:58 +00:00
|
|
|
node.copy_file_to_container(
|
|
|
|
os.path.join(script_dir, "./http_server.py"), "/http_server.py"
|
|
|
|
)
|
|
|
|
node.copy_file_to_container(
|
|
|
|
os.path.join(script_dir, "configs/dictionaries/source.csv"), "./source.csv"
|
|
|
|
)
|
|
|
|
node.exec_in_container(
|
|
|
|
[
|
|
|
|
"bash",
|
|
|
|
"-c",
|
|
|
|
"python3 /http_server.py --data-path={tbl} --schema=http --host=localhost --port=5555".format(
|
|
|
|
tbl=path
|
|
|
|
),
|
|
|
|
],
|
|
|
|
detach=True,
|
|
|
|
)
|
2020-04-08 21:48:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
prepare()
|
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2020-09-15 15:42:46 +00:00
|
|
|
|
2020-04-08 21:48:00 +00:00
|
|
|
def test_work(start_cluster):
|
|
|
|
query = instance.query
|
|
|
|
|
2020-09-15 15:42:46 +00:00
|
|
|
instance.query("SYSTEM RELOAD DICTIONARIES")
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert query("SELECT dictGetString('test_file', 'first', toUInt64(1))") == "\\'a\n"
|
|
|
|
assert query("SELECT dictGetString('test_file', 'second', toUInt64(1))") == '"b\n'
|
|
|
|
assert (
|
|
|
|
query("SELECT dictGetString('test_executable', 'first', toUInt64(1))")
|
|
|
|
== "\\'a\n"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
query("SELECT dictGetString('test_executable', 'second', toUInt64(1))")
|
|
|
|
== '"b\n'
|
|
|
|
)
|
2020-04-08 21:48:00 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
caught_exception = ""
|
2020-04-08 21:48:00 +00:00
|
|
|
try:
|
2022-03-22 16:39:58 +00:00
|
|
|
instance.query(
|
|
|
|
"CREATE TABLE source (id UInt64, first String, second String, third String) ENGINE=TinyLog;"
|
|
|
|
)
|
|
|
|
instance.query(
|
|
|
|
"INSERT INTO default.source VALUES (1, 'aaa', 'bbb', 'cccc'), (2, 'ddd', 'eee', 'fff')"
|
|
|
|
)
|
2020-04-08 21:48:00 +00:00
|
|
|
instance.query("SELECT dictGetString('test_clickhouse', 'second', toUInt64(1))")
|
|
|
|
except Exception as e:
|
|
|
|
caught_exception = str(e)
|
|
|
|
|
|
|
|
assert caught_exception.find("Limit for result exceeded") != -1
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert query("SELECT dictGetString('test_http', 'first', toUInt64(1))") == "\\'a\n"
|
|
|
|
assert query("SELECT dictGetString('test_http', 'second', toUInt64(1))") == '"b\n'
|