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