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 "distributeddb_tools_unit_test.h"
20 #include "log_print.h"
21 
22 using namespace testing::ext;
23 using namespace DistributedDB;
24 using namespace DistributedDBUnitTest;
25 using namespace std;
26 
27 namespace {
28     // define some variables to init a KvStoreDelegateManager object.
29     KvStoreDelegateManager g_mgr("app0", "user0");
30     string g_testDir;
31     KvStoreConfig g_config;
32     KvStoreObserverUnitTest *g_syncObserver = nullptr;
33     KvStoreObserverUnitTest *g_localObserver = nullptr;
34     Entry g_entry1;
35     Entry g_entry2;
36 
37     // define the g_kvNbDelegateCallback, used to get some information when open a kv store.
38     DBStatus g_kvDelegateStatus = INVALID_ARGS;
39     KvStoreNbDelegate *g_kvNbDelegatePtr = nullptr;
40 
41     const int OBSERVER_SLEEP_TIME = 100;
42 
KvStoreNbDelegateCallback(DBStatus statusSrc,KvStoreNbDelegate * kvStoreSrc,DBStatus & statusDst,KvStoreNbDelegate * & kvStoreDst)43     void KvStoreNbDelegateCallback(
44         DBStatus statusSrc, KvStoreNbDelegate *kvStoreSrc, DBStatus &statusDst, KvStoreNbDelegate *&kvStoreDst)
45     {
46         statusDst = statusSrc;
47         kvStoreDst = kvStoreSrc;
48     }
49 
50     // the type of g_kvNbDelegateCallback is function<void(DBStatus, KvStoreDelegate*)>
51     auto g_kvNbDelegateCallback = bind(&KvStoreNbDelegateCallback, placeholders::_1,
52         placeholders::_2, std::ref(g_kvDelegateStatus), std::ref(g_kvNbDelegatePtr));
53 
CheckUnpublishNotFound()54     static void CheckUnpublishNotFound()
55     {
56         Value valueRead;
57         EXPECT_EQ(g_kvNbDelegatePtr->Get(g_entry1.key, valueRead), NOT_FOUND);
58         EXPECT_EQ(g_kvNbDelegatePtr->Get(g_entry2.key, valueRead), OK);
59         EXPECT_EQ(g_entry2.value, valueRead);
60         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry1.key, valueRead), OK);
61         EXPECT_EQ(g_entry1.value, valueRead);
62         EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry2.key, valueRead), NOT_FOUND);
63     }
64 
RegisterObservers()65     static void RegisterObservers()
66     {
67         g_localObserver = new (std::nothrow) KvStoreObserverUnitTest;
68         ASSERT_TRUE(g_localObserver != nullptr);
69         g_syncObserver = new (std::nothrow) KvStoreObserverUnitTest;
70         ASSERT_TRUE(g_syncObserver != nullptr);
71         Key key;
72         EXPECT_EQ(g_kvNbDelegatePtr->RegisterObserver(key, 3, g_syncObserver), OK); // sync data observer.
73         EXPECT_EQ(g_kvNbDelegatePtr->RegisterObserver(key, 4, g_localObserver), OK); // local data observer.
74     }
75 }
76 
77 class DistributedDBInterfacesNBUnpublishTest : public testing::Test {
78 public:
79     static void SetUpTestCase(void);
80     static void TearDownTestCase(void);
81     void SetUp();
82     void TearDown();
83 };
84 
SetUpTestCase(void)85 void DistributedDBInterfacesNBUnpublishTest::SetUpTestCase(void)
86 {
87     DistributedDBToolsUnitTest::TestDirInit(g_testDir);
88     g_config.dataDir = g_testDir;
89     g_mgr.SetKvStoreConfig(g_config);
90 }
91 
TearDownTestCase(void)92 void DistributedDBInterfacesNBUnpublishTest::TearDownTestCase(void)
93 {
94     if (DistributedDBToolsUnitTest::RemoveTestDbFiles(g_testDir) != 0) {
95         LOGE("rm test db files error!");
96     }
97 }
98 
SetUp(void)99 void DistributedDBInterfacesNBUnpublishTest::SetUp(void)
100 {
101     DistributedDBToolsUnitTest::PrintTestCaseInfo();
102     KvStoreNbDelegate::Option option = {true, false, false};
103     g_mgr.GetKvStore("unpublish_test", option, g_kvNbDelegateCallback);
104     ASSERT_TRUE(g_kvNbDelegatePtr != nullptr);
105     EXPECT_TRUE(g_kvDelegateStatus == OK);
106     DistributedDBToolsUnitTest::GetRandomKeyValue(g_entry1.key);
107     DistributedDBToolsUnitTest::GetRandomKeyValue(g_entry1.value);
108     DistributedDBToolsUnitTest::GetRandomKeyValue(g_entry2.key);
109     DistributedDBToolsUnitTest::GetRandomKeyValue(g_entry2.value);
110 }
111 
TearDown(void)112 void DistributedDBInterfacesNBUnpublishTest::TearDown(void)
113 {
114     if (g_localObserver != nullptr) {
115         if (g_kvNbDelegatePtr != nullptr) {
116             g_kvNbDelegatePtr->UnRegisterObserver(g_localObserver);
117         }
118         delete g_localObserver;
119         g_localObserver = nullptr;
120     }
121 
122     if (g_syncObserver != nullptr) {
123         if (g_kvNbDelegatePtr != nullptr) {
124             g_kvNbDelegatePtr->UnRegisterObserver(g_syncObserver);
125         }
126         delete g_syncObserver;
127         g_syncObserver = nullptr;
128     }
129     if (g_kvNbDelegatePtr != nullptr) {
130         g_mgr.CloseKvStore(g_kvNbDelegatePtr);
131         g_kvNbDelegatePtr = nullptr;
132     }
133     g_mgr.DeleteKvStore("unpublish_test");
134 }
135 
136 /**
137   * @tc.name: CombineTest001
138   * @tc.desc: Test unpublish one nonexistent data.
139   * @tc.type: FUNC
140   * @tc.require: AR000DPTQ5
141   * @tc.author: wangbingquan
142   */
143 HWTEST_F(DistributedDBInterfacesNBUnpublishTest, SingleVerUnPublishKey001, TestSize.Level1)
144 {
145     /**
146      * @tc.steps:step1. Put [k1, v1] into the local zone, [k2, v2] into the sync zone.
147      * @tc.expected: step1. Get results OK.
148      */
149     EXPECT_EQ(g_kvNbDelegatePtr->PutLocal(g_entry1.key, g_entry1.value), OK);
150     EXPECT_EQ(g_kvNbDelegatePtr->Put(g_entry2.key, g_entry2.value), OK);
151 
152     /**
153      * @tc.steps:step2. Unpublish the k1 with para of deletePublic: true, updateTimestamp: true.
154      * @tc.expected: step2. Unpublish returns NOT_FOUND.
155      */
156     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry1.key, true, true), NOT_FOUND);
157 
158     /**
159      * @tc.steps:step3. Check the data in the local and sync zone.
160      * @tc.expected: step3. Both the data are not changed.
161      */
162     CheckUnpublishNotFound();
163 
164     /**
165      * @tc.steps:step4. Unpublish the k1 with para of deletePublic: true, updateTimestamp: false.
166      * @tc.expected: step4. Unpublish returns NOT_FOUND.
167      */
168     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry1.key, true, false), NOT_FOUND);
169 
170     /**
171      * @tc.steps:step5. Check the data in the local and sync zone.
172      * @tc.expected: step5. Both the data are not changed.
173      */
174     CheckUnpublishNotFound();
175 
176     /**
177      * @tc.steps:step6. Unpublish the k1 with para of deletePublic: false, updateTimestamp: true.
178      * @tc.expected: step6. Unpublish returns NOT_FOUND.
179      */
180     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry1.key, false, true), NOT_FOUND);
181 
182     /**
183      * @tc.steps:step7. Check the data in the local and sync zone.
184      * @tc.expected: step7. Both the data are not changed.
185      */
186     CheckUnpublishNotFound();
187 
188     /**
189      * @tc.steps:step8. Unpublish the k1 with para of deletePublic: false, updateTimestamp: false.
190      * @tc.expected: step8. Unpublish returns NOT_FOUND.
191      */
192     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry1.key, false, false), NOT_FOUND);
193 
194     /**
195      * @tc.steps:step9. Check the data in the local and sync zone.
196      * @tc.expected: step9. Both the data are not changed.
197      */
198     CheckUnpublishNotFound();
199 }
200 
201 /**
202   * @tc.name: SingleVerUnPublishKey002
203   * @tc.desc: Test unpublish existent data(no conflict with the local data).
204   * @tc.type: FUNC
205   * @tc.require: AR000DPTQ5
206   * @tc.author: wangbingquan
207   */
208 HWTEST_F(DistributedDBInterfacesNBUnpublishTest, SingleVerUnPublishKey002, TestSize.Level1)
209 {
210     /**
211      * @tc.steps:step1. Put [k1, v1], [k2, v2] into the sync zone.
212      * @tc.expected: step1. Put returns OK.
213      */
214     EXPECT_EQ(g_kvNbDelegatePtr->Put(g_entry1.key, g_entry1.value), OK);
215     EXPECT_EQ(g_kvNbDelegatePtr->Put(g_entry2.key, g_entry2.value), OK);
216 
217     /**
218      * @tc.steps:step2. Register the obsevers for the sync data and the local data.
219      */
220     RegisterObservers();
221 
222     /**
223      * @tc.steps:step3. Unpublish the k1 with para of deletePublic: false, updateTimestamp: false.
224      * @tc.expected: step3. Unpublish returns OK.
225      */
226     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry1.key, false, false), OK);
227 
228     /**
229      * @tc.steps:step4. Get the value of k1 from the local zone.
230      * @tc.expected: step4. Get returns OK, and the value is v1.
231      */
232     Value valueRead;
233     EXPECT_EQ(g_kvNbDelegatePtr->Get(g_entry1.key, valueRead), OK);
234     EXPECT_EQ(g_entry1.value, valueRead);
235     EXPECT_EQ(g_kvNbDelegatePtr->Get(g_entry2.key, valueRead), OK);
236     EXPECT_EQ(g_entry2.value, valueRead);
237     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry1.key, valueRead), OK);
238     EXPECT_EQ(g_entry1.value, valueRead);
239     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry2.key, valueRead), NOT_FOUND);
240 
241     /**
242      * @tc.steps:step5. Check the observer.
243      * @tc.expected: step5. local observer received one inserted data.
244      */
245     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
246     EXPECT_EQ(g_syncObserver->GetCallCount(), 0UL);
247     EXPECT_EQ(g_localObserver->GetCallCount(), 1UL);
248     EXPECT_EQ(g_localObserver->GetEntriesInserted().size(), 1UL);
249 
250     g_localObserver->ResetToZero();
251     g_syncObserver->ResetToZero();
252 
253     /**
254      * @tc.steps:step6. Unpublish the k2 with para of deletePublic: true, updateTimestamp: false.
255      * @tc.expected: step6. Unpublish returns OK.
256      */
257     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry2.key, true, false), OK);
258 
259     /**
260      * @tc.steps:step7. Get the value of k2 from the local zone and the sync zone.
261      * @tc.expected: step7. GetLocal returns OK, and the value is equal to v2. Get returns NOT_FOUND.
262      */
263     EXPECT_EQ(g_kvNbDelegatePtr->Get(g_entry2.key, valueRead), NOT_FOUND);
264     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry2.key, valueRead), OK);
265     EXPECT_EQ(g_entry2.value, valueRead);
266 
267     /**
268      * @tc.steps:step8. Check the observer.
269      * @tc.expected: step8. Sync observer received 1 delete data, and the local observer received one inserted data.
270      */
271     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
272     EXPECT_EQ(g_syncObserver->GetCallCount(), 1UL);
273     EXPECT_EQ(g_localObserver->GetCallCount(), 1UL);
274     EXPECT_EQ(g_localObserver->GetEntriesInserted().size(), 1UL);
275     EXPECT_EQ(g_syncObserver->GetEntriesDeleted().size(), 1UL);
276 }
277 
278 /**
279   * @tc.name: SingleVerUnPublishKey003
280   * @tc.desc: Test unpublish one existent data(conflict with the local data).
281   * @tc.type: FUNC
282   * @tc.require: AR000DPTQ5
283   * @tc.author: wangbingquan
284   */
285 HWTEST_F(DistributedDBInterfacesNBUnpublishTest, SingleVerUnPublishKey003, TestSize.Level1)
286 {
287     Value value3;
288     Value value4;
289     DistributedDBToolsUnitTest::GetRandomKeyValue(value3);
290     DistributedDBToolsUnitTest::GetRandomKeyValue(value4);
291 
292     /**
293      * @tc.steps:step1. Put [k1, v1] into the sync zone, [k1, v3][k2, v2] into the local zone,
294      *     and put the [k2, v4] into the sync zone.
295      * @tc.expected: step1. Put returns OK.
296      */
297     EXPECT_EQ(g_kvNbDelegatePtr->Put(g_entry1.key, g_entry1.value), OK);
298     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
299     EXPECT_EQ(g_kvNbDelegatePtr->PutLocal(g_entry1.key, value3), OK);
300     EXPECT_EQ(g_kvNbDelegatePtr->PutLocal(g_entry2.key, g_entry2.value), OK);
301     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
302     EXPECT_EQ(g_kvNbDelegatePtr->Put(g_entry2.key, value4), OK);
303 
304     /**
305      * @tc.steps:step2. Register the obsevers for the sync data and the local data.
306      */
307     RegisterObservers();
308 
309     /**
310      * @tc.steps:step3. Unpublish the k2 with para of deletePublic: false, updateTimestamp: false.
311      * @tc.expected: step3. Unpublish returns LOCAL_DEFEAT.
312      */
313     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry1.key, false, false), LOCAL_DEFEAT);
314     Value valueRead;
315 
316     /**
317      * @tc.steps:step4. Check the data of k1 in the local zone and the observer changes.
318      * @tc.expected: step4. Value of k1 is v3, and the observer has no change.
319      */
320     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry1.key, valueRead), OK);
321     EXPECT_EQ(valueRead, value3);
322     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
323     EXPECT_EQ(g_localObserver->GetCallCount(), 0UL);
324 
325     /**
326      * @tc.steps:step5. Unpublish the k1 with para of deletePublic: false, updateTimestamp: true.
327      * @tc.expected: step5. Unpublish returns LOCAL_COVERED.
328      */
329     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry1.key, false, true), LOCAL_COVERED);
330 
331     /**
332      * @tc.steps:step6. Check the data of k1 in the local zone and the observer changes.
333      * @tc.expected: step6. Value of k1 is v1, and the observer received one updated data.
334      */
335     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry1.key, valueRead), OK);
336     EXPECT_EQ(valueRead, g_entry1.value);
337     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
338     EXPECT_EQ(g_localObserver->GetCallCount(), 1UL);
339     EXPECT_EQ(g_localObserver->GetEntriesUpdated().size(), 1UL);
340     g_localObserver->ResetToZero();
341 
342     /**
343      * @tc.steps:step7. Unpublish the k2 with para of deletePublic: false, updateTimestamp: false.
344      * @tc.expected: step7. Unpublish returns LOCAL_COVERED.
345      */
346     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry2.key, false, false), LOCAL_COVERED);
347 
348     /**
349      * @tc.steps:step8. Check the data of k2 in the local zone and the observer changes.
350      * @tc.expected: step8. Value of k2 is v2, and the observer received one updated data.
351      */
352     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry2.key, valueRead), OK);
353     EXPECT_EQ(valueRead, value4);
354     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
355     EXPECT_EQ(g_localObserver->GetCallCount(), 1UL);
356     EXPECT_EQ(g_localObserver->GetEntriesUpdated().size(), 1UL);
357 }
358 
359 /**
360   * @tc.name: SingleVerUnPublishKey004
361   * @tc.desc: Test unpublish one deleted data(no conflict with the local data).
362   * @tc.type: FUNC
363   * @tc.require: AR000DPTQ5
364   * @tc.author: wangbingquan
365   */
366 HWTEST_F(DistributedDBInterfacesNBUnpublishTest, SingleVerUnPublishKey004, TestSize.Level1)
367 {
368     /**
369      * @tc.steps:step1. Put [k1, v1] into the sync zone, [k2, v2] into the local zone, delete k1 from sync zone.
370      * @tc.expected: step1. Put returns OK.
371      */
372     EXPECT_EQ(g_kvNbDelegatePtr->Put(g_entry1.key, g_entry1.value), OK);
373     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
374     EXPECT_EQ(g_kvNbDelegatePtr->PutLocal(g_entry2.key, g_entry2.value), OK);
375     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
376     EXPECT_EQ(g_kvNbDelegatePtr->Delete(g_entry1.key), OK);
377     RegisterObservers();
378 
379     /**
380      * @tc.steps:step2. Unpublish the k1 with para of deletePublic: false, updateTimestamp: false.
381      * @tc.expected: step2. Unpublish returns OK.
382      */
383     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry1.key, false, false), OK);
384 
385     /**
386      * @tc.steps:step3. Check the observer and the data change.
387      * @tc.expected: step3. Observer have no changes.
388      */
389     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
390     EXPECT_EQ(g_localObserver->GetCallCount(), 0UL);
391     EXPECT_EQ(g_syncObserver->GetCallCount(), 0UL);
392     Value valueRead;
393     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry1.key, valueRead), NOT_FOUND);
394     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry2.key, valueRead), OK);
395     EXPECT_EQ(valueRead, g_entry2.value);
396 }
397 
398 /**
399   * @tc.name: SingleVerUnPublishKey005
400   * @tc.desc: Test unpublish one existent data(conflict with the local data).
401   * @tc.type: FUNC
402   * @tc.require: AR000DPTQ5
403   * @tc.author: wangbingquan
404   */
405 HWTEST_F(DistributedDBInterfacesNBUnpublishTest, SingleVerUnPublishKey005, TestSize.Level1)
406 {
407     Value value3;
408     Value value4;
409     DistributedDBToolsUnitTest::GetRandomKeyValue(value3);
410     DistributedDBToolsUnitTest::GetRandomKeyValue(value4);
411 
412     /**
413      * @tc.steps:step1. Put [k1, v1] [k2, v2]into the sync zone, and delete the k1 from sync zone.
414      */
415     EXPECT_EQ(g_kvNbDelegatePtr->Put(g_entry1.key, g_entry1.value), OK);
416     EXPECT_EQ(g_kvNbDelegatePtr->Put(g_entry2.key, g_entry2.value), OK);
417     EXPECT_EQ(g_kvNbDelegatePtr->Delete(g_entry1.key), OK);
418     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
419 
420     /**
421      * @tc.steps:step2. Put [k1, v3] [k2, v4]into the local zone, and delete the k2 from sync zone.
422      */
423     EXPECT_EQ(g_kvNbDelegatePtr->PutLocal(g_entry1.key, value3), OK);
424     EXPECT_EQ(g_kvNbDelegatePtr->PutLocal(g_entry2.key, value4), OK);
425     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
426     EXPECT_EQ(g_kvNbDelegatePtr->Delete(g_entry2.key), OK);
427 
428     /**
429      * @tc.steps:step2. Register the obsevers for the sync data and the local data.
430      */
431     RegisterObservers();
432 
433     /**
434      * @tc.steps:step3. Unpublish the k1 with para of deletePublic: false, updateTimestamp: false.
435      * @tc.expected: step3. Unpublish returns LOCAL_DEFEAT.
436      */
437     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry1.key, false, false), LOCAL_DEFEAT);
438 
439     /**
440      * @tc.steps:step4. Check the value of k1 in the local zone and the observer changes.
441      * @tc.expected: step4. value of k1 is still v3, and the observer has no changes.
442      */
443     Value valueRead;
444     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry1.key, valueRead), OK);
445     EXPECT_EQ(valueRead, value3);
446     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
447     EXPECT_EQ(g_localObserver->GetCallCount(), 0UL);
448     EXPECT_EQ(g_syncObserver->GetCallCount(), 0UL);
449 
450     /**
451      * @tc.steps:step5. Unpublish the k2 with para of deletePublic: false, updateTimestamp: false.
452      * @tc.expected: step5. Unpublish returns LOCAL_DELETED.
453      */
454     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry2.key, false, false), LOCAL_DELETED);
455 
456     /**
457      * @tc.steps:step6. Check the value of k2 in the local zone and the observer changes.
458      * @tc.expected: step6. value of k2 is not found, and the local observer has one deleted data.
459      */
460     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry2.key, valueRead), NOT_FOUND);
461     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
462     EXPECT_EQ(g_localObserver->GetCallCount(), 1UL);
463     EXPECT_EQ(g_localObserver->GetEntriesDeleted().size(), 1UL);
464     g_localObserver->ResetToZero();
465 
466     /**
467      * @tc.steps:step7. Unpublish the k1 with para of deletePublic: false, updateTimestamp: true.
468      * @tc.expected: step7. Unpublish returns LOCAL_DELETED.
469      */
470     EXPECT_EQ(g_kvNbDelegatePtr->UnpublishToLocal(g_entry1.key, false, true), LOCAL_DELETED);
471 
472     /**
473      * @tc.steps:step8. Check the value of k1 in the local zone and the observer changes.
474      * @tc.expected: step8. value of k1 is not found, and the local observer has one deleted data.
475      */
476     EXPECT_EQ(g_kvNbDelegatePtr->GetLocal(g_entry1.key, valueRead), NOT_FOUND);
477     std::this_thread::sleep_for(std::chrono::milliseconds(OBSERVER_SLEEP_TIME));
478     EXPECT_EQ(g_localObserver->GetCallCount(), 1UL);
479     EXPECT_EQ(g_localObserver->GetEntriesDeleted().size(), 1UL);
480     g_localObserver->ResetToZero();
481 }
482