• 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 
16 #include <gtest/gtest.h>
17 #include <thread>
18 
19 #include "db_constant.h"
20 #include "db_errno.h"
21 #include "distributeddb_data_generate_unit_test.h"
22 #include "distributeddb_tools_unit_test.h"
23 #include "kv_store_nb_delegate_impl.h"
24 #include "log_print.h"
25 #include "sqlite_single_ver_natural_store.h"
26 
27 using namespace testing::ext;
28 using namespace DistributedDB;
29 using namespace DistributedDBUnitTest;
30 using namespace std;
31 
32 namespace {
33     string g_testDir;
34     KvStoreConfig g_config;
35     KvStoreDelegateManager g_mgr(APP_ID, USER_ID);
36     DBStatus g_kvDelegateStatus = INVALID_ARGS;
37     KvStoreNbDelegate *g_kvNbDelegatePtr = nullptr;
38 
39     const int OBSERVER_SLEEP_TIME = 100;
40     const int BATCH_PRESET_SIZE_TEST = 10;
41     const int DIVIDE_BATCH_PRESET_SIZE = 5;
42     const int VALUE_OFFSET = 5;
43     const int DEFAULT_KEY_VALUE_SIZE = 10;
44 
45     const Key KEY1{'k', 'e', 'y', '1'};
46     const Key KEY2{'k', 'e', 'y', '2'};
47     const Value VALUE1{'v', 'a', 'l', 'u', 'e', '1'};
48     const Value VALUE2{'v', 'a', 'l', 'u', 'e', '2'};
49 
50     const std::string VALID_SCHEMA_STRICT_DEFINE = "{\"SCHEMA_VERSION\":\"1.0\","
51         "\"SCHEMA_MODE\":\"STRICT\","
52         "\"SCHEMA_DEFINE\":{"
53             "\"field_name1\":\"BOOL\","
54             "\"field_name2\":\"INTEGER, NOT NULL\""
55         "},"
56         "\"SCHEMA_INDEXES\":[\"$.field_name1\"]}";
57 
58     CipherPassword g_passwd;
59     KvStoreNbDelegate::Option g_strictOpt = {
60         true, false, false, CipherType::DEFAULT, g_passwd,
61         VALID_SCHEMA_STRICT_DEFINE
62     };
63 
64     // the type of g_kvNbDelegateCallback is function<void(DBStatus, KvStoreDelegate*)>
65     auto g_kvNbDelegateCallback = bind(&DistributedDBToolsUnitTest::KvStoreNbDelegateCallback, placeholders::_1,
66         placeholders::_2, std::ref(g_kvDelegateStatus), std::ref(g_kvNbDelegatePtr));
67 
CreatEntrys(int recordSize,vector<Key> & keys,vector<Value> & values,vector<Entry> & entries)68     static void CreatEntrys(int recordSize, vector<Key> &keys, vector<Value> &values, vector<Entry> &entries)
69     {
70         keys.clear();
71         values.clear();
72         entries.clear();
73         for (int i = 0; i < recordSize; i++) {
74             string temp = to_string(i);
75             Entry entry;
76             Key keyTemp;
77             Value valueTemp;
78             for (auto &iter : temp) {
79                 entry.key.push_back(iter);
80                 entry.value.push_back(iter);
81                 keyTemp.push_back(iter);
82                 valueTemp.push_back(iter);
83             }
84             keys.push_back(keyTemp);
85             values.push_back(valueTemp);
86             entries.push_back(entry);
87         }
88     }
89 }
90 
91 class DistributedDBInterfacesNBDelegateLocalBatchTest : public testing::Test {
92 public:
93     static void SetUpTestCase(void);
94     static void TearDownTestCase(void);
95     void SetUp();
96     void TearDown();
97 };
98 
SetUpTestCase(void)99 void DistributedDBInterfacesNBDelegateLocalBatchTest::SetUpTestCase(void)
100 {
101     DistributedDBToolsUnitTest::TestDirInit(g_testDir);
102     g_config.dataDir = g_testDir;
103     g_mgr.SetKvStoreConfig(g_config);
104 }
105 
TearDownTestCase(void)106 void DistributedDBInterfacesNBDelegateLocalBatchTest::TearDownTestCase(void)
107 {
108     if (DistributedDBToolsUnitTest::RemoveTestDbFiles(g_testDir) != 0) {
109         LOGE("rm test db files error!");
110     }
111 }
112 
SetUp(void)113 void DistributedDBInterfacesNBDelegateLocalBatchTest::SetUp(void)
114 {
115     DistributedDBToolsUnitTest::PrintTestCaseInfo();
116     g_kvDelegateStatus = INVALID_ARGS;
117     g_kvNbDelegatePtr = nullptr;
118 }
119 
TearDown(void)120 void DistributedDBInterfacesNBDelegateLocalBatchTest::TearDown(void)
121 {
122     if (g_kvNbDelegatePtr != nullptr) {
123         g_mgr.CloseKvStore(g_kvNbDelegatePtr);
124         g_kvNbDelegatePtr = nullptr;
125     }
126 }
127 
128 /**
129   * @tc.name: PutLocalBatch001
130   * @tc.desc: This test case use to verify the PutLocalBatch interface function
131   * @tc.type: FUNC
132   * @tc.require:
133   * @tc.author: changguicai
134   */
135 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, PutLocalBatch001, TestSize.Level1)
136 {
137     /**
138      * @tc.steps: step1. Get singleVer kvStore by GetKvStore.
139      * @tc.expected: step1. Get database success.
140      */
141     const KvStoreNbDelegate::Option option = {true, true};
142     g_mgr.SetKvStoreConfig(g_config);
143     g_mgr.GetKvStore("distributed_PutLocalBatch_001", option, g_kvNbDelegateCallback);
144     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
145     EXPECT_TRUE(g_kvDelegateStatus == OK);
146 
147     /**
148      * @tc.steps: step2. Insert 10 records into database.
149      * @tc.expected: step2. Insert successfully.
150      */
151     vector<Entry> entries;
152     for (int i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
153         Entry entry;
154         entry.key.push_back(i);
155         entry.value.push_back(i);
156         entries.push_back(entry);
157     }
158 
159     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entries), OK);
160 
161     for (int i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
162         Key key;
163         key.push_back(i);
164         Value value;
165         g_kvNbDelegatePtr->GetLocal(key, value);
166         EXPECT_EQ(key, value);
167     }
168 
169     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
170     g_kvNbDelegatePtr = nullptr;
171 }
172 
173 /**
174   * @tc.name: PutLocalBatch002
175   * @tc.desc: This testCase use to verify the PutLocalBatch and DeleteLocalBatch function while conn is nullptr
176   * @tc.type: FUNC
177   * @tc.require:
178   * @tc.author: caihaoting
179   */
180 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, PutLocalBatch002, TestSize.Level1)
181 {
182     /**
183      * @tc.steps: step1. Get singleVer kvStore by GetKvStore.
184      * @tc.expected: step1. Get database success.
185      */
186     const KvStoreNbDelegate::Option option = {true, true};
187     g_mgr.SetKvStoreConfig(g_config);
188     g_mgr.GetKvStore("distributed_PutLocalBatch_002", option, g_kvNbDelegateCallback);
189     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
190     EXPECT_TRUE(g_kvDelegateStatus == OK);
191 
192     /**
193      * @tc.steps: step2. PutLocalBatch and DeleteLocalBatch 10 records into database while conn is nullptr.
194      * @tc.expected: step2. DB_ERROR.
195      */
196     vector<Entry> entries;
197     for (int i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
198         Entry entry;
199         entry.key.push_back(i);
200         entry.value.push_back(i);
201         entries.push_back(entry);
202     }
203 
204     auto kvStoreImpl = static_cast<KvStoreNbDelegateImpl *>(g_kvNbDelegatePtr);
205     EXPECT_EQ(kvStoreImpl->Close(), OK);
206     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entries), DB_ERROR);
207     vector<Key> keys;
208     vector<Value> values;
209     CreatEntrys(BATCH_PRESET_SIZE_TEST, keys, values, entries);
210     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keys), DB_ERROR);
211 
212     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
213     g_kvNbDelegatePtr = nullptr;
214 }
215 
216 /**
217   * @tc.name: SingleVerPutLocalBatch001
218   * @tc.desc: Check for illegal parameters
219   * @tc.type: FUNC
220   * @tc.require:
221   * @tc.author: changguicai
222   */
223 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerPutLocalBatch001, TestSize.Level1)
224 {
225     /**
226      * @tc.steps: step1.
227      *  Create and construct three sets of vector <Entry>, each set of three data contains records:
228      *  (K1, V1) It is illegal for K1 to be greater than 1K, and V1 is 1K in size
229      *  (K2, V2) K2 is legal, V2 is greater than 4M
230      *  (K3, V3) are not legal.
231      */
232     Key illegalKey;
233     DistributedDBToolsUnitTest::GetRandomKeyValue(illegalKey, DBConstant::MAX_KEY_SIZE + 1); // 1K + 1
234     Value illegalValue;
235     DistributedDBToolsUnitTest::GetRandomKeyValue(illegalValue, DBConstant::MAX_VALUE_SIZE + 1); // 4M + 1
236     vector<Entry> entrysKeyIllegal = {KV_ENTRY_1, KV_ENTRY_2, {illegalKey, VALUE_3}};
237     vector<Entry> entrysValueIllegal = {KV_ENTRY_1, KV_ENTRY_2, {KEY_3, illegalValue}};
238     vector<Entry> entrysIllegal = {KV_ENTRY_1, KV_ENTRY_2, {illegalKey, illegalValue}};
239 
240     const KvStoreNbDelegate::Option option = {true, false};
241     g_mgr.SetKvStoreConfig(g_config);
242     g_mgr.GetKvStore("distributed_SingleVerPutLocalBatch_001", option, g_kvNbDelegateCallback);
243     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
244     EXPECT_TRUE(g_kvDelegateStatus == OK);
245     /**
246      * @tc.steps: step2. PutBatch operates on three sets of data.
247      * @tc.expected: step2. All three operations return INVALID_ARGS.
248      */
249     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysKeyIllegal), INVALID_ARGS);
250     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysValueIllegal), INVALID_ARGS);
251     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysIllegal), INVALID_ARGS);
252 
253     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
254     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_SingleVerPutLocalBatch_001"), OK);
255     g_kvNbDelegatePtr = nullptr;
256 }
257 
258 /**
259   * @tc.name: SingleVerPutLocalBatch002
260   * @tc.desc: PutLocalBatch normal insert function test.
261   * @tc.type: FUNC
262   * @tc.require:
263   * @tc.author: changguicai
264   */
265 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerPutLocalBatch002, TestSize.Level1)
266 {
267     const KvStoreNbDelegate::Option option = {true, false};
268     g_mgr.SetKvStoreConfig(g_config);
269     g_mgr.GetKvStore("distributed_SingleVerPutLocalBatch_002", option, g_kvNbDelegateCallback);
270     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
271     EXPECT_TRUE(g_kvDelegateStatus == OK);
272     /**
273      * @tc.steps: step1.
274      *  Create and build 4 groups of vector <Entry>, which are:
275      *  Vect of empty objects;
276      *  Vect1 of a legal Entry record;
277      *  128 legal Entry records Vect2;
278      *  129 legal Entry records Vect3;
279      */
280     vector<Entry> entrysMaxNumber;
281     for (size_t i = 0; i < DBConstant::MAX_BATCH_SIZE; i++) {
282         Entry entry;
283         entry.key.push_back(i);
284         entry.value.push_back(i);
285         entrysMaxNumber.push_back(entry);
286     }
287     Key keyTemp = {'1', '1'};
288     Value valueTemp;
289     Entry entryTemp = {keyTemp, VALUE_1};
290     vector<Entry> entrysOneRecord = {entryTemp};
291     vector<Entry> entrysOverSize = entrysMaxNumber;
292     entrysOverSize.push_back(entryTemp);
293     /**
294      * @tc.steps: step2. PutBatch operates on four sets of data. and use get check the result of Vect3.
295      * @tc.expected: step2. Returns OK for 129 records.
296      */
297     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysOverSize), OK);
298     for (size_t i = 0; i < entrysOverSize.size(); i++) {
299         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(entrysOverSize[i].key, valueTemp), OK);
300     }
301     /**
302      * @tc.steps: step3. Use get check the result of Vect2.
303      * @tc.expected: step3. Return OK and get the correct value.
304      */
305     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysOneRecord), OK);
306     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(keyTemp, valueTemp), OK);
307     EXPECT_EQ(valueTemp, VALUE_1);
308     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysMaxNumber), OK);
309      /**
310      * @tc.steps: step4. Use get check the result of Vect3.
311      * @tc.expected: step4. Return OK and get the correct value.
312      */
313     for (size_t i = 0; i < entrysMaxNumber.size(); i++) {
314         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(entrysMaxNumber[i].key, valueTemp), OK);
315         EXPECT_EQ(valueTemp, entrysMaxNumber[i].value);
316     }
317 
318     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
319     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_SingleVerPutLocalBatch_002"), OK);
320     g_kvNbDelegatePtr = nullptr;
321 }
322 
323 /**
324   * @tc.name: SingleVerPutLocalBatch003
325   * @tc.desc: Check interface atomicity
326   * @tc.type: FUNC
327   * @tc.require:
328   * @tc.author: changguicai
329   */
330 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerPutLocalBatch003, TestSize.Level1)
331 {
332     const KvStoreNbDelegate::Option option = {true, false};
333     g_mgr.SetKvStoreConfig(g_config);
334     g_mgr.GetKvStore("distributed_SingleVerPutLocalBatch_003", option, g_kvNbDelegateCallback);
335     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
336     EXPECT_TRUE(g_kvDelegateStatus == OK);
337     /**
338      * @tc.steps: step1. Create and construct a set of vector <Entry> with a total of 128 data,
339      * including one illegal data. And call PutBatch interface to insert.
340      */
341     vector<Entry> entrysMaxNumber;
342     for (size_t i = 0; i < DBConstant::MAX_BATCH_SIZE; i++) {
343         Entry entry;
344         entry.key.push_back(i);
345         entry.value.push_back(i);
346         entrysMaxNumber.push_back(entry);
347     }
348     Key illegalKey;
349     Value valueTemp;
350     DistributedDBToolsUnitTest::GetRandomKeyValue(illegalKey, DBConstant::MAX_KEY_SIZE + 1); // 1K + 1
351     entrysMaxNumber[0].key = illegalKey;
352 
353     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysMaxNumber), INVALID_ARGS);
354     /**
355      * @tc.steps: step2. Use Get interface to query 128 corresponding key values.
356      * @tc.expected: step2. All Get interface return NOT_FOUND.
357      */
358     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(entrysMaxNumber[0].key, valueTemp), INVALID_ARGS);
359     for (size_t i = 1; i < entrysMaxNumber.size(); i++) {
360         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(entrysMaxNumber[i].key, valueTemp), NOT_FOUND);
361     }
362     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
363     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_SingleVerPutLocalBatch_003"), OK);
364     g_kvNbDelegatePtr = nullptr;
365 }
366 
PreparePutLocalBatch004(vector<Entry> & entrys1,vector<Entry> & entrys2,vector<Entry> & entrys3)367 static void PreparePutLocalBatch004(vector<Entry> &entrys1, vector<Entry> &entrys2, vector<Entry> &entrys3)
368 {
369     const KvStoreNbDelegate::Option option = {true, false};
370     g_mgr.SetKvStoreConfig(g_config);
371     g_mgr.GetKvStore("distributed_SingleVerPutLocalBatch_004", option, g_kvNbDelegateCallback);
372     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
373     EXPECT_TRUE(g_kvDelegateStatus == OK);
374 
375     for (int i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
376         Entry entry;
377         entry.key.push_back(i);
378         entry.value.push_back(i);
379         entrys1.push_back(entry);
380     }
381 
382     for (int i = 0; i < DIVIDE_BATCH_PRESET_SIZE; i++) {
383         Entry entry;
384         entry.key.push_back(i);
385         entry.value.push_back(i + VALUE_OFFSET);
386         entrys2.push_back(entry);
387     }
388 
389     for (int i = DIVIDE_BATCH_PRESET_SIZE; i < BATCH_PRESET_SIZE_TEST; i++) {
390         Entry entry;
391         entry.key.push_back(i);
392         entry.value.push_back(i - VALUE_OFFSET);
393         entrys3.push_back(entry);
394     }
395 }
396 
397 /**
398   * @tc.name: SingleVerPutLocalBatch004
399   * @tc.desc: Check interface data insertion and update functions.
400   * @tc.type: FUNC
401   * @tc.require:
402   * @tc.author: changguicai
403   */
404 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerPutLocalBatch004, TestSize.Level1)
405 {
406     /**
407      * @tc.steps: step1.
408      *  Construct three groups of three vector <Entry>:
409      *  (1) entrys1: key1 ~ 10, corresponding to Value1 ~ 10;
410      *  (2) entrys2: key1 ~ 5, corresponding to Value6 ~ 10;
411      *  (3) entrys3: key6 ~ 10, corresponding to Value1 ~ 5;
412      */
413     vector<Entry> entrys1;
414     vector<Entry> entrys2;
415     vector<Entry> entrys3;
416     PreparePutLocalBatch004(entrys1, entrys2, entrys3);
417     /**
418      * @tc.steps: step2. PutBatch entrys2.
419      * @tc.expected: step2. PutBatch return OK.
420      */
421     Value valueRead;
422     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrys2), OK);
423     /**
424      * @tc.steps: step3. Check PutBatch result.
425      * @tc.expected: step3. Get correct value of key1~5. Key6~10 return NOT_FOUND.
426      */
427     for (int i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
428         Key keyTemp;
429         keyTemp.push_back(i);
430         if (i < DIVIDE_BATCH_PRESET_SIZE) {
431             Value valueTemp;
432             valueTemp.push_back(i + VALUE_OFFSET);
433             EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(keyTemp, valueRead), OK);
434             EXPECT_EQ(valueRead, valueTemp);
435             continue;
436         }
437         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(keyTemp, valueRead), NOT_FOUND);
438     }
439     /**
440      * @tc.steps: step4. PutBatch entrys1.
441      * @tc.expected: step4. PutBatch return OK.
442      */
443     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrys1), OK);
444     /**
445      * @tc.steps: step5. Check PutBatch result.
446      * @tc.expected: step5. Update and insert value of key1~10 to value1~10.
447      */
448     for (int i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
449         Key keyTemp;
450         keyTemp.push_back(i);
451         if (i < DIVIDE_BATCH_PRESET_SIZE) {
452             EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(keyTemp, valueRead), OK);
453             EXPECT_EQ(valueRead, keyTemp);
454             continue;
455         }
456         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(keyTemp, valueRead), OK);
457         EXPECT_EQ(valueRead, keyTemp);
458     }
459     /**
460      * @tc.steps: step6. PutBatch entrys3.
461      * @tc.expected: step6. PutBatch return OK.
462      */
463     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrys3), OK);
464     /**
465      * @tc.steps: step7. Check PutBatch result of key1~10.
466      * @tc.expected: step7. Update value of key5~10 to value1~5.
467      */
468     for (int i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
469         Key keyTemp;
470         keyTemp.push_back(i);
471         if (i < DIVIDE_BATCH_PRESET_SIZE) {
472             EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(keyTemp, valueRead), OK);
473             EXPECT_EQ(valueRead, keyTemp);
474             continue;
475         }
476         Value valueTemp;
477         valueTemp.push_back(i - VALUE_OFFSET);
478         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(keyTemp, valueRead), OK);
479         EXPECT_EQ(valueRead, valueTemp);
480     }
481 
482     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
483     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_SingleVerPutLocalBatch_004"), OK);
484     g_kvNbDelegatePtr = nullptr;
485 }
486 
487 #ifndef LOW_LEVEL_MEM_DEV
488 /**
489   * @tc.name: SingleVerPutLocalBatch005
490   * @tc.desc: Check for legal parameters that the sum size of all entries is smaller than 512M.
491   * @tc.type: FUNC
492   * @tc.require:
493   * @tc.author: mazhao
494   */
495 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerPutLocalBatch005, TestSize.Level1)
496 {
497     /**
498      * @tc.steps: step1.
499      *  Create and construct two sets of vector <Entry>, each set of two data contains records:
500      */
501     Key legalKey;
502     DistributedDBToolsUnitTest::GetRandomKeyValue(legalKey, DBConstant::MAX_KEY_SIZE); // 1K
503     Value legalValue;
504     DistributedDBToolsUnitTest::GetRandomKeyValue(legalValue, DBConstant::MAX_VALUE_SIZE); // 4M
505     Value emptyValue; // 0k
506     vector<Entry> entrysKeyLegal; // size is 512M - 1kB
507     for (int i = 0; i < 524287; i++) { // 524287 * legalKey is equal to 512M - 1KB.
508         entrysKeyLegal.push_back({legalKey, emptyValue});
509     }
510 
511     vector<Entry> entrysMixLegal; // size is 511M + 511KB < 512M
512     for (int i = 0; i < 127; i++) { // 127 * (legalValue + legalKey) is equal to 508M + 127KB < 512M.
513         entrysMixLegal.push_back({legalKey, legalValue});
514     }
515 
516     const KvStoreNbDelegate::Option option = {true, false};
517     g_mgr.SetKvStoreConfig(g_config);
518     g_mgr.GetKvStore("SingleVerPutLocalBatch005", option, g_kvNbDelegateCallback);
519     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
520     EXPECT_TRUE(g_kvDelegateStatus == OK);
521     /**
522      * @tc.steps: step2. PutBatch operates on two sets of data.
523      * @tc.expected: step2. two operations return OK.
524      */
525     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysKeyLegal), OK);
526     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysMixLegal), OK);
527 
528     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
529     EXPECT_EQ(g_mgr.DeleteKvStore("SingleVerPutLocalBatch005"), OK);
530     g_kvNbDelegatePtr = nullptr;
531 }
532 
533 /**
534   * @tc.name: SingleVerPutLocalBatch006
535   * @tc.desc: Check for legal parameters that the sum size of all entries is equal to 512M.
536   * @tc.type: FUNC
537   * @tc.require:
538   * @tc.author: mazhao
539   */
540 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerPutLocalBatch006, TestSize.Level1)
541 {
542     /**
543      * @tc.steps: step1.
544      *  Create and construct two sets of vector <Entry>, each set of two data contains records:
545      */
546     Key legalKey;
547     DistributedDBToolsUnitTest::GetRandomKeyValue(legalKey, DBConstant::MAX_KEY_SIZE); // 1K
548     Value legalValue;
549     DistributedDBToolsUnitTest::GetRandomKeyValue(legalValue, DBConstant::MAX_VALUE_SIZE); // 4M
550     Value emptyValue; // 0k
551 
552     vector<Entry> entrysKeyLegal; // size is 512M
553     for (int i = 0; i < 524288; i++) { // 524288 * legalKey is equal to 512M.
554         entrysKeyLegal.push_back({legalKey, emptyValue});
555     }
556 
557     vector<Entry> entrysMixLegal; // size is 512M
558     for (int i = 0; i < 127; i++) { // 127 * (legalValue + legalKey) is equal to 508M + 127KB < 512M.
559         entrysMixLegal.push_back({legalKey, legalValue});
560     }
561     for (int i = 0; i < 3969; i++) { // 3969 * legalKey is equal to 3969KB.
562         entrysMixLegal.push_back({legalKey, emptyValue});
563     }
564 
565     const KvStoreNbDelegate::Option option = {true, false};
566     g_mgr.SetKvStoreConfig(g_config);
567     g_mgr.GetKvStore("SingleVerPutLocalBatch006", option, g_kvNbDelegateCallback);
568     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
569     EXPECT_TRUE(g_kvDelegateStatus == OK);
570     /**
571      * @tc.steps: step2. PutBatch operates on two sets of data.
572      * @tc.expected: step2. two operations return OK.
573      */
574     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysKeyLegal), OK);
575     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysMixLegal), OK);
576 
577     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
578     EXPECT_EQ(g_mgr.DeleteKvStore("SingleVerPutLocalBatch006"), OK);
579     g_kvNbDelegatePtr = nullptr;
580 }
581 
582 /**
583   * @tc.name: SingleVerPutLocalBatch007
584   * @tc.desc: Check for illegal parameters that the sum size of all entries is larger to 512M.
585   * @tc.type: FUNC
586   * @tc.require:
587   * @tc.author: mazhao
588   */
589 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerPutLocalBatch007, TestSize.Level1)
590 {
591     /**
592      * @tc.steps: step1.
593      *  Create and construct two sets of vector <Entry>, each set of two data contains records:
594      */
595     Key legalKey;
596     DistributedDBToolsUnitTest::GetRandomKeyValue(legalKey, DBConstant::MAX_KEY_SIZE); // 1K
597     Value legalValue;
598     DistributedDBToolsUnitTest::GetRandomKeyValue(legalValue, DBConstant::MAX_VALUE_SIZE); // 4M
599     Value emptyValue; // 0k
600 
601     vector<Entry> entrysKeyIllegal; // size is 512M + 1KB
602     for (int i = 0; i < 524289; i++) { // 524289 * legalKey is equal to 512M + 1KB.
603         entrysKeyIllegal.push_back({legalKey, emptyValue});
604     }
605 
606     vector<Entry> entrysMixIllegal; // size is 512M + 1KB
607     for (int i = 0; i < 127; i++) { // 127 * (legalValue + legalKey) is equal to 508M + 127KB < 512M.
608         entrysMixIllegal.push_back({legalKey, legalValue});
609     }
610     for (int i = 0; i < 3970; i++) { // 3970 * legalKey is equal to 3970KB.
611         entrysMixIllegal.push_back({legalKey, emptyValue});
612     }
613 
614     const KvStoreNbDelegate::Option option = {true, false};
615     g_mgr.SetKvStoreConfig(g_config);
616     g_mgr.GetKvStore("SingleVerPutLocalBatch007", option, g_kvNbDelegateCallback);
617     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
618     EXPECT_TRUE(g_kvDelegateStatus == OK);
619     /**
620      * @tc.steps: step2. PutBatch operates on two sets of data.
621      * @tc.expected: step2. two operations return INVALID_ARGS.
622      */
623     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysKeyIllegal), INVALID_ARGS);
624     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysMixIllegal), INVALID_ARGS);
625 
626     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
627     EXPECT_EQ(g_mgr.DeleteKvStore("SingleVerPutLocalBatch007"), OK);
628     g_kvNbDelegatePtr = nullptr;
629 }
630 
631 /**
632   * @tc.name: SingleVerPutLocalBatch008
633   * @tc.desc: Check for illegal parameters that the sum size of all entries excced uint32_t limit.
634   * @tc.type: FUNC
635   * @tc.require:
636   * @tc.author: mazhao
637   */
638 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerPutLocalBatch008, TestSize.Level1)
639 {
640     /**
641      * @tc.steps: step1.
642      *  Create and construct two sets of vector <Entry>, each set of two data contains records:
643      */
644     Key legalKey;
645     DistributedDBToolsUnitTest::GetRandomKeyValue(legalKey, DBConstant::MAX_KEY_SIZE); // 1K
646     Value emptyValue; // 0k
647 
648     vector<Entry> entrysIllegal; // size excced to the limit of uint32_t
649     for (int i = 0; i < 4194305; i++) { // 4194305 * legalKey is excced to the limit of uint32_t.
650         entrysIllegal.push_back({legalKey, emptyValue});
651     }
652 
653     const KvStoreNbDelegate::Option option = {true, false};
654     g_mgr.SetKvStoreConfig(g_config);
655     g_mgr.GetKvStore("SingleVerPutLocalBatch008", option, g_kvNbDelegateCallback);
656     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
657     EXPECT_TRUE(g_kvDelegateStatus == OK);
658     /**
659      * @tc.steps: step2. PutBatch operates on two sets of data.
660      * @tc.expected: step2. two operations return INVALID_ARGS.
661      */
662     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysIllegal), INVALID_ARGS);
663 
664     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
665     EXPECT_EQ(g_mgr.DeleteKvStore("SingleVerPutLocalBatch008"), OK);
666     g_kvNbDelegatePtr = nullptr;
667 }
668 #endif // LOW_LEVEL_MEM_DEV
669 
670 /**
671   * @tc.name: SingleVerDeleteLocalBatch001
672   * @tc.desc: Check for illegal parameters.
673   * @tc.type: FUNC
674   * @tc.require:
675   * @tc.author: changguicai
676   */
677 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerDeleteLocalBatch001, TestSize.Level1)
678 {
679     const KvStoreNbDelegate::Option option = {true, false};
680     g_mgr.SetKvStoreConfig(g_config);
681     g_mgr.GetKvStore("distributed_SingleVerDeleteLocalBatch_001", option, g_kvNbDelegateCallback);
682     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
683     EXPECT_TRUE(g_kvDelegateStatus == OK);
684     /**
685      * @tc.steps: step1. Create and construct a set of vector <Entry>, containing a total of 10 data keys1 ~ 10,
686      *  Value1 ~ 10, and call Putbatch interface to insert data.
687      * @tc.expected: step1. PutBatch successfully.
688      */
689     vector<Entry> entries;
690     vector<Key> keys;
691     vector<Value> values;
692     Value valueRead;
693     CreatEntrys(BATCH_PRESET_SIZE_TEST, keys, values, entries);
694     vector<Entry> entrysBase = entries;
695     vector<Key> keysBase = keys;
696     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysBase), OK);
697     /**
698      * @tc.steps: step2. Use Get to check data in database.
699      * @tc.expected: step2. Get value1~10 by key1~10 successfully.
700      */
701     for (size_t i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
702         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(entrysBase[i].key, valueRead), OK);
703     }
704     /**
705      * @tc.steps: step3. Use Get to check data in database.
706      * @tc.expected: step3. Key1~10 still in database.
707      */
708     for (size_t i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
709         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(entrysBase[i].key, valueRead), OK);
710     }
711     /**
712      * @tc.steps: step4. Use the DeleteBatch interface to pass in 10 included
713      *  keys6 ~ 10 + 123 additional key values ​​(128 in total).
714      * @tc.expected: step4. DeleteBatch OK.
715      */
716     CreatEntrys(DBConstant::MAX_BATCH_SIZE + DIVIDE_BATCH_PRESET_SIZE, keys, values, entries);
717     keys.erase(keys.begin(), keys.begin() + DIVIDE_BATCH_PRESET_SIZE);
718     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keys), OK);
719     /**
720      * @tc.steps: step5. Use Get to check key1~10 in database.
721      * @tc.expected: step5. Key1~5 in database, key6~10 have been deleted.
722      */
723     for (size_t i = 0; i < DIVIDE_BATCH_PRESET_SIZE; i++) {
724         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(entrysBase[i].key, valueRead), OK);
725     }
726     for (size_t i = DIVIDE_BATCH_PRESET_SIZE; i < BATCH_PRESET_SIZE_TEST; i++) {
727         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(entrysBase[i].key, valueRead), NOT_FOUND);
728     }
729     /**
730      * @tc.steps: step6. Repeat Putbatch key1~10, value1~10.
731      * @tc.expected: step6. Return OK.
732      */
733     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysBase), OK);
734 
735     Key illegalKey;
736     DistributedDBToolsUnitTest::GetRandomKeyValue(illegalKey, DBConstant::MAX_KEY_SIZE + 1); // 1K + 1
737     keysBase.push_back(illegalKey);
738     /**
739      * @tc.steps: step7. Use DeleteBatch interface to pass in 10 + 1(larger than 1K) keys.
740      * @tc.expected: step7. Return INVALID_ARGS.
741      */
742     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keysBase), INVALID_ARGS);
743     /**
744      * @tc.steps: step8. Use Get to check key1~10 in database.
745      * @tc.expected: step8. Delete those data failed.
746      */
747     for (size_t i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
748         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(entrysBase[i].key, valueRead), OK);
749     }
750     /**
751      * @tc.steps: step9. Use DeleteBatch interface to pass in 10(in database) + 1 valid keys.
752      * @tc.expected: step9. Delete those data successfully.
753      */
754     keysBase.back().erase(keysBase.back().begin(), keysBase.back().begin() + 1);
755     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keysBase), OK);
756     /**
757      * @tc.steps: step10. Check data.
758      * @tc.expected: step10. DeleteBatch successfully.
759      */
760     for (size_t i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
761         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(entrysBase[i].key, valueRead), NOT_FOUND);
762     }
763 
764     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
765     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_SingleVerDeleteLocalBatch_001"), OK);
766     g_kvNbDelegatePtr = nullptr;
767 }
768 
769 /**
770   * @tc.name: SingleVerDeleteLocalBatch002
771   * @tc.desc: Check normal delete batch ability.
772   * @tc.type: FUNC
773   * @tc.require:
774   * @tc.author: changguicai
775   */
776 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerDeleteLocalBatch002, TestSize.Level1)
777 {
778     const KvStoreNbDelegate::Option option = {true, false};
779     g_mgr.SetKvStoreConfig(g_config);
780     g_mgr.GetKvStore("distributed_SingleVerDeleteLocalBatch_002", option, g_kvNbDelegateCallback);
781     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
782     EXPECT_TRUE(g_kvDelegateStatus == OK);
783     /**
784      * @tc.steps: step1. Create a group of vector <Entry>, containing a total of 10 data keys1 ~ 10, Value1 ~ 10,
785      *  call the Putbatch interface to insert data.
786      * @tc.expected: step1. Insert to database successfully.
787      */
788     vector<Entry> entries;
789     vector<Key> keysBase;
790     vector<Value> values;
791     CreatEntrys(BATCH_PRESET_SIZE_TEST, keysBase, values, entries);
792 
793     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entries), OK);
794     /**
795      * @tc.steps: step2. Check data.
796      * @tc.expected: step2. Get key1~10 successfully.
797      */
798     Value valueRead;
799     for (size_t i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
800         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(keysBase[i], valueRead), OK);
801     }
802     /**
803      * @tc.steps: step3. DeleteBatch key1~5.
804      * @tc.expected: step3. Return OK.
805      */
806     vector<Key> keys(keysBase.begin(), keysBase.begin() + DIVIDE_BATCH_PRESET_SIZE);
807     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keys), OK);
808     /**
809      * @tc.steps: step4. Check key1~10.
810      * @tc.expected: step4. Key1~5 deleted, key6~10 existed.
811      */
812     for (size_t i = 0; i < DIVIDE_BATCH_PRESET_SIZE; i++) {
813         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(keysBase[i], valueRead), NOT_FOUND);
814     }
815     for (size_t i = DIVIDE_BATCH_PRESET_SIZE; i < BATCH_PRESET_SIZE_TEST; i++) {
816         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(keysBase[i], valueRead), OK);
817     }
818     /**
819      * @tc.steps: step5. DeleteBatch key1~10.
820      * @tc.expected: step5. Return OK.
821      */
822     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keysBase), OK);
823     /**
824      * @tc.steps: step6. Check key1~10.
825      * @tc.expected: step6. Key1~10 deleted successfully.
826      */
827     for (size_t i = 0; i < BATCH_PRESET_SIZE_TEST; i++) {
828         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(keysBase[i], valueRead), NOT_FOUND);
829     }
830     /**
831      * @tc.steps: step7. DeleteBatch key1~10 once again.
832      * @tc.expected: step7. Return OK.
833      */
834     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keysBase), OK);
835 
836     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
837     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_SingleVerDeleteLocalBatch_002"), OK);
838     g_kvNbDelegatePtr = nullptr;
839 }
840 
841 #ifndef LOW_LEVEL_MEM_DEV
842 /**
843   * @tc.name: SingleVerDeleteLocalBatch003
844   * @tc.desc: Check for legal parameters that the sum size of all Keys is smaller than 512M.
845   * @tc.type: FUNC
846   * @tc.require:
847   * @tc.author: mazhao
848   */
849 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerDeleteLocalBatch003, TestSize.Level1)
850 {
851     /**
852      * @tc.steps: step1.
853      *  Create and construct one sets of vector <Key>:
854      */
855     Key legalKey;
856     DistributedDBToolsUnitTest::GetRandomKeyValue(legalKey, DBConstant::MAX_KEY_SIZE); // 1K
857     vector<Key> keysLegal; // size is 512M - 1kB
858     for (int i = 0; i < 524287; i++) { // 524287 * legalKey is equal to 512M - 1KB.
859         keysLegal.push_back(legalKey);
860     }
861 
862     const KvStoreNbDelegate::Option option = {true, false};
863     g_mgr.SetKvStoreConfig(g_config);
864     g_mgr.GetKvStore("SingleVerDeleteLocalBatch003", option, g_kvNbDelegateCallback);
865     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
866     EXPECT_TRUE(g_kvDelegateStatus == OK);
867     /**
868      * @tc.steps: step2. DeleteBatch operates on sets of data.
869      * @tc.expected: step2. return OK.
870      */
871     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keysLegal), OK);
872 
873     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
874     EXPECT_EQ(g_mgr.DeleteKvStore("SingleVerDeleteLocalBatch003"), OK);
875     g_kvNbDelegatePtr = nullptr;
876 }
877 
878 /**
879   * @tc.name: SingleVerDeleteLocalBatch004
880   * @tc.desc: Check for legal parameters that the sum size of all entries is equal to 512M.
881   * @tc.type: FUNC
882   * @tc.require:
883   * @tc.author: mazhao
884   */
885 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerDeleteLocalBatch004, TestSize.Level1)
886 {
887     /**
888      * @tc.steps: step1.
889      *  Create and construct one sets of vector <Key>:
890      */
891     Key legalKey;
892     DistributedDBToolsUnitTest::GetRandomKeyValue(legalKey, DBConstant::MAX_KEY_SIZE); // 1K
893     vector<Key> keysLegal; // size is 512M
894     for (int i = 0; i < 524288; i++) { // 524288 * legalKey is equal to 512M.
895         keysLegal.push_back(legalKey);
896     }
897 
898     const KvStoreNbDelegate::Option option = {true, false};
899     g_mgr.SetKvStoreConfig(g_config);
900     g_mgr.GetKvStore("SingleVerDeleteLocalBatch004", option, g_kvNbDelegateCallback);
901     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
902     EXPECT_TRUE(g_kvDelegateStatus == OK);
903     /**
904      * @tc.steps: step2. DeleteBatch operates on sets of data.
905      * @tc.expected: step2. return OK.
906      */
907     EXPECT_EQ(g_kvNbDelegatePtr->DeleteBatch(keysLegal), OK);
908 
909     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
910     EXPECT_EQ(g_mgr.DeleteKvStore("SingleVerDeleteLocalBatch004"), OK);
911     g_kvNbDelegatePtr = nullptr;
912 }
913 
914 /**
915   * @tc.name: SingleVerDeleteLocalBatch005
916   * @tc.desc: Check for illegal parameters that the sum size of all entries is larger to 512M.
917   * @tc.type: FUNC
918   * @tc.require:
919   * @tc.author: mazhao
920   */
921 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerDeleteLocalBatch005, TestSize.Level1)
922 {
923     /**
924      * @tc.steps: step1.
925      *  Create and construct one sets of vector <Key>:
926      */
927     Key legalKey;
928     DistributedDBToolsUnitTest::GetRandomKeyValue(legalKey, DBConstant::MAX_KEY_SIZE); // 1K
929     vector<Key> keysIllLegal; // size is 512M + 1kB
930     for (int i = 0; i < 524289; i++) { // 524289 * legalKey is equal to 512M + 1KB.
931         keysIllLegal.push_back(legalKey);
932     }
933 
934     const KvStoreNbDelegate::Option option = {true, false};
935     g_mgr.SetKvStoreConfig(g_config);
936     g_mgr.GetKvStore("SingleVerDeleteLocalBatch005", option, g_kvNbDelegateCallback);
937     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
938     EXPECT_TRUE(g_kvDelegateStatus == OK);
939     /**
940      * @tc.steps: step2. DeleteLocalBatch operates on sets of data.
941      * @tc.expected: step2. return INVALID_ARGS.
942      */
943     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keysIllLegal), INVALID_ARGS);
944 
945     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
946     EXPECT_EQ(g_mgr.DeleteKvStore("SingleVerDeleteLocalBatch005"), OK);
947     g_kvNbDelegatePtr = nullptr;
948 }
949 
950 /**
951   * @tc.name: SingleVerDeleteLocalBatch006
952   * @tc.desc: Check for illegal parameters that the sum size of all entries excced uint32_t limit.
953   * @tc.type: FUNC
954   * @tc.require:
955   * @tc.author: mazhao
956   */
957 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerDeleteLocalBatch006, TestSize.Level1)
958 {
959     /**
960      * @tc.steps: step1.
961      *  Create and construct one sets of vector <Key>:
962      */
963     Key legalKey;
964     DistributedDBToolsUnitTest::GetRandomKeyValue(legalKey, DBConstant::MAX_KEY_SIZE); // 1K
965     vector<Key> keysIllLegal; // size excced to the limit of uint32_t
966     for (int i = 0; i < 4194305; i++) { // 4194305 * legalKey is excced to the limit of uint32_t.
967         keysIllLegal.push_back(legalKey);
968     }
969 
970     const KvStoreNbDelegate::Option option = {true, false};
971     g_mgr.SetKvStoreConfig(g_config);
972     g_mgr.GetKvStore("SingleVerDeleteLocalBatch006", option, g_kvNbDelegateCallback);
973     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
974     EXPECT_TRUE(g_kvDelegateStatus == OK);
975     /**
976      * @tc.steps: step2. DeleteLocalBatch operates on sets of data.
977      * @tc.expected: step2. return INVALID_ARGS.
978      */
979     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keysIllLegal), INVALID_ARGS);
980 
981     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
982     EXPECT_EQ(g_mgr.DeleteKvStore("SingleVerDeleteLocalBatch006"), OK);
983     g_kvNbDelegatePtr = nullptr;
984 }
985 #endif // LOW_LEVEL_MEM_DEV
986 
987 /**
988   * @tc.name: SingleVerPutLocalBatchObserver001
989   * @tc.desc: Test the observer function of PutLocalBatch() interface.
990   * @tc.type: FUNC
991   * @tc.require:
992   * @tc.author: changguicai
993   */
994 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerPutLocalBatchObserver001, TestSize.Level1)
995 {
996     /**
997      * @tc.steps:step1. Get the nb delegate.
998      * @tc.expected: step1. Get results OK and non-null delegate.
999      */
1000     KvStoreNbDelegate::Option option = {true, false, false};
1001     g_mgr.GetKvStore("distributed_SingleVerPutLocalBatchObserver_001", option, g_kvNbDelegateCallback);
1002     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
1003     EXPECT_TRUE(g_kvDelegateStatus == OK);
1004 
1005     KvStoreObserverUnitTest *observer = new (std::nothrow) KvStoreObserverUnitTest;
1006     ASSERT_TRUE(observer != nullptr);
1007     /**
1008      * @tc.steps:step2. Register the non-null observer for the special key.
1009      * @tc.expected: step2. Register results OK.
1010      */
1011     Key key;
1012     EXPECT_EQ(g_kvNbDelegatePtr->RegisterObserver(key, OBSERVER_CHANGES_LOCAL_ONLY, observer), OK);
1013     /**
1014      * @tc.steps:step3. Put batch data.
1015      * @tc.expected: step3. Returns OK.
1016      */
1017     vector<Entry> entrysBase;
1018     vector<Key> keysBase;
1019     DistributedDBUnitTest::GenerateRecords(BATCH_PRESET_SIZE_TEST + 1, entrysBase, keysBase);
1020 
1021     vector<Entry> entries(entrysBase.begin(), entrysBase.end() - 1);
1022     EXPECT_EQ(entries.size(), 10UL);
1023     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entries), OK);
1024     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
1025     EXPECT_TRUE(DistributedDBToolsUnitTest::CheckObserverResult(entries, observer->GetEntriesInserted()));
1026     /**
1027      * @tc.steps:step4. Delete the batch data.
1028      * @tc.expected: step4. Returns OK.
1029      */
1030     vector<Key> keys(keysBase.begin() + 5, keysBase.end());
1031     EXPECT_EQ(keys.size(), 6UL);
1032     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keys), OK);
1033     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
1034     vector<Entry> entrysDel(entrysBase.begin() + 5, entrysBase.end() - 1);
1035     EXPECT_EQ(entrysDel.size(), 5UL);
1036     EXPECT_TRUE(DistributedDBToolsUnitTest::CheckObserverResult(entrysDel, observer->GetEntriesDeleted()));
1037     /**
1038      * @tc.steps:step5. UnRegister the observer.
1039      * @tc.expected: step5. Returns OK.
1040      */
1041     EXPECT_EQ(g_kvNbDelegatePtr->UnRegisterObserver(observer), OK);
1042     delete observer;
1043     observer = nullptr;
1044 
1045     /**
1046      * @tc.steps:step6. Close the kv store.
1047      * @tc.expected: step6. Results OK and delete successfully.
1048      */
1049     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
1050     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_SingleVerPutLocalBatchObserver_001"), OK);
1051     g_kvNbDelegatePtr = nullptr;
1052 }
1053 
1054 /**
1055   * @tc.name: SingleVerPutLocalBatchObserver002
1056   * @tc.desc: Test the observer function of PutLocalBatch() for invalid input.
1057   * @tc.type: FUNC
1058   * @tc.require:
1059   * @tc.author: changguicai
1060   */
1061 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerPutLocalBatchObserver002, TestSize.Level4)
1062 {
1063     /**
1064      * @tc.steps:step1. Get the nb delegate.
1065      * @tc.expected: step1. Get results OK and non-null delegate.
1066      */
1067     KvStoreNbDelegate::Option option = {true, false, false};
1068     g_mgr.GetKvStore("distributed_SingleVerPutLocalBatchObserver_002", option, g_kvNbDelegateCallback);
1069     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
1070     EXPECT_TRUE(g_kvDelegateStatus == OK);
1071 
1072     KvStoreObserverUnitTest *observer = new (std::nothrow) KvStoreObserverUnitTest;
1073     ASSERT_TRUE(observer != nullptr);
1074     /**
1075      * @tc.steps:step2. Register the non-null observer for the special key.
1076      * @tc.expected: step2. Register results OK.
1077      */
1078     Key key;
1079     EXPECT_EQ(g_kvNbDelegatePtr->RegisterObserver(key, OBSERVER_CHANGES_LOCAL_ONLY, observer), OK);
1080     /**
1081      * @tc.steps:step3. Put invalid batch data.
1082      * @tc.expected: step3. Returns INVALID_ARGS.
1083      */
1084     vector<Entry> entrys2;
1085     vector<Key> keys2;
1086     DistributedDBUnitTest::GenerateRecords(BATCH_PRESET_SIZE_TEST, entrys2, keys2);
1087     EXPECT_EQ(entrys2.size(), 10UL);
1088 
1089     vector<Entry> entrysInvalid;
1090     vector<Key> keysInvalid;
1091     DistributedDBUnitTest::GenerateRecords(BATCH_PRESET_SIZE_TEST, entrysInvalid, keysInvalid,
1092         DBConstant::MAX_KEY_SIZE + 10);
1093     EXPECT_EQ(entrysInvalid.size(), 10UL);
1094     entrys2[0].key = entrysInvalid[0].key;
1095 
1096     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrys2), INVALID_ARGS);
1097     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
1098     EXPECT_TRUE(observer->GetEntriesInserted().empty());
1099     /**
1100      * @tc.steps:step4. Put MAX valid value batch data.
1101      * @tc.expected: step4. Returns OK.
1102      */
1103     vector<Entry> entrys3;
1104     vector<Key> keys3;
1105 
1106     DistributedDBUnitTest::GenerateRecords(DBConstant::MAX_BATCH_SIZE, entrys3, keys3);
1107     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrys3), OK);
1108     LOGD("sleep begin");
1109     // sleep 20 seconds
1110     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME * 10));
1111     LOGD("sleep end");
1112     EXPECT_TRUE(DistributedDBToolsUnitTest::CheckObserverResult(entrys3, observer->GetEntriesInserted()));
1113     /**
1114      * @tc.steps:step5. UnRegister the observer.
1115      * @tc.expected: step5. Returns OK.
1116      */
1117     EXPECT_EQ(g_kvNbDelegatePtr->UnRegisterObserver(observer), OK);
1118     delete observer;
1119     observer = nullptr;
1120 
1121     /**
1122      * @tc.steps:step6. Close the kv store.
1123      * @tc.expected: step6. Results OK and delete successfully.
1124      */
1125     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
1126     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_SingleVerPutLocalBatchObserver_002"), OK);
1127     g_kvNbDelegatePtr = nullptr;
1128 }
1129 
1130 /**
1131   * @tc.name: SingleVerPutLocalBatchObserver003
1132   * @tc.desc: Test the observer function of PutLocalBatch() update function.
1133   * @tc.type: FUNC
1134   * @tc.require:
1135   * @tc.author: changguicai
1136   */
1137 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerPutLocalBatchObserver003, TestSize.Level1)
1138 {
1139     /**
1140      * @tc.steps:step1. Get the nb delegate.
1141      * @tc.expected: step1. Get results OK and non-null delegate.
1142      */
1143     KvStoreNbDelegate::Option option = {true, false, false};
1144     g_mgr.GetKvStore("distributed_SingleVerPutLocalBatchObserver_003", option, g_kvNbDelegateCallback);
1145     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
1146     EXPECT_TRUE(g_kvDelegateStatus == OK);
1147 
1148     KvStoreObserverUnitTest *observer = new (std::nothrow) KvStoreObserverUnitTest;
1149     ASSERT_TRUE(observer != nullptr);
1150     /**
1151      * @tc.steps:step2. Register the non-null observer for the special key.
1152      * @tc.expected: step2. Register results OK.
1153      */
1154     Key key;
1155     EXPECT_EQ(g_kvNbDelegatePtr->RegisterObserver(key, OBSERVER_CHANGES_LOCAL_ONLY, observer), OK);
1156     /**
1157      * @tc.steps:step3. Put batch data.
1158      * @tc.expected: step3. Returns OK.
1159      */
1160     vector<Entry> entrysAdd;
1161     vector<Key> keysAdd;
1162     DistributedDBUnitTest::GenerateRecords(BATCH_PRESET_SIZE_TEST, entrysAdd, keysAdd);
1163 
1164     EXPECT_EQ(entrysAdd.size(), 10UL);
1165     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysAdd), OK);
1166     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
1167     EXPECT_TRUE(DistributedDBToolsUnitTest::CheckObserverResult(entrysAdd, observer->GetEntriesInserted()));
1168     /**
1169      * @tc.steps:step4. Update the batch data.
1170      * @tc.expected: step4. Returns OK.
1171      */
1172     vector<Entry> entrysUpdate;
1173     vector<Key> keysUpdate;
1174     DistributedDBUnitTest::GenerateRecords(BATCH_PRESET_SIZE_TEST, entrysUpdate, keysUpdate, DEFAULT_KEY_VALUE_SIZE,
1175         DEFAULT_KEY_VALUE_SIZE + 10);
1176 
1177     EXPECT_EQ(entrysUpdate.size(), 10UL);
1178     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrysUpdate), OK);
1179     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
1180     EXPECT_TRUE(DistributedDBToolsUnitTest::CheckObserverResult(entrysUpdate, observer->GetEntriesUpdated()));
1181     /**
1182      * @tc.steps:step5. UnRegister the observer.
1183      * @tc.expected: step5. Returns OK.
1184      */
1185     EXPECT_EQ(g_kvNbDelegatePtr->UnRegisterObserver(observer), OK);
1186     delete observer;
1187     observer = nullptr;
1188 
1189     /**
1190      * @tc.steps:step6. Close the kv store.
1191      * @tc.expected: step6. Results OK and delete successfully.
1192      */
1193     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
1194     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_SingleVerPutLocalBatchObserver_003"), OK);
1195     g_kvNbDelegatePtr = nullptr;
1196 }
1197 
1198 /**
1199   * @tc.name: SingleVerPutLocalBatchObserver004
1200   * @tc.desc: Test the observer function of PutLocalBatch(), same keys handle.
1201   * @tc.type: FUNC
1202   * @tc.require:
1203   * @tc.author: changguicai
1204   */
1205 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerPutLocalBatchObserver004, TestSize.Level1)
1206 {
1207     /**
1208      * @tc.steps:step1. Get the nb delegate.
1209      * @tc.expected: step1. Get results OK and non-null delegate.
1210      */
1211     KvStoreNbDelegate::Option option = {true, false, false};
1212     g_mgr.GetKvStore("distributed_SingleVerPutLocalBatchObserver_004", option, g_kvNbDelegateCallback);
1213     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
1214     EXPECT_TRUE(g_kvDelegateStatus == OK);
1215 
1216     KvStoreObserverUnitTest *observer = new (std::nothrow) KvStoreObserverUnitTest;
1217     ASSERT_TRUE(observer != nullptr);
1218     /**
1219      * @tc.steps:step2. Register the non-null observer for the special key.
1220      * @tc.expected: step2. Register results OK.
1221      */
1222     Key key;
1223     EXPECT_EQ(g_kvNbDelegatePtr->RegisterObserver(key, OBSERVER_CHANGES_LOCAL_ONLY, observer), OK);
1224     /**
1225      * @tc.steps:step3. Put batch data.
1226      * @tc.expected: step3. Returns OK.
1227      */
1228     vector<Entry> entrys1;
1229     vector<Key> keys1;
1230     DistributedDBUnitTest::GenerateRecords(BATCH_PRESET_SIZE_TEST, entrys1, keys1);
1231     vector<Entry> entrys2;
1232     vector<Key> keys2;
1233     DistributedDBUnitTest::GenerateRecords(BATCH_PRESET_SIZE_TEST, entrys2, keys2, DEFAULT_KEY_VALUE_SIZE,
1234         DEFAULT_KEY_VALUE_SIZE + 10);
1235     entrys1.insert(entrys1.end(), entrys2.begin(), entrys2.end());
1236 
1237     EXPECT_EQ(entrys1.size(), 20UL);
1238     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrys1), OK);
1239     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
1240     EXPECT_TRUE(DistributedDBToolsUnitTest::CheckObserverResult(entrys2, observer->GetEntriesInserted()));
1241     EXPECT_EQ(observer->GetEntriesUpdated().size(), 0UL);
1242 
1243     vector<Entry> entrys3;
1244     vector<Key> keys3;
1245     DistributedDBUnitTest::GenerateRecords(BATCH_PRESET_SIZE_TEST, entrys3, keys3, DEFAULT_KEY_VALUE_SIZE,
1246         DEFAULT_KEY_VALUE_SIZE + 20);
1247     vector<Entry> entrys4;
1248     vector<Key> keys4;
1249     DistributedDBUnitTest::GenerateRecords(BATCH_PRESET_SIZE_TEST, entrys4, keys4, DEFAULT_KEY_VALUE_SIZE,
1250         DEFAULT_KEY_VALUE_SIZE + 30);
1251     entrys3.insert(entrys3.end(), entrys4.begin(), entrys4.end());
1252     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entrys3), OK);
1253     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
1254     EXPECT_TRUE(DistributedDBToolsUnitTest::CheckObserverResult(entrys4, observer->GetEntriesUpdated()));
1255     EXPECT_EQ(observer->GetEntriesInserted().size(), 0UL);
1256 
1257     /**
1258      * @tc.steps:step4. UnRegister the observer.
1259      * @tc.expected: step4. Returns OK.
1260      */
1261     EXPECT_EQ(g_kvNbDelegatePtr->UnRegisterObserver(observer), OK);
1262     delete observer;
1263     observer = nullptr;
1264 
1265     /**
1266      * @tc.steps:step5. Close the kv store.
1267      * @tc.expected: step5. Results OK and delete successfully.
1268      */
1269     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
1270     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_SingleVerPutLocalBatchObserver_004"), OK);
1271     g_kvNbDelegatePtr = nullptr;
1272 }
1273 
1274 /**
1275   * @tc.name: SingleVerDeleteLocalBatchObserver001
1276   * @tc.desc: Test the observer function of DeleteLocalBatch() interface.
1277   * @tc.type: FUNC
1278   * @tc.require:
1279   * @tc.author: changguicai
1280   */
1281 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, SingleVerDeleteLocalBatchObserver001, TestSize.Level1)
1282 {
1283     /**
1284      * @tc.steps:step1. Get the nb delegate.
1285      * @tc.expected: step1. Get results OK and non-null delegate.
1286      */
1287     KvStoreNbDelegate::Option option = {true, false, false};
1288     g_mgr.GetKvStore("distributed_SingleVerDeleteLocalBatchObserver_001", option, g_kvNbDelegateCallback);
1289     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
1290     EXPECT_TRUE(g_kvDelegateStatus == OK);
1291 
1292     KvStoreObserverUnitTest *observer = new (std::nothrow) KvStoreObserverUnitTest;
1293     ASSERT_TRUE(observer != nullptr);
1294     /**
1295      * @tc.steps:step2. Register the non-null observer for the special key.
1296      * @tc.expected: step2. Register results OK.
1297      */
1298     Key key;
1299     EXPECT_EQ(g_kvNbDelegatePtr->RegisterObserver(key, OBSERVER_CHANGES_LOCAL_ONLY, observer), OK);
1300     /**
1301      * @tc.steps:step3. Put batch data.
1302      * @tc.expected: step3. Returns OK.
1303      */
1304     vector<Entry> entries;
1305     vector<Key> keys;
1306     DistributedDBUnitTest::GenerateRecords(BATCH_PRESET_SIZE_TEST, entries, keys);
1307     EXPECT_EQ(entries.size(), 10UL);
1308 
1309     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entries), OK);
1310     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
1311     EXPECT_TRUE(DistributedDBToolsUnitTest::CheckObserverResult(entries, observer->GetEntriesInserted()));
1312     /**
1313      * @tc.steps:step4. Delete the batch data.
1314      * @tc.expected: step4. Returns OK.
1315      */
1316     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keys), OK);
1317     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
1318     EXPECT_TRUE(DistributedDBToolsUnitTest::CheckObserverResult(entries, observer->GetEntriesDeleted()));
1319     /**
1320      * @tc.steps:step5. UnRegister the observer.
1321      * @tc.expected: step5. Returns OK.
1322      */
1323     EXPECT_EQ(g_kvNbDelegatePtr->UnRegisterObserver(observer), OK);
1324     delete observer;
1325     observer = nullptr;
1326 
1327     /**
1328      * @tc.steps:step6. Close the kv store.
1329      * @tc.expected: step6. Results OK and delete successfully.
1330      */
1331     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
1332     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_SingleVerDeleteLocalBatchObserver_001"), OK);
1333     g_kvNbDelegatePtr = nullptr;
1334 }
1335 #ifndef OMIT_JSON
1336 /**
1337   * @tc.name: LocalDataBatchNotCheckSchema001
1338   * @tc.desc: Local data does not check schema.
1339   * @tc.type: FUNC
1340   * @tc.require:
1341   * @tc.author: changguicai
1342   */
1343 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, LocalDataBatchNotCheckSchema001, TestSize.Level1)
1344 {
1345     g_mgr.GetKvStore("distributed_LocalDataBatchNotCheckSchema_001", g_strictOpt, g_kvNbDelegateCallback);
1346     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
1347     EXPECT_TRUE(g_kvDelegateStatus == OK);
1348 
1349     /**
1350      * @tc.steps:step1. Put one data whose value has more fields than the schema.
1351      * @tc.expected: step1. Return OK, because PutLocal does not verify the validity of the schema.
1352      */
1353     Key key;
1354     DistributedDBToolsUnitTest::GetRandomKeyValue(key);
1355     std::string moreData = "{\"field_name1\":true,\"field_name2\":10,\"field_name3\":10}";
1356     Value value(moreData.begin(), moreData.end());
1357     EXPECT_EQ(g_kvNbDelegatePtr->PutLocal(key, value), OK);
1358     Value getValue;
1359     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(key, getValue), OK);
1360     EXPECT_TRUE(DistributedDBToolsUnitTest::IsValueEqual(getValue, value));
1361 
1362     /**
1363      * @tc.steps:step2. Delete local data
1364      * @tc.expected: step2. DeleteLocal return OK, GetLocal return NOT_FOUND
1365      */
1366     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocal(key), OK);
1367     getValue.clear();
1368     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(key, getValue), NOT_FOUND);
1369 
1370     /**
1371      * @tc.steps:step3. PutLocalBatch local data whose value is mismatch with the schema.
1372      * @tc.expected: step3. return OK.
1373      */
1374     key.clear();
1375     DistributedDBToolsUnitTest::GetRandomKeyValue(key);
1376     std::string invalidData = "{\"field_name1\":true, \"field_name2\":null}";
1377     value.assign(invalidData.begin(), invalidData.end());
1378     std::vector<Key> keys;
1379     std::vector<Entry> entries;
1380     entries.push_back({key, value});
1381     keys.push_back(key);
1382 
1383     DistributedDBToolsUnitTest::GetRandomKeyValue(key);
1384     std::string validData = "{\"field_name1\":true, \"field_name2\":0}";
1385     value.assign(validData.begin(), validData.end());
1386     entries.push_back({key, value});
1387     keys.push_back(key);
1388 
1389     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entries), OK);
1390     std::vector<Entry> getEntries;
1391     Key keyPrefix;
1392     EXPECT_EQ(g_kvNbDelegatePtr->GetLocalEntries(keyPrefix, getEntries), OK);
1393     EXPECT_TRUE(DistributedDBToolsUnitTest::IsEntriesEqual(entries, getEntries, true));
1394 
1395     /**
1396      * @tc.steps:step4. Delete local data
1397      * @tc.expected: step4. DeleteLocal return OK, GetLocal return NOT_FOUND
1398      */
1399     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keys), OK);
1400     getEntries.clear();
1401     EXPECT_EQ(g_kvNbDelegatePtr->GetLocalEntries(keyPrefix, getEntries), NOT_FOUND);
1402     EXPECT_TRUE(getEntries.empty());
1403 
1404     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
1405     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_LocalDataBatchNotCheckSchema_001"), OK);
1406     g_kvNbDelegatePtr = nullptr;
1407 }
1408 
1409 /**
1410   * @tc.name: LocalDataBatchNotCheckReadOnly001
1411   * @tc.desc: Local data does not check readOnly.
1412   * @tc.type: FUNC
1413   * @tc.require:
1414   * @tc.author: changguicai
1415   */
1416 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, LocalDataBatchNotCheckReadOnly001, TestSize.Level1)
1417 {
1418     /**
1419      * @tc.steps:step1. Open the kv store with valid schema, and close it.
1420      * @tc.expected: step1. opened & closeed successfully - return OK.
1421      */
1422     g_mgr.GetKvStore("distributed_LocalDataBatchNotCheckReadOnly_001", g_strictOpt, g_kvNbDelegateCallback);
1423     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
1424     EXPECT_TRUE(g_kvDelegateStatus == OK);
1425     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
1426 
1427     /**
1428      * @tc.steps:step2. Open the kv store with no schema.
1429      * @tc.expected: step2. return OK.
1430      */
1431     DistributedDB::KvStoreNbDelegate::Option option = g_strictOpt;
1432     option.schema.clear();
1433     g_mgr.GetKvStore("distributed_LocalDataBatchNotCheckReadOnly_001", option, g_kvNbDelegateCallback);
1434     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
1435     EXPECT_TRUE(g_kvDelegateStatus == OK);
1436 
1437     /**
1438      * @tc.steps:step3. CRUD single local the data.
1439      * @tc.expected: step3. return OK.
1440      */
1441     Key key;
1442     DistributedDBToolsUnitTest::GetRandomKeyValue(key);
1443     std::string valueData = "{\"field_name1\":true,\"field_name2\":20}";
1444     Value value(valueData.begin(), valueData.end());
1445     EXPECT_EQ(g_kvNbDelegatePtr->PutLocal(key, value), OK);
1446 
1447     Value getValue;
1448     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(key, getValue), OK);
1449     EXPECT_TRUE(DistributedDBToolsUnitTest::IsValueEqual(getValue, value));
1450 
1451     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocal(key), OK);
1452     getValue.clear();
1453     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(key, getValue), NOT_FOUND);
1454 
1455     /**
1456      * @tc.steps:step3. CRUD batch local the data.
1457      * @tc.expected: step3. return OK.
1458      */
1459     key.clear();
1460     DistributedDBToolsUnitTest::GetRandomKeyValue(key);
1461     std::string invalidData = "{\"field_name1\":true, \"field_name2\":null}";
1462     value.assign(invalidData.begin(), invalidData.end());
1463     std::vector<Key> keys;
1464     std::vector<Entry> entries;
1465     entries.push_back({key, value});
1466     keys.push_back(key);
1467 
1468     DistributedDBToolsUnitTest::GetRandomKeyValue(key);
1469     std::string validData = "{\"field_name1\":true, \"field_name2\":0}";
1470     value.assign(validData.begin(), validData.end());
1471     entries.push_back({key, value});
1472     keys.push_back(key);
1473 
1474     EXPECT_EQ(g_kvNbDelegatePtr->PutLocalBatch(entries), OK);
1475     std::vector<Entry> getEntries;
1476     Key keyPrefix;
1477     EXPECT_EQ(g_kvNbDelegatePtr->GetLocalEntries(keyPrefix, getEntries), OK);
1478     EXPECT_TRUE(DistributedDBToolsUnitTest::IsEntriesEqual(entries, getEntries, true));
1479 
1480     EXPECT_EQ(g_kvNbDelegatePtr->DeleteLocalBatch(keys), OK);
1481     getEntries.clear();
1482     EXPECT_EQ(g_kvNbDelegatePtr->GetLocalEntries(keyPrefix, getEntries), NOT_FOUND);
1483     EXPECT_TRUE(getEntries.empty());
1484 
1485     /**
1486      * @tc.steps:step4. Close the kv store.
1487      * @tc.expected: step4. Results OK and delete successfully.
1488      */
1489     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
1490     EXPECT_EQ(g_mgr.DeleteKvStore("distributed_LocalDataBatchNotCheckReadOnly_001"), OK);
1491     g_kvNbDelegatePtr = nullptr;
1492 }
1493 #endif
1494 
1495 /**
1496  * @tc.name: RemoveDeviceDataEx001
1497  * @tc.desc: Test the remove device data without communicator.
1498  * @tc.type: FUNC
1499  * @tc.require:
1500  * @tc.author: zhangqiquan
1501  */
1502 HWTEST_F(DistributedDBInterfacesNBDelegateLocalBatchTest, RemoveDeviceDataEx001, TestSize.Level0)
1503 {
1504     const KvStoreNbDelegate::Option option = {true, true};
1505     g_mgr.SetKvStoreConfig(g_config);
1506     g_mgr.GetKvStore("RemoveDeviceDataEx001", option, g_kvNbDelegateCallback);
1507     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
1508     EXPECT_TRUE(g_kvDelegateStatus == OK);
1509 
1510     EXPECT_EQ(g_kvNbDelegatePtr->RemoveDeviceData("device"), OK);
1511     EXPECT_EQ(g_kvNbDelegatePtr->RemoveDeviceData(), OK);
1512 
1513     EXPECT_EQ(g_mgr.CloseKvStore(g_kvNbDelegatePtr), OK);
1514     g_kvNbDelegatePtr = nullptr;
1515 }
1516