From 90284e77680343b590f0f34de7eadaae1e2b4c09 Mon Sep 17 00:00:00 2001 From: bigteer Date: Thu, 24 Jul 2025 14:15:26 +0800 Subject: [PATCH] add device compress and get devicecount Signed-off-by: bigteer --- .../app/src/checker/bundle_checker.h | 2 +- .../service/rdb/rdb_general_store.cpp | 4 +- .../mock/relational_store_delegate_mock.h | 12 +-- .../service/test/rdb_general_store_test.cpp | 89 ++++++++++++++++++- 4 files changed, 93 insertions(+), 14 deletions(-) diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.h b/services/distributeddataservice/app/src/checker/bundle_checker.h index 1cce99b48..a7b07159c 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.h +++ b/services/distributeddataservice/app/src/checker/bundle_checker.h @@ -40,7 +40,7 @@ public: void DeleteCache(const std::string &bundleName, int32_t user, int32_t index) override; void ClearCache() override; private: - static constexpr int CACHE_SIZE = 32; + static constexpr int32_t CACHE_SIZE = 32; std::string GetAppidFromCache(const std::string &bundleName, int32_t userId); std::string GetKey(const std::string &bundleName, int32_t userId); static BundleChecker instance_; diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 9a3ba03cb..cc31eacc8 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -182,6 +182,7 @@ RdbGeneralStore::RdbGeneralStore(const StoreMetaData &meta) observer_.storeId_ = meta.storeId; observer_.meta_ = meta; RelationalStoreDelegate::Option option = GetOption(meta); + option.isNeedCompressOnSync = true; option.observer = &observer_; if (meta.isEncrypt) { option.passwd = GetDBPassword(meta); @@ -311,7 +312,8 @@ int32_t RdbGeneralStore::Close(bool isForce) return GeneralError::E_OK; } auto [dbStatus, downloadCount] = delegate_->GetDownloadingAssetsCount(); - if (!isForce && (delegate_->GetCloudSyncTaskCount() > 0 || downloadCount > 0)) { + if (!isForce && + (delegate_->GetCloudSyncTaskCount() > 0 || downloadCount > 0 || delegate_->GetDeviceSyncTaskCount() > 0)) { return GeneralError::E_BUSY; } auto status = manager_.CloseStore(delegate_); diff --git a/services/distributeddataservice/service/test/mock/relational_store_delegate_mock.h b/services/distributeddataservice/service/test/mock/relational_store_delegate_mock.h index 0f5308d45..fd3c770dc 100644 --- a/services/distributeddataservice/service/test/mock/relational_store_delegate_mock.h +++ b/services/distributeddataservice/service/test/mock/relational_store_delegate_mock.h @@ -15,6 +15,7 @@ #ifndef RELATIONAL_STORE_DELEGATE_MOCK_H #define RELATIONAL_STORE_DELEGATE_MOCK_H #include "rdb_general_store.h" +#include namespace DistributedDB { class MockRelationalStoreDelegate : public DistributedDB::RelationalStoreDelegate { public: @@ -26,13 +27,6 @@ public: return DBStatus::OK; } - int32_t GetCloudSyncTaskCount() override - { - static int32_t count = 0; - count = (count + 1) % 2; // The result of count + 1 is the remainder of 2. - return count; - } - DBStatus RemoveDeviceData(const std::string &device, const std::string &tableName) override { return DBStatus::OK; @@ -148,7 +142,9 @@ public: return DBStatus::OK; } static bool gTestResult; - + MOCK_METHOD(int32_t, GetDeviceSyncTaskCount, (), (override)); + MOCK_METHOD(int32_t, GetCloudSyncTaskCount, (), (override)); + MOCK_METHOD((std::pair), GetDownloadingAssetsCount, (), (override)); protected: DBStatus RemoveDeviceDataInner(const std::string &device, ClearMode mode) override { diff --git a/services/distributeddataservice/service/test/rdb_general_store_test.cpp b/services/distributeddataservice/service/test/rdb_general_store_test.cpp index 24e4dfab6..3f1eb74d7 100644 --- a/services/distributeddataservice/service/test/rdb_general_store_test.cpp +++ b/services/distributeddataservice/service/test/rdb_general_store_test.cpp @@ -18,6 +18,7 @@ #include #include +#include #include "bootstrap.h" #include "cloud/schema_meta.h" @@ -226,10 +227,10 @@ HWTEST_F(RdbGeneralStoreTest, Bind003, TestSize.Level1) } /** -* @tc.name: Close -* @tc.desc: RdbGeneralStore Close and IsBound function test -* @tc.type: FUNC -*/ + * @tc.name: Close + * @tc.desc: RdbGeneralStore Close and IsBound function test + * @tc.type: FUNC + */ HWTEST_F(RdbGeneralStoreTest, Close, TestSize.Level1) { auto result = store->IsBound(std::atoi(metaData_.user.c_str())); @@ -239,10 +240,90 @@ HWTEST_F(RdbGeneralStoreTest, Close, TestSize.Level1) EXPECT_EQ(ret, GeneralError::E_OK); metaData_.storeId = "mock"; store = std::make_shared(metaData_); + auto delegate = new MockRelationalStoreDelegate; + store->delegate_ = delegate; + EXPECT_CALL(*delegate, GetDeviceSyncTaskCount()).WillOnce(testing::Return(2)).WillRepeatedly(testing::Return(2)); + EXPECT_CALL(*delegate, GetCloudSyncTaskCount()).WillOnce(testing::Return(0)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*delegate, GetDownloadingAssetsCount()) + .WillOnce(testing::Return(std::make_pair(DBStatus::OK, 0))) + .WillRepeatedly(testing::Return(std::make_pair(DBStatus::OK, 0))); ret = store->Close(); EXPECT_EQ(ret, GeneralError::E_BUSY); } +/** + * @tc.name: Close1 + * @tc.desc: RdbGeneralStore Close and IsBound function test + * @tc.type: FUNC + */ +HWTEST_F(RdbGeneralStoreTest, Close1, TestSize.Level1) +{ + metaData_.storeId = "mock"; + auto store = std::make_shared(metaData_); + auto delegate = new MockRelationalStoreDelegate; + store->delegate_ = delegate; + EXPECT_CALL(*delegate, GetDeviceSyncTaskCount()).WillOnce(testing::Return(0)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*delegate, GetCloudSyncTaskCount()).WillOnce(testing::Return(2)).WillRepeatedly(testing::Return(2)); + EXPECT_CALL(*delegate, GetDownloadingAssetsCount()) + .WillOnce(testing::Return(std::make_pair(DBStatus::OK, 0))) + .WillRepeatedly(testing::Return(std::make_pair(DBStatus::OK, 0))); + auto ret = store->Close(); + EXPECT_EQ(ret, GeneralError::E_BUSY); +} + +/** + * @tc.name: Close2 + * @tc.desc: RdbGeneralStore Close and IsBound function test + * @tc.type: FUNC + */ +HWTEST_F(RdbGeneralStoreTest, Close2, TestSize.Level1) +{ + metaData_.storeId = "mock"; + auto store = std::make_shared(metaData_); + auto delegate = new MockRelationalStoreDelegate; + store->delegate_ = delegate; + EXPECT_CALL(*delegate, GetDeviceSyncTaskCount()).WillOnce(testing::Return(0)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*delegate, GetCloudSyncTaskCount()).WillOnce(testing::Return(0)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*delegate, GetDownloadingAssetsCount()) + .WillOnce(testing::Return(std::make_pair(DBStatus::OK, 1))) + .WillRepeatedly(testing::Return(std::make_pair(DBStatus::OK, 1))); + auto ret = store->Close(); + EXPECT_EQ(ret, GeneralError::E_BUSY); +} +/** + * @tc.name: Close3 + * @tc.desc: RdbGeneralStore Close and IsBound function test + * @tc.type: FUNC + */ +HWTEST_F(RdbGeneralStoreTest, Close3, TestSize.Level1) +{ + metaData_.storeId = "mock"; + auto store = std::make_shared(metaData_); + auto delegate = new MockRelationalStoreDelegate; + store->delegate_ = delegate; + auto ret = store->Close(true); + EXPECT_EQ(ret, GeneralError::E_OK); +} +/** + * @tc.name: Close4 + * @tc.desc: RdbGeneralStore Close and IsBound function test + * @tc.type: FUNC + */ +HWTEST_F(RdbGeneralStoreTest, Close4, TestSize.Level1) +{ + metaData_.storeId = "mock"; + auto store = std::make_shared(metaData_); + auto delegate = new MockRelationalStoreDelegate; + store->delegate_ = delegate; + EXPECT_CALL(*delegate, GetDeviceSyncTaskCount()).WillOnce(testing::Return(0)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*delegate, GetCloudSyncTaskCount()).WillOnce(testing::Return(0)).WillRepeatedly(testing::Return(0)); + EXPECT_CALL(*delegate, GetDownloadingAssetsCount()) + .WillOnce(testing::Return(std::make_pair(DBStatus::DB_ERROR, 0))) + .WillRepeatedly(testing::Return(std::make_pair(DBStatus::DB_ERROR, 0))); + auto ret = store->Close(); + EXPECT_EQ(ret, GeneralError::E_OK); +} + /** * @tc.name: Close * @tc.desc: RdbGeneralStore Close test -- Gitee