|
| 1 | +import os |
| 2 | +import yatest |
| 3 | +import pytest |
| 4 | + |
| 5 | +from ydb.tests.sql.lib.test_base import TestBase |
| 6 | +from ydb.tests.datashard.lib.types_of_variables import pk_types, non_pk_types, index_first, index_second, \ |
| 7 | + index_first_sync, index_second_sync, index_three_sync, index_four_sync, index_zero_sync |
| 8 | +from ydb.tests.datashard.lib.dml_operations import DMLOperations |
| 9 | + |
| 10 | + |
| 11 | +class TestDumpRestore(TestBase): |
| 12 | + @pytest.mark.parametrize( |
| 13 | + "table_name, pk_types, all_types, index, ttl, unique, sync", |
| 14 | + [ |
| 15 | + # ("table_index_4_UNIQUE_SYNC", pk_types, {}, b'Status: BAD_REQUEST\nIssues: \n<main>: |
| 16 | + # index_four_sync, "", "UNIQUE", "SYNC"), Info: path: /Root/table_index_3_UNIQUE_SYNC\n<main>: |
| 17 | + # ("table_index_3_UNIQUE_SYNC", pk_types, {}, Error: Failed item check: unsupported index type to build\n' |
| 18 | + # index_three_sync_not_Bool, "", "UNIQUE", "SYNC"), https://github.com/ydb-platform/ydb/issues/16594 |
| 19 | + # ("table_index_2_UNIQUE_SYNC", pk_types, {}, |
| 20 | + # index_second_sync, "", "UNIQUE", "SYNC"), |
| 21 | + # ("table_index_1_UNIQUE_SYNC", pk_types, {}, |
| 22 | + # index_first_sync, "", "UNIQUE", "SYNC"), |
| 23 | + # ("table_index_0_UNIQUE_SYNC", pk_types, {}, |
| 24 | + # index_zero_sync, "", "UNIQUE", "SYNC"), |
| 25 | + ("table_index_4__SYNC", pk_types, {}, |
| 26 | + index_four_sync, "", "", "SYNC"), |
| 27 | + ("table_index_3__SYNC", pk_types, {}, |
| 28 | + index_three_sync, "", "", "SYNC"), |
| 29 | + ("table_index_2__SYNC", pk_types, {}, |
| 30 | + index_second_sync, "", "", "SYNC"), |
| 31 | + ("table_index_1__SYNC", pk_types, {}, |
| 32 | + index_first_sync, "", "", "SYNC"), |
| 33 | + ("table_index_0__SYNC", pk_types, {}, |
| 34 | + index_zero_sync, "", "", "SYNC"), |
| 35 | + ("table_index_1__ASYNC", pk_types, {}, index_second, "", "", "ASYNC"), |
| 36 | + ("table_index_0__ASYNC", pk_types, {}, index_first, "", "", "ASYNC"), |
| 37 | + ("table_all_types", pk_types, { |
| 38 | + **pk_types, **non_pk_types}, {}, "", "", ""), |
| 39 | + ("table_ttl_DyNumber", pk_types, {}, {}, "DyNumber", "", ""), |
| 40 | + ("table_ttl_Uint32", pk_types, {}, {}, "Uint32", "", ""), |
| 41 | + ("table_ttl_Uint64", pk_types, {}, {}, "Uint64", "", ""), |
| 42 | + ("table_ttl_Datetime", pk_types, {}, {}, "Datetime", "", ""), |
| 43 | + ("table_ttl_Timestamp", pk_types, {}, {}, "Timestamp", "", ""), |
| 44 | + ("table_ttl_Date", pk_types, {}, {}, "Date", "", ""), |
| 45 | + ] |
| 46 | + ) |
| 47 | + def test_dump_restore(self, table_name: str, pk_types: dict[str, str], all_types: dict[str, str], index: dict[str, str], ttl: str, unique: str, sync: str): |
| 48 | + dml = DMLOperations(self) |
| 49 | + dml.create_table(table_name, pk_types, all_types, |
| 50 | + index, ttl, unique, sync) |
| 51 | + dml.insert(table_name, all_types, pk_types, index, ttl) |
| 52 | + self.dump(table_name) |
| 53 | + dml.query(f"drop table {table_name}") |
| 54 | + self.restore(table_name) |
| 55 | + dml.select_after_insert(table_name, all_types, pk_types, index, ttl) |
| 56 | + |
| 57 | + def dump(self, table_name): |
| 58 | + yatest.common.execute([ |
| 59 | + yatest.common.binary_path(os.getenv('YDB_CLI_BINARY')), |
| 60 | + '-e', 'grpc://'+self.get_endpoint(), |
| 61 | + "--database", self.get_database(), |
| 62 | + "tools", |
| 63 | + "dump", |
| 64 | + "--path", "/Root", |
| 65 | + "--output", |
| 66 | + f"dump_{table_name}" |
| 67 | + ]) |
| 68 | + |
| 69 | + def restore(self, table_name): |
| 70 | + yatest.common.execute([ |
| 71 | + yatest.common.binary_path(os.getenv('YDB_CLI_BINARY')), |
| 72 | + '-e', 'grpc://'+self.get_endpoint(), |
| 73 | + "--database", self.get_database(), |
| 74 | + "tools", |
| 75 | + "restore", |
| 76 | + "--path", "/Root", |
| 77 | + "--input", |
| 78 | + f"dump_{table_name}" |
| 79 | + ]) |
0 commit comments