diff --git a/frameworks/libs/distributeddb/interfaces/include/store_types.h b/frameworks/libs/distributeddb/interfaces/include/store_types.h index 6c48b9303e4605046c501b1a1de701fc6674c7a4..d2ecd82f52678d4f377061df6b3116ad7774c2f2 100644 --- a/frameworks/libs/distributeddb/interfaces/include/store_types.h +++ b/frameworks/libs/distributeddb/interfaces/include/store_types.h @@ -73,8 +73,8 @@ struct KvStoreConfig { enum PragmaCmd { AUTO_SYNC = 1, - SYNC_DEVICES = 2, - RM_DEVICE_DATA = 3, // remove the device data synced from remote by device name + SYNC_DEVICES = 2, // this cmd will be removed in the future, don't use it + RM_DEVICE_DATA = 3, // this cmd will be removed in the future, don't use it PERFORMANCE_ANALYSIS_GET_REPORT, PERFORMANCE_ANALYSIS_OPEN, PERFORMANCE_ANALYSIS_CLOSE, diff --git a/frameworks/libs/distributeddb/syncer/src/isync_state_machine.h b/frameworks/libs/distributeddb/syncer/src/isync_state_machine.h index 137f0351c75831b4e620560e20b151d742b7b2ed..a2dee92ccc1cd9c5a13615137587fc4dee9a0108 100644 --- a/frameworks/libs/distributeddb/syncer/src/isync_state_machine.h +++ b/frameworks/libs/distributeddb/syncer/src/isync_state_machine.h @@ -59,6 +59,12 @@ public: // check if need trigger query auto sync and get query from inMsg virtual bool IsNeedTriggerQueryAutoSync(Message *inMsg, QuerySyncObject &query) = 0; + + // start a timer to ResetWatchDog when get data and send notify ack if need + virtual void StartFeedDogForGetData(uint32_t sessionId) = 0; + + // start a timer to ResetWatchDog when get data + virtual void StopFeedDogForGetData() = 0; }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp b/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp index a8819c57d1a628729bdbe749dd3ee35336ae73aa..f36417c3839dd6bf727c92dd0c1f6c9d1443af71 100644 --- a/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp +++ b/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.cpp @@ -303,7 +303,7 @@ int MultiVerSyncStateMachine::PrepareNextSyncTask() return StartSyncInner(); } -void MultiVerSyncStateMachine::SendSaveDataNotifyPacket(uint32_t sessionId, uint32_t sequenceId, uint32_t inMsgId) +void MultiVerSyncStateMachine::SendNotifyPacket(uint32_t sessionId, uint32_t sequenceId, uint32_t inMsgId) { (void)sessionId; (void)sequenceId; diff --git a/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.h b/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.h index aa4a663111b7f61f18d786616e4792286624e34d..e8583a75b898ec927de7032e2bfc399b69ed43c6 100644 --- a/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.h +++ b/frameworks/libs/distributeddb/syncer/src/multi_ver_sync_state_machine.h @@ -72,7 +72,7 @@ protected: int PrepareNextSyncTask() override; // Called by StartSaveDataNotifyTimer, used to send a save data notify packet - void SendSaveDataNotifyPacket(uint32_t sessionId, uint32_t sequenceId, uint32_t inMsgId) override; + void SendNotifyPacket(uint32_t sessionId, uint32_t sequenceId, uint32_t inMsgId) override; bool IsNeedTriggerQueryAutoSync(Message *inMsg, QuerySyncObject &query) override; diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp index c12967fce165510523e2562159b0dcf6f60a2901..291518d1f412107711b7293b604f5191234c253a 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp @@ -289,7 +289,9 @@ int SingleVerDataSync::GetDataWithPerformanceRecord(SingleVerSyncTaskContext *co if (performance != nullptr) { performance->StepTimeRecordStart(PT_TEST_RECORDS::RECORD_READ_DATA); } + context->StartFeedDogForGetData(context->GetResponseSessionId()); int errCode = GetData(context, syncOutData.entries, packetSize); + context->StopFeedDogForGetData(); if (performance != nullptr) { performance->StepTimeRecordEnd(PT_TEST_RECORDS::RECORD_READ_DATA); } diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp index 641181562909104f940cb83818806205ac2210ed..5b43f4cd0bbf85a14928b0c2bbfb204fc35f6607 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp @@ -282,7 +282,7 @@ int SingleVerSyncStateMachine::PrepareNextSyncTask() return E_OK; } -void SingleVerSyncStateMachine::SendSaveDataNotifyPacket(uint32_t sessionId, uint32_t sequenceId, uint32_t inMsgId) +void SingleVerSyncStateMachine::SendNotifyPacket(uint32_t sessionId, uint32_t sequenceId, uint32_t inMsgId) { dataSync_->SendSaveDataNotifyPacket(context_, std::min(context_->GetRemoteSoftwareVersion(), SOFTWARE_VERSION_CURRENT), sessionId, sequenceId, inMsgId); diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.h b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.h index d7fbb6f7febdcfa0ba572d2123b9aad8f290bce1..18654f9caa4abcbad61d30aa5e656758b03b0843 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.h +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.h @@ -97,7 +97,6 @@ public: uint64_t &outValue); void InnerErrorAbort(uint32_t sessionId) override; - protected: // Step the SingleVerSyncStateMachine void SyncStep() override; @@ -123,7 +122,7 @@ protected: int PrepareNextSyncTask() override; // Called by StartSaveDataNotifyTimer, used to send a save data notify packet - void SendSaveDataNotifyPacket(uint32_t sessionId, uint32_t sequenceId, uint32_t inMsgId) override; + void SendNotifyPacket(uint32_t sessionId, uint32_t sequenceId, uint32_t inMsgId) override; int TimeMarkSyncRecv(const Message *inMsg); diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp index e4daa17e994f2cd620a84475d4830f5d8c1b877e..62426911c715cae4f6d81aae93a6129d097cf9cc 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp @@ -582,4 +582,14 @@ bool SingleVerSyncTaskContext::IsCurrentSyncTaskCanBeSkippedInner(const SyncOper } return false; } + +void SingleVerSyncTaskContext::StartFeedDogForGetData(uint32_t sessionId) +{ + stateMachine_->StartFeedDogForGetData(sessionId); +} + +void SingleVerSyncTaskContext::StopFeedDogForGetData() +{ + stateMachine_->StopFeedDogForGetData(); +} } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.h b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.h index e74b77c7a5b518604a14bc7514b2cd7f97b4d9e9..6528c11a7275618a8742c819b863b01c53f1c0b6 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.h +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_task_context.h @@ -140,6 +140,9 @@ public: virtual std::string GetDeleteSyncId() const = 0; void SetCommNormal(bool isCommNormal); + + void StartFeedDogForGetData(uint32_t sessionId); + void StopFeedDogForGetData(); protected: ~SingleVerSyncTaskContext() override; void CopyTargetData(const ISyncTarget *target, const TaskParam &taskParam) override; diff --git a/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp b/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp index daf71d2eb2b33b1579ff07d60436545a9a9bae40..826b97d0d08d068df108fc2c4f95395660dcc8fe 100644 --- a/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp +++ b/frameworks/libs/distributeddb/syncer/src/sync_state_machine.cpp @@ -30,7 +30,9 @@ SyncStateMachine::SyncStateMachine() watchDogStarted_(false), currentSyncProctolVersion_(SINGLE_VER_SYNC_PROCTOL_V3), saveDataNotifyTimerId_(0), - saveDataNotifyCount_(0) + saveDataNotifyCount_(0), + getDataNotifyTimerId_(0), + getDataNotifyCount_(0) { } @@ -227,7 +229,7 @@ bool SyncStateMachine::StartSaveDataNotify(uint32_t sessionId, uint32_t sequence // Incref to make sure context still alive before timer stopped. RefObject::IncObjRef(syncContext_); int errCode = RuntimeContext::GetInstance()->SetTimer( - SAVE_DATA_NOTIFY_INTERVAL, + DATA_NOTIFY_INTERVAL, [this, sessionId, sequenceId, inMsgId](TimerId timerId) { RefObject::IncObjRef(syncContext_); int ret = RuntimeContext::GetInstance()->ScheduleTask([this, sessionId, sequenceId, inMsgId]() { @@ -273,7 +275,7 @@ bool SyncStateMachine::StartFeedDogForSync(uint32_t time, SyncDirectionFlag flag return false; } - uint8_t cnt = GetFeedDogTimeout(time / SAVE_DATA_NOTIFY_INTERVAL); + uint8_t cnt = GetFeedDogTimeout(time / DATA_NOTIFY_INTERVAL); LOGI("[SyncStateMachine][feedDog] start cnt:%d, flag:%d", cnt, flag); std::lock_guard lockGuard(feedDogLock_[flag]); @@ -295,7 +297,7 @@ bool SyncStateMachine::StartFeedDogForSync(uint32_t time, SyncDirectionFlag flag RefObject::IncObjRef(syncContext_); watchDogController_[flag].feedDogUpperLimit = cnt; int errCode = RuntimeContext::GetInstance()->SetTimer( - SAVE_DATA_NOTIFY_INTERVAL, + DATA_NOTIFY_INTERVAL, [this, flag](TimerId timerId) { RefObject::IncObjRef(syncContext_); int ret = RuntimeContext::GetInstance()->ScheduleTask([this, flag]() { @@ -375,11 +377,11 @@ void SyncStateMachine::DoSaveDataNotify(uint32_t sessionId, uint32_t sequenceId, (void)ResetWatchDog(); } std::lock_guard innerLock(saveDataNotifyLock_); - if (saveDataNotifyCount_ >= MAXT_SAVE_DATA_NOTIFY_COUNT) { + if (saveDataNotifyCount_ >= MAX_DATA_NOTIFY_COUNT) { StopSaveDataNotifyNoLock(); return; } - SendSaveDataNotifyPacket(sessionId, sequenceId, inMsgId); + SendNotifyPacket(sessionId, sequenceId, inMsgId); saveDataNotifyCount_++; } @@ -402,4 +404,80 @@ void SyncStateMachine::InnerErrorAbort(uint32_t sessionId) // do nothing (void) sessionId; } + +void SyncStateMachine::StartFeedDogForGetData(uint32_t sessionId) +{ + std::lock_guard lockGuard(getDataNotifyLock_); + if (getDataNotifyTimerId_ > 0) { + getDataNotifyCount_ = 0; + LOGW("[SyncStateMachine][StartFeedDogForGetData] timer has been started!"); + } + + // Incref to make sure context still alive before timer stopped. + RefObject::IncObjRef(syncContext_); + int errCode = RuntimeContext::GetInstance()->SetTimer( + DATA_NOTIFY_INTERVAL, + [this, sessionId](TimerId timerId) { + RefObject::IncObjRef(syncContext_); + int ret = RuntimeContext::GetInstance()->ScheduleTask([this, sessionId, timerId]() { + DoGetAndSendDataNotify(sessionId); + int getDataNotifyCount = 0; + { + std::lock_guard autoLock(getDataNotifyLock_); + getDataNotifyCount = getDataNotifyCount_; + } + if (getDataNotifyCount >= MAX_DATA_NOTIFY_COUNT) { + StopFeedDogForGetDataInner(timerId); + } + RefObject::DecObjRef(syncContext_); + }); + if (ret != E_OK) { + LOGE("[SyncStateMachine] [StartFeedDogForGetData] ScheduleTask failed errCode %d", ret); + RefObject::DecObjRef(syncContext_); + } + return ret; + }, + [this]() { RefObject::DecObjRef(syncContext_); }, + getDataNotifyTimerId_); + if (errCode != E_OK) { + LOGW("[SyncStateMachine][StartFeedDogForGetData] start timer failed err %d !", errCode); + } +} + +void SyncStateMachine::StopFeedDogForGetData() +{ + TimerId timerId = 0; + { + std::lock_guard lockGuard(getDataNotifyLock_); + timerId = getDataNotifyTimerId_; + } + if (timerId == 0) { + return; + } + StopFeedDogForGetDataInner(timerId); +} + +void SyncStateMachine::DoGetAndSendDataNotify(uint32_t sessionId) +{ + (void)ResetWatchDog(); + std::lock_guard autoLock(getDataNotifyLock_); + if (getDataNotifyCount_ >= MAX_DATA_NOTIFY_COUNT) { + return; + } + if (sessionId != 0) { + SendNotifyPacket(sessionId, 0, DATA_SYNC_MESSAGE); + } + getDataNotifyCount_++; +} + +void SyncStateMachine::StopFeedDogForGetDataInner(TimerId timerId) +{ + std::lock_guard lockGuard(getDataNotifyLock_); + if (getDataNotifyTimerId_ == 0 || getDataNotifyTimerId_ != timerId) { + return; + } + RuntimeContext::GetInstance()->RemoveTimer(timerId); + getDataNotifyTimerId_ = 0; + getDataNotifyCount_ = 0; +} } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/syncer/src/sync_state_machine.h b/frameworks/libs/distributeddb/syncer/src/sync_state_machine.h index 0a73b0cc778768a463a9b46d8d9ecd43792bf220..e1f6003bb925c145af4ffa46c3f5195d6485fe34 100644 --- a/frameworks/libs/distributeddb/syncer/src/sync_state_machine.h +++ b/frameworks/libs/distributeddb/syncer/src/sync_state_machine.h @@ -68,6 +68,12 @@ public: // stop timer to ResetWatchDog when sync data one (key,value) size bigger than mtu void StopFeedDogForSync(SyncDirectionFlag flag) override; + + // start a timer to ResetWatchDog when get data and send notify ack if need + void StartFeedDogForGetData(uint32_t sessionId) override; + + // start a timer to ResetWatchDog when get data and stop send notify ack if need + void StopFeedDogForGetData() override; protected: // SyncOperation is timeout, step to timeout state @@ -98,7 +104,7 @@ protected: virtual int PrepareNextSyncTask() = 0; // Called by StartSaveDataNotifyTimer, Sub class should realize this function to send a heartbeet packet - virtual void SendSaveDataNotifyPacket(uint32_t sessionId, uint32_t sequenceId, uint32_t inMsgId) = 0; + virtual void SendNotifyPacket(uint32_t sessionId, uint32_t sequenceId, uint32_t inMsgId) = 0; // Used to parse state table to switch machine state, this function must be called in stateMachineLock int SwitchMachineState(uint8_t event); @@ -136,6 +142,10 @@ protected: void DoFeedDogForSync(SyncDirectionFlag flag); + void DoGetAndSendDataNotify(uint32_t sessionId); + + void StopFeedDogForGetDataInner(TimerId timerId); + DISABLE_COPY_ASSIGN_MOVE(SyncStateMachine); ISyncTaskContext *syncContext_; @@ -148,13 +158,17 @@ protected: uint32_t currentSyncProctolVersion_; // For save data notify - static const int SAVE_DATA_NOTIFY_INTERVAL = 2000; // 2s for save data notify - static const int MAXT_SAVE_DATA_NOTIFY_COUNT = 15; // only notify 15 times + static const int DATA_NOTIFY_INTERVAL = 2000; // 2s for save/get data notify + static const int MAX_DATA_NOTIFY_COUNT = 15; // only notify 15 times static const int SYNC_DIRECTION_NUM = 2; // send receive std::mutex saveDataNotifyLock_; TimerId saveDataNotifyTimerId_; uint8_t saveDataNotifyCount_; + std::mutex getDataNotifyLock_; + TimerId getDataNotifyTimerId_; + uint8_t getDataNotifyCount_; + // used for one (key,value) bigger than mtu size, in this case, send packet need more longger time std::mutex feedDogLock_[SYNC_DIRECTION_NUM]; WatchDogController watchDogController_[SYNC_DIRECTION_NUM] = {{0}, {0}}; diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_check_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_check_test.cpp index 50e356d30acea18a57ebd66394186c724fba5044..44a5353779d26b556dbd3d14af8ff75f0d3ab40b 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_check_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_check_test.cpp @@ -40,6 +40,8 @@ namespace { const int SLEEP_MILLISECONDS = 500; const int TEN_SECONDS = 10; const int THREE_HUNDRED = 300; + const int WAIT_30_SECONDS = 30000; + const int WAIT_40_SECONDS = 40000; KvStoreDelegateManager g_mgr(APP_ID, USER_ID); KvStoreConfig g_config; @@ -1311,4 +1313,63 @@ HWTEST_F(DistributedDBSingleVerP2PSyncCheckTest, QuerySyncMergeCheck004, TestSiz ASSERT_TRUE(status == OK); std::this_thread::sleep_for(std::chrono::seconds(TEN_SECONDS)); EXPECT_EQ(sendRequestCount, 0); +} + +/** + * @tc.name: GetDataNotify001 + * @tc.desc: Test GetDataNotify function, delay < 30s should sync ok, > 36 should timeout + * @tc.type: FUNC + * @tc.require: AR000D4876 + * @tc.author: zhangqiquan + */ +HWTEST_F(DistributedDBSingleVerP2PSyncCheckTest, GetDataNotify001, TestSize.Level3) +{ + ASSERT_NE(g_kvDelegatePtr, nullptr); + DBStatus status = OK; + std::vector devices; + devices.push_back(g_deviceB->GetDeviceId()); + const std::string DEVICE_A = "real_device"; + /** + * @tc.steps: step1. deviceB set get data delay 40s + */ + g_deviceB->DelayGetSyncData(WAIT_40_SECONDS); + + /** + * @tc.steps: step2. deviceA call sync and wait + * @tc.expected: step2. sync should return OK. onComplete should be called, deviceB sync TIME_OUT. + */ + std::map result; + std::map virtualRes; + status = g_tool.SyncTest(g_kvDelegatePtr, devices, SYNC_MODE_PULL_ONLY, result, true); + EXPECT_EQ(status, OK); + EXPECT_EQ(result.size(), devices.size()); + EXPECT_EQ(result[DEVICE_B], TIME_OUT); + std::this_thread::sleep_for(std::chrono::seconds(TEN_SECONDS)); + Query query = Query::Select(); + g_deviceB->Sync(SYNC_MODE_PUSH_ONLY, query, [&virtualRes](std::map resMap) { + virtualRes = std::move(resMap); + }, true); + EXPECT_EQ(virtualRes.size(), devices.size()); + EXPECT_EQ(virtualRes[DEVICE_A], static_cast(SyncOperation::OP_TIMEOUT)); + std::this_thread::sleep_for(std::chrono::seconds(TEN_SECONDS)); + + /** + * @tc.steps: step3. deviceB set get data delay 30s + */ + g_deviceB->DelayGetSyncData(WAIT_30_SECONDS); + /** + * @tc.steps: step4. deviceA call sync and wait + * @tc.expected: step4. sync should return OK. onComplete should be called, deviceB sync OK. + */ + status = g_tool.SyncTest(g_kvDelegatePtr, devices, SYNC_MODE_PULL_ONLY, result, true); + EXPECT_EQ(status, OK); + EXPECT_EQ(result.size(), devices.size()); + EXPECT_EQ(result[DEVICE_B], OK); + std::this_thread::sleep_for(std::chrono::seconds(TEN_SECONDS)); + g_deviceB->Sync(SYNC_MODE_PUSH_ONLY, query, [&virtualRes](std::map resMap) { + virtualRes = std::move(resMap); + }, true); + EXPECT_EQ(virtualRes.size(), devices.size()); + EXPECT_EQ(virtualRes[DEVICE_A], static_cast(SyncOperation::OP_FINISHED_ALL)); + g_deviceB->DelayGetSyncData(0); } \ No newline at end of file diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.cpp index 1cfde89e9e08139e31e3d7ce3080b671306e6879..b272d6e19b46e09045f23742ffb978ff3ee3d050 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.cpp @@ -69,13 +69,18 @@ int KvVirtualDevice::Commit() return syncInterface->Commit(); } - void KvVirtualDevice::SetSaveDataDelayTime(uint64_t milliDelayTime) { VirtualSingleVerSyncDBInterface *syncInterface = static_cast(storage_); syncInterface->SetSaveDataDelayTime(milliDelayTime); } +void KvVirtualDevice::DelayGetSyncData(uint64_t milliDelayTime) +{ + VirtualSingleVerSyncDBInterface *syncInterface = static_cast(storage_); + syncInterface->DelayGetSyncData(milliDelayTime); +} + int KvVirtualDevice::Subscribe(QuerySyncObject query, bool wait, int id) { auto operation = new (std::nothrow) SyncOperation(id, {remoteDeviceId_}, SUBSCRIBE_QUERY, nullptr, wait); diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.h index 220aabc4b41d30ffb03c574df6ed69811a5e5ad0..b95e5402958ffedd3eb1d88fb4b1ea0ec0236025 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.h +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.h @@ -33,6 +33,7 @@ public: int StartTransaction(); int Commit(); void SetSaveDataDelayTime(uint64_t milliDelayTime); + void DelayGetSyncData(uint64_t milliDelayTime); int Subscribe(QuerySyncObject query, bool wait, int id); int UnSubscribe(QuerySyncObject query, bool wait, int id); diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_single_ver_sync_db_Interface.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_single_ver_sync_db_Interface.cpp index f4de94fe463f93a066944ce3d00f2bc9d79ed6a2..b826d4845cbf454d11337cf3b7b176c62ee97cc6 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_single_ver_sync_db_Interface.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_single_ver_sync_db_Interface.cpp @@ -218,6 +218,7 @@ int VirtualSingleVerSyncDBInterface::GetSyncDataNext(std::vector &dataItems, ContinueToken &continueStmtToken) const { + std::this_thread::sleep_for(std::chrono::milliseconds(getDataDelayTime_)); for (const auto &data : dbData_) { if (data.isLocal) { if (data.writeTimestamp >= begin && data.writeTimestamp < end) { @@ -318,6 +319,7 @@ int VirtualSingleVerSyncDBInterface::GetSyncData(QueryObject &query, const SyncT const DataSizeSpecInfo &dataSizeInfo, ContinueToken &continueStmtToken, std::vector &entries) const { + std::this_thread::sleep_for(std::chrono::milliseconds(getDataDelayTime_)); const auto &startKey = query.GetPrefixKey(); Key endKey = startKey; endKey.resize(DBConstant::MAX_KEY_SIZE, UCHAR_MAX); @@ -441,4 +443,9 @@ void VirtualSingleVerSyncDBInterface::SetDbProperties(KvDBProperties &kvDBProper { properties_ = kvDBProperties; } + +void VirtualSingleVerSyncDBInterface::DelayGetSyncData(uint32_t milliDelayTime) +{ + getDataDelayTime_ = milliDelayTime; +} } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_single_ver_sync_db_Interface.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_single_ver_sync_db_Interface.h index 43508e5b365d54fd280936249ea8a66df870fdbf..efb16751af2dfc4f062bc44651edf7c4086ac33b 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_single_ver_sync_db_Interface.h +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_single_ver_sync_db_Interface.h @@ -129,6 +129,8 @@ public: void SetIdentifier(std::vector &identifier); void SetDbProperties(KvDBProperties &kvDBProperties); + + void DelayGetSyncData(uint32_t milliDelayTime); private: int GetSyncData(Timestamp begin, Timestamp end, uint32_t blockSize, std::vector& dataItems, ContinueToken& continueStmtToken) const; @@ -150,6 +152,7 @@ private: std::mutex deviceDataLock_; std::map> deviceData_; std::vector identifier_; + uint64_t getDataDelayTime_ = 0; }; } // namespace DistributedDB