1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef DISTRIBUTED_DB_MODULE_TEST_TYPES_H 16 #define DISTRIBUTED_DB_MODULE_TEST_TYPES_H 17 18 #include <string> 19 #include <vector> 20 #include <cmath> 21 #include "kv_store_delegate.h" 22 #include "kv_store_delegate_manager.h" 23 #include "distributed_test_sysinfo.h" 24 #include "distributeddb_log_print.h" 25 #include "distributeddb_constant.h" 26 27 struct EntrySize { 28 unsigned int keySize = 0; 29 unsigned int valSize = 0; SetEntrySize30 void Set(unsigned int keySizeInput, unsigned int valSizeInput) 31 { 32 this->keySize = keySizeInput; 33 this->valSize = valSizeInput; 34 } 35 }; 36 37 enum DBTypeInner { 38 UNENCRYPTED_DISK_DB = 0, 39 ENCRYPTED_DISK_DB, 40 MEMORY_DB 41 }; 42 43 struct TimeSamp { 44 std::vector<uint64_t> startTime; 45 std::vector<uint64_t> endTime; TimeSampTimeSamp46 TimeSamp() 47 { 48 } 49 }; 50 51 struct ImagePerSamp { 52 std::vector<uint64_t> firstStep; 53 std::vector<uint64_t> secondStep; ImagePerSampImagePerSamp54 ImagePerSamp() 55 { 56 } 57 }; 58 59 struct PerTimeLength { 60 std::vector<double> entriesDuration; 61 std::vector<double> cursorDuration; 62 std::vector<double> moveNextDuration; 63 std::vector<double> entryDurationForward; 64 std::vector<double> movePreviousDuration; 65 std::vector<double> entryDurationBackup; 66 }; 67 68 struct Schema { 69 std::vector<std::string> version; 70 std::vector<std::string> mode; 71 std::vector<std::string> define; 72 std::vector<std::string> index; 73 }; 74 struct LongDefine { 75 int recordNum; 76 int recordSize; 77 char prefix; 78 }; 79 80 struct NumberSize { 81 EntrySize entrySize; 82 int recordsNumber; 83 bool isRoundBack = false; NumberSizeNumberSize84 NumberSize() : recordsNumber(0) 85 { 86 } 87 }; 88 89 enum class RandType { 90 ALPHA_NUM, 91 ALPHA_NUM_UNDERLINE, 92 SPECIAL, 93 }; 94 95 // ************************ number class ********************************** 96 const unsigned int OBSERVER_NUM = 8; 97 const int BUFFER_COUNT = 5; 98 const unsigned int NB_OBSERVER_NUM = 4; 99 const unsigned int NB_OPERATION_NUM = 100; 100 const unsigned int NB_PREDATA_NUM = 50; 101 const unsigned int RECORDS_SMALL_CNT = 2; 102 const unsigned int NO_RECORD = 0; 103 const unsigned int THREE_RECORDS = 3; 104 const unsigned int THREE_PERF_DATA = 3; 105 const unsigned int BATCH_RECORDS = 128; 106 const static int ONE_RECORD = 1; 107 const static int TWO_RECORDS = 2; 108 const static int FOUR_RECORDS = 4; 109 const static int FIVE_RECORDS = 5; 110 const static int SIX_RECORDS = 6; 111 const static int EIGHT_RECORDS = 8; 112 const static int NINE_RECORDS = 9; 113 const static int TEN_RECORDS = 10; 114 const static int SIXTEEN_RECORDS = 16; 115 const static int TWENTY_RECORDS = 20; 116 const static int THIRTY_RECORDS = 30; 117 const static int THIRTYTWO_RECORDS = 32; 118 const static int FORTY_RECORDS = 40; 119 const static int FIFTY_RECORDS = 50; 120 const static int SIXTY_RECORDS = 60; 121 const static int EIGHTY_RECORDS = 80; 122 const static int ONE_HUNDRED_RECORDS = 100; 123 const static int TWO_HUNDREDS_RECORDS = 200; 124 const static int FIVE_HUNDREDS_RECORDS = 500; 125 const static int SIX_HUNDREDS_RECORDS = 600; 126 const static int ONE_THOUSAND_RECORDS = 1000; 127 const static int TWO_THOUSANDS_RECORDS = 2000; 128 const static int TWO_FIVE_ZERO_ZERO_RECORDS = 2500; 129 const static int TWO_FIVE_SIX_ZERO_RECORDS = 2560; 130 const static int FIVE_THOUSANDS_RECORDS = 5000; 131 const static int TEN_THOUSAND_RECORDS = 10000; 132 const static int FIFTEEN_THOUSAND_RECORDS = 15000; 133 const static int TWENTY_THOUSAND_RECORDS = 20000; 134 const static int THIRTY_THOUSAND_RECORDS = 30000; 135 const static int FIFTY_THOUSAND_RECORDS = 50000; 136 const static int HUNDRED_THOUSAND_RECORDS = 100000; 137 const static int FOUR_HUNDRED_THOUSAND_RECORDS = 400000; 138 const static int FIVE_HUNDRED_THOUSAND_RECORDS = 500000; 139 const static int TWO_FIVE_SIX_RECORDS = 256; 140 const static int FIRST_RECORD = 1; 141 const static int SECOND_RECORD = 2; 142 const static int DATAS_ACCOUNT = 300; 143 const static int DATA_LEN = 13; 144 const static int NINE_CNT = 9; 145 const static int TEN_CNT = 10; 146 const static unsigned int TWO_DEVICES = 2; 147 const static unsigned int FOUR_DEVICES = 4; 148 const static int THIRD_FUNC = 3; 149 const static int FOURTH_FUNC = 4; 150 const static int FIFTH_FUNC = 5; 151 const static int THREE_DBS = 3; 152 const static int EIGHT_DBS = 8; 153 const static int TEN_DBS = 10; 154 const static int ELEVEN_DBS = 11; 155 const static int TWELVE_DBS = 12; 156 const static int FIRST_DB = 1; 157 const static int FIFTH_DB = 5; 158 const static int TENTH_DB = 10; 159 const static int ELEVENTH_DB = 11; 160 const static int TWELFTH_DB = 12; 161 162 // ************************ loop times class ************************** 163 const unsigned int MOD_NUM = 2; 164 const unsigned int BIG_MOD_NUM = 3; 165 166 const unsigned int ID_CNT_START = 0; 167 const unsigned int ID_MIN_CNT = 2; 168 const unsigned int ID_MEDIUM_CNT = 3; 169 const unsigned int ID_MAX_CNT = 16; 170 const unsigned int STORE_CNT = 4; 171 const unsigned int DIR_CNT_START = 0; 172 const unsigned int DIR_MAX_CNT = 14; 173 const static int MANYTINES = 3; 174 const static int ONE_TIME = 1; 175 const static int TWO_TIMES = 2; 176 const static int FIVE_TIMES = 5; 177 const static int TEN_TIMES = 10; 178 const static int FIFTY_TIMES = 50; 179 const static int HUNDRED_TIMES = 100; 180 181 // ************************ time class ************************** 182 const unsigned int UNIQUE_SECOND = 1; 183 const unsigned int TWO_SECONDS = 2; 184 const unsigned int THREE_SECONDS = 3; 185 const unsigned int FOUR_SECONDS = 4; 186 const unsigned int FIVE_SECONDS = 5; 187 const unsigned int SIX_SECONDS = 6; 188 const unsigned int TEN_SECONDS = 10; 189 const unsigned int FIFTEEN_SECONDS = 15; 190 const unsigned int TWENTY_SECONDS = 20; 191 const unsigned int THIRTY_SECONDS = 30; 192 const unsigned int FORTY_SECONDS = 40; 193 const unsigned int SIXTY_SECONDS = 60; 194 const unsigned int ONE_HUNDRED_SECONDS = 100; 195 const unsigned int TWO_HUNDREDS_SECONDS = 200; 196 const unsigned int THREE_HUNDREDS_SECONDS = 300; 197 const unsigned int FOUR_HUNDREDS_SECONDS = 400; 198 const unsigned int FIVE_HUNDREDS_SECONDS = 500; 199 const unsigned int SIX_HUNDREDS_SECONDS = 600; 200 const unsigned int SEVEN_HUNDREDS_SECONDS = 700; 201 const unsigned int EIGHT_HUNDREDS_SECONDS = 800; 202 const unsigned int TEN_HUNDREDS_SECONDS = 1000; 203 const unsigned int ONE_FIVE_ZERO_ZERO_SECONDS = 1500; 204 const unsigned int SIXTEEN_HUNDREDS_SECONDS = 1600; 205 const unsigned int EIGHTEEN_HUNDREDS_SECONDS = 1800; 206 const unsigned int TWENTY_HUNDREDS_SECONDS = 2000; 207 const unsigned int THREE_THOUSANDS_SECONDS = 3000; 208 const unsigned int THREE_SIX_ZERO_ZERO_SECONDS = 3600; 209 const unsigned int EIGHT_THOUSANDS_SECONDS = 8000; 210 const unsigned int TEN_THOUSANDS_SECONDS = 10000; 211 const unsigned int WAIT_FOR_LONG_TIME = 15000; 212 const unsigned int WAIT_FOR_FIFTY_MS = 50000; 213 const unsigned int WAIT_FOR_LAST_SYNC = 500000; 214 const unsigned int WAIT_FOR_TWO_HUNDREDS_MS = 200000; 215 const int FIFTY_MILI_SECONDS = 50; 216 const int HUNDRED_MILLI_SECONDS = 100; 217 const static int MILLSECONDS_PER_SECOND = 1000; 218 219 // ************************ length of key class ************************** 220 const static int KEY_SIX_BYTE = 6; 221 const static int KEY_EIGHT_BYTE = 8; 222 const static int KEY_THIRTYTWO_BYTE = 32; 223 const static int KEY_SIXTYFOUR_BYTE = 64; 224 const static int KEY_TWO_FIVE_SIX_BYTE = 256; 225 const static int KEY_ONE_K_BYTE = 1024; 226 const static int KEY_ONE_HUNDRED_BYTE = 100; 227 228 // ************************ length of value class ************************** 229 const unsigned int SMALL_VALUE_SIZE = 2; 230 const unsigned int ONE_K_LONG_STRING = 1024; // 1K 231 const unsigned int TWO_K_LONG_STRING = 2048; // 2K 232 const unsigned int TWO_POINT_FOUR_LONG = 2400; // 2.4K 233 const unsigned int THREE_K_LONG_STRING = 3072; // 3K 234 const unsigned int FOUR_K_LONG_STRING = 4096; // 4K 235 const unsigned int ONE_M_LONG_STRING = 1048576; // 1M 236 const unsigned int TWO_M_LONG_STRING = 2097152; // 2M 237 const unsigned int FOUR_M_LONG_STRING = 4194304; // 4M 238 const unsigned int TEN_M_LONG_STRING = 10485760; // 10M 239 const static int VALUE_SIX_BYTE = 6; 240 const static int VALUE_ONE_HUNDRED_BYTE = 100; 241 const static int VALUE_FIVE_HUNDRED_BYTE = 500; 242 const static int VALUE_ONE_K_BYTE = 1024; 243 const static int VALUE_HUNDRED_K_BYTE = 102400; 244 const static int VALUE_TWENTY_K_BYTE = 20480; 245 const static int VALUE_TWO_POINT_FOUR_K_BYTE = 2458; 246 const static int PASSWD_BYTE = 129; 247 248 // ************************ bool class ************************************* 249 const bool IS_LOCAL_ONLY = true; 250 const bool IS_NOT_LOCAL_ONLY = false; 251 const bool IS_NEED_CREATE = true; 252 const bool IS_NOT_NEED_CREATE = false; 253 254 // ************************ range verify class ***************************** 255 const static int CHANGED_ZERO_TIME = 0; 256 const static int CHANGED_ONE_TIME = 1; 257 const static int CHANGED_TWO_TIMES = 2; 258 const static int CHANGED_THREE_TIMES = 3; 259 const static int CHANGED_ONE_HUNDRED_TIMES = 100; 260 const static int CHANGED_TWO_HUNDRED_TIMES = 200; 261 const static int CHANGED_TWO_FIVE_SIX_TIMES = 256; 262 const static int CHANGED_ONE_THOUSAND_TIMES = 1000; 263 const static int CHANGED_TEN_THOUSAND_TIMES = 10000; 264 const unsigned int RECORDS_NUM_START = 1; 265 const unsigned int RECORDS_NUM_END = 128; 266 const unsigned int DEFAULT_START = 1; 267 const unsigned int DEFAULT_ANOTHER_START = 11; 268 const unsigned int OBSERVER_CNT_START = 0; 269 const unsigned int OBSERVER_CNT_END = 8; 270 const unsigned int NB_OBSERVER_CNT_START = 0; 271 const unsigned int NB_OBSERVER_CNT_END = 4; 272 const unsigned int NB_OPERATION_CNT_START = 0; 273 const unsigned int NB_OPERATION_CNT_END = 5; 274 275 const int LOCAL_OPER_CNT = 2; 276 const int NATIVE_OPER_CNT = 6; 277 const static int OPER_CNT_START = 0; 278 const static int OPER_CNT_END = 10; 279 const static int MODE_RAND_MIN = 0; 280 const static int MODE_RAND_MAX = 2; 281 282 // ************************ USED FOR THREAD ******************************** 283 const unsigned int SINGLE_THREAD_NUM = 2; 284 const unsigned int CHAR_SPAN_MIN = 0; 285 const unsigned int CHAR_SPAN_MAX = 255; 286 287 // ************************ USED FOR INDEX ********************************* 288 const int INDEX_ZEROTH = 0; 289 const int INDEX_FIRST = 1; 290 const int INDEX_SECOND = 2; 291 const int INDEX_THIRD = 3; 292 const int INDEX_FORTH = 4; 293 const int INDEX_FIFTH = 5; 294 const int INDEX_SIXTH = 6; 295 const int INDEX_SEVENTH = 7; 296 const int INDEX_EIGHTTH = 8; 297 const int INDEX_NINTH = 9; 298 const int INDEX_TENTH = 10; 299 const int INDEX_NINE_NINE_NINTH = 999; 300 const int INDEX_FIVE_THOUSANDS = 5000; 301 const int INDEX_TEN_THOUSANDS = 10000; 302 const int INDEX_FIFTEEN_THOUSANDS = 15000; 303 304 // ************************ OTHER CLASS ************************************ 305 const int TABLE_MAX = 60; 306 307 const static int ENCRYPT_COUNT = 100; 308 309 const static int EVEN_NUMBER = 2; 310 311 const int VALUE_FIVE_HUNDRED = 500; 312 const int VALUE_SUM = VALUE_FIVE_HUNDRED + VALUE_FIVE_HUNDRED; 313 const int VALUE_CHANGE1_FIRST = 400; 314 const int VALUE_CHANGE1_SECOND = VALUE_SUM - VALUE_CHANGE1_FIRST; 315 const int VALUE_CHANGE2_FIRST = 700; 316 const int VALUE_CHANGE2_SECOND = VALUE_SUM - VALUE_CHANGE2_FIRST; 317 318 const static std::string MULTIDB = "/multi_ver/value_storage.db"; 319 const static std::string KVMULTIDB = "/multi_ver/multi_ver_data.db"; 320 const static std::string SYNC_MULTI_VER_QUERY_SQL = "select count(*) from version_data;"; 321 const static std::string DATABASE_INFOR_FILE = "/single_ver/main/gen_natural_store.db"; 322 const static std::string SYNC_VALUE_SLICE_QUERY_SQL = "select count(*) from data;"; 323 const static std::string QUERY_SQL = "select count(*) from version_data where key = ?;"; 324 const static std::string MULTI_KEY_QUERY_SQL = "select count(*) from version_data where key = ? or key = ?;"; 325 326 typedef std::chrono::time_point<std::chrono::steady_clock, std::chrono::microseconds> microClock_type; 327 328 // place some const values for testcases in namespace. 329 namespace DistributedDBDataGenerator { 330 const std::string STORE_ID = ""; 331 const std::string STORE_ID_1 = "STORE_ID_1"; 332 const std::string STORE_ID_2 = "STORE_ID_2"; 333 const std::string STORE_ID_3 = "STORE_ID_3"; 334 const std::string STORE_ID_4 = "STORE_ID_4"; 335 const std::string STORE_ID_5 = "STORE_ID_5"; 336 const std::string STORE_ID_6 = "STORE_ID_6"; 337 const std::string STORE_ID_7 = "STORE_ID_7"; 338 const std::string STORE_ID_8 = "STORE_ID_8"; 339 const std::string STORE_ID_9 = "STORE_ID_9"; 340 const std::string STORE_ID_10 = "STORE_ID_10"; 341 const std::string JSON_SCHEMA_STORE_ID_11 = "JSON_SCHEMA_STORE_ID_11"; 342 const std::string STORE_ID_PERFORM = "STORE_ID_PERFORM"; 343 const static std::string STORE_ID_SYNC_1 = "SYNC1"; 344 const static std::string STORE_ID_SYNC_2 = "SYNC2"; 345 const static std::string STORE_ID_SYNC_3 = "SYNC3"; 346 const static std::string STORE_ID_SYNC_4 = "SYNC4"; 347 const static std::string STORE_ID_SYNC_5 = "SYNC5"; 348 const static std::string STORE_ID_SYNC_6 = "SYNC6"; 349 const static std::string STORE_ID_SYNC_7 = "SYNC7"; 350 const static std::string STORE_ID_SYNC_8 = "SYNC8"; 351 const static std::string STORE_ID_SYNC_9 = "SYNC9"; 352 const static std::string STORE_ID_SYNC_10 = "SYNC10"; 353 354 const std::string APP_ID = "APP_ID"; 355 const std::string APP_ID_1 = "APP_ID_1"; 356 const std::string APP_ID_2 = "APP_ID_2"; 357 const std::string APP_ID_3 = "APP_ID_3"; 358 const std::string APP_ID_4 = "APP_ID_4"; 359 const std::string APP_ID_5 = "APP_ID_5"; 360 const std::string APP_ID_6 = "APP_ID_6"; 361 const std::string APP_ID_PERFORM = "APP_ID_PERFORM"; 362 const std::string APP_ID_NB_1 = "APP_ID_NB_1"; 363 const std::string APP_ID_NB_2 = "APP_ID_NB_2"; 364 const std::string APP_ID_LOCAL_1 = "APP_ID_LOCAL_1"; 365 366 const std::string USER_ID = "USER_ID"; 367 const std::string USER_ID_1 = "USER_ID_1"; 368 const std::string USER_ID_2 = "USER_ID_2"; 369 const std::string USER_ID_3 = "USER_ID_3"; 370 const std::string USER_ID_4 = "USER_ID_4"; 371 const std::string USER_ID_5 = "USER_ID_5"; 372 const std::string USER_ID_6 = "USER_ID_6"; 373 const std::string USER_ID_PERFORM = "USER_ID_PERFORM"; 374 375 const std::vector<uint8_t> K1_HASH_KEY = { 0xA2, 0xAB, 0x19, 0x59, 0xC1, 0xC3, 0xBF, 0xA2, 0x95, 0xB0, 0xFC, 0x90, 376 0x19, 0x93, 0x78, 0x27, 0x2D, 0xB7, 0x6B, 0x45}; 377 const std::vector<uint8_t> K2_HASH_KEY = { 0xBF, 0xEB, 0x73, 0x4D, 0x2E, 0xB5, 0xD0, 0x91, 0x51, 0x45, 0xC1, 0x86, 378 0x12, 0x48, 0x75, 0x7D, 0x4F, 0xD3, 0x2B, 0xC2 }; 379 const std::vector<uint8_t> K3_HASH_KEY = { 0xB5, 0x32, 0xA5, 0x44, 0x0D, 0xD8, 0x42, 0x2D, 0x9D, 0x5F, 0x8D, 0x99, 380 0x9B, 0x31, 0x06, 0x87, 0xD4, 0xA2, 0xFE, 0xD9 }; 381 const std::vector<uint8_t> K4_HASH_KEY = { 0x5E, 0xF8, 0x76, 0x6D, 0xE9, 0x35, 0x32, 0x44, 0x24, 0xB5, 0x63, 0xAA, 382 0x3E, 0xB0, 0xC7, 0x46, 0x6B, 0x29, 0x3C, 0x94 }; 383 const std::vector<uint8_t> NULL_HASH_KEY = {}; 384 const DistributedDB::Key KEY_1 = { 'k', '1' }; 385 const DistributedDB::Key KEY_2 = { 'k', '2' }; 386 const DistributedDB::Key KEY_3 = { 'k', '3' }; 387 const DistributedDB::Key KEY_4 = { 'k', '4' }; 388 const DistributedDB::Key KEY_5 = { 'k', '5' }; 389 const DistributedDB::Key KEY_6 = { 'k', '6' }; 390 const DistributedDB::Key KEY_7 = { 'k', '7' }; 391 const DistributedDB::Key KEY_8 = { 'k', '8' }; 392 const DistributedDB::Key KEY_9 = { 'k', '9' }; 393 const DistributedDB::Key KEY_10 = { 'k', '1', '0' }; 394 const DistributedDB::Key KEY_6_BYTE = { 'k', 'k', 'k', 'k', 'k', '1' }; 395 const DistributedDB::Key KEY_A_1 = { 'a', 'b', 'c' }; 396 const DistributedDB::Key KEY_A_2 = { 'a', 'b', 'c', 'd', 'a', 's', 'd' }; 397 const DistributedDB::Key KEY_A_3 = { 'a', 'b', 'c', 'd', 's' }; 398 const DistributedDB::Key KEY_BIG_1 = { 'b', 'i', 'g', '1' }; 399 400 const std::vector<uint8_t> NULL_K1 = {}; 401 const DistributedDB::Key KEY_EMPTY = { }; 402 const DistributedDB::Key KEY_K = { 'k' }; 403 const DistributedDB::Key KEY_A = { 'a' }; 404 const DistributedDB::Key KEY_E = { 'k', 'e' }; 405 const DistributedDB::Key OK_KEY_1 = { 'o', 'k' }; 406 407 const DistributedDB::Value VALUE_1 = { 'v', '1' }; 408 const DistributedDB::Value VALUE_2 = { 'v', '2' }; 409 const DistributedDB::Value VALUE_3 = { 'v', '3' }; 410 const DistributedDB::Value VALUE_4 = { 'v', '4' }; 411 const DistributedDB::Value VALUE_5 = { 'v', '5' }; 412 const DistributedDB::Value VALUE_6 = { 'v', '6' }; 413 const DistributedDB::Value VALUE_7 = { 'v', '7' }; 414 const DistributedDB::Value VALUE_8 = { 'v', '8' }; 415 const DistributedDB::Value VALUE_9 = { 'v', '9' }; 416 const DistributedDB::Value VALUE_10 = { 'v', '1', '0' }; 417 const DistributedDB::Value VALUE_A_1 = { 'a', '1' }; 418 const DistributedDB::Value VALUE_A_2 = { 'a', '2' }; 419 const DistributedDB::Value VALUE_A_3 = { 'a', '3' }; 420 const DistributedDB::Value VALUE_EMPTY = { }; 421 const DistributedDB::Value OK_VALUE_1 = { 'o', 'k' }; 422 423 const std::vector<uint8_t> IMAGE_KEY_PRE = {'a', 'l', 'b', 'u', 'm', '_'}; 424 const std::vector<uint8_t> IMAGE_FILE_KEY_PRE = {'f', 'i', 'l', 'e', '_'}; 425 const std::string IMAGE_VALUE_PRE = {"\"_id\":23,\"local_media_id\":0," \ 426 "\"_data\":\"/storage/emulated/0/Pictures/.Gallery2/recycle/GF6DA7BR\"," \ 427 "\"_size\":427460,\"date_added\":1518606965,\"date_modified\":1519460678," \ 428 "\"mime_type\":\"image/jpeg\",\"title\":\"MagazinePic-05-2.3.001-bigpicture_05_4\"," \ 429 "\"description\":\"\",\"_display_name\":\"MagazinePic-05-2.3.001-bigpicture_05_4.jpg\"," \ 430 "\"orientation\":0,\"latitude\":0,\"longitude\":0,\"datetaken\":1514792938000," \ 431 "\"bucket_id\":771419238,\"bucket_display_name\":\"MagazineUnlock\",\"duration\":0," \ 432 "\"resolution\":\"1440x2560\",\"media_type\":1,\"storage_id\":65537,\"width\":1440," \ 433 "\"height\":2560,\"is_hdr\":0,\"is_hw_privacy\":0,\"hw_voice_offset\":0,\"is_hw_favorite\":0," \ 434 "\"hw_image_refocus\":0,\"is_hw_burst\":0,\"hw_rectify_offset\":0,\"contenturi\":\"\"," \ 435 "\"hash\":\"e46cf1bb4773421fbded2e2583fe7130\",\"special_file_list\":0,\"special_file_type\":0," \ 436 "\"special_file_offset\":0,\"relative_bucket_id\":1793967153,\"albumId\":\"default-album-3\",\"fileType\":1," \ 437 "\"fileId\":0,\"videoThumbId\":0,\"thumbId\":0,\"lcdThumbId\":0,\"thumbType\":3,\"localThumbPath\":\"\"," \ 438 "\"localBigThumbPath\":\"\",\"expand\":\"\",\"showDateToken\":1514792938000,\"visit_time\":0," \ 439 "\"last_update_time\":1519461225861,\"source\":\"\",\"geo_code\":0,\"location_key\":104473884060," \ 440 "\"story_id\":0,\"story_cluster_state\":\"todo\",\"search_data_status\":0,\"category_id\":-2," \ 441 "\"portrait_id\":0,\"portrait_cluster_state\":\"todo\",\"dirty\":0,\"recycleFlag\":2," \ 442 "\"recycledTime\":1519550100614,\"sourcePath\":\"/storage/emulated/0/MagazineUnlock/MagazinePic\"," \ 443 "\"sourceFileName\":\"MagazinePic-05-2.3.001-bigpict\",\"garbage\":0,\"uniqueId\":0,\"localKey\":\"\"," \ 444 "\"picture_score\":99,\"cam_perception\":\"\",\"cam_exif_flag\":1,\"sync_status\":0," \ 445 "\"album_name\":\".MagazineUnlock\",\"ocr_status\":0"}; 446 447 const DistributedDB::Key KEY_SEARCH_0 = KEY_A; 448 const DistributedDB::Key KEY_SEARCH = { 'a', 'b' }; 449 const DistributedDB::Key KEY_SEARCH_2 = { 'a', 'b', 'c', 'd', 'e' }; 450 const std::vector<uint8_t> K_SEARCH_3 = { 'b', 'i', 'g'}; 451 const DistributedDB::Key KEY_SEARCH_3 = { 'b', 'i', 'g'}; 452 const DistributedDB::Key KEY_SEARCH_4 = { 'k' }; 453 const std::vector<uint8_t> K_SEARCH_5 = { 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k' }; 454 const DistributedDB::Key KEY_SEARCH_6 = { 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', '6' }; 455 const DistributedDB::Key PERFORMANCEKEY = { 'p', 'e', 'r' }; 456 const DistributedDB::Key KEY_CONS_1 = { 'c', 'o', 'n', 's', '1' }; 457 const DistributedDB::Key KEY_CONS_2 = { 'c', 'o', 'n', 's', '2' }; 458 const DistributedDB::Key KEY_BATCH_CONS_1 = { 'r', 'e', 's', 'u', 'l', 't', '1' }; 459 const DistributedDB::Key KEY_BATCH_CONS_2 = { 'r', 'e', 's', 'u', 'l', 't', '2' }; 460 const DistributedDB::Key KEY_BATCH_CONS_3 = { 'r', 'e', 's', 'u', 'l', 't', '3' }; 461 const std::vector<DistributedDB::Key> KEYS_1 = { KEY_1, KEY_2 }; 462 const DistributedDB::Entry ENTRY_1 = { .key = KEY_1, .value = VALUE_1 }; 463 const DistributedDB::Entry ENTRY_2 = { .key = KEY_2, .value = VALUE_2 }; 464 const DistributedDB::Entry ENTRY_3 = { .key = KEY_3, .value = VALUE_3 }; 465 const DistributedDB::Entry ENTRY_4 = { .key = KEY_4, .value = VALUE_4 }; 466 const DistributedDB::Entry ENTRY_5 = { .key = KEY_5, .value = VALUE_5 }; 467 const DistributedDB::Entry ENTRY_6 = { .key = KEY_6, .value = VALUE_6 }; 468 const DistributedDB::Entry ENTRY_7 = { .key = KEY_7, .value = VALUE_7 }; 469 const DistributedDB::Entry ENTRY_8 = { .key = KEY_8, .value = VALUE_8 }; 470 const DistributedDB::Entry ENTRY_9 = { .key = KEY_9, .value = VALUE_9 }; 471 const DistributedDB::Entry ENTRY_10 = { .key = KEY_10, .value = VALUE_10 }; 472 const DistributedDB::Entry ENTRY_1_2 = { .key = KEY_1, .value = VALUE_2 }; 473 const DistributedDB::Entry ENTRY_2_3 = { .key = KEY_2, .value = VALUE_3 }; 474 const DistributedDB::Entry ENTRY_3_1 = { .key = KEY_3, .value = VALUE_1 }; 475 const DistributedDB::Entry ENTRY_4_5 = { .key = KEY_4, .value = VALUE_5 }; 476 const DistributedDB::Entry ENTRY_5_6 = { .key = KEY_5, .value = VALUE_6 }; 477 const DistributedDB::Entry ENTRY_2_1 = { .key = KEY_2, .value = VALUE_1 }; 478 const DistributedDB::Entry ENTRY_1_3 = { .key = KEY_1, .value = VALUE_3 }; 479 const DistributedDB::Entry ENTRY_2_4 = { .key = KEY_2, .value = VALUE_4 }; 480 const DistributedDB::Entry ENTRY_1_4 = { .key = KEY_1, .value = VALUE_4 }; 481 const DistributedDB::Entry ENTRY_3_4 = { .key = KEY_3, .value = VALUE_4 }; 482 const DistributedDB::Entry ENTRY_1_NULL = { .key = KEY_1, .value = VALUE_EMPTY }; 483 const DistributedDB::Entry ENTRY_2_NULL = { .key = KEY_2, .value = VALUE_EMPTY }; 484 const DistributedDB::Entry ENTRY_3_NULL = { .key = KEY_3, .value = VALUE_EMPTY }; 485 const DistributedDB::Entry ENTRY_NULL_1 = { .key = KEY_EMPTY, .value = VALUE_2 }; 486 const DistributedDB::Entry ENTRY_NULL_2 = { .key = KEY_EMPTY, .value = VALUE_3 }; 487 const DistributedDB::Entry ENTRY_NULL_3 = { .key = KEY_EMPTY, .value = VALUE_1 }; 488 const DistributedDB::Entry ENTRY_NULL = { .key = KEY_EMPTY, .value = VALUE_EMPTY }; 489 const DistributedDB::Entry ENTRY_A_1 = { .key = KEY_A_1, .value = VALUE_A_1 }; 490 const DistributedDB::Entry ENTRY_A_2 = { .key = KEY_A_2, .value = VALUE_A_2 }; 491 const DistributedDB::Entry ENTRY_A_3 = { .key = KEY_A_3, .value = VALUE_A_3 }; 492 const DistributedDB::Entry ENTRY_A_1_2 = { .key = KEY_A_1, .value = VALUE_A_2 }; 493 const DistributedDB::Entry ENTRY_A_2_3 = { .key = KEY_A_2, .value = VALUE_A_3 }; 494 const DistributedDB::Entry ENTRY_A_3_1 = { .key = KEY_A_3, .value = VALUE_A_1 }; 495 496 const DistributedDB::CipherPassword NULL_PASSWD; 497 const std::vector<uint8_t> NULL_PASSWD_VECTOR = {}; 498 const std::vector<uint8_t> PASSWD_VECTOR_1 = {'P', 'a', 's', 's', 'w', 'o', 'r', 'd', '@', '1', '2', '3'}; 499 const std::vector<uint8_t> PASSWD_VECTOR_2 = {'P', 'a', 's', 's', 'w', 'o', 'r', 'd', '@', 'c', 'o', 'm'}; 500 const std::vector<uint8_t> FILE_PASSWD_VECTOR_1 = {'F', 'i', 'l', 'e', 'p', 'a', 's', 's', 'w', 'd', '1'}; 501 const std::vector<uint8_t> FILE_PASSWD_VECTOR_2 = {'F', 'i', 'l', 'e', 'p', 'a', 's', 's', 'w', 'd', '2'}; 502 503 void GenerateRecord(unsigned int keyNo, DistributedDB::Entry &entry, std::vector<uint8_t> keyPrifix = { 'k' }); 504 505 void GenerateCharSet(std::vector<uint8_t> &charSet); 506 507 void GenerateAlphaNumUnderlineCharSet(std::vector<uint8_t> &charSet); 508 509 void GenerateSpecialCharSet(std::vector<uint8_t> &charSet); 510 511 void GenerateFixedLenRandString(unsigned int neededLen, RandType randType, std::string &genString); 512 513 void GenerateRandRecord(DistributedDB::Entry &entry, EntrySize &entrySize, unsigned int keyNo); 514 515 void GenerateRecords(unsigned int recordNum, unsigned int start, 516 std::vector<DistributedDB::Key> &allKeys, std::vector<DistributedDB::Entry> &entriesBatch, 517 std::vector<uint8_t> keyPrifix = { 'k' }); 518 void GenerateMaxBigRecord(unsigned int keyNo, DistributedDB::Entry &entry, 519 const std::vector<uint8_t> &keyPrefix, unsigned int num); 520 bool GenerateMaxBigRecords(unsigned int recordNum, unsigned int start, 521 std::vector<DistributedDB::Key> &allKeys, std::vector<DistributedDB::Entry> &entriesBatch); 522 523 void GenerateTenThousandRecords(unsigned int recordNum, unsigned int start, 524 std::vector<DistributedDB::Key> &allKeys, std::vector<DistributedDB::Entry> &entriesBatch); 525 526 void GenerateNormalAsciiRecords(DistributedDB::Entry &entry); 527 528 void GenerateFullAsciiRecords(DistributedDB::Entry &entry); 529 530 void GenerateBiggistKeyRecords(DistributedDB::Entry &entry); 531 532 DistributedDB::Entry GenerateFixedLenKVRecord(unsigned int serialNo, 533 unsigned int keyLen, uint8_t keyFilledChr, unsigned int valueLen, uint8_t valueFilledChr); 534 535 void GenerateFixedRecords(std::vector<DistributedDB::Entry> &entries, std::vector<DistributedDB::Key> &allKeys, 536 int recordNum, unsigned int keySize, unsigned int valSize); 537 538 void GenerateOneRecordForImage(int entryNo, const EntrySize &entrySize, 539 const std::vector<uint8_t> &keyPrefix, const std::vector<uint8_t> &val, DistributedDB::Entry &entry); 540 void GenerateRecordsForImage(std::vector<DistributedDB::Entry> &entries, EntrySize &entrySize, 541 int num, std::vector<uint8_t> keyPrefix = {'k'}, std::vector<uint8_t> val = {'v'}); 542 543 void GenerateAppointPrefixAndSizeRecord(int recordNo, const EntrySize &entrySize, 544 const std::vector<uint8_t> &keyPrefix, const std::vector<uint8_t> &valPrefix, DistributedDB::Entry &entry); 545 void GenerateAppointPrefixAndSizeRecords(std::vector<DistributedDB::Entry> &entries, const EntrySize &entrySize, 546 int num, const std::vector<uint8_t> &keyPrefix = {'k'}, const std::vector<uint8_t> &valPrefix = {'v'}); 547 void GenerateAppointPrefixAndSizeRecords(std::vector<DistributedDB::Entry> &entries, int startpoint, 548 const NumberSize param, const std::vector<uint8_t> &keyPrefix = {'k'}, 549 const std::vector<uint8_t> &valPrefix = {'v'}); 550 551 int GetRandInt(const int randMin, const int randMax); 552 553 void GenerateFixedLenRandRecords(std::vector<DistributedDB::Entry> &entries, std::vector<DistributedDB::Key> &allKeys, 554 int recordNum, unsigned int keySize, unsigned int valSize); 555 std::vector<DistributedDB::Entry> GenerateFixedLenRandRecords(std::vector<DistributedDB::Key> &allKeys, 556 int recordNum, const EntrySize &entrySize, const std::vector<uint8_t> &keyPrefix = {'k'}, 557 const std::vector<uint8_t> &valPrefix = {'v'}); 558 559 const std::string GetDbType(const int type); 560 void GenerateRandomRecords(std::vector<DistributedDB::Entry> &entries, EntrySize &entrySize, int num); 561 void GetLongSchemaDefine(LongDefine ¶m, std::string &longDefine); 562 const std::string SpliceToSchema(const std::string &version, const std::string &mode, 563 const std::string &define, const std::string &index = "", const std::string &skipSize = ""); 564 std::vector<std::string> GetValidSchema(Schema &validSchema, bool hasIndex); 565 std::map<int, std::vector<std::string>> GetInvalidSchema(Schema &invalidSchema, Schema &validSchema, bool hasIndex); 566 } // DistributedDBDataGenerator 567 #endif // DISTRIBUTED_DB_MODULE_TEST_TYPES_H 568