• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <gtest/gtest.h>
16 #include <ctime>
17 #include <cmath>
18 #include <cstdlib>
19 #include <thread>
20 #include <cstdio>
21 #include <random>
22 #include <chrono>
23 #include <string>
24 
25 #include "distributeddb_data_generator.h"
26 #include "distributed_test_tools.h"
27 #include "distributed_crud_transaction_tools.h"
28 #include "kv_store_delegate.h"
29 #include "kv_store_delegate_manager.h"
30 
31 using namespace std;
32 using namespace testing;
33 #if defined TESTCASES_USING_GTEST_EXT
34 using namespace testing::ext;
35 #endif
36 using namespace DistributedDB;
37 using namespace DistributedDBDataGenerator;
38 
39 namespace DistributeddbKvTransaction {
40 const bool IS_LOCAL = false;
41 const int REPEAT_TIMES = 5;
42 const long SLEEP_WHEN_CONSISTENCY_NOT_FINISHED = 20000;
43 const long SLEEP_ISOLATION_TRANSACTION = 5;
44 const unsigned long WAIT_FOR_CHECKING_SECONDS = 1;
45 const int BASIC_ACID_RUN_TIME = 1;
46 
47 class DistributeddbKvTransactionTest : public testing::Test {
48 public:
49     static void SetUpTestCase(void);
50     static void TearDownTestCase(void);
51     void SetUp();
52     void TearDown();
53 private:
54 };
55 
56 KvStoreDelegate *g_transactionDelegate = nullptr; // the delegate used in this suit.
57 KvStoreDelegateManager *g_transactionManager = nullptr;
SetUpTestCase(void)58 void DistributeddbKvTransactionTest::SetUpTestCase(void)
59 {
60 }
61 
TearDownTestCase(void)62 void DistributeddbKvTransactionTest::TearDownTestCase(void)
63 {
64 }
65 
SetUp(void)66 void DistributeddbKvTransactionTest::SetUp(void)
67 {
68     MST_LOG("SetUpTestCase before all cases local[%d].", IS_LOCAL);
69     RemoveDir(DIRECTOR);
70 
71     UnitTest *test = UnitTest::GetInstance();
72     ASSERT_NE(test, nullptr);
73     const TestInfo *testinfo = test->current_test_info();
74     ASSERT_NE(testinfo, nullptr);
75     string testCaseName = string(testinfo->name());
76     MST_LOG("[SetUp] test case %s is start to run", testCaseName.c_str());
77 
78     g_transactionDelegate = DistributedTestTools::GetDelegateSuccess(g_transactionManager,
79         g_kvdbParameter1, g_kvOption);
80     ASSERT_TRUE(g_transactionManager != nullptr && g_transactionDelegate != nullptr);
81 }
82 
TearDown(void)83 void DistributeddbKvTransactionTest::TearDown(void)
84 {
85     EXPECT_EQ(g_transactionManager->CloseKvStore(g_transactionDelegate), OK);
86     g_transactionDelegate = nullptr;
87     DBStatus status = g_transactionManager->DeleteKvStore(STORE_ID_1);
88     EXPECT_EQ(status, DistributedDB::DBStatus::OK) << "fail to delete exist kvdb";
89     delete g_transactionManager;
90     g_transactionManager = nullptr;
91     RemoveDir(DIRECTOR);
92 }
93 
94 /*
95  * @tc.name: BasicAction 001
96  * @tc.desc: Verify that can start and commit a transaction successfully.
97  * @tc.type: FUNC
98  * @tc.require: SR000CQDTL
99  * @tc.author: luqianfu
100  */
101 HWTEST_F(DistributeddbKvTransactionTest, BasicAction001, TestSize.Level1)
102 {
103     /**
104      * @tc.steps: step1. start transaction .
105      * @tc.expected: step1. start transaction successfully.
106      */
107     DBStatus statusStart = g_transactionDelegate->StartTransaction();
108     EXPECT_TRUE(statusStart == DBStatus::OK);
109     EXPECT_TRUE(g_transactionDelegate->Put(KEY_1, VALUE_1) == DBStatus::OK);
110     EXPECT_TRUE(g_transactionDelegate->Put(KEY_2, VALUE_2) == DBStatus::OK);
111     Value valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
112     EXPECT_TRUE(valueResult.size() == 0);
113     valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
114     EXPECT_TRUE(valueResult.size() == 0);
115     /**
116      * @tc.steps: step2. commit transaction.
117      * @tc.expected: step2. commit transaction successfully.
118      */
119     DBStatus statusCommit = g_transactionDelegate->Commit();
120     EXPECT_TRUE(statusCommit == DBStatus::OK);
121     valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
122     EXPECT_TRUE(valueResult.size() != 0);
123     EXPECT_TRUE(DistributedTestTools::IsValueEquals(valueResult, VALUE_1));
124     valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
125     EXPECT_TRUE(valueResult.size() != 0);
126     EXPECT_TRUE(DistributedTestTools::IsValueEquals(valueResult, VALUE_2));
127 }
128 
129 /*
130  * @tc.name: BasicAction 002
131  * @tc.desc: Verify that can start and rollback a transaction successfully.
132  * @tc.type: FUNC
133  * @tc.require: SR000CQDTL
134  * @tc.author: luqianfu
135  */
136 HWTEST_F(DistributeddbKvTransactionTest, BasicAction002, TestSize.Level1)
137 {
138     /**
139      * @tc.steps: step1. start transaction and Put (k1, v1) and check the record.
140      * @tc.expected: step1. start transaction successfully and can't find the record in db.
141      */
142     DBStatus statusStart = g_transactionDelegate->StartTransaction();
143     EXPECT_TRUE(statusStart == DBStatus::OK);
144     EXPECT_TRUE(g_transactionDelegate->Put(KEY_1, VALUE_1) == DBStatus::OK);
145     Value valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
146     EXPECT_TRUE(valueResult.size() == 0);
147     /**
148      * @tc.steps: step2. rollback transaction and check the recordd of (k1, v1).
149      * @tc.expected: step2. rollback transaction successfully and can't find the record in db still.
150      */
151     DBStatus statusRollback = g_transactionDelegate->Rollback();
152     EXPECT_TRUE(statusRollback == DBStatus::OK);
153     valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
154     EXPECT_TRUE(valueResult.size() == 0);
155 }
156 
157 /*
158  * @tc.name: BasicAction 003
159  * @tc.desc: Verify that can not start the same transaction repeatedly.
160  * @tc.type: FUNC
161  * @tc.require: SR000CQDTL
162  * @tc.author: luqianfu
163  */
164 HWTEST_F(DistributeddbKvTransactionTest, BasicAction003, TestSize.Level1)
165 {
166     /**
167      * @tc.steps: step1. start transaction.
168      * @tc.expected: step1. start transaction successfully.
169      */
170     DBStatus status = g_transactionDelegate->StartTransaction();
171     EXPECT_TRUE(status == DBStatus::OK);
172     /**
173      * @tc.steps: step2. start the same transaction again.
174      * @tc.expected: step2. start transaction failed.
175      */
176     status = g_transactionDelegate->StartTransaction();
177     EXPECT_EQ(status, DBStatus::DB_ERROR);
178 
179     status = g_transactionDelegate->Rollback();
180     EXPECT_TRUE(status == DBStatus::OK);
181 }
182 
183 /*
184  * @tc.name: BasicAction 004
185  * @tc.desc: Verify that can not commit transaction without starting it.
186  * @tc.type: FUNC
187  * @tc.require: SR000BUH3J
188  * @tc.author: luqianfu
189  */
190 HWTEST_F(DistributeddbKvTransactionTest, BasicAction004, TestSize.Level1)
191 {
192     /**
193      * @tc.steps: step1. start transaction then rollback.
194      * @tc.expected: step1. Construct that has no transaction start.
195      */
196     EXPECT_EQ(DBStatus::OK, g_transactionDelegate->StartTransaction());
197     EXPECT_EQ(DBStatus::OK, g_transactionDelegate->Rollback());
198     /**
199      * @tc.steps: step2. commit transaction directly.
200      * @tc.expected: step2. Commit failed and return errcode correctly.
201      */
202     DBStatus status = g_transactionDelegate->Commit();
203     EXPECT_EQ(status, DBStatus::DB_ERROR);
204 }
205 
206 /*
207  * @tc.name: BasicAction 005
208  * @tc.desc: Verify that can not rollback transaction without starting it.
209  * @tc.type: FUNC
210  * @tc.require: SR000BUH3J
211  * @tc.author: luqianfu
212  */
213 HWTEST_F(DistributeddbKvTransactionTest, BasicAction005, TestSize.Level1)
214 {
215     /**
216      * @tc.steps: step1. rollback transaction which is not exist at all.
217      * @tc.expected: step1. Rollback failed and return DB_ERROR.
218      */
219     DBStatus status = g_transactionDelegate->Rollback();
220     EXPECT_EQ(status, DBStatus::DB_ERROR);
221 }
222 
223 /*
224  * @tc.name: BasicAction 006
225  * @tc.desc: Verify that can not commit transaction repeatedly.
226  * @tc.type: FUNC
227  * @tc.require: SR000BUH3J
228  * @tc.author: luqianfu
229  */
230 HWTEST_F(DistributeddbKvTransactionTest, BasicAction006, TestSize.Level1)
231 {
232     /**
233      * @tc.steps: step1. start transaction.
234      * @tc.expected: step1. start successfully.
235      */
236     DBStatus statusStart = g_transactionDelegate->StartTransaction();
237     EXPECT_EQ(statusStart, DBStatus::OK);
238     /**
239      * @tc.steps: step2. commit transaction.
240      * @tc.expected: step2. commit successfully.
241      */
242     DBStatus statusCommit = g_transactionDelegate->Commit();
243     EXPECT_EQ(statusCommit, DBStatus::OK);
244     /**
245      * @tc.steps: step3. commit transaction again.
246      * @tc.expected: step3. commit failed.
247      */
248     statusCommit = g_transactionDelegate->Commit();
249     EXPECT_EQ(statusCommit, DBStatus::DB_ERROR);
250 }
251 
252 /*
253  * @tc.name: BasicAction 007
254  * @tc.desc: Verify that can not rollback transaction after committing it.
255  * @tc.type: FUNC
256  * @tc.require: SR000BUH3J
257  * @tc.author: luqianfu
258  */
259 HWTEST_F(DistributeddbKvTransactionTest, BasicAction007, TestSize.Level1)
260 {
261     /**
262      * @tc.steps: step1. start transaction.
263      * @tc.expected: step1. start successfully.
264      */
265     DBStatus statusStart = g_transactionDelegate->StartTransaction();
266     EXPECT_TRUE(statusStart == DBStatus::OK);
267     /**
268      * @tc.steps: step2. commit transaction.
269      * @tc.expected: step2. commit successfully.
270      */
271     DBStatus statusCommit = g_transactionDelegate->Commit();
272     EXPECT_TRUE(statusCommit == DBStatus::OK);
273     /**
274      * @tc.steps: step3. rollback transaction.
275      * @tc.expected: step3. rollback failed.
276      */
277     DBStatus statusRollback = g_transactionDelegate->Rollback();
278     EXPECT_TRUE(statusRollback != DBStatus::OK);
279 }
280 
281 /*
282  * @tc.name: BasicAction 008
283  * @tc.desc: Verify that can not commit transaction after rollabcking it.
284  * @tc.type: FUNC
285  * @tc.require: SR000BUH3J
286  * @tc.author: luqianfu
287  */
288 HWTEST_F(DistributeddbKvTransactionTest, BasicAction008, TestSize.Level1)
289 {
290     /**
291      * @tc.steps: step1. start transaction.
292      * @tc.expected: step1. start successfully.
293      */
294     DBStatus statusStart = g_transactionDelegate->StartTransaction();
295     EXPECT_TRUE(statusStart == DBStatus::OK);
296     /**
297      * @tc.steps: step2. rollback transaction.
298      * @tc.expected: step2. rollback successfully.
299      */
300     DBStatus statusRollback = g_transactionDelegate->Rollback();
301     EXPECT_TRUE(statusRollback == DBStatus::OK);
302     /**
303      * @tc.steps: step3. commit transaction.
304      * @tc.expected: step3. commit failed.
305      */
306     DBStatus statusCommit = g_transactionDelegate->Commit();
307     EXPECT_EQ(statusCommit, DBStatus::DB_ERROR);
308 }
309 
310 /*
311  * @tc.name: BasicAction 009
312  * @tc.desc: Verify that can not rollback transaction repeatedly.
313  * @tc.type: FUNC
314  * @tc.require: SR000BUH3J
315  * @tc.author: luqianfu
316  */
317 HWTEST_F(DistributeddbKvTransactionTest, BasicAction009, TestSize.Level1)
318 {
319     /**
320      * @tc.steps: step1. start transaction.
321      * @tc.expected: step1. start successfully.
322      */
323     DBStatus statusStart = g_transactionDelegate->StartTransaction();
324     EXPECT_TRUE(statusStart == DBStatus::OK);
325     /**
326      * @tc.steps: step2. rollback transaction.
327      * @tc.expected: step2. rollback successfully.
328      */
329     DBStatus statusRollback = g_transactionDelegate->Rollback();
330     EXPECT_TRUE(statusRollback == DBStatus::OK);
331     /**
332      * @tc.steps: step3. rollback transaction again.
333      * @tc.expected: step3. rollback failed.
334      */
335     statusRollback = g_transactionDelegate->Rollback();
336     EXPECT_TRUE(statusRollback != DBStatus::OK);
337 }
338 
339 /*
340  * @tc.name: BasicAction 0010
341  * @tc.desc: Verify that can start and commit, then start and rollback repeatedly.
342  * @tc.type: FUNC
343  * @tc.require: SR000BUH3J
344  * @tc.author: luqianfu
345  */
346 HWTEST_F(DistributeddbKvTransactionTest, BasicAction010, TestSize.Level1)
347 {
348     /**
349      * @tc.steps: step1. start transaction and put (k1, v1) to db and commit,
350      *    then start and put (k2, v2) to db and rollback it for 5 times, and at the end check the data in db.
351      * @tc.expected: step1. Operate successfully every time and (k1, v1) is in db and (k2, v2) is not.
352      */
353     for (int time = 0; time < REPEAT_TIMES; ++time) {
354         DBStatus statusStart1 = g_transactionDelegate->StartTransaction();
355         EXPECT_TRUE(g_transactionDelegate->Put(KEY_1, VALUE_1) == DBStatus::OK);
356         DBStatus statusCommit = g_transactionDelegate->Commit();
357         EXPECT_TRUE(statusStart1 == DBStatus::OK);
358         EXPECT_TRUE(statusCommit == DBStatus::OK);
359 
360         DBStatus statusStart2 = g_transactionDelegate->StartTransaction();
361         EXPECT_TRUE(g_transactionDelegate->Put(KEY_2, VALUE_2) == DBStatus::OK);
362         DBStatus statusRollback = g_transactionDelegate->Rollback();
363         EXPECT_TRUE(statusStart2 == DBStatus::OK);
364         EXPECT_TRUE(statusRollback == DBStatus::OK);
365     }
366     Value valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
367     EXPECT_TRUE(valueResult.size() != 0);
368     EXPECT_TRUE(DistributedTestTools::IsValueEquals(valueResult, VALUE_1));
369     valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
370     EXPECT_TRUE(valueResult.size() == 0);
371 }
372 
373 /*
374  * @tc.name: Crud 001
375  * @tc.desc: Verify that can insert and commit a transaction.
376  * @tc.type: FUNC
377  * @tc.require: SR000BUH3J
378  * @tc.author: luqianfu
379  */
380 HWTEST_F(DistributeddbKvTransactionTest, Crud001, TestSize.Level1)
381 {
382     /**
383      * @tc.steps: step1. start transaction.
384      * @tc.expected: step1. start successfully.
385      */
386     DBStatus statusStart = g_transactionDelegate->StartTransaction();
387     EXPECT_TRUE(statusStart == DBStatus::OK);
388     /**
389      * @tc.steps: step2. put(k1,v1) to db.
390      * @tc.expected: step2. put successfully.
391      */
392     DBStatus statusPut = DistributedTestTools::Put(*g_transactionDelegate, KEY_1, VALUE_1);
393     EXPECT_TRUE(statusPut == DBStatus::OK);
394     /**
395      * @tc.steps: step3. commit transaction and get.
396      * @tc.expected: step3. commit successfully and get v1 of k1.
397      */
398     DBStatus statusCommit = g_transactionDelegate->Commit();
399     EXPECT_TRUE(statusCommit == DBStatus::OK);
400     Value value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
401     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_1));
402 }
403 
404 /*
405  * @tc.name: Crud 002
406  * @tc.desc: Verify that can update and commit a transaction.
407  * @tc.type: FUNC
408  * @tc.require: SR000BUH3J
409  * @tc.author: luqianfu
410  */
411 HWTEST_F(DistributeddbKvTransactionTest, Crud002, TestSize.Level1)
412 {
413     /**
414      * @tc.steps: step1.put(k1,v1) to db.
415      * @tc.expected: step1. put successfully to construct exist data in db.
416      */
417     DBStatus statusPut = DistributedTestTools::Put(*g_transactionDelegate, KEY_1, VALUE_1);
418     ASSERT_TRUE(statusPut == DBStatus::OK);
419     Value value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
420     ASSERT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_1));
421     /**
422      * @tc.steps: step2. start transaction.
423      * @tc.expected: step2. start successfully.
424      */
425     DBStatus statusStart = g_transactionDelegate->StartTransaction();
426     EXPECT_TRUE(statusStart == DBStatus::OK);
427     /**
428      * @tc.steps: step3. update (k1,v1) to (k1,v2).
429      * @tc.expected: step3. update successfully.
430      */
431     statusPut = DistributedTestTools::Put(*g_transactionDelegate, KEY_1, VALUE_2);
432     EXPECT_TRUE(statusPut == DBStatus::OK);
433     /**
434      * @tc.steps: step4. commit transaction and get.
435      * @tc.expected: step4. commit successfully and get v2 of k1.
436      */
437     DBStatus statusCommit = g_transactionDelegate->Commit();
438     EXPECT_TRUE(statusCommit == DBStatus::OK);
439     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
440     ASSERT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_2));
441 }
442 
443 /*
444  * @tc.name: Crud 003
445  * @tc.desc: Verify that can delete and commit a transaction.
446  * @tc.type: FUNC
447  * @tc.require: SR000BUH3J
448  * @tc.author: luqianfu
449  */
450 HWTEST_F(DistributeddbKvTransactionTest, Crud003, TestSize.Level1)
451 {
452     /**
453      * @tc.steps: step1.put(k1,v1) to db and get.
454      * @tc.expected: step1. put successfully get v1 of k1.
455      */
456     DBStatus statusPut = DistributedTestTools::Put(*g_transactionDelegate, KEY_1, VALUE_1);
457     ASSERT_TRUE(statusPut == DBStatus::OK);
458     Value value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
459     ASSERT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_1));
460     /**
461      * @tc.steps: step2. start transaction.
462      * @tc.expected: step2. start successfully.
463      */
464     DBStatus statusStart = g_transactionDelegate->StartTransaction();
465     EXPECT_TRUE(statusStart == DBStatus::OK);
466     /**
467      * @tc.steps: step3. delete (k1) from db.
468      * @tc.expected: step3. delete successfully.
469      */
470     statusPut = DistributedTestTools::Delete(*g_transactionDelegate, KEY_1);
471     EXPECT_TRUE(statusPut == DBStatus::OK);
472     /**
473      * @tc.steps: step4. commit transaction and get.
474      * @tc.expected: step4. commit successfully and get null.
475      */
476     DBStatus statusCommit = g_transactionDelegate->Commit();
477     EXPECT_TRUE(statusCommit == DBStatus::OK);
478     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
479     EXPECT_TRUE(value.size() == 0);
480 }
481 
482 /*
483  * @tc.name: Crud 004
484  * @tc.desc: Verify that can insert patch and commit a transaction.
485  * @tc.type: FUNC
486  * @tc.require: SR000BUH3J
487  * @tc.author: luqianfu
488  */
489 HWTEST_F(DistributeddbKvTransactionTest, Crud004, TestSize.Level1)
490 {
491     DistributedTestTools::Clear(*g_transactionDelegate);
492     vector<Entry> entries1;
493     entries1.push_back(ENTRY_1);
494     entries1.push_back(ENTRY_2);
495     /**
496      * @tc.steps: step1. start transaction.
497      * @tc.expected: step1. start successfully.
498      */
499     DBStatus statusStart = g_transactionDelegate->StartTransaction();
500     EXPECT_TRUE(statusStart == DBStatus::OK);
501     /**
502      * @tc.steps: step2. putBatch (k1,v1)(k2,v2) to db.
503      * @tc.expected: step2. putBatch successfully.
504      */
505     DBStatus statusPut = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1);
506     EXPECT_TRUE(statusPut == DBStatus::OK);
507     /**
508      * @tc.steps: step3. commit transaction and get.
509      * @tc.expected: step3. commit successfully and get v1 of k1, v2 of k2.
510      */
511     DBStatus statusCommit = g_transactionDelegate->Commit();
512     EXPECT_TRUE(statusCommit == DBStatus::OK);
513     Value valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
514     EXPECT_TRUE(valueResult.size() != 0);
515     EXPECT_TRUE(DistributedTestTools::IsValueEquals(valueResult, VALUE_1));
516     valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
517     EXPECT_TRUE(valueResult.size() != 0);
518     EXPECT_TRUE(DistributedTestTools::IsValueEquals(valueResult, VALUE_2));
519 }
520 
521 /*
522  * @tc.name: Crud 005
523  * @tc.desc: Verify that can update patch and commit a transaction.
524  * @tc.type: FUNC
525  * @tc.require: SR000BUH3J
526  * @tc.author: luqianfu
527  */
528 HWTEST_F(DistributeddbKvTransactionTest, Crud005, TestSize.Level1)
529 {
530     DistributedTestTools::Clear(*g_transactionDelegate);
531     vector<Entry> entries1;
532     entries1.push_back(ENTRY_1);
533     entries1.push_back(ENTRY_2);
534     vector<Entry> entries1Up;
535     entries1Up.push_back(ENTRY_1_2);
536     entries1Up.push_back(ENTRY_2_3);
537     /**
538      * @tc.steps: step1. putBatch (k1,v1)(k2,v2) to db and get.
539      * @tc.expected: step1. putBatch successfully and get v1 of k1, v2 of k2.
540      */
541     DBStatus status = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1);
542     EXPECT_TRUE(status == DBStatus::OK);
543     Value valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
544     EXPECT_TRUE(valueResult.size() != 0);
545     EXPECT_TRUE(DistributedTestTools::IsValueEquals(valueResult, VALUE_1));
546     valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
547     EXPECT_TRUE(valueResult.size() != 0);
548     EXPECT_TRUE(DistributedTestTools::IsValueEquals(valueResult, VALUE_2));
549     /**
550      * @tc.steps: step2. start transaction.
551      * @tc.expected: step2. start successfully.
552      */
553     DBStatus statusStart = g_transactionDelegate->StartTransaction();
554     EXPECT_TRUE(statusStart == DBStatus::OK);
555     /**
556      * @tc.steps: step3. update (k1,v1)(k2,v2) to (k1,v2)(k2,v3).
557      * @tc.expected: step3. start successfully.
558      */
559     DBStatus statusPut = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1Up);
560     EXPECT_TRUE(statusPut == DBStatus::OK);
561     /**
562      * @tc.steps: step4. commit transaction and get.
563      * @tc.expected: step4. commit successfully and get v2 of k1, v3 of k2.
564      */
565     DBStatus statusCommit = g_transactionDelegate->Commit();
566     EXPECT_TRUE(statusCommit == DBStatus::OK);
567     valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
568     EXPECT_TRUE(valueResult.size() != 0);
569     EXPECT_TRUE(DistributedTestTools::IsValueEquals(valueResult, VALUE_2));
570     valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
571     EXPECT_TRUE(valueResult.size() != 0);
572     EXPECT_TRUE(DistributedTestTools::IsValueEquals(valueResult, VALUE_3));
573 }
574 
575 /*
576  * @tc.name: Crud 006
577  * @tc.desc: Verify that can delete patch and commit a transaction.
578  * @tc.type: FUNC
579  * @tc.require: SR000BUH3J
580  * @tc.author: luqianfu
581  */
582 HWTEST_F(DistributeddbKvTransactionTest, Crud006, TestSize.Level1)
583 {
584     DistributedTestTools::Clear(*g_transactionDelegate);
585     vector<Entry> entries1;
586     entries1.push_back(ENTRY_1);
587     entries1.push_back(ENTRY_2);
588     vector<Key> keys1;
589     keys1.push_back(ENTRY_1.key);
590     keys1.push_back(ENTRY_2.key);
591     /**
592      * @tc.steps: step1. putBatch (k1,v1)(k2,v2) to db and get.
593      * @tc.expected: step1. putBatch successfully and get v1 of k1, v2 of k2.
594      */
595     DBStatus status = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1);
596     EXPECT_TRUE(status == DBStatus::OK);
597     Value value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
598     EXPECT_TRUE(value.size() != 0);
599     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_1));
600     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
601     EXPECT_TRUE(value.size() != 0);
602     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_2));
603     /**
604      * @tc.steps: step2. start transaction.
605      * @tc.expected: step2. start successfully.
606      */
607     DBStatus statusStart = g_transactionDelegate->StartTransaction();
608     EXPECT_TRUE(statusStart == DBStatus::OK);
609     /**
610      * @tc.steps: step3. deleteBatch (k1)(k2).
611      * @tc.expected: step3. deleteBatch successfully.
612      */
613     DBStatus statusPut = DistributedTestTools::DeleteBatch(*g_transactionDelegate, keys1);
614     EXPECT_TRUE(statusPut == DBStatus::OK);
615     /**
616      * @tc.steps: step4. commit transaction and get.
617      * @tc.expected: step4. commit successfully and get null of k1,k2.
618      */
619     DBStatus statusCommit = g_transactionDelegate->Commit();
620     EXPECT_TRUE(statusCommit == DBStatus::OK);
621     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
622     EXPECT_TRUE(value.size() == 0);
623     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
624     EXPECT_TRUE(value.size() == 0);
625 }
626 
627 /*
628  * @tc.name: Crud 007
629  * @tc.desc: Verify that can clear and commit a transaction.
630  * @tc.type: FUNC
631  * @tc.require: SR000BUH3J
632  * @tc.author: luqianfu
633  */
634 HWTEST_F(DistributeddbKvTransactionTest, Crud007, TestSize.Level1)
635 {
636     DistributedTestTools::Clear(*g_transactionDelegate);
637     vector<Entry> entries1;
638     entries1.push_back(ENTRY_1);
639     entries1.push_back(ENTRY_2);
640     /**
641      * @tc.steps: step1. putBatch (k1,v1)(k2,v2) to db.
642      * @tc.expected: step1. putBatch successfully.
643      */
644     DBStatus status = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1);
645     EXPECT_TRUE(status == DBStatus::OK);
646     /**
647      * @tc.steps: step2. start transaction.
648      * @tc.expected: step2. start successfully.
649      */
650     DBStatus statusStart = g_transactionDelegate->StartTransaction();
651     EXPECT_TRUE(statusStart == DBStatus::OK);
652     /**
653      * @tc.steps: step3. clear db.
654      * @tc.expected: step3. clear successfully.
655      */
656     DBStatus statusPut = DistributedTestTools::Clear(*g_transactionDelegate);
657     EXPECT_TRUE(statusPut == DBStatus::OK);
658     /**
659      * @tc.steps: step4. commit transaction and get.
660      * @tc.expected: step4. commit successfully and get null of k1,k2.
661      */
662     DBStatus statusCommit = g_transactionDelegate->Commit();
663     EXPECT_TRUE(statusCommit == DBStatus::OK);
664     Value valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
665     EXPECT_TRUE(valueResult.size() == 0);
666     valueResult = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
667     EXPECT_TRUE(valueResult.size() == 0);
668 }
669 
670 /*
671  * @tc.name: Crud 008
672  * @tc.desc: Verify that can insert then update and commit a transaction.
673  * @tc.type: FUNC
674  * @tc.require: SR000BUH3J
675  * @tc.author: luqianfu
676  */
677 HWTEST_F(DistributeddbKvTransactionTest, Crud008, TestSize.Level1)
678 {
679     /**
680      * @tc.steps: step1. start transaction.
681      * @tc.expected: step1. start successfully.
682      */
683     DBStatus statusStart = g_transactionDelegate->StartTransaction();
684     EXPECT_TRUE(statusStart == DBStatus::OK);
685     /**
686      * @tc.steps: step2. put (k1,v1) to db.
687      * @tc.expected: step2. put successfully.
688      */
689     DBStatus statusPut1 = DistributedTestTools::Put(*g_transactionDelegate, KEY_1, VALUE_1);
690     EXPECT_TRUE(statusPut1 == DBStatus::OK);
691     /**
692      * @tc.steps: step3. update (k1,v1) to (k1,v2).
693      * @tc.expected: step3. update successfully.
694      */
695     DBStatus statusPut2 = DistributedTestTools::Put(*g_transactionDelegate, KEY_1, VALUE_2);
696     EXPECT_TRUE(statusPut2 == DBStatus::OK);
697     /**
698      * @tc.steps: step4. commit transaction and get.
699      * @tc.expected: step4. commit successfully and get v1 of k1, v2 of k2.
700      */
701     DBStatus statusCommit = g_transactionDelegate->Commit();
702     EXPECT_TRUE(statusCommit == DBStatus::OK);
703     Value value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
704     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_2));
705 }
706 
707 /*
708  * @tc.name: Crud 009
709  * @tc.desc: Verify that can complex update and commit a transaction.
710  * @tc.type: FUNC
711  * @tc.require: SR000BUH3J
712  * @tc.author: luqianfu
713  */
714 HWTEST_F(DistributeddbKvTransactionTest, Crud009, TestSize.Level1)
715 {
716     DistributedTestTools::Clear(*g_transactionDelegate);
717     vector<Entry> entries1, entries2;
718     entries1.push_back(ENTRY_1);
719     entries1.push_back(ENTRY_2);
720     entries2.push_back(ENTRY_3);
721     vector<Key> keys2;
722     keys2.push_back(ENTRY_3.key);
723     /**
724      * @tc.steps: step1. start transaction.
725      * @tc.expected: step1. start successfully.
726      */
727     DBStatus startStatus = g_transactionDelegate->StartTransaction();
728     EXPECT_TRUE(startStatus == DBStatus::OK);
729     /**
730      * @tc.steps: step2. clear db.
731      * @tc.expected: step2. clear successfully.
732      */
733     DBStatus statusClear = DistributedTestTools::Clear(*g_transactionDelegate);
734     EXPECT_TRUE(statusClear == DBStatus::OK);
735     /**
736      * @tc.steps: step3. putBatch (k1,v1)(k2,v2) to db.
737      * @tc.expected: step3. putBatch successfully.
738      */
739     DBStatus putBatchStatus1 = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1);
740     EXPECT_TRUE(putBatchStatus1 == DBStatus::OK);
741     /**
742      * @tc.steps: step4. putBatch (k3,v3) to db.
743      * @tc.expected: step4. putBatch successfully.
744      */
745     DBStatus putBatchStatus2 = DistributedTestTools::PutBatch(*g_transactionDelegate, entries2);
746     EXPECT_TRUE(putBatchStatus2 == DBStatus::OK);
747     /**
748      * @tc.steps: step5. deleteBatch entries2 from db.
749      * @tc.expected: step5. deleteBatch successfully.
750      */
751     DBStatus statusDeleteBatch2 = DistributedTestTools::DeleteBatch(*g_transactionDelegate, keys2);
752     EXPECT_TRUE(statusDeleteBatch2 == DBStatus::OK);
753     /**
754      * @tc.steps: step6. delete(k1)(k2) from db.
755      * @tc.expected: step6. delete successfully.
756      */
757     DBStatus statusDelete1 = DistributedTestTools::Delete(*g_transactionDelegate, ENTRY_1.key);
758     EXPECT_TRUE(statusDelete1 == DBStatus::OK);
759     DBStatus statusDelete2 = DistributedTestTools::Delete(*g_transactionDelegate, ENTRY_2.key);
760     EXPECT_TRUE(statusDelete2 == DBStatus::OK);
761     /**
762      * @tc.steps: step7. put(k1,v2) to db.
763      * @tc.expected: step7. put successfully.
764      */
765     DBStatus statusPut = DistributedTestTools::Put(*g_transactionDelegate, ENTRY_1_2.key, ENTRY_1_2.value);
766     EXPECT_TRUE(statusPut == DBStatus::OK);
767     /**
768      * @tc.steps: step8. commit transaction and get.
769      * @tc.expected: step8. commit successfully and get v2 of k1, null of k2,k3.
770      */
771     DBStatus statusCommit = g_transactionDelegate->Commit();
772     EXPECT_TRUE(statusCommit == DBStatus::OK);
773     Value value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
774     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_2));
775     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
776     EXPECT_TRUE(value.size() == 0);
777     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_3);
778     EXPECT_TRUE(value.size() == 0);
779 }
780 
781 /*
782  * @tc.name: Pressure 001
783  * @tc.desc: Verify that insert invalid key and commit a transaction will fail.
784  * @tc.type: FUNC
785  * @tc.require: SR000BUH3J
786  * @tc.author: luqianfu
787  */
788 HWTEST_F(DistributeddbKvTransactionTest, Pressure001, TestSize.Level1)
789 {
790     DistributedTestTools::Clear(*g_transactionDelegate);
791     vector<Entry> entries;
792     entries.push_back(ENTRY_1);
793     entries.push_back(ENTRY_2);
794     /**
795      * @tc.steps: step1. start transaction.
796      * @tc.expected: step1. start successfully.
797      */
798     DBStatus statusStart = g_transactionDelegate->StartTransaction();
799     EXPECT_TRUE(statusStart == DBStatus::OK);
800     /**
801      * @tc.steps: step2. putBatch (k1,v1)(k2,v2) to db.
802      * @tc.expected: step2. putBatch successfully.
803      */
804     DBStatus statusPutBatch1 = DistributedTestTools::PutBatch(*g_transactionDelegate, entries);
805     EXPECT_TRUE(statusPutBatch1 == DBStatus::OK);
806     /**
807      * @tc.steps: step3. put (null,null) to db.
808      * @tc.expected: step3. put failed.
809      */
810     DBStatus statusPut = DistributedTestTools::Put(*g_transactionDelegate, KEY_EMPTY, VALUE_1);
811     EXPECT_TRUE(statusPut != DBStatus::OK);
812     /**
813      * @tc.steps: step4. commit transaction and check the data on db.
814      * @tc.expected: step4. commit successfully and there are only 2 records and equal to entries.
815      */
816     DBStatus statusCommit = g_transactionDelegate->Commit();
817     EXPECT_TRUE(statusCommit == DBStatus::OK);
818 
819     std::vector<DistributedDB::Entry> entriesGot = DistributedTestTools::GetEntries(*g_transactionDelegate, KEY_EMPTY);
820     EXPECT_EQ(entriesGot.size(), entries.size());
821     EXPECT_TRUE(CompareEntriesVector(entriesGot, entries));
822 }
823 
824 /*
825  * @tc.name: Pressure 005
826  * @tc.desc: Verify that support complex update and rollback a transaction.
827  * @tc.type: FUNC
828  * @tc.require: SR000BUH3J
829  * @tc.author: luqianfu
830  */
831 HWTEST_F(DistributeddbKvTransactionTest, Pressure005, TestSize.Level1)
832 {
833     DistributedTestTools::Clear(*g_transactionDelegate);
834     vector<Entry> entries1;
835     entries1.push_back(ENTRY_1);
836     entries1.push_back(ENTRY_2);
837     vector<Entry> entries2;
838     entries2.push_back(ENTRY_3);
839     vector<Key> keys2;
840     keys2.push_back(ENTRY_3.key);
841     /**
842      * @tc.steps: step1. start transaction.
843      * @tc.expected: step1. start successfully.
844      */
845     DBStatus statusStart = g_transactionDelegate->StartTransaction();
846     EXPECT_TRUE(statusStart == DBStatus::OK);
847     /**
848      * @tc.steps: step2. clear db.
849      * @tc.expected: step2. clear successfully.
850      */
851     DBStatus statusClear = DistributedTestTools::Clear(*g_transactionDelegate);
852     EXPECT_TRUE(statusClear == DBStatus::OK);
853     /**
854      * @tc.steps: step3. putBatch (k1,v1)(k2,v2) to db.
855      * @tc.expected: step3. putBatch successfully.
856      */
857     DBStatus statusPutBatch1 = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1);
858     EXPECT_TRUE(statusPutBatch1 == DBStatus::OK);
859     /**
860      * @tc.steps: step4. putBatch (k3,v3) to db.
861      * @tc.expected: step4. putBatch successfully.
862      */
863     DBStatus statusPutBatch2 = DistributedTestTools::PutBatch(*g_transactionDelegate, entries2);
864     EXPECT_TRUE(statusPutBatch2 == DBStatus::OK);
865     /**
866      * @tc.steps: step5. deleteBatch (k3) to db.
867      * @tc.expected: step5. deleteBatch successfully.
868      */
869     DBStatus statusDeleteBatch2 = DistributedTestTools::DeleteBatch(*g_transactionDelegate, keys2);
870     EXPECT_TRUE(statusDeleteBatch2 == DBStatus::OK);
871     /**
872      * @tc.steps: step6. delete (k1)(k2) from db.
873      * @tc.expected: step6. delete successfully.
874      */
875     DBStatus statusDelete1 = DistributedTestTools::Delete(*g_transactionDelegate, ENTRY_1.key);
876     EXPECT_TRUE(statusDelete1 == DBStatus::OK);
877     DBStatus statusDelete2 = DistributedTestTools::Delete(*g_transactionDelegate, ENTRY_2.key);
878     EXPECT_TRUE(statusDelete2 == DBStatus::OK);
879     /**
880      * @tc.steps: step6. put (k1,v2) to db again.
881      * @tc.expected: step6. put successfully.
882      */
883     DBStatus statusPut = DistributedTestTools::Put(*g_transactionDelegate, KEY_1, VALUE_2);
884     EXPECT_TRUE(statusPut == DBStatus::OK);
885     /**
886      * @tc.steps: step6. rollback transaction and get.
887      * @tc.expected: step6. rollback successfully and get null of k1,k2,k3.
888      */
889     DBStatus statusRollback = g_transactionDelegate->Rollback();
890     EXPECT_TRUE(statusRollback == DBStatus::OK);
891     std::vector<DistributedDB::Entry> entriesGot = DistributedTestTools::GetEntries(*g_transactionDelegate, KEY_EMPTY);
892     EXPECT_TRUE(entriesGot.empty());
893 }
894 
895 /*
896  * @tc.name: Pressure 006
897  * @tc.desc: Verify that insert invalid key and rollback a transaction successfully.
898  * @tc.type: FUNC
899  * @tc.require: SR000BUH3J
900  * @tc.author: luqianfu
901  */
902 HWTEST_F(DistributeddbKvTransactionTest, Pressure006, TestSize.Level1)
903 {
904     DistributedTestTools::Clear(*g_transactionDelegate);
905     vector<Entry> entries1;
906     entries1.push_back(ENTRY_1);
907     entries1.push_back(ENTRY_2);
908     /**
909      * @tc.steps: step1. start transaction.
910      * @tc.expected: step1. start successfully.
911      */
912     DBStatus statusStart = g_transactionDelegate->StartTransaction();
913     EXPECT_TRUE(statusStart == DBStatus::OK);
914     /**
915      * @tc.steps: step2. putBatch (k1,v1)(k2,v2) to db.
916      * @tc.expected: step2. putBatch successfully.
917      */
918     DBStatus statusPutBatch1 = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1);
919     EXPECT_TRUE(statusPutBatch1 == DBStatus::OK);
920     /**
921      * @tc.steps: step3. put (k,v) that k=null to db.
922      * @tc.expected: step3. put failed.
923      */
924     DBStatus statusPut = DistributedTestTools::Put(*g_transactionDelegate, KEY_EMPTY, VALUE_1);
925     EXPECT_TRUE(statusPut != DBStatus::OK);
926      /**
927      * @tc.steps: step4. rollback transaction and get.
928      * @tc.expected: step4. rollback successfully and get null of k1,k2.
929      */
930     DBStatus statusRollback = g_transactionDelegate->Rollback();
931     EXPECT_TRUE(statusRollback == DBStatus::OK);
932     std::vector<DistributedDB::Entry> entriesGot = DistributedTestTools::GetEntries(*g_transactionDelegate, KEY_EMPTY);
933     EXPECT_TRUE(entriesGot.empty());
934 }
935 
936 /*
937  * @tc.name: Pressure 007
938  * @tc.desc: Verify that start a transaction and close conn before rollback will result in transaction is invalid.
939  * @tc.type: Fault injection
940  * @tc.require: SR000BUH3J
941  * @tc.author: luqianfu
942  */
943 HWTEST_F(DistributeddbKvTransactionTest, Pressure007, TestSize.Level1)
944 {
945     KvStoreDelegate *delegate = nullptr;
946     KvStoreDelegateManager *manager = nullptr;
947     delegate = DistributedTestTools::GetDelegateSuccess(manager, g_kvdbParameter2_1_2, g_kvOption);
948     ASSERT_TRUE(manager != nullptr && delegate != nullptr);
949 
950     vector<Entry> entries;
951     entries.push_back(ENTRY_1);
952     entries.push_back(ENTRY_2);
953     /**
954      * @tc.steps: step1. start transaction.
955      * @tc.expected: step1. start successfully.
956      */
957     DBStatus statusStart = delegate->StartTransaction();
958     EXPECT_TRUE(statusStart == DBStatus::OK);
959     /**
960      * @tc.steps: step2. putBatch (k1,v1)(k2,v2) to db.
961      * @tc.expected: step2. putBatch successfully.
962      */
963     DBStatus statusPutBatch = DistributedTestTools::PutBatch(*delegate, entries);
964     EXPECT_TRUE(statusPutBatch == DBStatus::OK);
965     /**
966      * @tc.steps: step3. close db before rollback transaction.
967      * @tc.expected: step3. close successfully.
968      */
969     DBStatus closeStatus = manager->CloseKvStore(delegate);
970     EXPECT_TRUE(closeStatus == DBStatus::OK);
971     delegate = nullptr;
972     delete manager;
973     manager = nullptr;
974     /**
975      * @tc.steps: step4. rollback transaction and get.
976      * @tc.expected: step4. rollback failed and get null of k1,k2.
977      */
978     delegate = DistributedTestTools::GetDelegateSuccess(manager,
979         g_kvdbParameter2_1_2, g_kvOption);
980     ASSERT_TRUE(manager != nullptr && delegate != nullptr);
981     DBStatus statusRollback = delegate->Rollback();
982     EXPECT_TRUE(statusRollback != DBStatus::OK);
983     if (delegate == nullptr) {
984         MST_LOG("delegate nullptr");
985     }
986     Value value = DistributedTestTools::Get(*delegate, KEY_1);
987     EXPECT_TRUE(value.size() == 0);
988     value = DistributedTestTools::Get(*delegate, KEY_2);
989     EXPECT_TRUE(value.size() == 0);
990 
991     closeStatus = manager->CloseKvStore(delegate);
992     EXPECT_TRUE(closeStatus == DBStatus::OK);
993     delegate = nullptr;
994     EXPECT_EQ(manager->DeleteKvStore(STORE_ID_2), OK);
995     delete manager;
996     manager = nullptr;
997 }
998 
999 /*
1000  * @tc.name: Acid 001
1001  * @tc.desc: Verify that single action's atomic.
1002  * @tc.type: FUNC
1003  * @tc.require: SR000BUH3J
1004  * @tc.author: luqianfu
1005  */
1006 HWTEST_F(DistributeddbKvTransactionTest, Acid001, TestSize.Level1)
1007 {
1008     DistributedTestTools::Clear(*g_transactionDelegate);
1009     DBStatus status = DistributedTestTools::Put(*g_transactionDelegate, KEY_1, VALUE_1);
1010     EXPECT_TRUE(status == DBStatus::OK);
1011     /**
1012      * @tc.steps: step1. start transaction.
1013      * @tc.expected: step1. start successfully.
1014      */
1015     DBStatus statusStart = g_transactionDelegate->StartTransaction();
1016     EXPECT_TRUE(statusStart == DBStatus::OK);
1017     /**
1018      * @tc.steps: step2. update (k1,v1) to (k2,v2).
1019      * @tc.expected: step2. update successfully.
1020      */
1021     DBStatus statusPut = DistributedTestTools::Put(*g_transactionDelegate, KEY_1, VALUE_2);
1022     EXPECT_TRUE(statusPut == DBStatus::OK);
1023     /**
1024      * @tc.steps: step3. get (k1).
1025      * @tc.expected: step3. get v1 of k1.
1026      */
1027     Value value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
1028     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_1));
1029     /**
1030      * @tc.steps: step4. delete (k1).
1031      * @tc.expected: step4. delete successfully.
1032      */
1033     DBStatus statusDelete1 = DistributedTestTools::Delete(*g_transactionDelegate, KEY_1);
1034     EXPECT_TRUE(statusDelete1 == DBStatus::OK);
1035     /**
1036      * @tc.steps: step5. get (k1).
1037      * @tc.expected: step5. get v1 of k1.
1038      */
1039     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
1040     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_1));
1041     /**
1042      * @tc.steps: step6. put (k2,v2) to db.
1043      * @tc.expected: step6. put successfully.
1044      */
1045     DBStatus statusPut2 = DistributedTestTools::Put(*g_transactionDelegate, KEY_2, VALUE_2);
1046     EXPECT_TRUE(statusPut2 == DBStatus::OK);
1047     /**
1048      * @tc.steps: step7. get (k2).
1049      * @tc.expected: step7. get null of k2.
1050      */
1051     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
1052     EXPECT_TRUE(value.size() == 0);
1053     /**
1054      * @tc.steps: step7. commit transaction and get.
1055      * @tc.expected: step7. get null of k1, v2 of k2.
1056      */
1057     DBStatus statusCommit = g_transactionDelegate->Commit();
1058     EXPECT_TRUE(statusCommit == DBStatus::OK);
1059     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
1060     EXPECT_TRUE(value.size() == 0);
1061     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
1062     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_2));
1063 }
1064 
1065 /*
1066  * @tc.name: Acid 002
1067  * @tc.desc: Verify that batch action's atomic.
1068  * @tc.type: FUNC
1069  * @tc.require: SR000BUH3J
1070  * @tc.author: luqianfu
1071  */
1072 HWTEST_F(DistributeddbKvTransactionTest, Acid002, TestSize.Level1)
1073 {
1074     DistributedTestTools::Clear(*g_transactionDelegate);
1075     vector<Entry> entries1, entries2, entries1Up;
1076     entries1.push_back(ENTRY_1);
1077     entries1.push_back(ENTRY_2);
1078     entries2.push_back(ENTRY_3);
1079     entries1Up.push_back(ENTRY_1_2);
1080     entries1Up.push_back(ENTRY_2_3);
1081     vector<Key> keys1;
1082     keys1.push_back(ENTRY_1.key);
1083     keys1.push_back(ENTRY_2.key);
1084     DBStatus status = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1);
1085     EXPECT_TRUE(status == DBStatus::OK);
1086     /**
1087      * @tc.steps: step1. start transaction.
1088      * @tc.expected: step1. start successfully.
1089      */
1090     DBStatus statusStart = g_transactionDelegate->StartTransaction();
1091     EXPECT_TRUE(statusStart == DBStatus::OK);
1092     /**
1093      * @tc.steps: step2. updateBatch (k1,v2) to (k2,v3).
1094      * @tc.expected: step2. updateBatch successfully.
1095      */
1096     DBStatus statusPut = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1Up);
1097     EXPECT_TRUE(statusPut == DBStatus::OK);
1098     /**
1099      * @tc.steps: step3. Get (k1)(k2).
1100      * @tc.expected: step3. get v1 of k1, v2 of k2.
1101      */
1102     Value value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
1103     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_1));
1104     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
1105     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_2));
1106     /**
1107      * @tc.steps: step4. DeleteBatch (k1)(k2).
1108      * @tc.expected: step4. DeleteBatch successfully.
1109      */
1110     DBStatus statusDelete1 = DistributedTestTools::DeleteBatch(*g_transactionDelegate, keys1);
1111     EXPECT_TRUE(statusDelete1 == DBStatus::OK);
1112     /**
1113      * @tc.steps: step5. Get.
1114      * @tc.expected: step5. get v1 of k1, v2 of k2.
1115      */
1116     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
1117     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_1));
1118     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
1119     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_2));
1120     /**
1121      * @tc.steps: step6. putBatch (k3,v3) to db.
1122      * @tc.expected: step6. putBatch successfully.
1123      */
1124     DBStatus statusPut2 = DistributedTestTools::PutBatch(*g_transactionDelegate, entries2);
1125     EXPECT_TRUE(statusPut2 == DBStatus::OK);
1126     /**
1127      * @tc.steps: step7. get (k3).
1128      * @tc.expected: step7. get null 0f k3.
1129      */
1130     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_3);
1131     EXPECT_TRUE(value.size() == 0);
1132     /**
1133      * @tc.steps: step8. commit transaction and get.
1134      * @tc.expected: step8. get null of k1,k2, v3 of k3.
1135      */
1136     DBStatus statusCommit = g_transactionDelegate->Commit();
1137     EXPECT_TRUE(statusCommit == DBStatus::OK);
1138     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
1139     EXPECT_TRUE(value.size() == 0);
1140     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_2);
1141     EXPECT_TRUE(value.size() == 0);
1142     value = DistributedTestTools::Get(*g_transactionDelegate, KEY_3);
1143     EXPECT_TRUE(DistributedTestTools::IsValueEquals(value, VALUE_3));
1144 }
1145 
1146 int g_singleThreadComplete = 0;
1147 bool g_singleThreadSuccess = true;
ConsistencyCheck(Key kLeft,Key kRight)1148 void ConsistencyCheck(Key kLeft, Key kRight)
1149 {
1150     KvStoreDelegate *delegate = nullptr;
1151     KvStoreDelegateManager *delegateManager = nullptr;
1152     delegate = DistributedTestTools::GetDelegateSuccess(delegateManager,
1153         g_kvdbParameter1, g_kvOption);
1154     ASSERT_TRUE(delegateManager != nullptr && delegate != nullptr);
1155 
1156     while (g_singleThreadComplete < static_cast<int>(SINGLE_THREAD_NUM)) {
1157         KvStoreSnapshotDelegate *snapShot = DistributedTestTools::GetKvStoreSnapshot(*delegate);
1158         if (snapShot == nullptr) {
1159             MST_LOG("ConsistencyCheck get snapShot failed.");
1160             return;
1161         }
1162         Value left = DistributedTestTools::Get(*snapShot, kLeft);
1163         Value right = DistributedTestTools::Get(*snapShot, kRight);
1164         MST_LOG("ConsistencyCheck get sum %d,%d.", GetIntValue(left), GetIntValue(right));
1165         if (GetIntValue(left) + GetIntValue(right) != VALUE_SUM) {
1166             g_singleThreadSuccess = false;
1167             MST_LOG("ConsistencyCheck get sum %d,%d failed.", GetIntValue(left), GetIntValue(right));
1168             break;
1169         }
1170         EXPECT_EQ(delegate->ReleaseKvStoreSnapshot(snapShot), OK);
1171         snapShot = nullptr;
1172         std::this_thread::sleep_for(std::chrono::duration<float, std::milli>(FIFTY_MILI_SECONDS));
1173     }
1174 
1175     EXPECT_EQ(delegateManager->CloseKvStore(delegate), OK);
1176     delegate = nullptr;
1177     delete delegateManager;
1178     delegateManager = nullptr;
1179 }
1180 
ConsistencyBusiness(Key kLeft,Value vLeft,Key kRight,Value vRight)1181 void ConsistencyBusiness(Key kLeft, Value vLeft, Key kRight, Value vRight)
1182 {
1183     // wait 100 ms, let ConsistencyCheck begin
1184     std::this_thread::sleep_for(std::chrono::duration<float, std::milli>(HUNDRED_MILLI_SECONDS));
1185     KvStoreDelegate *delegate = nullptr;
1186     KvStoreDelegateManager *delegateManager = nullptr;
1187     delegate = DistributedTestTools::GetDelegateSuccess(delegateManager,
1188         g_kvdbParameter1, g_kvOption);
1189     ASSERT_TRUE(delegateManager != nullptr && delegate != nullptr);
1190 
1191     MST_LOG("ConsistencyBusiness put %d,%d.", GetIntValue(vLeft), GetIntValue(vRight));
1192     DBStatus statusStart = delegate->StartTransaction();
1193     std::this_thread::sleep_for(std::chrono::duration<float, std::milli>(FIFTY_MILI_SECONDS));
1194     DBStatus statusPutLeft = delegate->Put(kLeft, vLeft);
1195     std::this_thread::sleep_for(std::chrono::duration<float, std::milli>(FIFTY_MILI_SECONDS));
1196     DBStatus statusPutRight = delegate->Put(kRight, vRight);
1197     std::this_thread::sleep_for(std::chrono::duration<float, std::milli>(FIFTY_MILI_SECONDS));
1198     DBStatus statusCommit = delegate->Commit();
1199     std::this_thread::sleep_for(std::chrono::duration<float, std::milli>(FIFTY_MILI_SECONDS));
1200     if (statusPutLeft != DBStatus::OK || statusPutRight != DBStatus::OK ||
1201         statusStart != DBStatus::OK || statusCommit != DBStatus::OK) {
1202         MST_LOG("ConsistencyBusiness put failed.");
1203         g_singleThreadComplete++;
1204         g_singleThreadSuccess = false;
1205         return;
1206     }
1207 
1208     g_singleThreadComplete++;
1209     EXPECT_EQ(delegateManager->CloseKvStore(delegate), OK);
1210     delegate = nullptr;
1211     delete delegateManager;
1212     delegateManager = nullptr;
1213 }
1214 
1215 /*
1216  * @tc.name: Acid 003
1217  * @tc.desc: Verify that single action's consistency.
1218  * @tc.type: FUNC
1219  * @tc.require: SR000BUH3J
1220  * @tc.author: luqianfu
1221  */
1222 HWTEST_F(DistributeddbKvTransactionTest, Acid003, TestSize.Level1)
1223 {
1224     DistributedTestTools::Clear(*g_transactionDelegate);
1225 
1226     int baseNumer = VALUE_FIVE_HUNDRED;
1227     Value base = GetValueWithInt(baseNumer);
1228 
1229     Entry entry1, entry2;
1230     vector<Entry> entries1;
1231     entry1 = {KEY_CONS_1, base};
1232     entry2 = {KEY_CONS_2, base};
1233     entries1.push_back(entry1);
1234     entries1.push_back(entry2);
1235     /**
1236      * @tc.steps: step1. putBatch (k1=cons1,v1=500) (k2=cons2,v2=500).
1237      * @tc.expected: step1. putBatch successfully to construct exist v1+v2=1000.
1238      */
1239     DBStatus status = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1);
1240     EXPECT_TRUE(status == DBStatus::OK);
1241     Value value = DistributedTestTools::Get(*g_transactionDelegate, entry1.key);
1242     EXPECT_EQ(GetIntValue(value), baseNumer);
1243     value = DistributedTestTools::Get(*g_transactionDelegate, entry2.key);
1244     EXPECT_EQ(GetIntValue(value), baseNumer);
1245 
1246     /**
1247      * @tc.steps: step2. start a thread to update k1=cons1's value to 400, update k2=cons2's value to 600.
1248      * @tc.expected: step2. run thread successfully and k1+k2=1000 is true in child thread.
1249      */
1250     std::vector<std::thread> bussinessThreads;
1251     bussinessThreads.push_back(std::thread(ConsistencyBusiness, KEY_CONS_1, GetValueWithInt(VALUE_CHANGE1_FIRST),
1252         KEY_CONS_2, GetValueWithInt(VALUE_CHANGE1_SECOND)));
1253     /**
1254      * @tc.steps: step3. start another thread to update k1=cons1's value to 700, update k2=cons2's value to 300.
1255      * @tc.expected: step3. run thread successfully and k1+k2=1000 is true in child thread.
1256      */
1257     bussinessThreads.push_back(std::thread(ConsistencyBusiness, KEY_CONS_1, GetValueWithInt(VALUE_CHANGE2_FIRST),
1258         KEY_CONS_2, GetValueWithInt(VALUE_CHANGE2_SECOND)));
1259     for (auto& th : bussinessThreads) {
1260         th.detach();
1261     }
1262 
1263     ConsistencyCheck(KEY_CONS_1, KEY_CONS_2);
1264     ASSERT_TRUE(g_singleThreadSuccess);
1265 }
1266 
1267 bool g_batchThreadSuccess = true;
1268 bool g_batchThreadComplete = false;
ConsistencyBatchCheck(vector<Key> * kLeft,vector<Key> * kRight,int size)1269 void ConsistencyBatchCheck(vector<Key> *kLeft, vector<Key> *kRight, int size)
1270 {
1271     KvStoreDelegate *delegate = nullptr;
1272     KvStoreDelegateManager *delegateManager = nullptr;
1273     delegate = DistributedTestTools::GetDelegateSuccess(delegateManager, g_kvdbParameter1, g_kvOption);
1274     ASSERT_TRUE(delegateManager != nullptr && delegate != nullptr);
1275 
1276     while (!g_batchThreadComplete) {
1277         KvStoreSnapshotDelegate *snapShot = DistributedTestTools::GetKvStoreSnapshot(*delegate);
1278         if (snapShot == nullptr) {
1279             MST_LOG("ConsistencyBatchCheck get snapShot failed.");
1280             return;
1281         }
1282         for (int i = 0; i < size; ++i) {
1283             Value left = DistributedTestTools::Get(*snapShot, kLeft->at(i));
1284             Value right = DistributedTestTools::Get(*snapShot, kRight->at(i));
1285             if (GetIntValue(left) + GetIntValue(right) != size) {
1286                 g_batchThreadSuccess = false;
1287                 MST_LOG("ConsistencyBatchCheck get sum %d failed.", size);
1288                 break;
1289             }
1290         }
1291         EXPECT_EQ(delegate->ReleaseKvStoreSnapshot(snapShot), OK);
1292         snapShot = nullptr;
1293     }
1294 
1295     MST_LOG("g_batchThreadComplete.");
1296     EXPECT_EQ(delegateManager->CloseKvStore(delegate), OK);
1297     delegate = nullptr;
1298     delete delegateManager;
1299     delegateManager = nullptr;
1300 }
1301 
TransactionCheckConsistency(vector<Entry> & entries1,vector<Key> & allKeys1,vector<Entry> & entries2,vector<Key> & allKeys2)1302 void TransactionCheckConsistency(vector<Entry> &entries1, vector<Key> &allKeys1,
1303     vector<Entry> &entries2, vector<Key> &allKeys2)
1304 {
1305     Key query1 = {'k', 'a'};
1306     Key query2 = {'k', 'b'};
1307     /**
1308      * @tc.steps: step1. putBatch 20 items of (keys1,values1)(key2,values2).
1309      * @tc.expected: step1. putBatch successfully to construct exist data in db.
1310      */
1311     DBStatus status = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1);
1312     EXPECT_TRUE(status == DBStatus::OK);
1313     status = DistributedTestTools::PutBatch(*g_transactionDelegate, entries2);
1314     EXPECT_TRUE(status == DBStatus::OK);
1315 
1316     /**
1317      * @tc.steps: step2. start child thread to query keys1 and keys2 continuously.
1318      * @tc.expected: step2. if keys1.size()+keys2.size()!=20 print info.
1319      */
1320     thread readThread = thread(ConsistencyBatchCheck, &allKeys1, &allKeys2, TWENTY_RECORDS);
1321     readThread.detach();
1322     /**
1323      * @tc.steps: step3. start transaction.
1324      * @tc.expected: step3. start transaction successfully.
1325      */
1326     status = g_transactionDelegate->StartTransaction();
1327     EXPECT_TRUE(status == DBStatus::OK);
1328     /**
1329      * @tc.steps: step4. getEntries with keyprefix before updateBatch.
1330      * @tc.expected: step4. getEntries successfully that the size of them is 20.
1331      */
1332     vector<Entry> values1 = DistributedTestTools::GetEntries(*g_transactionDelegate, query1);
1333     vector<Entry> values2 = DistributedTestTools::GetEntries(*g_transactionDelegate, query2);
1334     ASSERT_EQ(static_cast<int>(values1.size()), TWENTY_RECORDS);
1335     ASSERT_EQ(static_cast<int>(values2.size()), TWENTY_RECORDS);
1336     /**
1337      * @tc.steps: step5. updateBatch values1+1 of keys1, values2-1 of keys2.
1338      * @tc.expected: step5. updateBatch successfully.
1339      */
1340     for (int i = 0; i != TWENTY_RECORDS; ++i) {
1341         entries1[i].value = GetValueWithInt(GetIntValue(values1[i].value) + 1);
1342         entries2[i].value = GetValueWithInt(GetIntValue(values2[i].value) - 1);
1343     }
1344     status = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1);
1345     EXPECT_TRUE(status == DBStatus::OK);
1346     status = DistributedTestTools::PutBatch(*g_transactionDelegate, entries2);
1347     EXPECT_TRUE(status == DBStatus::OK);
1348     /**
1349      * @tc.steps: step6. updateBatch values1+2 of keys1, values2-2 of keys2.
1350      * @tc.expected: step6. updateBatch successfully.
1351      */
1352     for (int i = 0; i != TWENTY_RECORDS; ++i) {
1353         entries1[i].value = GetValueWithInt(GetIntValue(values1[i].value) + EVEN_NUMBER);
1354         entries2[i].value = GetValueWithInt(GetIntValue(values2[i].value) - EVEN_NUMBER);
1355     }
1356     status = DistributedTestTools::PutBatch(*g_transactionDelegate, entries1);
1357     EXPECT_TRUE(status == DBStatus::OK);
1358     status = DistributedTestTools::PutBatch(*g_transactionDelegate, entries2);
1359     EXPECT_TRUE(status == DBStatus::OK);
1360     /**
1361      * @tc.steps: step7. commit transaction and stop child thread.
1362      * @tc.expected: step7. operate successfully.
1363      */
1364     status = g_transactionDelegate->Commit();
1365     EXPECT_TRUE(status == DBStatus::OK);
1366     MST_LOG("after commit");
1367 }
1368 
1369 /*
1370  * @tc.name: Acid 004
1371  * @tc.desc: Verify that batch action's consistency.
1372  * @tc.type: FUNC
1373  * @tc.require: SR000BUH3J
1374  * @tc.author: luqianfu
1375  */
1376 HWTEST_F(DistributeddbKvTransactionTest, Acid004, TestSize.Level2)
1377 {
1378     DistributedTestTools::Clear(*g_transactionDelegate);
1379 
1380     uint8_t left = 'a';
1381     uint8_t right = 'b';
1382     vector<Entry> entries1;
1383     vector<Key> allKeys1;
1384     GenerateRecords(TWENTY_RECORDS, DEFAULT_START, allKeys1, entries1);
1385     vector<Entry> entries2;
1386     vector<Key> allKeys2;
1387     GenerateRecords(TWENTY_RECORDS, DEFAULT_START, allKeys2, entries2);
1388     for (int i = 0; i < TWENTY_RECORDS; ++i) {
1389         entries1[i].key.insert(entries1[i].key.begin() + 1, left);
1390         entries2[i].key.insert(entries2[i].key.begin() + 1, right);
1391         allKeys1[i].insert(allKeys1[i].begin() + 1, left);
1392         allKeys2[i].insert(allKeys2[i].begin() + 1, right);
1393         entries1[i].value = GetValueWithInt(i);
1394         entries2[i].value = GetValueWithInt(TWENTY_RECORDS - i);
1395     }
1396 
1397     TransactionCheckConsistency(entries1, allKeys1, entries2, allKeys2);
1398 
1399     g_batchThreadComplete = true;
1400     ASSERT_TRUE(g_batchThreadSuccess);
1401 
1402     std::this_thread::sleep_for(std::chrono::duration<float, std::milli>(MILLSECONDS_PER_SECOND));
1403 }
1404 
1405 vector<Key> g_holdingKeys;
1406 std::mutex g_holdingMutex;
CheckKeyHolding(Key applyKey)1407 bool CheckKeyHolding(Key applyKey)
1408 {
1409     std::unique_lock<std::mutex> lock(g_holdingMutex);
1410     for (auto key = g_holdingKeys.begin(); key != g_holdingKeys.end(); ++key) {
1411         if (CompareVector(applyKey, *key)) {
1412             string str;
1413             Uint8VecToString(*key, str);
1414             MST_LOG("key %s is hold.", str.c_str());
1415             return false;
1416         }
1417     }
1418     g_holdingKeys.push_back(applyKey);
1419     return true;
1420 }
1421 
GetKey(KvStoreDelegate * & delegate,KvStoreSnapshotDelegate * & snapShot,vector<Key> * & allKeys)1422 Key GetKey(KvStoreDelegate *&delegate, KvStoreSnapshotDelegate *&snapShot, vector<Key> *&allKeys)
1423 {
1424     Key num = KEY_EMPTY;
1425     Value ticket;
1426 
1427     for (auto ticketNum = allKeys->begin(); ticketNum != allKeys->end(); ++ticketNum) {
1428         ticket = DistributedTestTools::Get(*snapShot, *ticketNum);
1429         if (GetIntValue(ticket) == 1) {
1430             if (!CheckKeyHolding(*ticketNum)) {
1431                 continue;
1432             }
1433             num = *ticketNum;
1434             break;
1435         }
1436     }
1437     return num;
1438 }
1439 
IsolationBussiness(vector<Key> * allKeys,Key key)1440 void IsolationBussiness(vector<Key> *allKeys, Key key)
1441 {
1442     KvStoreDelegate *delegate = nullptr;
1443     KvStoreDelegateManager *delegateManager = nullptr;
1444     delegate = DistributedTestTools::GetDelegateSuccess(delegateManager, g_kvdbParameter1, g_kvOption);
1445     ASSERT_TRUE(delegateManager != nullptr && delegate != nullptr);
1446     bool hasTickets = true;
1447     while (hasTickets) {
1448         KvStoreSnapshotDelegate *snapShot = DistributedTestTools::GetKvStoreSnapshot(*delegate);
1449         if (snapShot == nullptr) {
1450             MST_LOG("IsolationBussiness get snapShot failed.");
1451             return;
1452         }
1453         Key num = GetKey(delegate, snapShot, allKeys);
1454         if (num == KEY_EMPTY) {
1455             MST_LOG("IsolationBussiness there have no tickets.");
1456             hasTickets = false;
1457             EXPECT_EQ(delegate->ReleaseKvStoreSnapshot(snapShot), OK);
1458             snapShot = nullptr;
1459             continue;
1460         }
1461         Value result = DistributedTestTools::Get(*snapShot, key);
1462         int resultPlus = GetIntValue(result) + 1;
1463         DBStatus statusStart = delegate->StartTransaction();
1464         std::this_thread::sleep_for(std::chrono::duration<float, std::milli>(SLEEP_ISOLATION_TRANSACTION));
1465         DBStatus statusGetTicket = delegate->Put(num, GetValueWithInt(0));
1466         DBStatus statusPut = delegate->Put(key, GetValueWithInt(resultPlus));
1467         std::this_thread::sleep_for(std::chrono::duration<float, std::milli>(SLEEP_ISOLATION_TRANSACTION));
1468         DBStatus statusCommit = delegate->Commit();
1469         std::this_thread::sleep_for(std::chrono::duration<float, std::milli>(SLEEP_ISOLATION_TRANSACTION));
1470         if (statusPut != DBStatus::OK || statusGetTicket != DBStatus::OK || statusStart != DBStatus::OK ||
1471             statusCommit != DBStatus::OK) {
1472             MST_LOG("IsolationBussiness put failed.");
1473             EXPECT_EQ(delegate->ReleaseKvStoreSnapshot(snapShot), OK);
1474             snapShot = nullptr;
1475             return;
1476         }
1477 
1478         EXPECT_EQ(delegate->ReleaseKvStoreSnapshot(snapShot), OK);
1479         snapShot = nullptr;
1480     }
1481     EXPECT_EQ(delegateManager->CloseKvStore(delegate), OK);
1482     delegate = nullptr;
1483     delete delegateManager;
1484     delegateManager = nullptr;
1485 }
1486 
1487 /*
1488  * @tc.name: Acid 005
1489  * @tc.desc: Verify that action's IsolationBussiness.
1490  * @tc.type: FUNC
1491  * @tc.require: SR000BUH3J
1492  * @tc.author: luqianfu
1493  */
1494 HWTEST_F(DistributeddbKvTransactionTest, Acid005, TestSize.Level3)
1495 {
1496     EXPECT_EQ(DistributedTestTools::Clear(*g_transactionDelegate), OK);
1497     /**
1498      * @tc.steps: step1. putBatch 20 items of (keys1,values1) where values=1.
1499      * @tc.expected: step1. putBatch successfully to construct exist data in db.
1500      */
1501     vector<Entry> entriesBatch;
1502     vector<Key> allKeys;
1503     GenerateRecords(TWENTY_RECORDS, DEFAULT_START, allKeys, entriesBatch);
1504     vector<Key> randomKeys = GetKeysFromEntries(entriesBatch, true);
1505     vector<Key> inversionKeys;
1506     inversionKeys.assign(allKeys.rbegin(), allKeys.rend());
1507 
1508     for (int i = 0; i < TWENTY_RECORDS; ++i) {
1509         entriesBatch[i].value = GetValueWithInt(1);
1510     }
1511     /**
1512      * @tc.steps: step2. start 3 threads to query the items of value=1, if find then item+1.
1513      * @tc.expected: step2. put the result to result1,2,3 of thread1,2,3.
1514      */
1515     DBStatus status = DistributedTestTools::PutBatch(*g_transactionDelegate, entriesBatch);
1516     EXPECT_TRUE(status == DBStatus::OK);
1517     status = DistributedTestTools::Put(*g_transactionDelegate, KEY_BATCH_CONS_1, GetValueWithInt(0));
1518     EXPECT_TRUE(status == DBStatus::OK);
1519     status = DistributedTestTools::Put(*g_transactionDelegate, KEY_BATCH_CONS_2, GetValueWithInt(0));
1520     EXPECT_TRUE(status == DBStatus::OK);
1521     status = DistributedTestTools::Put(*g_transactionDelegate, KEY_BATCH_CONS_3, GetValueWithInt(0));
1522     EXPECT_TRUE(status == DBStatus::OK);
1523     vector<thread> bussinessThreads;
1524     bussinessThreads.push_back(thread(IsolationBussiness, &allKeys, KEY_BATCH_CONS_1));
1525     bussinessThreads.push_back(thread(IsolationBussiness, &inversionKeys, KEY_BATCH_CONS_2));
1526     bussinessThreads.push_back(thread(IsolationBussiness, &randomKeys, KEY_BATCH_CONS_3));
1527     for (auto& th : bussinessThreads) {
1528         th.join();
1529     }
1530     Value result1 = DistributedTestTools::Get(*g_transactionDelegate, KEY_BATCH_CONS_1);
1531     Value result2 = DistributedTestTools::Get(*g_transactionDelegate, KEY_BATCH_CONS_2);
1532     Value result3 = DistributedTestTools::Get(*g_transactionDelegate, KEY_BATCH_CONS_3);
1533     /**
1534      * @tc.steps: step3. calculate the sum of result1,result2 and result3.
1535      * @tc.expected: step3. the sum is equle 20.
1536      */
1537     int sum = GetIntValue(result1) + GetIntValue(result2) + GetIntValue(result3);
1538     MST_LOG("sum %d", sum);
1539     ASSERT_EQ(sum, TWENTY_RECORDS);
1540     std::this_thread::sleep_for(std::chrono::duration<float, std::milli>(SLEEP_WHEN_CONSISTENCY_NOT_FINISHED));
1541     g_holdingKeys.clear();
1542 }
1543 
1544 /*
1545  * @tc.name: Acid 006
1546  * @tc.desc: Verify that action's PersistenceBussiness.
1547  * @tc.type: FUNC
1548  * @tc.require: SR000BUH3J
1549  * @tc.author: luqianfu
1550  */
1551 HWTEST_F(DistributeddbKvTransactionTest, Acid006, TestSize.Level1)
1552 {
1553     DistributedTestTools::Clear(*g_transactionDelegate);
1554 
1555     KvStoreDelegate *delegate = nullptr;
1556     KvStoreDelegateManager *delegateManager = nullptr;
1557     delegate = DistributedTestTools::GetDelegateSuccess(delegateManager, g_kvdbParameter1, g_kvOption);
1558     ASSERT_TRUE(delegateManager != nullptr && delegate != nullptr);
1559     vector<Entry> entries1;
1560     entries1.push_back(ENTRY_1);
1561     entries1.push_back(ENTRY_2);
1562 
1563     /**
1564      * @tc.steps: step1. start transaction.
1565      * @tc.expected: step1. start successfully.
1566      */
1567     DBStatus statusStart = delegate->StartTransaction();
1568     EXPECT_TRUE(statusStart == DBStatus::OK);
1569     /**
1570      * @tc.steps: step2. putBatch (k1,v1)(k2,v2) to db.
1571      * @tc.expected: step2. putBatch successfully.
1572      */
1573     DBStatus statusPut = delegate->PutBatch(entries1);
1574     EXPECT_TRUE(statusPut == DBStatus::OK);
1575     /**
1576      * @tc.steps: step3. commit transaction.
1577      * @tc.expected: step3. commit successfully.
1578      */
1579     DBStatus statusCommit = delegate->Commit();
1580     EXPECT_TRUE(statusCommit == DBStatus::OK);
1581     /**
1582      * @tc.steps: step4. close kv db then open a new db.
1583      * @tc.expected: step4. operate successfully.
1584      */
1585     DBStatus statusClose = delegateManager->CloseKvStore(delegate);
1586     EXPECT_TRUE(statusClose == DBStatus::OK);
1587     delegate = nullptr;
1588     KvStoreDelegate *delegateNew = nullptr;
1589     KvStoreDelegateManager *delegateManagerNew = nullptr;
1590     delegateNew = DistributedTestTools::GetDelegateSuccess(delegateManagerNew, g_kvdbParameter1, g_kvOption);
1591     ASSERT_TRUE(delegateManagerNew != nullptr && delegateNew != nullptr) << "fail to create exist kvdb";
1592     /**
1593      * @tc.steps: step5. get (k1)(k2).
1594      * @tc.expected: step5. get v1 of k1, v2 of k2.
1595      */
1596     Value valueResult = DistributedTestTools::Get(*delegateNew, KEY_1);
1597     EXPECT_TRUE(DistributedTestTools::IsValueEquals(valueResult, VALUE_1));
1598     valueResult = DistributedTestTools::Get(*delegateNew, KEY_2);
1599     EXPECT_TRUE(DistributedTestTools::IsValueEquals(valueResult, VALUE_2));
1600 
1601     statusClose = delegateManagerNew->CloseKvStore(delegateNew);
1602     delegateNew = nullptr;
1603     EXPECT_TRUE(statusClose == DBStatus::OK);
1604     delete delegateManager;
1605     delegateManager = nullptr;
1606     delete delegateManagerNew;
1607     delegateManagerNew = nullptr;
1608 }
1609 
1610 /*
1611  * @tc.name: ComplexAction 001
1612  * @tc.desc: Verify that can start transaction in new conn after close db.
1613  * @tc.type: FUNC
1614  * @tc.require: SR000BUH3J
1615  * @tc.author: luqianfu
1616  */
1617 HWTEST_F(DistributeddbKvTransactionTest, ComplexAction001, TestSize.Level1)
1618 {
1619     DistributedTestTools::Clear(*g_transactionDelegate);
1620     /**
1621      * @tc.steps: step1. open db then close it.
1622      * @tc.expected: step1. close successfully.
1623      */
1624     EXPECT_TRUE(g_transactionManager->CloseKvStore(g_transactionDelegate) == DBStatus::OK);
1625     g_transactionDelegate = nullptr;
1626     delete g_transactionManager;
1627     g_transactionManager = nullptr;
1628 
1629     /**
1630      * @tc.steps: step2. open db in new conn then start transaction and put (k1, v1) to db
1631      *    and then close the db without the transaction committed.
1632      * @tc.expected: step2. start the db and transaction and close the db successfully.
1633      */
1634     KvStoreDelegateManager *manager = nullptr;
1635     KvOption option = g_kvOption;
1636     option.createIfNecessary = false;
1637     KvStoreDelegate *delegate = DistributedTestTools::GetDelegateSuccess(manager, g_kvdbParameter1, option);
1638     ASSERT_TRUE(manager != nullptr && delegate != nullptr);
1639     EXPECT_EQ(delegate->StartTransaction(), DBStatus::OK);
1640     DBStatus status = DistributedTestTools::Put(*delegate, KEY_1, VALUE_1);
1641     EXPECT_EQ(status, DBStatus::OK);
1642     EXPECT_EQ(manager->CloseKvStore(delegate), DBStatus::OK);
1643     delegate = nullptr;
1644     delete manager;
1645     manager = nullptr;
1646     /**
1647      * @tc.steps: step3. reopen the same db again and the data on db.
1648      * @tc.expected: step3. can't find the data on db.
1649      */
1650     g_transactionDelegate = DistributedTestTools::GetDelegateSuccess(g_transactionManager,
1651         g_kvdbParameter1, g_kvOption);
1652     ASSERT_TRUE(g_transactionManager != nullptr && g_transactionDelegate != nullptr);
1653     Value value = DistributedTestTools::Get(*g_transactionDelegate, KEY_1);
1654     EXPECT_TRUE(value.size() == 0);
1655 }
1656 
1657 /*
1658  * @tc.name: ComplexAction 002
1659  * @tc.desc: Verify that can not start transaction after delete kv db.
1660  * @tc.type: FUNC
1661  * @tc.require: SR000BUH3J
1662  * @tc.author: luqianfu
1663  */
1664 HWTEST_F(DistributeddbKvTransactionTest, ComplexAction002, TestSize.Level1)
1665 {
1666     KvStoreDelegate *delegate = nullptr;
1667     KvStoreDelegateManager *delegateManager = nullptr;
1668     delegate = DistributedTestTools::GetDelegateSuccess(delegateManager,
1669         g_kvdbParameter2_1_1, g_kvOption);
1670     ASSERT_TRUE(delegateManager != nullptr && delegate != nullptr) << "fail to create exist kvdb";
1671     EXPECT_TRUE(delegateManager->CloseKvStore(delegate) == OK);
1672     delegate = nullptr;
1673     /**
1674      * @tc.steps: step1. delete kv db.
1675      * @tc.expected: step1. delete successfully.
1676      */
1677     DBStatus statusDelete = delegateManager->DeleteKvStore(STORE_ID_2);
1678     EXPECT_TRUE(statusDelete == DBStatus::OK);
1679     delete delegateManager;
1680     delegateManager = nullptr;
1681 }
1682 
1683 /*
1684  * @tc.name: ComplexAction 003
1685  * @tc.desc: Verify that can not delete kv db after start transaction.
1686  * @tc.type: FUNC
1687  * @tc.require: SR000BUH3J
1688  * @tc.author: luqianfu
1689  */
1690 HWTEST_F(DistributeddbKvTransactionTest, ComplexAction003, TestSize.Level1)
1691 {
1692     DistributedTestTools::Clear(*g_transactionDelegate);
1693 
1694     KvStoreDelegate *delegate = nullptr;
1695     KvStoreDelegateManager *delegateManager = nullptr;
1696     delegate = DistributedTestTools::GetDelegateSuccess(delegateManager, g_kvdbParameter2_1_1, g_kvOption);
1697     ASSERT_TRUE(delegateManager != nullptr && delegate != nullptr) << "fail to create exist kvdb";
1698     /**
1699      * @tc.steps: step1. start transaction.
1700      * @tc.expected: step1. start successfully.
1701      */
1702     DBStatus statusStart = delegate->StartTransaction();
1703     EXPECT_TRUE(statusStart == DBStatus::OK);
1704     /**
1705      * @tc.steps: step2. delete db.
1706      * @tc.expected: step2. delete failed.
1707      */
1708     DBStatus statusDelete = delegateManager->DeleteKvStore(STORE_ID_2);
1709     EXPECT_TRUE(statusDelete != DBStatus::OK);
1710 
1711     DBStatus statusCommit = delegate->Commit();
1712     EXPECT_TRUE(statusCommit == DBStatus::OK);
1713     DBStatus statusClose = delegateManager->CloseKvStore(delegate);
1714     delegate = nullptr;
1715     EXPECT_TRUE(statusClose == DBStatus::OK);
1716     delete delegateManager;
1717     delegateManager = nullptr;
1718 }
1719 
1720 /*
1721  * @tc.name: CommitHistory 001
1722  * @tc.desc: Verify that execute a transaction will generate a record.
1723  * @tc.type: FUNC
1724  * @tc.require: SR000BUH3J
1725  * @tc.author: luqianfu
1726  */
1727 HWTEST_F(DistributeddbKvTransactionTest, CommitHistory001, TestSize.Level2)
1728 {
1729     DistributedTestTools::Clear(*g_transactionDelegate);
1730     KvStoreDelegate *delegate = nullptr;
1731     KvStoreDelegateManager *delegateManager = nullptr;
1732     delegate = DistributedTestTools::GetDelegateSuccess(delegateManager, g_kvdbParameter1, g_kvOption);
1733     ASSERT_TRUE(delegateManager != nullptr && delegate != nullptr) << "fail to create exist kvdb";
1734 
1735     vector<Entry> entries1, entries1Up, entries2;
1736     entries1.push_back(ENTRY_1);
1737     entries1.push_back(ENTRY_2);
1738     entries1Up.push_back(ENTRY_1_2);
1739     entries1Up.push_back(ENTRY_2_3);
1740     entries2.push_back(ENTRY_3);
1741     entries2.push_back(ENTRY_2_4);
1742     /**
1743      * @tc.steps: step1. start transaction and put(k1,v1) then commit.
1744      * @tc.expected: step1. operate successfully.
1745      */
1746     EXPECT_TRUE(delegate->StartTransaction() == DBStatus::OK);
1747     EXPECT_TRUE(DistributedTestTools::Put(*delegate, KEY_1, VALUE_1) == DBStatus::OK);
1748     EXPECT_TRUE(delegate->Commit() == DBStatus::OK);
1749     /**
1750      * @tc.steps: step2. start transaction and update(k1,v1) to (k1,v2) then commit.
1751      * @tc.expected: step2. operate successfully.
1752      */
1753     EXPECT_TRUE(delegate->StartTransaction() == DBStatus::OK);
1754     EXPECT_TRUE(DistributedTestTools::Put(*delegate, KEY_1, VALUE_2) == DBStatus::OK);
1755     EXPECT_TRUE(delegate->Commit() == DBStatus::OK);
1756     /**
1757      * @tc.steps: step3. start transaction and delete(k1) then commit.
1758      * @tc.expected: step3. operate successfully.
1759      */
1760     EXPECT_TRUE(delegate->StartTransaction() == DBStatus::OK);
1761     EXPECT_TRUE(DistributedTestTools::Delete(*delegate, KEY_1) == DBStatus::OK);
1762     EXPECT_TRUE(delegate->Commit() == DBStatus::OK);
1763     /**
1764      * @tc.steps: step4. start transaction and putBatch(k1,v1)(k2,v2) then commit.
1765      * @tc.expected: step4. operate successfully.
1766      */
1767     EXPECT_TRUE(delegate->StartTransaction() == DBStatus::OK);
1768     EXPECT_TRUE(delegate->PutBatch(entries1) == DBStatus::OK);
1769     EXPECT_TRUE(delegate->Commit() == DBStatus::OK);
1770     /**
1771      * @tc.steps: step5. start transaction and putBatch(k1,v2)(k2,v3) then commit.
1772      * @tc.expected: step5. operate successfully.
1773      */
1774     EXPECT_TRUE(delegate->StartTransaction() == DBStatus::OK);
1775     EXPECT_TRUE(delegate->PutBatch(entries1Up) == DBStatus::OK);
1776     EXPECT_TRUE(delegate->Commit() == DBStatus::OK);
1777     /**
1778      * @tc.steps: step6. start transaction and deleteBatch(k1)(k2) putBatch (k2,v4)(k3,v3) then commit.
1779      * @tc.expected: step6. operate successfully.
1780      */
1781     EXPECT_TRUE(delegate->StartTransaction() == DBStatus::OK);
1782     EXPECT_TRUE(delegate->DeleteBatch(KEYS_1) == DBStatus::OK);
1783     EXPECT_TRUE(delegate->PutBatch(entries2) == DBStatus::OK);
1784     EXPECT_TRUE(delegate->Commit() == DBStatus::OK);
1785     /**
1786      * @tc.steps: step7. check transaction committion records by hand.
1787      * @tc.expected: step7. There are 6 records.
1788      */
1789     MST_LOG("please check the committed transaction records...");
1790     std::this_thread::sleep_for(std::chrono::duration<int>(WAIT_FOR_CHECKING_SECONDS));
1791 
1792     EXPECT_TRUE(delegateManager->CloseKvStore(delegate) == DBStatus::OK);
1793     delegate = nullptr;
1794     delete delegateManager;
1795     delegateManager = nullptr;
1796 }
1797 
1798 /*
1799  * @tc.name: CommitHistory 003
1800  * @tc.desc: Verify that transaction record will be null if rollback transaction.
1801  * @tc.type: Fault injection
1802  * @tc.require: SR000BUH3J
1803  * @tc.author: luqianfu
1804  */
1805 HWTEST_F(DistributeddbKvTransactionTest, CommitHistory003, TestSize.Level2)
1806 {
1807     DistributedTestTools::Clear(*g_transactionDelegate);
1808 
1809     KvStoreDelegate *delegate = nullptr;
1810     KvStoreDelegateManager *delegateManager = nullptr;
1811     delegate = DistributedTestTools::GetDelegateSuccess(delegateManager,
1812         g_kvdbParameter1, g_kvOption);
1813     ASSERT_TRUE(delegateManager != nullptr && delegate != nullptr) << "fail to create exist kvdb";
1814 
1815     /**
1816      * @tc.steps: step1. start transaction and put(k1,v1) then rollback.
1817      * @tc.expected: step1. operate successfully.
1818      */
1819     DBStatus statusStart = g_transactionDelegate->StartTransaction();
1820     EXPECT_TRUE(statusStart == DBStatus::OK);
1821     DBStatus statusPut = DistributedTestTools::Put(*g_transactionDelegate, KEY_1, VALUE_1);
1822     EXPECT_TRUE(statusPut == DBStatus::OK);
1823     DBStatus statusRollback = g_transactionDelegate->Rollback();
1824     EXPECT_TRUE(statusRollback == DBStatus::OK);
1825     /**
1826      * @tc.steps: step2. check submit records by hand.
1827      * @tc.expected: step2. record is null.
1828      */
1829     MST_LOG("please check the committed transaction records, and verify it is deleted...");
1830     std::this_thread::sleep_for(std::chrono::duration<int>(WAIT_FOR_CHECKING_SECONDS));
1831 
1832     delegateManager->CloseKvStore(delegate);
1833     delegate = nullptr;
1834     delete delegateManager;
1835     delegateManager = nullptr;
1836 }
1837 
1838 /*
1839  * @tc.name: BasicActionAcid 001
1840  * @tc.desc: Verify that transaction between put and putbatch.
1841  * @tc.type: Pressure
1842  * @tc.require: SR000BUH3J
1843  * @tc.author: luqianfu
1844  */
1845 HWTEST_F(DistributeddbKvTransactionTest, BasicActionAcid001, TestSize.Level2)
1846 {
1847     /**
1848      * @tc.steps: step1. start transaction and putBatch (k0-k127,1) then update v1=2 of k1.
1849      * @tc.expected: step1. operate successfully and get v1=2 of k1 finally.
1850      */
1851     for (int index = 0; index < BASIC_ACID_RUN_TIME; ++index) {
1852         DistributedCrudTransactionTools transactionTools(*g_transactionDelegate, CrudMode::PUT_BATCH, CrudMode::PUT,
1853             false, IS_LOCAL);
1854         EXPECT_TRUE(transactionTools.testCrudTransaction());
1855     }
1856 }
1857 
1858 /*
1859  * @tc.name: BasicActionAcid 002
1860  * @tc.desc: Verify that transaction between delete and deletebatch.
1861  * @tc.type: Pressure
1862  * @tc.require: SR000BUH3J
1863  * @tc.author: luqianfu
1864  */
1865 HWTEST_F(DistributeddbKvTransactionTest, BasicActionAcid002, TestSize.Level2)
1866 {
1867     /**
1868      * @tc.steps: step1. start transaction and deleteBatch (k0-k127,1) then delete k1.
1869      * @tc.expected: step1. operate successfully and no data exist in db.
1870      */
1871     for (int index = 0; index < BASIC_ACID_RUN_TIME; ++index) {
1872         DistributedCrudTransactionTools transactionTools(*g_transactionDelegate, CrudMode::DELETE_BATCH,
1873             CrudMode::DELETE, true, IS_LOCAL);
1874         EXPECT_TRUE(transactionTools.testCrudTransaction());
1875     }
1876 }
1877 
1878 /*
1879  * @tc.name: BasicActionAcid 003
1880  * @tc.desc: Verify that transaction between put and deletebatch.
1881  * @tc.type: Pressure
1882  * @tc.require: SR000BUH3J
1883  * @tc.author: luqianfu
1884  */
1885 HWTEST_F(DistributeddbKvTransactionTest, BasicActionAcid003, TestSize.Level2)
1886 {
1887     /**
1888      * @tc.steps: step1. start transaction and deleteBatch (k0-k127,1) then put (k1,v1=2).
1889      * @tc.expected: step1. operate successfully and get v1=2 of k1.
1890      */
1891     for (int index = 0; index < BASIC_ACID_RUN_TIME; ++index) {
1892         DistributedCrudTransactionTools transactionTools(*g_transactionDelegate, CrudMode::DELETE_BATCH,
1893             CrudMode::PUT, true, IS_LOCAL);
1894         EXPECT_TRUE(transactionTools.testCrudTransaction());
1895     }
1896 }
1897 
1898 /*
1899  * @tc.name: BasicActionAcid 004
1900  * @tc.desc: Verify that transaction between putbatch and delete.
1901  * @tc.type: Pressure
1902  * @tc.require: SR000BUH3J
1903  * @tc.author: luqianfu
1904  */
1905 HWTEST_F(DistributeddbKvTransactionTest, BasicActionAcid004, TestSize.Level2)
1906 {
1907     /**
1908      * @tc.steps: step1. start transaction and putBatch (k0-k127,1) then delete k1.
1909      * @tc.expected: step1. operate successfully and get null of k1 but the size of keys is 128.
1910      */
1911     for (int index = 0; index < BASIC_ACID_RUN_TIME; ++index) {
1912         DistributedCrudTransactionTools transactionTools(*g_transactionDelegate, CrudMode::PUT_BATCH,
1913             CrudMode::DELETE, false, IS_LOCAL);
1914         EXPECT_TRUE(transactionTools.testCrudTransaction());
1915     }
1916 }
1917 
1918 /*
1919  * @tc.name: BasicActionAcid 005
1920  * @tc.desc: Verify that transaction between put and clear.
1921  * @tc.type: Pressure
1922  * @tc.require: SR000BUH3J
1923  * @tc.author: luqianfu
1924  */
1925 HWTEST_F(DistributeddbKvTransactionTest, BasicActionAcid005, TestSize.Level2)
1926 {
1927     /**
1928      * @tc.steps: step1. start transaction and clear db then put (k1,v1=2).
1929      * @tc.expected: step1. operate successfully and get v1=2 of k1.
1930      */
1931     for (int index = 0; index < BASIC_ACID_RUN_TIME; ++index) {
1932         DistributedCrudTransactionTools transactionTools(*g_transactionDelegate, CrudMode::CLEAR,
1933             CrudMode::PUT, true, IS_LOCAL);
1934         EXPECT_TRUE(transactionTools.testCrudTransaction());
1935     }
1936 }
1937 
1938 /*
1939  * @tc.name: BasicActionAcid 006
1940  * @tc.desc: Verify that transaction between putbatch and clear.
1941  * @tc.type: Pressure
1942  * @tc.require: SR000BUH3J
1943  * @tc.author: luqianfu
1944  */
1945 HWTEST_F(DistributeddbKvTransactionTest, BasicActionAcid006, TestSize.Level2)
1946 {
1947     /**
1948      * @tc.steps: step1. start transaction and putBatch(k0-k127,values=2) then clear db.
1949      * @tc.expected: step1. operate successfully and get null of db.
1950      */
1951     for (int index = 0; index < BASIC_ACID_RUN_TIME; ++index) {
1952         DistributedCrudTransactionTools transactionTools(*g_transactionDelegate, CrudMode::PUT_BATCH,
1953             CrudMode::CLEAR, true, IS_LOCAL);
1954         EXPECT_TRUE(transactionTools.testCrudTransaction());
1955     }
1956 }
1957 
1958 /*
1959  * @tc.name: BasicActionAcid 007
1960  * @tc.desc: Verify that transaction between deletebatch and putbatch.
1961  * @tc.type: Pressure
1962  * @tc.require: SR000BUH3J
1963  * @tc.author: luqianfu
1964  */
1965 HWTEST_F(DistributeddbKvTransactionTest, BasicActionAcid007, TestSize.Level2)
1966 {
1967     /**
1968      * @tc.steps: step1. start transaction and deleteBatch(keys,values) then putBatch(k0-k127,v=2).
1969      * @tc.expected: step1. operate successfully and the size getEntries is 128,values=2.
1970      */
1971     for (int index = 0; index < BASIC_ACID_RUN_TIME; ++index) {
1972         DistributedCrudTransactionTools transactionTools(*g_transactionDelegate,
1973             CrudMode::DELETE_BATCH, CrudMode::PUT_BATCH, true, IS_LOCAL);
1974         EXPECT_TRUE(transactionTools.testCrudTransaction());
1975     }
1976 }
1977 
1978 /*
1979  * @tc.name: BasicActionAcid 008
1980  * @tc.desc: Verify that transaction between deletebatch and clear.
1981  * @tc.type: Pressure
1982  * @tc.require: SR000BUH3J
1983  * @tc.author: luqianfu
1984  */
1985 HWTEST_F(DistributeddbKvTransactionTest, BasicActionAcid008, TestSize.Level2)
1986 {
1987     /**
1988      * @tc.steps: step1. start transaction and clear then deleteBatch(k0-k127,v=2).
1989      * @tc.expected: step1. operate successfully and no data exist in db finally.
1990      */
1991     for (int index = 0; index < BASIC_ACID_RUN_TIME; ++index) {
1992         DistributedCrudTransactionTools transactionTools(*g_transactionDelegate, CrudMode::DELETE_BATCH,
1993             CrudMode::CLEAR, true, IS_LOCAL);
1994         EXPECT_TRUE(transactionTools.testCrudTransaction());
1995     }
1996 }
1997 }