|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +import os |
| 3 | + |
| 4 | +import ydb |
| 5 | + |
| 6 | +from ydb.tests.library.harness.kikimr_runner import KiKiMR |
| 7 | +from ydb.tests.library.harness.kikimr_config import KikimrConfigGenerator |
| 8 | +from ydb.tests.library.common.types import Erasure |
| 9 | + |
| 10 | + |
| 11 | +class TestYdbKvWorkload(object): |
| 12 | + @classmethod |
| 13 | + def setup_class(cls): |
| 14 | + cls.cluster = KiKiMR(KikimrConfigGenerator(erasure=Erasure.NONE)) |
| 15 | + cls.cluster.start() |
| 16 | + cls.driver = ydb.Driver( |
| 17 | + ydb.DriverConfig( |
| 18 | + database='/Root', |
| 19 | + endpoint="%s:%s" % ( |
| 20 | + cls.cluster.nodes[1].host, cls.cluster.nodes[1].port |
| 21 | + ) |
| 22 | + ) |
| 23 | + ) |
| 24 | + cls.driver.wait() |
| 25 | + cls.pool = ydb.QuerySessionPool(cls.driver) |
| 26 | + |
| 27 | + @classmethod |
| 28 | + def teardown_class(cls): |
| 29 | + cls.pool.stop() |
| 30 | + cls.driver.stop() |
| 31 | + cls.cluster.stop() |
| 32 | + |
| 33 | + def setup(self): |
| 34 | + current_test_full_name = os.environ.get("PYTEST_CURRENT_TEST") |
| 35 | + self.table_path = "table_" + current_test_full_name.replace("::", ".").removesuffix(" (setup)") |
| 36 | + print(self.table_path) |
| 37 | + |
| 38 | + def test_minimal_maximal_values(self): |
| 39 | + """ |
| 40 | + Test verifies correctness of handling minimal and maximal values for types |
| 41 | + """ |
| 42 | + |
| 43 | + type_to_values_to_check = { |
| 44 | + "Int32": [-2 ** 31, 2 ** 31 - 1], |
| 45 | + "Uint32": [0, 2 ** 32 - 1], |
| 46 | + "Int64": [-2 ** 63, 2 ** 63 - 1], |
| 47 | + "Uint64": [0, 2 ** 64 - 1], |
| 48 | + } |
| 49 | + |
| 50 | + for type_, values in type_to_values_to_check.items(): |
| 51 | + for i, value in enumerate(values): |
| 52 | + table_name = table_name = "{}/{}_{}".format(self.table_path, type_, i) |
| 53 | + |
| 54 | + self.pool.execute_with_retries( |
| 55 | + f""" |
| 56 | + CREATE TABLE `{table_name}` ( |
| 57 | + id Int64, |
| 58 | + value {type_}, |
| 59 | + PRIMARY KEY (id) |
| 60 | + );""" |
| 61 | + ) |
| 62 | + |
| 63 | + self.pool.execute_with_retries( |
| 64 | + f""" |
| 65 | + UPSERT INTO `{table_name}` (id, value) VALUES (1, {value}); |
| 66 | + """ |
| 67 | + ) |
| 68 | + |
| 69 | + result = self.pool.execute_with_retries( |
| 70 | + f""" |
| 71 | + SELECT id, value FROM `{table_name}` WHERE id = 1; |
| 72 | + """ |
| 73 | + ) |
| 74 | + |
| 75 | + rows = result[0].rows |
| 76 | + assert len(rows) == 1, "Expected one row" |
| 77 | + assert rows[0].id == 1, "ID does not match" |
| 78 | + assert rows[0].value == value, "Value does not match" |
0 commit comments