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
16 #include <gtest/gtest.h>
17
18 #include "db_constant.h"
19 #include "db_common.h"
20 #include "distributeddb_storage_single_ver_natural_store_testcase.h"
21 #include "mock_sqlite_single_ver_natural_store.h"
22
23 using namespace testing::ext;
24 using namespace DistributedDB;
25 using namespace DistributedDBUnitTest;
26 using namespace std;
27
28 namespace {
29 DistributedDB::KvStoreConfig g_config;
30
31 std::string g_testDir;
32 std::string g_databaseName;
33 std::string g_identifier;
34
35 DistributedDB::SQLiteSingleVerNaturalStore *g_store = nullptr;
36 DistributedDB::SQLiteSingleVerNaturalStoreConnection *g_connection = nullptr;
37
38 class DistributedDBStorageSQLiteSingleVerNaturalStoreTest : public testing::Test {
39 public:
40 static void SetUpTestCase(void);
41 static void TearDownTestCase(void);
42 void SetUp();
43 void TearDown();
44 };
45
SetUpTestCase(void)46 void DistributedDBStorageSQLiteSingleVerNaturalStoreTest::SetUpTestCase(void)
47 {}
48
TearDownTestCase(void)49 void DistributedDBStorageSQLiteSingleVerNaturalStoreTest::TearDownTestCase(void) {}
50
SetUp(void)51 void DistributedDBStorageSQLiteSingleVerNaturalStoreTest::SetUp(void)
52 {
53 DistributedDBToolsUnitTest::PrintTestCaseInfo();
54 DistributedDBToolsUnitTest::TestDirInit(g_testDir);
55 LOGD("DistributedDBStorageSQLiteSingleVerNaturalStoreTest dir is %s", g_testDir.c_str());
56 std::string oriIdentifier = APP_ID + "-" + USER_ID + "-" + "TestGeneralNB";
57 std::string identifier = DBCommon::TransferHashString(oriIdentifier);
58 std::string g_identifier = DBCommon::TransferStringToHex(identifier);
59
60 g_databaseName = "/" + g_identifier + "/" + DBConstant::SINGLE_SUB_DIR + "/" + DBConstant::MAINDB_DIR + "/" +
61 DBConstant::SINGLE_VER_DATA_STORE + ".db";
62 DistributedDBToolsUnitTest::RemoveTestDbFiles(g_testDir + "/" + g_identifier + "/" + DBConstant::SINGLE_SUB_DIR);
63 KvDBProperties property;
64 property.SetStringProp(KvDBProperties::DATA_DIR, g_testDir);
65 property.SetStringProp(KvDBProperties::STORE_ID, "TestGeneralNB");
66 property.SetStringProp(KvDBProperties::IDENTIFIER_DIR, g_identifier);
67 property.SetIntProp(KvDBProperties::DATABASE_TYPE, KvDBProperties::SINGLE_VER_TYPE_SQLITE);
68
69 g_store = new (std::nothrow) SQLiteSingleVerNaturalStore;
70 ASSERT_NE(g_store, nullptr);
71 ASSERT_EQ(g_store->Open(property), E_OK);
72
73 int erroCode = E_OK;
74 g_connection = static_cast<SQLiteSingleVerNaturalStoreConnection *>(g_store->GetDBConnection(erroCode));
75 ASSERT_NE(g_connection, nullptr);
76 g_store->DecObjRef(g_store);
77 EXPECT_EQ(erroCode, E_OK);
78 }
79
TearDown(void)80 void DistributedDBStorageSQLiteSingleVerNaturalStoreTest::TearDown(void)
81 {
82 if (g_connection != nullptr) {
83 g_connection->Close();
84 }
85
86 g_store = nullptr;
87 DistributedDBToolsUnitTest::RemoveTestDbFiles(g_testDir + "/" + g_identifier + "/" +
88 DBConstant::SINGLE_SUB_DIR);
89 }
90
91 /**
92 * @tc.name: GetSyncData001
93 * @tc.desc: To test the function of querying the data in the time stamp range in the database.
94 * @tc.type: FUNC
95 * @tc.require: AR000CCPOM
96 * @tc.author: wangbingquan
97 */
98 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, GetSyncData001, TestSize.Level1)
99 {
100 /**
101 * @tc.steps:step1. Obtain the data within the time stamp range
102 * through the GetSyncData(A, C) interface of the NaturalStore, where A<B<C.
103 * @tc.expected: step1. GetSyncData The number of output parameter
104 * in the output parameter OK, dataItems is 1.
105 */
106 DistributedDBStorageSingleVerNaturalStoreTestCase::GetSyncData001(g_store, g_connection);
107 }
108
109 /**
110 * @tc.name: GetSyncData002
111 * @tc.desc: Test the function that the database does not query the data in the time stamp range.
112 * @tc.type: FUNC
113 * @tc.require: AR000CCPOM
114 * @tc.author: wangbingquan
115 */
116 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, GetSyncData002, TestSize.Level1)
117 {
118 /**
119 * @tc.steps:step1. Obtain the data within the time stamp range
120 * through the GetSyncData(A, B) interface of the NaturalStore,
121 * where A<B<C and interference data processing are added.
122 * @tc.expected: step1. GetSyncData The number of output parameters
123 * in the output parameter E_NOT_FOUND,dataItems is 0.
124 */
125 DistributedDBStorageSingleVerNaturalStoreTestCase::GetSyncData002(g_store, g_connection);
126 }
127
128 /**
129 * @tc.name: GetSyncData003
130 * @tc.desc: To test the function of querying data when the timestamp range
131 * in the data obtaining interface is invalid.
132 * @tc.type: FUNC
133 * @tc.require: AR000CCPOM
134 * @tc.author: wangbingquan
135 */
136 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, GetSyncData003, TestSize.Level1)
137 {
138 /**
139 * @tc.steps:step1. Obtain the data within the time stamp range
140 * through the GetSyncData(A, B) interface of the NaturalStore, where A>B
141 * @tc.expected: step1. The value of GetSyncData is E_INVALID_ARG.
142 */
143 DistributedDBStorageSingleVerNaturalStoreTestCase::GetSyncData003(g_store, g_connection);
144 }
145
146 /**
147 * @tc.name: GetSyncData004
148 * @tc.desc: To the test database Subcon reading, a large number of data records exist in the time stamp range.
149 * @tc.type: FUNC
150 * @tc.require: AR000CCPOM
151 * @tc.author: wangbingquan
152 */
153 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, GetSyncData004, TestSize.Level1)
154 {
155 /**
156 * @tc.steps:step1. Obtain the data within the time stamp range
157 * through the GetSyncData(A, B) interface of the NaturalStore.
158 * @tc.expected: step1. Return E_GET_UNFINISHED.
159 */
160 /**
161 * @tc.steps:step2. Continue to obtain data through the GetSyncDataNext() interface
162 * of the NaturalStore until the E_GET_FINISHED message is returned.
163 * @tc.expected: step2. When the GetSyncDataNext returns E_GET_FINISHED,
164 * the total number of obtained data is the number of inserted data and the data is consistent.
165 */
166 DistributedDBStorageSingleVerNaturalStoreTestCase::GetSyncData004(g_store, g_connection);
167 }
168
169 /**
170 * @tc.name: GetSyncData005
171 * @tc.desc: In the test database, if a large number of data records exist
172 * in the time stamp range, a packet is read successfully.
173 * @tc.type: FUNC
174 * @tc.require: AR000CCPOM
175 * @tc.author: wangbingquan
176 */
177 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, GetSyncData005, TestSize.Level1)
178 {
179 /**
180 * @tc.steps:step1. Obtain the data within the time stamp range
181 * through the GetSyncData(A, B) interface of the NaturalStore.
182 * @tc.expected: step1. The total size of all data in OK, dataItems is 99K.
183 */
184 DistributedDBStorageSingleVerNaturalStoreTestCase::GetSyncData005(g_store, g_connection);
185 }
186
187 /**
188 * @tc.name: GetSyncData006
189 * @tc.desc: To test the function of reading data when the time stamp range in the database
190 * is greater than the value of blockSize.
191 * @tc.type: FUNC
192 * @tc.require: AR000CCPOM
193 * @tc.author: wangbingquan
194 */
195 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, GetSyncData006, TestSize.Level1)
196 {
197 /**
198 * @tc.steps:step1. Use the GetSyncData(A, B) interface of the NaturalStore
199 * and set blockSize to 50 kb to obtain the data within the time stamp range.
200 * @tc.expected: step1. The system returns E_GET_FINISHED. The size of the obtained data is 1 kb.
201 */
202 DistributedDBStorageSingleVerNaturalStoreTestCase::GetSyncData006(g_store, g_connection);
203 }
204
205 /**
206 * @tc.name: PutSyncData001
207 * @tc.desc: To test the function of synchronizing the new data of the remote device that synchronizes the database.
208 * @tc.type: FUNC
209 * @tc.require: AR000CCPOM
210 * @tc.author: wangbingquan
211 */
212 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, PutSyncData001, TestSize.Level1)
213 {
214 /**
215 * @tc.steps:step1/2. Set Ioption to synchronous data and insert a (key1, value1) data record by put interface.
216 */
217 /**
218 * @tc.steps:step3. Insert a (key1, value2!=value1, timestamp, false) data record
219 * through the PutSyncData interface. The value of timestamp is less than or equal
220 * to the value of timestamp. For Compare the timestamp to determine whether to synchronization data.
221 * @tc.expected: step3. Return OK.
222 */
223 /**
224 * @tc.steps:step4. The Ioption is set to synchronize data
225 * through the Get interface to obtain the value data of the key1.
226 * @tc.expected: step4. Return OK.The obtained value is value1.
227 */
228 /**
229 * @tc.steps:step5. Insert a (key1, value3!=value1, timestamp, false) data record
230 * through the PutSyncData interface of the NaturalStore. The value of timestamp
231 * is greater than that of timestamp inserted in 2.
232 * @tc.expected: step5. Return OK.
233 */
234 /**
235 * @tc.steps:step6. The Ioption is set to synchronize data through the Get interface
236 * to obtain the value data of the key1.
237 * @tc.expected: step6. Return OK.
238 */
239 /**
240 * @tc.steps:step7. Insert a (key2, value4) data record through the PutSyncData interface.
241 * @tc.expected: step7. Return OK.
242 */
243 /**
244 * @tc.steps:step8. The Ioption is set to synchronize data
245 * through the Get interface to obtain the value data of the key2.
246 * @tc.expected: step8. Returns OK, and the obtained data is value4.
247 */
248 DistributedDBStorageSingleVerNaturalStoreTestCase::PutSyncData001(g_store, g_connection);
249 }
250
251 /**
252 * @tc.name: PutSyncData002
253 * @tc.desc: To test the function of synchronizing data from the remote device
254 * to the local device after the data is deleted from the remote device.
255 * @tc.type: FUNC
256 * @tc.require: AR000CCPOM
257 * @tc.author: wangbingquan
258 */
259 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, PutSyncData002, TestSize.Level1)
260 {
261 /**
262 * @tc.steps:step1/2. Set Ioption to synchronous data and insert a (key1, value1) data record by put interface.
263 */
264 /**
265 * @tc.steps:step3. Insert a (key1, value2!=value1, timestamp, false) data record
266 * through the PutSyncData interface. The value of timestamp is less than or equal
267 * to the value of timestamp. For Compare the timestamp to determine whether delete data.
268 * @tc.expected: step3. Return OK.
269 */
270 /**
271 * @tc.steps:step4. The Ioption is set to synchronize data
272 * through the Get interface to obtain the value data of the key1.
273 * @tc.expected: step4. Return OK.The obtained value is value1.
274 */
275 /**
276 * @tc.steps:step5. Insert a (key1, value3!=value1, timestamp, false) data record
277 * through the PutSyncData interfac. The value of timestamp
278 * is greater than that of timestamp inserted in step2.
279 * @tc.expected: step5. Return OK.
280 */
281 /**
282 * @tc.steps:step6. The Ioption is set to synchronize data through the Get interface
283 * to obtain the value data of the key1.
284 * @tc.expected: step6. Return E_NOT_FOUND.
285 */
286 DistributedDBStorageSingleVerNaturalStoreTestCase::PutSyncData002(g_store, g_connection);
287 }
288
289 /**
290 * @tc.name: PutSyncData003
291 * @tc.desc: To test the function of synchronizing the mixed data of the added
292 * and deleted data from the remote device to the local device.
293 * @tc.type: FUNC
294 * @tc.require: AR000CCPOM
295 * @tc.author: wangbingquan
296 */
297 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, PutSyncData003, TestSize.Level1)
298 {
299 /**
300 * @tc.steps:step1. Insert a data record (key1,value1 is not null) and (key2, value2 is not null)
301 * through the PutSyncData interface.
302 * @tc.expected: step1. Return OK.
303 */
304 /**
305 * @tc.steps:step2. Set Ioption as the synchronization data to obtain the data of key1 and key2.
306 * @tc.expected: step2. The Get interface returns OK. The value of key1 is value1,
307 * and the value of key2 is value2.
308 */
309 /**
310 * @tc.steps:step3. Insert a (key3, value3) and delete the data of the (key1, value1).
311 * @tc.expected: step3. The PutSyncData returns OK.
312 */
313 /**
314 * @tc.steps:step4. Set Ioption to the synchronization data and obtain the data of key1, key2, and key3.
315 * @tc.expected: step4. Get key1 returns E_NOT_FOUND,Get key2.
316 * The value of OK,value is value2, the value of Get key3 is OK,
317 * and the value of value is value3.
318 */
319 DistributedDBStorageSingleVerNaturalStoreTestCase::PutSyncData003(g_store, g_connection);
320 }
321
322 /**
323 * @tc.name: PutMetaData001
324 * @tc.desc: Test metadata insertion and modification.
325 * @tc.type: FUNC
326 * @tc.require: AR000CCPOM
327 * @tc.author: wangbingquan
328 */
329 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, PutMetaData001, TestSize.Level1)
330 {
331 /**
332 * @tc.steps:step1. Run the PutMetaData command to insert a non-empty key1 non-empty value1 data record.
333 * @tc.expected: step1. Return OK.
334 */
335 /**
336 * @tc.steps:step2. Run the PutMetaData command to insert a non-empty key1 non-empty value1 data record.
337 * @tc.expected: step2. The obtained value is the same as the value of value1.
338 */
339 /**
340 * @tc.steps:step3. The key value is key1, the value is not empty,
341 * and the value of value2 is different from the value of value1 through the PutMetaData interface.
342 * @tc.expected: step3. Return OK.
343 */
344 /**
345 * @tc.steps:step4. Run the GetMetaData command to obtain the value of key1
346 * and check whether the value is the same as the value of value2.
347 * @tc.expected: step4. The obtained value is the same as the value of value2.
348 */
349 /**
350 * @tc.steps:step5. Use PutMetaData to insert a record whose key is empty and value is not empty.
351 * @tc.expected: step5. Return E_INVALID_ARGS.
352 */
353 /**
354 * @tc.steps:step6. Use PutMetaData in NaturalStore to insert data whose key2(!=key1)
355 * is not empty and value is empty.
356 * @tc.expected: step6. Return OK.
357 */
358 /**
359 * @tc.steps:step7. Obtain the value of key2 and check whether the value is empty.
360 * @tc.expected: step7. The obtained value is empty.
361 */
362 /**
363 * @tc.steps:step8. Insert the data whose key size is 1024 and value size is 4Mb
364 * through PutMetaData of NaturalStore.
365 * @tc.expected: step8. Return OK.
366 */
367 /**
368 * @tc.steps:step9/10. Insert data items whose key size is greater than 1 kb
369 * or value size greater than 4Mb through PutMetaData of NaturalStore.
370 * @tc.expected: step9/10. Return E_INVALID_ARGS.
371 */
372 DistributedDBStorageSingleVerNaturalStoreTestCase::PutMetaData001(g_store, g_connection);
373 }
374
375 /**
376 * @tc.name: GetMetaData001
377 * @tc.desc: To test the function of reading the metadata of a key in the database.
378 * @tc.type: FUNC
379 * @tc.require: AR000CCPOM
380 * @tc.author: wangbingquan
381 */
382 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, GetMetaData001, TestSize.Level1)
383 {
384 /**
385 * @tc.steps:step1. Run the PutMetaData command to insert a non-empty key1 non-empty value1 data record.
386 * @tc.expected: step1. Return OK.
387 */
388 /**
389 * @tc.steps:step2. Run the PutMetaData command to insert a non-empty key1 non-empty value1 data record.
390 * @tc.expected: step2. The obtained value is the same as the value of value1.
391 */
392 /**
393 * @tc.steps:step3. The key value is key1, the value is not empty,
394 * and the value of value2 is different from the value of value1 through the PutMetaData interface.
395 * @tc.expected: step3. Return OK.
396 */
397 /**
398 * @tc.steps:step4. Run the GetMetaData command to obtain the value of key1
399 * and check whether the value is the same as the value of value2.
400 * @tc.expected: step4. The obtained value is the same as the value of value2.
401 */
402 /**
403 * @tc.steps:step5. Use PutMetaData to insert a record whose key is empty and value is not empty.
404 * @tc.expected: step5. Return E_INVALID_ARGS.
405 */
406 /**
407 * @tc.steps:step6. Use PutMetaData in NaturalStore to insert data whose key2(!=key1)
408 * is not empty and value is empty.
409 * @tc.expected: step6. Return OK.
410 */
411 /**
412 * @tc.steps:step7. Obtain the value of key2 and check whether the value is empty.
413 * @tc.expected: step7. The obtained value is empty.
414 */
415 /**
416 * @tc.steps:step8. Insert the data whose key size is 1024 and value size is 4Mb
417 * through PutMetaData of NaturalStore.
418 * @tc.expected: step8. Return OK.
419 */
420 /**
421 * @tc.steps:step9/10. Insert data items whose key size is greater than 1 kb
422 * or value size greater than 4Mb through PutMetaData of NaturalStore.
423 * @tc.expected: step9/10. Return E_INVALID_ARGS.
424 */
425 DistributedDBStorageSingleVerNaturalStoreTestCase::GetMetaData001(g_store, g_connection);
426 }
427
428 /**
429 * @tc.name: DeleteMetaData001
430 * @tc.desc: * @tc.name: To test the function of deleting the metadata with prefix key in the database.
431 * @tc.type: FUNC
432 * @tc.require: AR000CCPOM
433 * @tc.author: wangbingquan
434 */
435 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, DeleteMetaData001, TestSize.Level1)
436 {
437 /**
438 * @tc.steps:step1. Put a1, b1, a2, b2.
439 * @tc.expected: step1. Return OK.
440 */
441 /**
442 * @tc.steps:step2. Delete meta data with prefix key 'b'.
443 * @tc.expected: step2. Return OK.
444 */
445 /**
446 * @tc.steps:step3. Get a1, b1, a2, b2.
447 * @tc.expected: step3. Get a1, a2 successfully, and get b1, b2 failed.
448 */
449 DistributedDBStorageSingleVerNaturalStoreTestCase::DeleteMetaData001(g_store, g_connection);
450 }
451
452
453 /**
454 * @tc.name: GetCurrentMaxTimestamp001
455 * @tc.desc: To test the function of obtaining the maximum timestamp when a record exists in the database.
456 * @tc.type: FUNC
457 * @tc.require: AR000CCPOM
458 * @tc.author: wangbingquan
459 */
460 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, GetCurrentMaxTimestamp001, TestSize.Level1)
461 {
462 /**
463 * @tc.steps:step1/2. Insert a data record into the synchronization database.
464 */
465 /**
466 * @tc.steps:step3. The current maximum timestamp is A.
467 */
468 /**
469 * @tc.steps:step4. Insert a data record into the synchronization database.
470 */
471 /**
472 * @tc.steps:step5. Obtain the maximum timestamp B and check whether B>=A exists.
473 * @tc.expected: step5. The obtained timestamp is B>=A.
474 */
475 DistributedDBStorageSingleVerNaturalStoreTestCase::GetCurrentMaxTimestamp001(g_store, g_connection);
476 }
477
478 /**
479 * @tc.name: GetCurrentMaxTimestamp002
480 * @tc.desc: Obtain the maximum timestamp when no record exists in the test record library.
481 * @tc.type: FUNC
482 * @tc.require: AR000CCPOM
483 * @tc.author: wangbingquan
484 */
485 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, GetCurrentMaxTimestamp002, TestSize.Level1)
486 {
487 /**
488 * @tc.steps:step1. Obtains the maximum timestamp in the current database record.
489 * @tc.expected: step1. Return timestamp is 0.
490 */
491 DistributedDBStorageSingleVerNaturalStoreTestCase::GetCurrentMaxTimestamp002(g_store);
492 }
493
494 /**
495 * @tc.name: LocalDatabaseOperate001
496 * @tc.desc: Test the function of inserting data in the local database of the NaturalStore.
497 * @tc.type: FUNC
498 * @tc.require: AR000CCPOM
499 * @tc.author: wangbingquan
500 */
501 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, LocalDatabaseOperate001, TestSize.Level1)
502 {
503 /**
504 * @tc.steps: step1/2. Set Ioption to the local data and insert a record of key1 and value1.
505 * @tc.expected: step1/2. Return OK.
506 */
507 /**
508 * @tc.steps: step3. Set Ioption to the local data and obtain the value of key1.
509 * Check whether the value is the same as the value of value1.
510 * @tc.expected: step3. The obtained value and value2 are the same.
511 */
512 /**
513 * @tc.steps: step4. Ioption Set this parameter to the local data. Insert key1.
514 * The value cannot be empty. value2(!=value1)
515 * @tc.expected: step4. Return OK.
516 */
517 /**
518 * @tc.steps: step5. Set Ioption to the local data, GetMetaData to obtain the value of key1,
519 * and check whether the value is the same as the value of value2.
520 * @tc.expected: step5. The obtained value and value2 are the same.
521 */
522 /**
523 * @tc.steps: step6. The Ioption parameter is set to the local data.
524 * The data record whose key is empty and value is not empty is inserted.
525 * @tc.expected: step6. Return E_INVALID_DATA.
526 */
527 /**
528 * @tc.steps: step7. Set Ioption to the local data, insert data
529 * whose key2(!=key1) is not empty, and value is empty.
530 * @tc.expected: step7. Return OK.
531 */
532 /**
533 * @tc.steps: step8. Set option to local data, obtain the value of key2,
534 * and check whether the value is empty.
535 * @tc.expected: step8. Return OK, value is empty.
536 */
537 /**
538 * @tc.steps: step9. Ioption Set the local data.
539 * Insert the data whose key size is 1024 and value size is 4Mb.
540 * @tc.expected: step9. Return OK.
541 */
542 /**
543 * @tc.steps: step10/11. Set Ioption to the local data and insert data items
544 * whose value is greater than 4Mb or key is bigger than 1Kb
545 * @tc.expected: step10/11. Return E_INVALID_ARGS.
546 */
547 DistributedDBStorageSingleVerNaturalStoreTestCase::LocalDatabaseOperate001(g_store, g_connection);
548 }
549
550 /**
551 * @tc.name: LocalDatabaseOperate002
552 * @tc.desc: Test the function of deleting data from the local database of the NaturalStore.
553 * @tc.type: FUNC
554 * @tc.require: AR000CCPOM
555 * @tc.author: wangbingquan
556 */
557 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, LocalDatabaseOperate002, TestSize.Level1)
558 {
559 /**
560 * @tc.steps: step1/2. Set Ioption to the local data and insert a record of key1 and value1.
561 * @tc.expected: step1/2. Return OK.
562 */
563 /**
564 * @tc.steps: step3. Set Ioption to the local data and obtain the value of key1.
565 * Check whether the value is the same as the value of value1.
566 * @tc.expected: step3. The obtained value and value2 are the same.
567 */
568 /**
569 * @tc.steps: step4. Ioption Set this parameter to the local data. Insert key1.
570 * The value cannot be empty. value2(!=value1)
571 * @tc.expected: step4. Return OK.
572 */
573 /**
574 * @tc.steps: step5. Set Ioption to the local data, GetMetaData to obtain the value of key1,
575 * and check whether the value is the same as the value of value2.
576 * @tc.expected: step5. The obtained value and value2 are the same.
577 */
578 /**
579 * @tc.steps: step6. The Ioption parameter is set to the local data.
580 * The data record whose key is empty and value is not empty is inserted.
581 * @tc.expected: step6. Return E_INVALID_DATA.
582 */
583 /**
584 * @tc.steps: step7. Set Ioption to the local data, insert data
585 * whose key2(!=key1) is not empty, and value is empty.
586 * @tc.expected: step7. Return OK.
587 */
588 /**
589 * @tc.steps: step8. Set option to local data, obtain the value of key2,
590 * and check whether the value is empty.
591 * @tc.expected: step8. Return OK, value is empty.
592 */
593 /**
594 * @tc.steps: step9. Ioption Set the local data.
595 * Insert the data whose key size is 1024 and value size is 4Mb.
596 * @tc.expected: step9. Return OK.
597 */
598 /**
599 * @tc.steps: step10/11. Set Ioption to the local data and insert data items
600 * whose value is greater than 4Mb or key is bigger than 1Kb
601 * @tc.expected: step10/11. Return E_INVALID_ARGS.
602 */
603 DistributedDBStorageSingleVerNaturalStoreTestCase::LocalDatabaseOperate002(g_store, g_connection);
604 }
605
606 /**
607 * @tc.name: LocalDatabaseOperate003
608 * @tc.desc: To test the function of reading data from the local database of the NaturalStore.
609 * @tc.type: FUNC
610 * @tc.require: AR000CCPOM
611 * @tc.author: wangbingquan
612 */
613 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, LocalDatabaseOperate003, TestSize.Level1)
614 {
615 /**
616 * @tc.steps: step1/2. Set Ioption to the local data and insert a record of key1 and value1.
617 * @tc.expected: step1/2. Return OK.
618 */
619 /**
620 * @tc.steps: step3. Set Ioption to the local data and obtain the value of key1.
621 * Check whether the value is the same as the value of value1.
622 * @tc.expected: step3. The obtained value and value2 are the same.
623 */
624 /**
625 * @tc.steps: step4. Ioption Set this parameter to the local data. Insert key1.
626 * The value cannot be empty. value2(!=value1)
627 * @tc.expected: step4. Return OK.
628 */
629 /**
630 * @tc.steps: step5. Set Ioption to the local data, GetMetaData to obtain the value of key1,
631 * and check whether the value is the same as the value of value2.
632 * @tc.expected: step5. The obtained value and value2 are the same.
633 */
634 /**
635 * @tc.steps: step6. The Ioption parameter is set to the local data.
636 * The data record whose key is empty and value is not empty is inserted.
637 * @tc.expected: step6. Return E_INVALID_DATA.
638 */
639 /**
640 * @tc.steps: step7. Set Ioption to the local data, insert data
641 * whose key2(!=key1) is not empty, and value is empty.
642 * @tc.expected: step7. Return OK.
643 */
644 /**
645 * @tc.steps: step8. Set option to local data, obtain the value of key2,
646 * and check whether the value is empty.
647 * @tc.expected: step8. Return OK, value is empty.
648 */
649 /**
650 * @tc.steps: step9. Ioption Set the local data.
651 * Insert the data whose key size is 1024 and value size is 4Mb.
652 * @tc.expected: step9. Return OK.
653 */
654 /**
655 * @tc.steps: step10/11. Set Ioption to the local data and insert data items
656 * whose value is greater than 4Mb or key is bigger than 1Kb
657 * @tc.expected: step10/11. Return E_INVALID_ARGS.
658 */
659 DistributedDBStorageSingleVerNaturalStoreTestCase::LocalDatabaseOperate003(g_store, g_connection);
660 }
661
662 /**
663 * @tc.name: SyncDatabaseOperate001
664 * @tc.desc: To test the function of inserting data of the local device in the synchronization database.
665 * @tc.type: FUNC
666 * @tc.require: AR000CCPOM
667 * @tc.author: wangbingquan
668 */
669 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, SyncDatabaseOperate001, TestSize.Level1)
670 {
671 /**
672 * @tc.steps: step1/2. Set Ioption to the local data and insert a record of key1 and value1.
673 * @tc.expected: step1/2. Return OK.
674 */
675 /**
676 * @tc.steps: step3. Set Ioption to the local data and obtain the value of key1.
677 * Check whether the value is the same as the value of value1.
678 * @tc.expected: step3. The obtained value and value2 are the same.
679 */
680 /**
681 * @tc.steps: step4. Ioption Set this parameter to the local data. Insert key1.
682 * The value cannot be empty. value2(!=value1)
683 * @tc.expected: step4. Return OK.
684 */
685 /**
686 * @tc.steps: step5. Set Ioption to the local data, GetMetaData to obtain the value of key1,
687 * and check whether the value is the same as the value of value2.
688 * @tc.expected: step5. The obtained and value2 are the same.
689 */
690 /**
691 * @tc.steps: step6. The Ioption parameter is set to the local data.
692 * The data record whose key is empty and value is not empty is inserted.
693 * @tc.expected: step6. Return E_INVALID_DATA.
694 */
695 /**
696 * @tc.steps: step7. Set Ioption to the local data, insert data
697 * whose key2(!=key1) is not empty, and value is empty.
698 * @tc.expected: step7. Return OK.
699 */
700 /**
701 * @tc.steps: step8. Set option to local data, obtain the value of key2,
702 * and check whether the value is empty.
703 * @tc.expected: step8. Return OK, value is empty.
704 */
705 /**
706 * @tc.steps: step9. Ioption Set the local data.
707 * Insert the data whose key size is 1024 and value size is 4Mb.
708 * @tc.expected: step9. Return OK.
709 */
710 /**
711 * @tc.steps: step10/11. Set Ioption to the local data and insert data items
712 * whose value is greater than 4Mb or key is bigger than 1Kb
713 * @tc.expected: step10/11. Return E_INVALID_ARGS.
714 */
715 DistributedDBStorageSingleVerNaturalStoreTestCase::SyncDatabaseOperate001(g_store, g_connection);
716 }
717
718 /**
719 * @tc.name: SyncDatabaseOperate002
720 * @tc.desc: test the put operation after data synced from other devices.
721 * @tc.type: FUNC
722 * @tc.require: AR000CCPOM
723 * @tc.author: wangbingquan
724 */
725 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, SyncDatabaseOperate002, TestSize.Level1)
726 {
727 /**
728 * @tc.steps: step1/2. Add a remote synchronization data record. (key1, value1).
729 */
730 /**
731 * @tc.steps: step3. Ioption is set to synchronous data. Obtains the value data of the key1.
732 * @tc.expected: step3. Return OK. The value is the same as the value of value1.
733 */
734 /**
735 * @tc.steps: step4. Ioption Set the data to be synchronized and insert the data of key1,value2.
736 * @tc.expected: step4. Return OK.
737 */
738 /**
739 * @tc.steps: step3. Ioption is set to synchronous data. Obtains the value data of the key1.
740 * @tc.expected: step3. Return OK. The value is the same as the value of value2.
741 */
742 DistributedDBStorageSingleVerNaturalStoreTestCase::SyncDatabaseOperate002(g_store, g_connection);
743 }
744
745 /**
746 * @tc.name: SyncDatabaseOperate003
747 * @tc.desc: test the delete operation in sync database.
748 * @tc.type: FUNC
749 * @tc.require: AR000CCPOM
750 * @tc.author: wangbingquan
751 */
752 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, SyncDatabaseOperate003, TestSize.Level1)
753 {
754 /**
755 * @tc.steps: step2. Set Ioption to the local data and delete the data whose key is key1 (empty).
756 * @tc.expected: step2. Return E_INVALID_ARGS.
757 */
758 /**
759 * @tc.steps: step3. Set Ioption to the local data, insert non-null key1, and non-null value1 data.
760 * @tc.expected: step3. Return E_OK.
761 */
762 /**
763 * @tc.steps: step4. Set Ioption to the local data, obtain the value of key1,
764 * and check whether the value is the same as that of value1.
765 * @tc.expected: step4. Return E_OK. The obtained value is the same as the value of value1.
766 */
767 /**
768 * @tc.steps: step5. Set Ioption to the local data and delete the data whose key is key1.
769 * @tc.expected: step5. Return E_OK.
770 */
771 /**
772 * @tc.steps: step5. Set Ioption to the local data and obtain the value of Key1.
773 * @tc.expected: step5. Return E_NOT_FOUND.
774 */
775 DistributedDBStorageSingleVerNaturalStoreTestCase::SyncDatabaseOperate003(g_store, g_connection);
776 }
777
778 /**
779 * @tc.name: SyncDatabaseOperate004
780 * @tc.desc: test the delete for the data from other devices in sync database.
781 * @tc.type: FUNC
782 * @tc.require: AR000CCPOM
783 * @tc.author: wangbingquan
784 */
785 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, SyncDatabaseOperate004, TestSize.Level1)
786 {
787 /**
788 * @tc.steps: step2. The Ioption parameter is set to synchronize data to obtain the value data of the key1.
789 * @tc.expected: step2. Return OK. The value is the same as the value of value1.
790 */
791 /**
792 * @tc.steps: step3. The Ioption parameter is set to synchronize data, and the key1 data is deleted.
793 * @tc.expected: step3. Return OK.
794 */
795 /**
796 * @tc.steps: step4. The Ioption parameter is set to synchronize data to obtain the value data of the key1.
797 * @tc.expected: step4. Return E_NOT_FOUND.
798 */
799 DistributedDBStorageSingleVerNaturalStoreTestCase::SyncDatabaseOperate004(g_store, g_connection);
800 }
801
802 /**
803 * @tc.name: SyncDatabaseOperate005
804 * @tc.desc: test the reading for sync database.
805 * @tc.type: FUNC
806 * @tc.require: AR000CCPOM
807 * @tc.author: wangbingquan
808 */
809 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, SyncDatabaseOperate005, TestSize.Level1)
810 {
811 /**
812 * @tc.steps: step2. Set Ioption to the local data and delete the data whose key is key1 (empty).
813 * @tc.expected: step2. Return E_INVALID_ARGS.
814 */
815 /**
816 * @tc.steps: step3. Set Ioption to the local data, insert non-null key1, and non-null value1 data.
817 * @tc.expected: step3. Return E_OK.
818 */
819 /**
820 * @tc.steps: step4. Set Ioption to the local data, obtain the value of key1,
821 * and check whether the value is the same as that of value1.
822 * @tc.expected: step4. Return E_OK. The obtained value is the same as the value of value1.
823 */
824 /**
825 * @tc.steps: step5. Set Ioption to the local data and obtain the value data of Key1.
826 * Check whether the value is the same as the value of value2.
827 * @tc.expected: step4. Return E_OK, and the value is the same as the value of value2.
828 */
829 /**
830 * @tc.steps: step5. The Ioption is set to the local.
831 * The data of the key1 and value2(!=value1) is inserted.
832 * @tc.expected: step4. Return E_OK.
833 */
834 DistributedDBStorageSingleVerNaturalStoreTestCase::SyncDatabaseOperate005(g_store, g_connection);
835 }
836
837 /**
838 * @tc.name: SyncDatabaseOperate006
839 * @tc.desc: test the get entries for sync database
840 * @tc.type: FUNC
841 * @tc.require: AR000CCPOM
842 * @tc.author: wangbingquan
843 */
844 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, SyncDatabaseOperate006, TestSize.Level1)
845 {
846 /**
847 * @tc.steps: step2/3/4. Set Ioption to synchronous data.
848 * Insert the data of key=keyPrefix + 'a', value1.
849 * Insert the data of key=keyPrefix + 'c', value2.
850 * Insert the data of key length=keyPrefix length - 1, value3.
851 * @tc.expected: step2/3/4. Return E_NOT_FOUND.
852 */
853 /**
854 * @tc.steps: step5. Obtain all data whose prefixKey is keyPrefix.
855 * @tc.expected: step5. Return OK. The number of obtained data records is 2.
856 */
857 /**
858 * @tc.steps: step6. Obtain all data whose prefixKey is empty.
859 * @tc.expected: step6. Return OK. The number of obtained data records is 3.
860 */
861 /**
862 * @tc.steps: step7. Obtain all data whose prefixKey is keyPrefix.
863 * @tc.expected: step7. Return E_NOT_SUPPORT.
864 */
865 DistributedDBStorageSingleVerNaturalStoreTestCase::SyncDatabaseOperate006(g_store, g_connection);
866 }
867
868 /**
869 * @tc.name: ClearRemoteData001
870 * @tc.desc: test the clear data synced from the remote by device.
871 * @tc.type: FUNC
872 * @tc.require: AR000CIFDA AR000CQS3T
873 * @tc.author: wangbingquan
874 */
875 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, ClearRemoteData001, TestSize.Level1)
876 {
877 /**
878 * @tc.steps: step1. New data is inserted to the B end of the device. [keyB, valueB].
879 */
880 /**
881 * @tc.steps: step2. The device pulls the data of the device B, and the device inserts the [keyA, valueA].
882 */
883 /**
884 * @tc.steps: step3. The device obtains the data of keyA and valueB.
885 * @tc.expected: step3. Obtain [keyA, valueA] and [keyB, valueB].
886 */
887 /**
888 * @tc.steps: step4.Invoke the interface for clearing the synchronization data of the B device.
889 */
890 /**
891 * @tc.steps: step5. The device obtains the data of keyA and valueB.
892 * @tc.expected: step5. The value of [keyA, valueA] is obtained,
893 * and the value of NOT_FOUND is obtained by querying keyB.
894 */
895 DistributedDBStorageSingleVerNaturalStoreTestCase::ClearRemoteData001(g_store, g_connection);
896 }
897
898 /**
899 * @tc.name: DeleteUserKeyValue001
900 * @tc.desc: When a user deletes a data record, the system clears the user record.
901 * @tc.type: FUNC
902 * @tc.require: AR000CKRTC AR000CQE0D
903 * @tc.author: sunpeng
904 */
905 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, DeleteUserKeyValue001, TestSize.Level1)
906 {
907 /**
908 * @tc.steps: step1. delete K1.
909 * @tc.expected: step1. delete K1 successfully.
910 */
911 /**
912 * @tc.steps: step2. Real query by sqlite3.
913 * @tc.expected: step2. Find KEY_1, not find K2.
914 */
915 const std::string url = g_testDir + g_databaseName;
916 DistributedDBStorageSingleVerNaturalStoreTestCase::DeleteUserKeyValue001(g_store, g_connection, url);
917 }
918
919 /**
920 * @tc.name: DeleteUserKeyValue002
921 * @tc.desc: After the synchronization library data is deleted locally, add the same key data locally.
922 * @tc.type: FUNC
923 * @tc.require: AR000CKRTC AR000CQE0D
924 * @tc.author: sunpeng
925 */
926 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, DeleteUserKeyValue002, TestSize.Level1)
927 {
928 /**
929 * @tc.steps: step1. Delete key1 data via Delete interface.
930 * @tc.expected: step1. Delete successfully.
931 */
932 /**
933 * @tc.steps: step2. New data from key1, value3 via Put interface.
934 * @tc.expected: step2. New data from key1, value3 via Put interface successfully.
935 */
936 /**
937 * @tc.steps: step3. Query key1 data via Get interface.
938 * @tc.expected: step3. Query key1 data via Get interface successfully, get value3 by key1.
939 */
940 /**
941 * @tc.steps: step4. Query key1 real data by sqlite3.
942 * @tc.expected: step4. Two records were found.
943 */
944 const std::string url = g_testDir + g_databaseName;
945 DistributedDBStorageSingleVerNaturalStoreTestCase::DeleteUserKeyValue002(g_store, g_connection, url);
946 }
947
948 /**
949 * @tc.name: DeleteUserKeyValue003
950 * @tc.desc: After the synchronization database data is deleted locally, the same key data is added from the remote end.
951 * @tc.type: FUNC
952 * @tc.require: AR000CKRTC AR000CQE0D
953 * @tc.author: sunpeng
954 */
955 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, DeleteUserKeyValue003, TestSize.Level1)
956 {
957 /**
958 * @tc.steps: step1. Delete data by key1.
959 * @tc.expected: step1. Delete successfully.
960 */
961 /**
962 * @tc.steps: step2. Get data by key1.
963 * @tc.expected: step1. Key1 not exist in database.
964 */
965 /**
966 * @tc.steps: step3. Get a new data from remote device B , key1, value3,
967 * with a smaller timestamp than the current timestamp.
968 */
969 /**
970 * @tc.steps: step4. Get data by key1.
971 * @tc.expected: step4. Key1 not exist in database.
972 */
973 /**
974 * @tc.steps: step5. Get a new data from remote device C , key1, value4,
975 * and the timestamp is larger than the current timestamp.
976 */
977 /**
978 * @tc.steps: step6. Get data by key1.
979 * @tc.expected: step6. Key1 not exist in database.
980 */
981 /**
982 * @tc.steps: step7. Get real data by key1.
983 * @tc.expected: step7. Get 1 record.
984 */
985 const std::string url = g_testDir + g_databaseName;
986 DistributedDBStorageSingleVerNaturalStoreTestCase::DeleteUserKeyValue003(g_store, g_connection, url);
987 }
988
989 /**
990 * @tc.name: DeleteUserKeyValue004
991 * @tc.desc: Changes in key after remote delete data syncs to local
992 * @tc.type: FUNC
993 * @tc.require: AR000CKRTC AR000CQE0D
994 * @tc.author: sunpeng
995 */
996 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, DeleteUserKeyValue004, TestSize.Level1)
997 {
998 /**
999 * @tc.steps: step1 2 3. Synchronize data to another device B; delete key1 data from device B;
1000 * pull the action of key1 to local.
1001 */
1002 /**
1003 * @tc.steps: step4. Close database.
1004 */
1005 /**
1006 * @tc.steps: step5 6. Get real data by key1;and get the number of records.
1007 * @tc.expected: step5 6. Not exist key1 real data in database;Get 1 record.
1008 */
1009 const std::string url = g_testDir + g_databaseName;
1010 DistributedDBStorageSingleVerNaturalStoreTestCase::DeleteUserKeyValue004(g_store, g_connection, url);
1011 }
1012
1013 /**
1014 * @tc.name: DeleteUserKeyValue005
1015 * @tc.desc: New unified key data locally after remote delete data syncs to local
1016 * @tc.type: FUNC
1017 * @tc.require: AR000CKRTC AR000CQE0D
1018 * @tc.author: sunpeng
1019 */
1020 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, DeleteUserKeyValue005, TestSize.Level1)
1021 {
1022 /**
1023 * @tc.steps: step1 2 3. Synchronize data to another device B; delete key1 data from device B;
1024 * pull the action of key1 to local.
1025 */
1026 /**
1027 * @tc.steps: step4. Put K1 V1 to database.
1028 * @tc.expected: step4. Put successfully.
1029 */
1030 /**
1031 * @tc.steps: step5. Close database.
1032 */
1033 /**
1034 * @tc.steps: step6 7. Get real data by key1;and get the number of records.
1035 * @tc.expected: step6 7. Not exist key1 real data in database;Get 2 record.
1036 */
1037 const std::string url = g_testDir + g_databaseName;
1038 DistributedDBStorageSingleVerNaturalStoreTestCase::DeleteUserKeyValue005(g_store, g_connection, url);
1039 }
1040
1041 /**
1042 * @tc.name: DeleteUserKeyValue006
1043 * @tc.desc: After the remote delete data is synced to the local,
1044 * the same key data is added from the remote other devices
1045 * @tc.type: FUNC
1046 * @tc.require: AR000CKRTC AR000CQE0D
1047 * @tc.author: sunpeng
1048 */
1049 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, DeleteUserKeyValue006, TestSize.Level1)
1050 {
1051 /**
1052 * @tc.steps: step1. Remote device B sync deletes data key1 and pushes to local.
1053 */
1054 /**
1055 * @tc.steps: step2. Get key1 from database.
1056 * @tc.expected: step2. Not exist key1.
1057 */
1058 /**
1059 * @tc.steps: step3. Remote device C syncs new data (key1, value2),
1060 * timestamp is less than delete timestamp, to local.
1061 */
1062 /**
1063 * @tc.steps: step4. Get key1 from database.
1064 * @tc.expected: step4. Not exist key1.
1065 */
1066 /**
1067 * @tc.steps: step5. Remote device C syncs new data (key1, value2),
1068 * timestamp is bigger than delete timestamp, to local.
1069 */
1070 /**
1071 * @tc.steps: step6. Get key1 from database.
1072 * @tc.expected: step6. Exist key1.
1073 */
1074 /**
1075 * @tc.steps: step7. Get real data from database.
1076 * @tc.expected: step7. Get 1 record.
1077 */
1078 const std::string url = g_testDir + g_databaseName;
1079 DistributedDBStorageSingleVerNaturalStoreTestCase::DeleteUserKeyValue006(g_store, g_connection, url);
1080 }
1081
1082 /**
1083 * @tc.name: EraseDeviceWaterMark001
1084 * @tc.desc: Test erase water mark
1085 * @tc.type: FUNC
1086 * @tc.require: AR000CKRTC AR000CQE0D
1087 * @tc.author: zhangqiquan
1088 */
1089 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, EraseDeviceWaterMark001, TestSize.Level1)
1090 {
1091 auto store = new (std::nothrow) SQLiteSingleVerNaturalStore;
1092 ASSERT_NE(store, nullptr);
1093 if (RuntimeContext::GetInstance()->IsCommunicatorAggregatorValid()) {
1094 EXPECT_EQ(store->EraseDeviceWaterMark("", true), -E_INVALID_DB);
1095 } else {
1096 EXPECT_EQ(store->EraseDeviceWaterMark("", true), -E_NOT_INIT);
1097 }
1098 RefObject::KillAndDecObjRef(store);
1099 }
1100
1101 /**
1102 * @tc.name: ExportBusy001
1103 * @tc.desc: Test export with busy
1104 * @tc.type: FUNC
1105 * @tc.require:
1106 * @tc.author: zhangqiquan
1107 */
1108 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, ExportBusy001, TestSize.Level1)
1109 {
1110 ASSERT_NE(g_store, nullptr);
1111 ASSERT_EQ(g_store->TryToDisableConnection(OperatePerm::NORMAL_WRITE), E_OK);
1112 CipherPassword password;
1113 EXPECT_EQ(g_store->Export(g_testDir, password), -E_BUSY);
1114 g_store->ReEnableConnection(OperatePerm::NORMAL_WRITE);
1115 }
1116
1117 /**
1118 * @tc.name: MigrationAndReleaseResourcesTest001
1119 * @tc.desc: concurrent test of Migration and ReleaseResources
1120 * @tc.type: FUNC
1121 * @tc.require:
1122 * @tc.author: zhangshijie
1123 */
1124 HWTEST_F(DistributedDBStorageSQLiteSingleVerNaturalStoreTest, MigrationAndReleaseResourcesTest001, TestSize.Level1)
1125 {
1126 KvDBProperties property;
1127 property.SetStringProp(KvDBProperties::DATA_DIR, g_testDir);
1128 property.SetStringProp(KvDBProperties::STORE_ID, "TestGeneralNBMigration");
1129 property.SetStringProp(KvDBProperties::IDENTIFIER_DIR, g_identifier);
1130 property.SetIntProp(KvDBProperties::DATABASE_TYPE, KvDBProperties::SINGLE_VER_TYPE_SQLITE);
1131
1132 int iterCount = 100;
1133 for (int i = 0; i < iterCount; i++) {
1134 DistributedDB::MockSqliteSingleVerNaturalStore *store = new(std::nothrow) MockSqliteSingleVerNaturalStore;
1135 ASSERT_NE(store, nullptr);
1136
1137 store->IncRefCount();
__anonf7793cfd0202() 1138 std::thread dataMigrationThread([&store]() {
1139 store->CallAsyncDataMigration();
1140 });
__anonf7793cfd0302() 1141 std::thread releaseThread([&store]() {
1142 store->CallReleaseResources();
1143 });
1144
1145 dataMigrationThread.join();
1146 releaseThread.join();
1147 store->DecObjRef(store);
1148 }
1149 }
1150 }