diff --git a/services/distributeddataservice/framework/test/store_test.cpp b/services/distributeddataservice/framework/test/store_test.cpp index 7bc31f25e4a6de819cff4fdb9f756785ad325c62..24e8f52181939b49bec3c1adccfc696b78d2d903 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_.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), + 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_.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), + 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 f986bd04bfd2499c30738257cfa90dd9c989e229..bc19b107b1c29f4ae79c2ba187c1ce91b70eeb30 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_;