From 8aac6a9a2bc4d048bbe862a29ec9fd59368eaf02 Mon Sep 17 00:00:00 2001 From: gecheng Date: Mon, 7 Apr 2025 14:58:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gecheng --- .../framework/test/store_test.cpp | 64 +++++++++++++++++++ .../service/cloud/sync_manager.h | 7 +- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/framework/test/store_test.cpp b/services/distributeddataservice/framework/test/store_test.cpp index 7bc31f25e..f84c0aa0d 100644 --- a/services/distributeddataservice/framework/test/store_test.cpp +++ b/services/distributeddataservice/framework/test/store_test.cpp @@ -30,6 +30,8 @@ using namespace testing::ext; using namespace OHOS::DistributedData; namespace OHOS::Test { +static constexpr const char *TEST_CLOUD_STORE = "test_cloud_store"; + class GeneralValueTest : public testing::Test { public: static void SetUpTestCase(void){}; @@ -260,4 +262,66 @@ HWTEST_F(AutoCacheTest, GetDBStore, TestSize.Level2) meta.area = GeneralStore::EL5; EXPECT_NE(AutoCache::GetInstance().GetDBStore(meta, watchers).first, GeneralError::E_SCREEN_LOCKED); } + +/** +* @tc.name: CloseStore001 +* @tc.desc: AutoCache CloseStore001 +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ +HWTEST_F(AutoCacheTest, CloseStore001, TestSize.Level2) +{ + GeneralStoreMock* store = new (std::nothrow) GeneralStoreMock(); + ASSERT_NE(store, nullptr); + AutoCache::Watchers watchers; + mock_->isLocked_ = true; + StoreMetaData meta; + meta.area = GeneralStore::EL1; + meta.dataDir = 'abc'; + uint32_t tokenId = 123; + std::string storeId = TEST_CLOUD_STORE; + std::string userId = ""; + AutoCache autoCache; + autoCache.stores_.Computer(tokenId, + [this, &meta, &watchers, &store](auto &, std::map &stores) -> bool { + std::string storeKey = "key"; + stores.emplace(std::piecewise_construct, std::forward_as_tuple(storeKey), + std::forward_as_tuple(store, watchers, 0, meta)); + return !stores.empty(); + }); + autoCache.CloseStore(tokenId, storeId, userId); + EXPECT_TRUE(autoCache.stores_.empty()); + } + + /** +* @tc.name: CloseStore002 +* @tc.desc: AutoCache CloseStore002 +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ +HWTEST_F(AutoCacheTest, CloseStore002, TestSize.Level2) +{ + GeneralStoreMock* store = new (std::nothrow) GeneralStoreMock(); + ASSERT_NE(store, nullptr); + AutoCache::Watchers watchers; + mock_->isLocked_ = true; + StoreMetaData meta; + meta.area = GeneralStore::EL4; + meta.dataDir = 'abc'; + uint32_t tokenId = 123; + std::string storeId = TEST_CLOUD_STORE; + std::string userId = ""; + AutoCache autoCache; + autoCache.stores_.Computer(tokenId, + [this, &meta, &watchers, &store](auto &, std::map &stores) -> bool { + std::string storeKey = "key"; + stores.emplace(std::piecewise_construct, std::forward_as_tuple(storeKey), + std::forward_as_tuple(store, watchers, 0, meta)); + return !stores.empty(); + }); + autoCache.CloseStore(tokenId, storeId, userId); + EXPECT_FALSE(autoCache.stores_.empty()); + } } // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/sync_manager.h b/services/distributeddataservice/service/cloud/sync_manager.h index f986bd04b..bc19b107b 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.h +++ b/services/distributeddataservice/service/cloud/sync_manager.h @@ -144,6 +144,10 @@ private: static std::pair GetLastResults(std::map &infos); static std::pair GetLastSyncInfoFromMeta(const QueryKey &queryKey); static void SaveLastSyncInfo(const QueryKey &queryKey, CloudLastSyncInfo &&info); + static void BatchReport(int32_t userId, const TraceIds &traceIds, SyncStage syncStage, int32_t errCode, + const std::string &message = ""); + static void ReportSyncEvent(const DistributedData::SyncEvent &evt, DistributedDataDfx::BizState bizState, + int32_t code); Task GetSyncTask(int32_t times, bool retry, RefCount ref, SyncInfo &&syncInfo); void UpdateSchema(const SyncInfo &syncInfo); std::function GetSyncHandler(Retryer retryer); @@ -164,13 +168,10 @@ private: Retryer retryer, int32_t triggerMode, const std::string &prepareTraceId, int32_t user); void BatchUpdateFinishState(const std::vector> &cloudSyncInfos, int32_t code); bool NeedSaveSyncInfo(const QueryKey &queryKey); - void BatchReport(int32_t userId, const TraceIds &traceIds, SyncStage syncStage, int32_t errCode, - const std::string &message = ""); void StartCloudSync(const DistributedData::SyncEvent &evt, const StoreMetaData &meta, const AutoCache::Store &store, Retryer retryer, DistributedData::GenDetails &details); std::pair GetMetaData(const StoreInfo &storeInfo); void AddCompensateSync(const StoreMetaData &meta); - void ReportSyncEvent(const DistributedData::SyncEvent &evt, DistributedDataDfx::BizState bizState, int32_t code); static std::atomic genId_; std::shared_ptr executor_; ConcurrentMap actives_; -- Gitee From 5e6da5776901411c23e245c289e3401f6aea51dd Mon Sep 17 00:00:00 2001 From: gecheng Date: Mon, 7 Apr 2025 15:06:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gecheng --- .../framework/test/store_test.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/framework/test/store_test.cpp b/services/distributeddataservice/framework/test/store_test.cpp index f84c0aa0d..24e8f5218 100644 --- a/services/distributeddataservice/framework/test/store_test.cpp +++ b/services/distributeddataservice/framework/test/store_test.cpp @@ -278,12 +278,12 @@ HWTEST_F(AutoCacheTest, CloseStore001, TestSize.Level2) mock_->isLocked_ = true; StoreMetaData meta; meta.area = GeneralStore::EL1; - meta.dataDir = 'abc'; + meta.dataDir = "abc"; uint32_t tokenId = 123; std::string storeId = TEST_CLOUD_STORE; std::string userId = ""; AutoCache autoCache; - autoCache.stores_.Computer(tokenId, + autoCache.stores_.Compute(tokenId, [this, &meta, &watchers, &store](auto &, std::map &stores) -> bool { std::string storeKey = "key"; stores.emplace(std::piecewise_construct, std::forward_as_tuple(storeKey), @@ -291,10 +291,10 @@ HWTEST_F(AutoCacheTest, CloseStore001, TestSize.Level2) return !stores.empty(); }); autoCache.CloseStore(tokenId, storeId, userId); - EXPECT_TRUE(autoCache.stores_.empty()); - } + EXPECT_TRUE(autoCache.stores_.Empty()); +} - /** +/** * @tc.name: CloseStore002 * @tc.desc: AutoCache CloseStore002 * @tc.type: FUNC @@ -309,12 +309,12 @@ HWTEST_F(AutoCacheTest, CloseStore002, TestSize.Level2) mock_->isLocked_ = true; StoreMetaData meta; meta.area = GeneralStore::EL4; - meta.dataDir = 'abc'; + meta.dataDir = "abc"; uint32_t tokenId = 123; std::string storeId = TEST_CLOUD_STORE; std::string userId = ""; AutoCache autoCache; - autoCache.stores_.Computer(tokenId, + autoCache.stores_.Compute(tokenId, [this, &meta, &watchers, &store](auto &, std::map &stores) -> bool { std::string storeKey = "key"; stores.emplace(std::piecewise_construct, std::forward_as_tuple(storeKey), @@ -322,6 +322,6 @@ HWTEST_F(AutoCacheTest, CloseStore002, TestSize.Level2) return !stores.empty(); }); autoCache.CloseStore(tokenId, storeId, userId); - EXPECT_FALSE(autoCache.stores_.empty()); - } + EXPECT_FALSE(autoCache.stores_.Empty()); +} } // namespace OHOS::Test \ No newline at end of file -- Gitee