From cce8070b51ec6e99014e38a26c7745ea681664ee Mon Sep 17 00:00:00 2001 From: Hollokin Date: Fri, 1 Aug 2025 16:23:35 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9EventCenter?= =?UTF-8?q?=E7=9A=84Unsubscribe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hollokin --- .../service/cloud/cloud_service_impl.cpp | 8 ++++++++ .../service/cloud/cloud_service_impl.h | 2 +- .../distributeddataservice/service/cloud/sync_manager.cpp | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 64ce9ff50..4bb30cf4f 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -123,6 +123,14 @@ CloudServiceImpl::CloudServiceImpl() }, true); } +CloudServiceImpl::~CloudServiceImpl() +{ + executor_ = nullptr; + EventCenter::GetInstance().Unsubscribe(CloudEvent::GET_SCHEMA); + EventCenter::GetInstance().Unsubscribe(CloudEvent::CLOUD_SHARE); + EventCenter::GetInstance().Unsubscribe(CloudEvent::UPGRADE_SCHEMA); +} + int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map &switches) { XCollie xcollie( diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 4410519c1..b78eea08f 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -41,7 +41,7 @@ public: using StoreMetaData = DistributedData::StoreMetaData; using StoreInfo = DistributedData::StoreInfo; CloudServiceImpl(); - ~CloudServiceImpl() = default; + ~CloudServiceImpl(); int32_t EnableCloud(const std::string &id, const std::map &switches) override; int32_t DisableCloud(const std::string &id) override; int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) override; diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 773fca44b..16341a989 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -225,6 +225,9 @@ SyncManager::SyncManager() SyncManager::~SyncManager() { + EventCenter::GetInstance().Unsubscribe(CloudEvent::LOCK_CLOUD_CONTAINER); + EventCenter::GetInstance().Unsubscribe(CloudEvent::UNLOCK_CLOUD_CONTAINER); + EventCenter::GetInstance().Unsubscribe(CloudEvent::LOCAL_CHANGE); if (executor_ != nullptr) { actives_.ForEachCopies([this](auto &syncId, auto &taskId) { executor_->Remove(taskId); -- Gitee From 2be650e8f2d2430377a9df302693a1e5c5e03ccf Mon Sep 17 00:00:00 2001 From: Hollokin Date: Mon, 4 Aug 2025 10:46:35 +0800 Subject: [PATCH 2/5] TDD Signed-off-by: Hollokin --- .../service/test/cloud_service_impl_test.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp index dbe572a55..d90c1e9db 100644 --- a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp @@ -104,6 +104,29 @@ void CloudServiceImplTest::SetUp() { } void CloudServiceImplTest::TearDown() { } +/** + * @tc.name: CloudServiceImpl_Deconstruct_Test + * @tc.desc: Test CloudServiceImpl Deconstruct functions. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CloudServiceImplTest, CloudServiceImpl_Deconstruct_Test, TestSize.Level0) +{ + ZLOGI("CloudServiceImplTest CloudServiceImpl_Deconstruct_Test start"); + // LOCAL_CHANGE event subscribed when construct CloudServiceImpl. + auto cloudServiceImpl = std::make_shared(); + ASSERT_NE(cloudServiceImpl, nullptr); + auto [found, observers] = EventCenter::GetInstance().observers_.Find(CloudEvent::LOCAL_CHANGE); + EXPECT_EQ(found, true); + EXPECT_NE(observers.size(), 0); + + cloudServiceImpl = nullptr; + std::tie(found, observers) = EventCenter::GetInstance().observers_.Find(CloudEvent::LOCAL_CHANGE); + EXPECT_EQ(found, false); + EXPECT_EQ(observers.size(), 0); + ZLOGI("CloudServiceImplTest CloudServiceImpl_Deconstruct_Test end"); +} + /** * @tc.name: EnableCloud001 * @tc.desc: Test EnableCloud functions with user is invalid. -- Gitee From 344453909fb7bdbd12cdf18b66d579314d332cd0 Mon Sep 17 00:00:00 2001 From: Hollokin Date: Mon, 4 Aug 2025 11:00:26 +0800 Subject: [PATCH 3/5] TDD Signed-off-by: Hollokin --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 1 + .../service/test/cloud_service_impl_test.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 4bb30cf4f..c1f433e3d 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -129,6 +129,7 @@ CloudServiceImpl::~CloudServiceImpl() EventCenter::GetInstance().Unsubscribe(CloudEvent::GET_SCHEMA); EventCenter::GetInstance().Unsubscribe(CloudEvent::CLOUD_SHARE); EventCenter::GetInstance().Unsubscribe(CloudEvent::UPGRADE_SCHEMA); + MetaDataManager::GetInstance().UnSubscribe(); } int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map &switches) diff --git a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp index d90c1e9db..ef81e4a4c 100644 --- a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp @@ -119,11 +119,13 @@ HWTEST_F(CloudServiceImplTest, CloudServiceImpl_Deconstruct_Test, TestSize.Level auto [found, observers] = EventCenter::GetInstance().observers_.Find(CloudEvent::LOCAL_CHANGE); EXPECT_EQ(found, true); EXPECT_NE(observers.size(), 0); + EXPECT_NE(MetaDataManager::GetInstance().capObserver_, nullptr); cloudServiceImpl = nullptr; std::tie(found, observers) = EventCenter::GetInstance().observers_.Find(CloudEvent::LOCAL_CHANGE); EXPECT_EQ(found, false); EXPECT_EQ(observers.size(), 0); + EXPECT_EQ(MetaDataManager::GetInstance().capObserver_, nullptr); ZLOGI("CloudServiceImplTest CloudServiceImpl_Deconstruct_Test end"); } -- Gitee From 15e9ff7cf98c2e18704a244ff8b064091bb97289 Mon Sep 17 00:00:00 2001 From: Hollokin Date: Mon, 4 Aug 2025 11:14:54 +0800 Subject: [PATCH 4/5] TDD Signed-off-by: Hollokin --- .../service/cloud/cloud_service_impl.cpp | 2 +- .../service/test/cloud_service_impl_test.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index c1f433e3d..1f5841840 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -129,7 +129,7 @@ CloudServiceImpl::~CloudServiceImpl() EventCenter::GetInstance().Unsubscribe(CloudEvent::GET_SCHEMA); EventCenter::GetInstance().Unsubscribe(CloudEvent::CLOUD_SHARE); EventCenter::GetInstance().Unsubscribe(CloudEvent::UPGRADE_SCHEMA); - MetaDataManager::GetInstance().UnSubscribe(); + MetaDataManager::GetInstance().Unsubscribe(Subscription::GetPrefix({ "" })); } int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map &switches) diff --git a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp index ef81e4a4c..6b6d9e672 100644 --- a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp @@ -119,13 +119,18 @@ HWTEST_F(CloudServiceImplTest, CloudServiceImpl_Deconstruct_Test, TestSize.Level auto [found, observers] = EventCenter::GetInstance().observers_.Find(CloudEvent::LOCAL_CHANGE); EXPECT_EQ(found, true); EXPECT_NE(observers.size(), 0); - EXPECT_NE(MetaDataManager::GetInstance().capObserver_, nullptr); + auto [isExist, metaObserver] = MetaDataManager::GetInstance().metaObservers_.Find(Subscription::GetPrefix({ "" })); + EXPECT_EQ(isExist, true); + EXPECT_NE(metaObserver, nullptr); cloudServiceImpl = nullptr; std::tie(found, observers) = EventCenter::GetInstance().observers_.Find(CloudEvent::LOCAL_CHANGE); EXPECT_EQ(found, false); EXPECT_EQ(observers.size(), 0); - EXPECT_EQ(MetaDataManager::GetInstance().capObserver_, nullptr); + std::tie(isExist, metaObserver) = + MetaDataManager::GetInstance().metaObservers_.Find(Subscription::GetPrefix({ "" })); + EXPECT_EQ(isExist, false); + EXPECT_EQ(metaObserver, nullptr); ZLOGI("CloudServiceImplTest CloudServiceImpl_Deconstruct_Test end"); } -- Gitee From 4c2089b3d93eb39f2ea8e0638b025800bc8bb130 Mon Sep 17 00:00:00 2001 From: Hollokin Date: Mon, 4 Aug 2025 14:29:31 +0800 Subject: [PATCH 5/5] TDD Signed-off-by: Hollokin --- .../service/test/cloud_service_impl_test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp index 6b6d9e672..10c8becc5 100644 --- a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp @@ -113,6 +113,8 @@ void CloudServiceImplTest::TearDown() { } HWTEST_F(CloudServiceImplTest, CloudServiceImpl_Deconstruct_Test, TestSize.Level0) { ZLOGI("CloudServiceImplTest CloudServiceImpl_Deconstruct_Test start"); + std::shared_ptr dbStoreMock = std::make_shared(); + MetaDataManager::GetInstance().Initialize(dbStoreMock, nullptr, ""); // LOCAL_CHANGE event subscribed when construct CloudServiceImpl. auto cloudServiceImpl = std::make_shared(); ASSERT_NE(cloudServiceImpl, nullptr); -- Gitee