|
4 | 4 | import time |
5 | 5 | from ydb.tests.olap.lib.results_processor import ResultsProcessor |
6 | 6 | from ydb.tests.olap.scenario.helpers.scenario_tests_helper import TestContext, ScenarioTestHelper |
| 7 | +from ydb.tests.olap.lib.ydb_cluster import YdbCluster |
7 | 8 | from ydb.tests.olap.lib.utils import external_param_is_true |
| 9 | +from ydb.tests.olap.lib.utils import get_external_param |
8 | 10 | from ydb.tests.olap.lib.allure_utils import allure_test_description |
| 11 | +from ydb.tests.library.harness.kikimr_runner import KiKiMR |
| 12 | +from ydb.tests.library.harness.kikimr_config import KikimrConfigGenerator |
| 13 | + |
9 | 14 |
|
10 | 15 | LOGGER = logging.getLogger() |
11 | 16 |
|
12 | 17 | SCENARIO_PREFIX = 'scenario_' |
13 | 18 |
|
14 | 19 |
|
| 20 | +class YdbClusterInstance(): |
| 21 | + ''' |
| 22 | + Represents either long-running external cluster or create temporary cluster for local run |
| 23 | + ''' |
| 24 | + _temp_ydb_cluster = None |
| 25 | + _endpoint = None |
| 26 | + _database = None |
| 27 | + |
| 28 | + def __init__(self, endpoint, database): |
| 29 | + if endpoint is not None: |
| 30 | + self._endpoint = endpoint |
| 31 | + self._database = database |
| 32 | + self._mon_port = 8765 |
| 33 | + else: |
| 34 | + config = KikimrConfigGenerator() |
| 35 | + cluster = KiKiMR(configurator=config) |
| 36 | + cluster.start() |
| 37 | + node = cluster.nodes[1] |
| 38 | + self._endpoint = "grpc://%s:%d" % (node.host, node.port) |
| 39 | + self._database = config.domain_name |
| 40 | + self._mon_port = node.mon_port |
| 41 | + self._temp_ydb_cluster = cluster |
| 42 | + LOGGER.info(f'Using YDB, endpoint:{self._endpoint}, database:{self._database}') |
| 43 | + |
| 44 | + def endpoint(self): |
| 45 | + return self._endpoint |
| 46 | + |
| 47 | + def database(self): |
| 48 | + return self._database |
| 49 | + |
| 50 | + def mon_port(self): |
| 51 | + return self._mon_port |
| 52 | + |
| 53 | + def stop(self): |
| 54 | + if self._temp_ydb_cluster is not None: |
| 55 | + self._temp_ydb_cluster.stop() |
| 56 | + self._temp_ydb_cluster = None |
| 57 | + |
| 58 | + |
15 | 59 | class BaseTestSet: |
16 | 60 | @classmethod |
17 | 61 | def get_suite_name(cls): |
18 | 62 | return cls.__name__ |
19 | 63 |
|
20 | 64 | @classmethod |
21 | 65 | def setup_class(cls): |
| 66 | + ydb_endpoint = get_external_param('ydb-endpoint', None) |
| 67 | + ydb_database = get_external_param('ydb-db', "").lstrip('/') |
| 68 | + cls._ydb_instance = YdbClusterInstance(ydb_endpoint, ydb_database) |
| 69 | + YdbCluster.reset(cls._ydb_instance.endpoint(), cls._ydb_instance.database(), cls._ydb_instance.mon_port()) |
22 | 70 | if not external_param_is_true('reuse-tables'): |
23 | 71 | ScenarioTestHelper(None).remove_path(cls.get_suite_name()) |
24 | 72 |
|
25 | 73 | @classmethod |
26 | 74 | def teardown_class(cls): |
27 | 75 | if not external_param_is_true('keep-tables'): |
28 | 76 | ScenarioTestHelper(None).remove_path(cls.get_suite_name()) |
| 77 | + cls._ydb_instance.stop() |
29 | 78 |
|
30 | 79 | def test(self, ctx: TestContext): |
31 | 80 | start_time = time.time() |
|
0 commit comments