From b835a887339a54f6aacbee6489e391f992f6b524 Mon Sep 17 00:00:00 2001 From: cheerful_ricky Date: Wed, 23 Apr 2025 18:09:06 +0800 Subject: [PATCH] revert rdb memory refactor Signed-off-by: cheerful_ricky --- .../ans/include/notification_rdb_data_mgr.h | 5 +- .../ans/src/notification_rdb_data_mgr.cpp | 187 +++++++++--------- .../mock_rdb_helper.cpp | 14 -- .../notification_rdb_data_mgr_test.cpp | 44 ++--- 4 files changed, 117 insertions(+), 133 deletions(-) diff --git a/services/ans/include/notification_rdb_data_mgr.h b/services/ans/include/notification_rdb_data_mgr.h index 9e55df71d..e8e980312 100644 --- a/services/ans/include/notification_rdb_data_mgr.h +++ b/services/ans/include/notification_rdb_data_mgr.h @@ -149,7 +149,6 @@ public: int32_t DropUserTable(const int32_t userId); private: - std::shared_ptr GetConnection(); int32_t GetUserTableName(const int32_t &userId, std::string &tableName); std::vector GenerateOperatedTables(const int32_t &userId); int32_t DeleteData(const std::string tableName, const std::string key, int32_t &rowId); @@ -158,11 +157,13 @@ private: int32_t QueryDataBeginWithKey(const std::string tableName, const std::string key, std::unordered_map &values); int32_t QueryAllData(const std::string tableName, std::unordered_map &datas); - int32_t InitCreatedTables(std::shared_ptr rdbConnection); + int32_t InitCreatedTables(); int32_t RestoreForMasterSlaver(); private: NotificationRdbConfig notificationRdbConfig_; + std::shared_ptr rdbStore_; + mutable std::mutex rdbStorePtrMutex_; std::set createdTables_; mutable std::mutex createdTableMutex_; }; diff --git a/services/ans/src/notification_rdb_data_mgr.cpp b/services/ans/src/notification_rdb_data_mgr.cpp index 7ea2e77fe..57383a351 100644 --- a/services/ans/src/notification_rdb_data_mgr.cpp +++ b/services/ans/src/notification_rdb_data_mgr.cpp @@ -32,6 +32,7 @@ const std::string NOTIFICATION_VALUE = "VALUE"; const int32_t NOTIFICATION_KEY_INDEX = 0; const int32_t NOTIFICATION_VALUE_INDEX = 1; const std::ptrdiff_t MAX_SIZE_PER_BATCH = 100; +const int32_t NOTIFICATION_RDB_MAX_MEMORY_SIZE = 1; } // namespace RdbStoreDataCallBackNotificationStorage::RdbStoreDataCallBackNotificationStorage( const NotificationRdbConfig ¬ificationRdbConfig): notificationRdbConfig_(notificationRdbConfig) @@ -95,18 +96,15 @@ NotificationDataMgr::NotificationDataMgr(const NotificationRdbConfig ¬ificati } int32_t NotificationDataMgr::Init() -{ - std::shared_ptr rdbConnection = GetConnection(); - if (rdbConnection == nullptr) { - ANS_LOGE("notification rdb is null"); - return NativeRdb::E_ERROR; - } - return NativeRdb::E_OK; -} - -std::shared_ptr NotificationDataMgr::GetConnection() { ANS_LOGD("Create rdbStore"); + { + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ != nullptr) { + ANS_LOGD("notification rdb has existed"); + return NativeRdb::E_OK; + } + } NativeRdb::RdbStoreConfig rdbStoreConfig( notificationRdbConfig_.dbPath + notificationRdbConfig_.dbName, NativeRdb::StorageMode::MODE_DISK, @@ -116,46 +114,41 @@ std::shared_ptr NotificationDataMgr::GetConnection() notificationRdbConfig_.syncMode); rdbStoreConfig.SetSecurityLevel(NativeRdb::SecurityLevel::S1); rdbStoreConfig.SetHaMode(NativeRdb::HAMode::MAIN_REPLICA); + rdbStoreConfig.SetClearMemorySize(NOTIFICATION_RDB_MAX_MEMORY_SIZE); RdbStoreDataCallBackNotificationStorage rdbDataCallBack_(notificationRdbConfig_); - - int32_t ret = NativeRdb::E_OK; - std::shared_ptr rdbStore = NativeRdb::RdbHelper::GetRdbStore(rdbStoreConfig, - notificationRdbConfig_.version, rdbDataCallBack_, ret); - if (rdbStore == nullptr) { - ANS_LOGE("notification rdb init fail"); - return nullptr; - } - InitCreatedTables(rdbStore); - return rdbStore; -} - -int32_t NotificationDataMgr::InitCreatedTables(std::shared_ptr rdbConnection) -{ + std::lock_guard lock(createdTableMutex_); { - std::lock_guard lock(createdTableMutex_); - if (!createdTables_.empty()) { - return NativeRdb::E_OK; + std::lock_guard lock(rdbStorePtrMutex_); + int32_t ret = NativeRdb::E_OK; + rdbStore_ = NativeRdb::RdbHelper::GetRdbStore(rdbStoreConfig, notificationRdbConfig_.version, + rdbDataCallBack_, ret); + if (rdbStore_ == nullptr) { + ANS_LOGE("notification rdb init fail"); + return NativeRdb::E_ERROR; } + return InitCreatedTables(); } +} + +int32_t NotificationDataMgr::InitCreatedTables() +{ std::string queryTableSql = "SELECT name FROM sqlite_master WHERE type='table'"; - auto absSharedResultSet = rdbConnection->QuerySql(queryTableSql); + auto absSharedResultSet = rdbStore_->QuerySql(queryTableSql); int32_t ret = absSharedResultSet->GoToFirstRow(); if (ret != NativeRdb::E_OK) { ANS_LOGE("Query tableName failed. It's empty!"); return NativeRdb::E_EMPTY_VALUES_BUCKET; } - { - std::lock_guard lock(createdTableMutex_); - do { - std::string tableName; - ret = absSharedResultSet->GetString(0, tableName); - if (ret != NativeRdb::E_OK) { - ANS_LOGE("GetString string failed from sqlite_master table."); - return NativeRdb::E_ERROR; - } - createdTables_.insert(tableName); - } while (absSharedResultSet->GoToNextRow() == NativeRdb::E_OK); - } + + do { + std::string tableName; + ret = absSharedResultSet->GetString(0, tableName); + if (ret != NativeRdb::E_OK) { + ANS_LOGE("GetString string failed from sqlite_master table."); + return NativeRdb::E_ERROR; + } + createdTables_.insert(tableName); + } while (absSharedResultSet->GoToNextRow() == NativeRdb::E_OK); absSharedResultSet->Close(); return NativeRdb::E_OK; } @@ -165,6 +158,15 @@ int32_t NotificationDataMgr::Destroy() ANS_LOGD("Destory rdbStore"); std::lock_guard lock(createdTableMutex_); createdTables_.clear(); + { + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ == nullptr) { + ANS_LOGE("notification rdb is null"); + return NativeRdb::E_ERROR; + } + + rdbStore_ = nullptr; + } int32_t ret = NativeRdb::RdbHelper::DeleteRdbStore(notificationRdbConfig_.dbPath + notificationRdbConfig_.dbName); if (ret != NativeRdb::E_OK) { ANS_LOGE("failed to destroy db store"); @@ -185,8 +187,8 @@ int32_t NotificationDataMgr::InsertData(const std::string &key, const std::strin ANS_LOGE("Get user table name failed."); return NativeRdb::E_ERROR; } - std::shared_ptr rdbConnection = GetConnection(); - if (rdbConnection == nullptr) { + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ == nullptr) { ANS_LOGE("notification rdb is null"); return NativeRdb::E_ERROR; } @@ -194,7 +196,7 @@ int32_t NotificationDataMgr::InsertData(const std::string &key, const std::strin NativeRdb::ValuesBucket valuesBucket; valuesBucket.PutString(NOTIFICATION_KEY, key); valuesBucket.PutString(NOTIFICATION_VALUE, value); - ret = rdbConnection->InsertWithConflictResolution(rowId, tableName, valuesBucket, + ret = rdbStore_->InsertWithConflictResolution(rowId, tableName, valuesBucket, NativeRdb::ConflictResolution::ON_CONFLICT_REPLACE); if (ret == NativeRdb::E_SQLITE_CORRUPT) { RestoreForMasterSlaver(); @@ -219,8 +221,8 @@ int32_t NotificationDataMgr::InsertData(const std::string &key, const std::vecto ANS_LOGE("Get user table name failed."); return NativeRdb::E_ERROR; } - std::shared_ptr rdbConnection = GetConnection(); - if (rdbConnection == nullptr) { + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ == nullptr) { ANS_LOGE("notification rdb is null"); return NativeRdb::E_ERROR; } @@ -228,7 +230,7 @@ int32_t NotificationDataMgr::InsertData(const std::string &key, const std::vecto NativeRdb::ValuesBucket valuesBucket; valuesBucket.PutString(NOTIFICATION_KEY, key); valuesBucket.PutBlob(NOTIFICATION_VALUE, value); - ret = rdbConnection->InsertWithConflictResolution(rowId, tableName, valuesBucket, + ret = rdbStore_->InsertWithConflictResolution(rowId, tableName, valuesBucket, NativeRdb::ConflictResolution::ON_CONFLICT_REPLACE); if (ret == NativeRdb::E_SQLITE_CORRUPT) { RestoreForMasterSlaver(); @@ -254,8 +256,8 @@ int32_t NotificationDataMgr::InsertBatchData(const std::unordered_map rdbConnection = GetConnection(); - if (rdbConnection == nullptr) { + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ == nullptr) { ANS_LOGE("notification rdb is null"); return NativeRdb::E_ERROR; } @@ -267,7 +269,7 @@ int32_t NotificationDataMgr::InsertBatchData(const std::unordered_mapBatchInsert(rowId, tableName, buckets); + ret = rdbStore_->BatchInsert(rowId, tableName, buckets); if (ret == NativeRdb::E_SQLITE_CORRUPT) { RestoreForMasterSlaver(); } @@ -286,7 +288,11 @@ int32_t NotificationDataMgr::DeleteData(const std::string &key, const int32_t &u ANS_LOGD("DeleteData start"); std::vector operatedTables = GenerateOperatedTables(userId); std::reverse(operatedTables.begin(), operatedTables.end()); - + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ == nullptr) { + ANS_LOGE("notification rdb is null"); + return NativeRdb::E_ERROR; + } int32_t ret = NativeRdb::E_OK; int32_t rowId = -1; for (auto tableName : operatedTables) { @@ -303,12 +309,7 @@ int32_t NotificationDataMgr::DeleteData(const std::string tableName, const std:: NativeRdb::AbsRdbPredicates absRdbPredicates(tableName); HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_10, EventBranchId::BRANCH_6); absRdbPredicates.EqualTo(NOTIFICATION_KEY, key); - std::shared_ptr rdbConnection = GetConnection(); - if (rdbConnection == nullptr) { - ANS_LOGE("notification rdb is null"); - return NativeRdb::E_ERROR; - } - int32_t ret = rdbConnection->Delete(rowId, absRdbPredicates); + int32_t ret = rdbStore_->Delete(rowId, absRdbPredicates); if (ret == NativeRdb::E_SQLITE_CORRUPT) { RestoreForMasterSlaver(); } @@ -328,8 +329,8 @@ int32_t NotificationDataMgr::DeleteBatchData(const std::vector &key { std::vector operatedTables = GenerateOperatedTables(userId); std::reverse(operatedTables.begin(), operatedTables.end()); - std::shared_ptr rdbConnection = GetConnection(); - if (rdbConnection == nullptr) { + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ == nullptr) { ANS_LOGE("notification rdb is null"); return NativeRdb::E_ERROR; } @@ -346,7 +347,7 @@ int32_t NotificationDataMgr::DeleteBatchData(const std::vector &key NativeRdb::AbsRdbPredicates absRdbPredicates(tableName); for (const auto &batchKey : batchKeys) { absRdbPredicates.In(NOTIFICATION_KEY, batchKey); - int32_t ret = rdbConnection->Delete(rowId, absRdbPredicates); + int32_t ret = rdbStore_->Delete(rowId, absRdbPredicates); if (ret == NativeRdb::E_SQLITE_CORRUPT) { RestoreForMasterSlaver(); } @@ -365,6 +366,11 @@ int32_t NotificationDataMgr::QueryData(const std::string &key, std::string &valu { ANS_LOGD("QueryData start"); std::vector operatedTables = GenerateOperatedTables(userId); + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ == nullptr) { + ANS_LOGE("notification rdb is null"); + return NativeRdb::E_ERROR; + } int32_t ret = NativeRdb::E_OK; for (auto tableName : operatedTables) { ret = QueryData(tableName, key, value); @@ -380,12 +386,7 @@ int32_t NotificationDataMgr::QueryData(const std::string tableName, const std::s NativeRdb::AbsRdbPredicates absRdbPredicates(tableName); HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_10, EventBranchId::BRANCH_2); absRdbPredicates.EqualTo(NOTIFICATION_KEY, key); - std::shared_ptr rdbConnection = GetConnection(); - if (rdbConnection == nullptr) { - ANS_LOGE("notification rdb is null"); - return NativeRdb::E_ERROR; - } - auto absSharedResultSet = rdbConnection->Query(absRdbPredicates, std::vector()); + auto absSharedResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (absSharedResultSet == nullptr) { ANS_LOGE("absSharedResultSet failed from %{public}s table.", tableName.c_str()); return NativeRdb::E_ERROR; @@ -422,6 +423,11 @@ int32_t NotificationDataMgr::QueryData(const std::string tableName, const std::s int32_t NotificationDataMgr::QueryData(const std::string &key, std::vector &values, const int32_t &userId) { std::vector operatedTables = GenerateOperatedTables(userId); + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ == nullptr) { + ANS_LOGE("notification rdb is null"); + return NativeRdb::E_ERROR; + } int32_t ret = NativeRdb::E_OK; for (auto tableName : operatedTables) { ret = QueryData(tableName, key, values); @@ -437,12 +443,7 @@ int32_t NotificationDataMgr::QueryData(const std::string tableName, const std::s NativeRdb::AbsRdbPredicates absRdbPredicates(tableName); HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_10, EventBranchId::BRANCH_3); absRdbPredicates.EqualTo(NOTIFICATION_KEY, key); - std::shared_ptr rdbConnection = GetConnection(); - if (rdbConnection == nullptr) { - ANS_LOGE("notification rdb is null"); - return NativeRdb::E_ERROR; - } - auto absSharedResultSet = rdbConnection->Query(absRdbPredicates, std::vector()); + auto absSharedResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (absSharedResultSet == nullptr) { ANS_LOGE("absSharedResultSet failed from %{public}s table.", tableName.c_str()); return NativeRdb::E_ERROR; @@ -479,7 +480,11 @@ int32_t NotificationDataMgr::QueryDataBeginWithKey( { ANS_LOGD("QueryData BeginWithKey start"); std::vector operatedTables = GenerateOperatedTables(userId); - + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ == nullptr) { + ANS_LOGE("notification rdb is null"); + return NativeRdb::E_ERROR; + } int32_t ret = NativeRdb::E_OK; for (auto tableName : operatedTables) { ret = QueryDataBeginWithKey(tableName, key, values); @@ -499,12 +504,7 @@ int32_t NotificationDataMgr::QueryDataBeginWithKey( NativeRdb::AbsRdbPredicates absRdbPredicates(tableName); HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_10, EventBranchId::BRANCH_5); absRdbPredicates.BeginsWith(NOTIFICATION_KEY, key); - std::shared_ptr rdbConnection = GetConnection(); - if (rdbConnection == nullptr) { - ANS_LOGE("notification rdb is null"); - return NativeRdb::E_ERROR; - } - auto absSharedResultSet = rdbConnection->Query(absRdbPredicates, std::vector()); + auto absSharedResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (absSharedResultSet == nullptr) { ANS_LOGE("absSharedResultSet failed from %{public}s table.", tableName.c_str()); return NativeRdb::E_ERROR; @@ -555,6 +555,11 @@ int32_t NotificationDataMgr::QueryAllData(std::unordered_map operatedTables = GenerateOperatedTables(userId); + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ == nullptr) { + ANS_LOGE("notification rdb is null"); + return NativeRdb::E_ERROR; + } int32_t ret = NativeRdb::E_OK; for (auto tableName : operatedTables) { ret = QueryAllData(tableName, datas); @@ -573,12 +578,7 @@ int32_t NotificationDataMgr::QueryAllData( { NativeRdb::AbsRdbPredicates absRdbPredicates(tableName); HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_10, EventBranchId::BRANCH_4); - std::shared_ptr rdbConnection = GetConnection(); - if (rdbConnection == nullptr) { - ANS_LOGE("notification rdb is null"); - return NativeRdb::E_ERROR; - } - auto absSharedResultSet = rdbConnection->Query(absRdbPredicates, std::vector()); + auto absSharedResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (absSharedResultSet == nullptr) { ANS_LOGE("absSharedResultSet failed from %{public}s table.", tableName.c_str()); return NativeRdb::E_ERROR; @@ -633,12 +633,12 @@ int32_t NotificationDataMgr::DropUserTable(const int32_t userId) std::lock_guard lock(createdTableMutex_); int32_t ret = NativeRdb::E_OK; { - std::shared_ptr rdbConnection = GetConnection(); - if (rdbConnection == nullptr) { + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ == nullptr) { return NativeRdb::E_ERROR; } std::string dropTableSql = "DROP TABLE IF EXISTS " + tableName; - ret = rdbConnection->ExecuteSql(dropTableSql); + ret = rdbStore_->ExecuteSql(dropTableSql); } if (ret == NativeRdb::E_OK) { createdTables_.erase(tableName); @@ -655,10 +655,6 @@ int32_t NotificationDataMgr::GetUserTableName(const int32_t &userId, std::string tableName = notificationRdbConfig_.tableName; return NativeRdb::E_OK; } - std::shared_ptr rdbConnection = GetConnection(); - if (rdbConnection == nullptr) { - return NativeRdb::E_ERROR; - } const char *keySpliter = "_"; std::stringstream stream; @@ -667,9 +663,13 @@ int32_t NotificationDataMgr::GetUserTableName(const int32_t &userId, std::string if (createdTables_.find(tableName) == createdTables_.end()) { std::lock_guard lock(createdTableMutex_); if (createdTables_.find(tableName) == createdTables_.end()) { + std::lock_guard lock(rdbStorePtrMutex_); + if (rdbStore_ == nullptr) { + return NativeRdb::E_ERROR; + } std::string createTableSql = "CREATE TABLE IF NOT EXISTS " + tableName + " (KEY TEXT NOT NULL PRIMARY KEY, VALUE TEXT NOT NULL);"; - int32_t ret = rdbConnection->ExecuteSql(createTableSql); + int32_t ret = rdbStore_->ExecuteSql(createTableSql); if (ret != NativeRdb::E_OK) { ANS_LOGW("createTable %{public}s failed, code: %{public}d", tableName.c_str(), ret); message.ErrorCode(ret).Message("create table failed."); @@ -707,8 +707,7 @@ int32_t NotificationDataMgr::RestoreForMasterSlaver() .ErrorCode(NativeRdb::E_SQLITE_CORRUPT).Message("Rdb is corruped."); NotificationAnalyticsUtil::ReportModifyEvent(message); ANS_LOGI("RestoreForMasterSlaver start"); - std::shared_ptr rdbConnection = GetConnection(); - int32_t result = rdbConnection->Restore(""); + int32_t result = rdbStore_->Restore(""); ANS_LOGI("RestoreForMasterSlaver result = %{public}d", result); return result; } diff --git a/services/ans/test/unittest/notification_rdb_data_mgr_test/mock_rdb_helper.cpp b/services/ans/test/unittest/notification_rdb_data_mgr_test/mock_rdb_helper.cpp index 786637533..d9dc91209 100755 --- a/services/ans/test/unittest/notification_rdb_data_mgr_test/mock_rdb_helper.cpp +++ b/services/ans/test/unittest/notification_rdb_data_mgr_test/mock_rdb_helper.cpp @@ -15,26 +15,12 @@ #include "rdb_errno.h" #include "rdb_helper.h" -#include "rdb_store.h" -using namespace OHOS::NativeRdb; - -namespace { - std::shared_ptr g_mockRdbStore = nullptr; -} - -void MockRdbStore(std::shared_ptr rdbStore) -{ - g_mockRdbStore = rdbStore; -} namespace OHOS { namespace NativeRdb { std::shared_ptr RdbHelper::GetRdbStore( const RdbStoreConfig &config, int version, RdbOpenCallback &openCallback, int &errCode) { - if (g_mockRdbStore) { - return g_mockRdbStore; - } return nullptr; } diff --git a/services/ans/test/unittest/notification_rdb_data_mgr_test/notification_rdb_data_mgr_test.cpp b/services/ans/test/unittest/notification_rdb_data_mgr_test/notification_rdb_data_mgr_test.cpp index 745d171bc..fe194ca70 100755 --- a/services/ans/test/unittest/notification_rdb_data_mgr_test/notification_rdb_data_mgr_test.cpp +++ b/services/ans/test/unittest/notification_rdb_data_mgr_test/notification_rdb_data_mgr_test.cpp @@ -37,8 +37,6 @@ extern void MockGetString(bool mockRet); using namespace testing::ext; using namespace OHOS::NativeRdb; -extern void MockRdbStore(std::shared_ptr rdbStore); - namespace OHOS { namespace Notification { class RdbStoreDataCallBackNotificationStorageTest : public testing::Test { @@ -404,7 +402,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00500 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); ASSERT_EQ(notificationDataMgr->Destroy(), NativeRdb::E_ERROR); } @@ -418,7 +416,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00600 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - + notificationDataMgr->rdbStore_ = nullptr; std::string key = ""; std::string value = ""; ASSERT_EQ(notificationDataMgr->InsertData(key, value, -1), NativeRdb::E_ERROR); @@ -434,7 +432,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00700 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); std::string key = ""; std::string value = ""; ASSERT_EQ(notificationDataMgr->InsertData(key, value, -1), NativeRdb::E_ERROR); @@ -450,7 +448,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00800 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - + notificationDataMgr->rdbStore_ = nullptr; std::unordered_map values; ASSERT_EQ(notificationDataMgr->InsertBatchData(values, -1), NativeRdb::E_ERROR); } @@ -465,7 +463,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00900 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); std::unordered_map values = { { "--help", "--help"}, { "--all", "--all"}, @@ -487,7 +485,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01000 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - + notificationDataMgr->rdbStore_ = nullptr; std::string key = ""; ASSERT_EQ(notificationDataMgr->DeleteData(key, -1), NativeRdb::E_ERROR); } @@ -502,7 +500,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01100 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); std::string key = ""; ASSERT_EQ(notificationDataMgr->DeleteData(key, -1), NativeRdb::E_ERROR); } @@ -517,7 +515,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01200 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - + notificationDataMgr->rdbStore_ = nullptr; std::vector keys; ASSERT_EQ(notificationDataMgr->DeleteBatchData(keys, -1), NativeRdb::E_ERROR); } @@ -532,7 +530,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01300 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); std::vector keys; std::string key = ""; keys.emplace_back(key); @@ -549,7 +547,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01400 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - + notificationDataMgr->rdbStore_ = nullptr; std::string key = ""; std::string value = ""; ASSERT_EQ(notificationDataMgr->QueryData(key, value, -1), NativeRdb::E_ERROR); @@ -565,7 +563,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01500 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); std::string key = ""; std::string value = ""; g_mockQueryRet = true; @@ -582,7 +580,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01600 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); std::string key = ""; std::string value = ""; g_mockQueryRet = false; @@ -602,7 +600,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01700 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - + notificationDataMgr->rdbStore_ = nullptr; std::string key = ""; std::unordered_map values; ASSERT_EQ(notificationDataMgr->QueryDataBeginWithKey(key, values, -1), NativeRdb::E_ERROR); @@ -618,7 +616,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01800 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); g_mockQueryRet = true; std::string key = ""; std::unordered_map values; @@ -635,7 +633,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01900 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); g_mockQueryRet = false; MockHasBlock(true); MockGoToFirstRow(true); @@ -655,7 +653,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02000 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - + notificationDataMgr->rdbStore_ = nullptr; std::unordered_map datas; ASSERT_EQ(notificationDataMgr->QueryAllData(datas, -1), NativeRdb::E_ERROR); } @@ -670,7 +668,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02100 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); g_mockQueryRet = true; std::unordered_map datas; ASSERT_EQ(notificationDataMgr->QueryAllData(datas, -1), NativeRdb::E_ERROR); @@ -686,7 +684,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02200 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); g_mockQueryRet = false; MockHasBlock(true); MockGoToFirstRow(false); @@ -704,7 +702,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02300 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); g_mockQueryRet = false; MockHasBlock(true); MockGoToFirstRow(true); @@ -723,7 +721,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02400 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); g_mockQueryRet = false; MockHasBlock(true); MockGoToFirstRow(true); @@ -742,7 +740,7 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoWreDataCallBack_0250 NotificationRdbConfig notificationRdbConfig; std::unique_ptr notificationDataMgr = std::make_unique(notificationRdbConfig); - MockRdbStore(std::make_shared()); + notificationDataMgr->rdbStore_ = std::make_shared(); ASSERT_EQ(notificationDataMgr->DropUserTable(-1), NativeRdb::E_OK); } -- Gitee