|
| 1 | +""" |
| 2 | +Copyright (c) 2015, Baidu.com, Inc. All Rights Reserved |
| 3 | +Use of this source code is governed by a BSD-style license that can be |
| 4 | +found in the LICENSE file. |
| 5 | +""" |
| 6 | + |
| 7 | +import nose |
| 8 | +import time |
| 9 | + |
| 10 | +import common |
| 11 | +from conf import const |
| 12 | + |
| 13 | + |
| 14 | +@nose.tools.with_setup(common.create_kv_table, common.cleanup) |
| 15 | +def test_rollback_kv(): |
| 16 | + """ |
| 17 | + test kv rollback |
| 18 | + 1. write data set 1 |
| 19 | + 2. create snapshot |
| 20 | + 3. write data set 2 |
| 21 | + 4. scan & compare with set 2 |
| 22 | + 5. rollback to snapshot |
| 23 | + 6. scan & compare snapshot 1 |
| 24 | + 7. compact then compare |
| 25 | + :return: |
| 26 | + """ |
| 27 | + table_name = 'test' |
| 28 | + dump_file1 = 'dump1.out' |
| 29 | + dump_file2 = 'dump2.out' |
| 30 | + scan_file = 'scan.out' |
| 31 | + common.run_tera_mark([(dump_file1, False)], op='w', table_name=table_name, random='random', |
| 32 | + key_seed=1, value_seed=10, value_size=100, num=10000, key_size=20) |
| 33 | + snapshot = common.snapshot_op(table_name) |
| 34 | + common.run_tera_mark([(dump_file2, False)], op='w', table_name=table_name, random='random', |
| 35 | + key_seed=1, value_seed=11, value_size=100, num=10000, key_size=20) |
| 36 | + common.scan_table(table_name=table_name, file_path=scan_file, allversion=False, snapshot=0) |
| 37 | + nose.tools.assert_true(common.compare_files(dump_file2, scan_file, need_sort=True)) |
| 38 | + |
| 39 | + common.rollback_op(table_name, snapshot, 'roll') |
| 40 | + common.scan_table(table_name=table_name, file_path=scan_file, allversion=False, snapshot=0) |
| 41 | + nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=True)) |
| 42 | + |
| 43 | + common.compact_tablets(common.get_tablet_list(table_name)) |
| 44 | + nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=False)) |
| 45 | + |
| 46 | + |
| 47 | +@nose.tools.with_setup(common.create_singleversion_table, common.cleanup) |
| 48 | +def test_rollback_table(): |
| 49 | + """ |
| 50 | + test table rollback |
| 51 | + 1. write data set 1 |
| 52 | + 2. create snapshot |
| 53 | + 3. write data set 2 |
| 54 | + 4. scan & compare with set 2 |
| 55 | + 5. rollback to snapshot |
| 56 | + 6. scan & compare snapshot 1 |
| 57 | + 7. compact then compare |
| 58 | + :return: |
| 59 | + """ |
| 60 | + table_name = 'test' |
| 61 | + dump_file1 = 'dump1.out' |
| 62 | + dump_file2 = 'dump2.out' |
| 63 | + scan_file = 'scan.out' |
| 64 | + common.run_tera_mark([(dump_file1, False)], op='w', table_name=table_name, cf='cf0:q,cf1:q', random='random', |
| 65 | + key_seed=1, value_seed=10, value_size=100, num=10000, key_size=20) |
| 66 | + snapshot = common.snapshot_op(table_name) |
| 67 | + common.run_tera_mark([(dump_file2, False)], op='w', table_name=table_name, cf='cf0:q,cf1:q', random='random', |
| 68 | + key_seed=1, value_seed=11, value_size=100, num=10000, key_size=20) |
| 69 | + common.scan_table(table_name=table_name, file_path=scan_file, allversion=False, snapshot=0) |
| 70 | + nose.tools.assert_true(common.compare_files(dump_file2, scan_file, need_sort=True)) |
| 71 | + |
| 72 | + common.rollback_op(table_name, snapshot, 'roll') |
| 73 | + common.scan_table(table_name=table_name, file_path=scan_file, allversion=False, snapshot=0) |
| 74 | + nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=True)) |
| 75 | + |
| 76 | + common.compact_tablets(common.get_tablet_list(table_name)) |
| 77 | + nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=True)) |
| 78 | + |
| 79 | + |
| 80 | +@nose.tools.with_setup(common.create_kv_table) |
| 81 | +def test_rollback_kv_relaunch(): |
| 82 | + """ |
| 83 | + test kv rollback w/relaunch |
| 84 | + 1. test_rollback_kv() |
| 85 | + 2. relaunch |
| 86 | + 3. compare |
| 87 | + :return: |
| 88 | + """ |
| 89 | + table_name = 'test' |
| 90 | + dump_file1 = 'dump1.out' |
| 91 | + scan_file = 'scan.out' |
| 92 | + test_rollback_kv() |
| 93 | + |
| 94 | + common.cluster_op('kill') |
| 95 | + common.cluster_op('launch') |
| 96 | + time.sleep(2) |
| 97 | + |
| 98 | + common.scan_table(table_name=table_name, file_path=scan_file, allversion=False, snapshot=0) |
| 99 | + nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=True)) |
| 100 | + |
| 101 | + common.compact_tablets(common.get_tablet_list(table_name)) |
| 102 | + nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=False)) |
| 103 | + |
| 104 | + |
| 105 | +@nose.tools.with_setup(common.create_singleversion_table, common.cleanup) |
| 106 | +def test_rollback_table_relaunch(): |
| 107 | + """ |
| 108 | + test table rollback w/relaunch |
| 109 | + 1. test_rollback_table() |
| 110 | + 2. relaunch |
| 111 | + 3. compare |
| 112 | + :return: |
| 113 | + """ |
| 114 | + table_name = 'test' |
| 115 | + dump_file1 = 'dump1.out' |
| 116 | + scan_file = 'scan.out' |
| 117 | + test_rollback_table() |
| 118 | + |
| 119 | + common.cluster_op('kill') |
| 120 | + common.cluster_op('launch') |
| 121 | + time.sleep(2) |
| 122 | + |
| 123 | + common.scan_table(table_name=table_name, file_path=scan_file, allversion=False, snapshot=0) |
| 124 | + nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=True)) |
| 125 | + |
| 126 | + common.compact_tablets(common.get_tablet_list(table_name)) |
| 127 | + nose.tools.assert_true(common.compare_files(dump_file1, scan_file, need_sort=False)) |
| 128 | + |
| 129 | + |
| 130 | +@nose.tools.with_setup(None, common.cleanup) |
| 131 | +def test_rollback_kv_multitablets(): |
| 132 | + """ |
| 133 | + test kv rollback w/multi tablets |
| 134 | + 1. test_rollback_kv_relaunch() |
| 135 | + :return: |
| 136 | + """ |
| 137 | + |
| 138 | + common.createbyfile(schema=const.data_path + 'kv.schema', deli=const.data_path + 'deli.10') |
| 139 | + test_rollback_kv_relaunch() |
| 140 | + |
| 141 | + |
| 142 | +@nose.tools.with_setup(None, common.cleanup) |
| 143 | +def test_rollback_table_multitablets(): |
| 144 | + """ |
| 145 | + test table rollback w/multi tablets |
| 146 | + 1. test_rollback_table_relaunch() |
| 147 | + :return: |
| 148 | + """ |
| 149 | + |
| 150 | + common.createbyfile(schema=const.data_path + 'table.schema', deli=const.data_path + 'deli.10') |
| 151 | + test_rollback_table_relaunch() |
0 commit comments