userver: en/testsuite/databases/clickhouse/service.py Source File
Loading...
Searching...
No Matches
service.py
1import pathlib
2import typing
3
4from testsuite.environment import service, utils
5
6from . import classes
7
8DEFAULT_CLICKHOUSE_TCP_PORT = 17123
9DEFAULT_CLICKHOUSE_HTTP_PORT = 17124
10
11SERVICE_SCRIPT_PATH = pathlib.Path(__file__).parent.joinpath(
12 'scripts/service-clickhouse',
13)
14
15
16class ServiceSettings(typing.NamedTuple):
17 tcp_port: int
18 http_port: int
19
20 def get_connection_info(self) -> classes.ConnectionInfo:
22 host='localhost',
23 tcp_port=self.tcp_port,
24 http_port=self.http_port,
25 )
26
27
28def create_clickhouse_service(
29 service_name,
30 working_dir,
31 settings: ServiceSettings | None = None,
32 env: dict[str, str] | None = None,
33):
34 if settings is None:
35 settings = get_service_settings()
37 service_name=service_name,
38 script_path=str(SERVICE_SCRIPT_PATH),
39 working_dir=working_dir,
40 environment={
41 'CLICKHOUSE_TMPDIR': working_dir,
42 'CLICKHOUSE_TCP_PORT': str(settings.tcp_port),
43 'CLICKHOUSE_HTTP_PORT': str(settings.http_port),
44 **(env or {}),
45 },
46 check_ports=[settings.tcp_port, settings.http_port],
47 start_timeout=utils.getenv_float(
48 key='TESTSUITE_CLICKHOUSE_SERVER_START_TIMEOUT',
49 default=20.0,
50 ),
51 )
52
53
54def get_service_settings():
55 return ServiceSettings(
56 utils.getenv_int(
57 key='TESTSUITE_CLICKHOUSE_SERVER_TCP_PORT',
58 default=DEFAULT_CLICKHOUSE_TCP_PORT,
59 ),
60 utils.getenv_int(
61 key='TESTSUITE_CLICKHOUSE_SERVER_HTTP_PORT',
62 default=DEFAULT_CLICKHOUSE_HTTP_PORT,
63 ),
64 )