From cc0cccc2108adf91648adc8db7edae14f23f0afa Mon Sep 17 00:00:00 2001 From: archane Date: Sat, 26 Jul 2025 17:10:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=97=B6=E9=97=B4=E9=97=B4=E9=9A=94=EF=BC=8C?= =?UTF-8?q?=E5=BB=B6=E9=95=BF=E8=87=B3=E6=9C=80=E9=95=BF1=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: archane Change-Id: Idd5d81a80ea8d4798b14115c7c39b58f12be92f4 --- .../service/data_share/common/db_delegate.cpp | 8 +- .../service/data_share/common/db_delegate.h | 2 +- .../service/data_share/common/kv_delegate.cpp | 50 +++- .../service/data_share/common/kv_delegate.h | 3 + .../data_share/data_share_service_impl.cpp | 2 +- .../data_share/dfx/hiview_fault_adapter.h | 1 + .../service/test/BUILD.gn | 2 +- .../data_share_scheduler_manager_test.cpp | 4 +- .../service/test/kv_dalegate_test.cpp | 278 +++++++++++++++++- 9 files changed, 325 insertions(+), 25 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.cpp b/services/distributeddataservice/service/data_share/common/db_delegate.cpp index 2a3e97079..06c408e75 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/db_delegate.cpp @@ -167,13 +167,13 @@ void DBDelegate::EraseStoreCache(const int32_t tokenId) storesEncrypt_.Erase(tokenId); } -std::shared_ptr KvDBDelegate::GetInstance( - bool reInit, const std::string &dir, const std::shared_ptr &executors) +std::shared_ptr KvDBDelegate::GetInstance(const std::string &dir, + const std::shared_ptr &executors) { static std::shared_ptr delegate = nullptr; static std::mutex mutex; std::lock_guard lock(mutex); - if ((delegate == nullptr || reInit) && executors != nullptr) { + if (delegate == nullptr && executors != nullptr) { delegate = std::make_shared(dir, executors); } return delegate; @@ -215,4 +215,4 @@ const std::string &KvData::GetId() const } KvData::KvData(const Id &id) : id(DistributedData::Serializable::Marshall(id)) {} -} // namespace OHOS::DataShare \ No newline at end of file +} // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index a59a516c4..804a67633 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -129,7 +129,7 @@ public: static constexpr const char *DATA_TABLE = "data_"; static constexpr const char *PROXYDATA_TABLE = "proxydata_"; static std::shared_ptr GetInstance( - bool reInit = false, const std::string &dir = "", const std::shared_ptr &executors = nullptr); + const std::string &dir = "", const std::shared_ptr &executors = nullptr); virtual ~KvDBDelegate() = default; virtual std::pair Upsert(const std::string &collectionName, const KvData &value) = 0; virtual std::pair Delete(const std::string &collectionName, const std::string &filter) = 0; diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp index 8afa880df..1c2375d43 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp @@ -15,6 +15,7 @@ #define LOG_TAG "KvAdaptor" #include +#include #include #include #include @@ -23,14 +24,16 @@ #include "datashare_errno.h" #include "directory/directory_manager.h" +#include "hiview_fault_adapter.h" #include "grd_base/grd_error.h" #include "grd_document/grd_document_api.h" #include "ipc_skeleton.h" #include "log_print.h" #include "log_debug.h" +#include "time_service_client.h" namespace OHOS::DataShare { -constexpr int WAIT_TIME = 30; +constexpr int64_t TIME_LIMIT_BY_MILLISECONDS = 18 * 3600 * 1000; // 18 hours // If using multi-process access, back up dataShare.db.map as well. Check config file to see whether // using multi-process maccess @@ -126,6 +129,8 @@ bool KvDelegate::RestoreIfNeed(int32_t dbStatus) db_ = nullptr; isInitDone_ = false; } + DataShareFaultInfo faultInfo{HiViewFaultAdapter::kvDBCorrupt, "", "", "", __FUNCTION__, dbStatus, ""}; + HiViewFaultAdapter::ReportDataFault(faultInfo); // If db is NULL, it has been closed. Restore(); return true; @@ -185,11 +190,39 @@ std::pair KvDelegate::Delete(const std::string &collectionName return std::make_pair(E_OK, deleteCount); } +void KvDelegate::ScheduleBackup() +{ + auto currTime = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs(); + if (currTime < 0) { + // Only do an error log print since schedule time does not rely on the time gets by GetBootTimeMs(). + ZLOGE("GetBootTimeMs failed, status %{public}" PRId64 "", currTime); + } else { + absoluteWaitTime_ = currTime + TIME_LIMIT_BY_MILLISECONDS; + } + + taskId_ = executors_->Schedule(std::chrono::seconds(waitTime_), [this]() { + std::lock_guard lock(mutex_); + GRD_DBClose(db_, GRD_DB_CLOSE); + db_ = nullptr; + isInitDone_ = false; + taskId_ = ExecutorPool::INVALID_TASK_ID; + Backup(); + }); +} + bool KvDelegate::Init() { if (isInitDone_) { if (executors_ != nullptr) { - executors_->Reset(taskId_, std::chrono::seconds(WAIT_TIME)); + auto currTime = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs(); + if (currTime < 0) { + ZLOGE("GetBootTimeMs failed, status %{public}" PRId64 "", currTime); + // still return true since kv can work normally + return true; + } + if (currTime < absoluteWaitTime_) { + executors_->Reset(taskId_, std::chrono::seconds(waitTime_)); + } } return true; } @@ -201,14 +234,8 @@ bool KvDelegate::Init() return false; } if (executors_ != nullptr) { - taskId_ = executors_->Schedule(std::chrono::seconds(WAIT_TIME), [this]() { - std::lock_guard lock(mutex_); - GRD_DBClose(db_, GRD_DB_CLOSE); - db_ = nullptr; - isInitDone_ = false; - taskId_ = ExecutorPool::INVALID_TASK_ID; - Backup(); - }); + // schedule first backup task + ScheduleBackup(); } status = GRD_CreateCollection(db_, TEMPLATE_TABLE, nullptr, 0); if (status != GRD_OK) { @@ -233,7 +260,6 @@ bool KvDelegate::Init() RestoreIfNeed(status); return false; } - isInitDone_ = true; return true; } @@ -377,4 +403,4 @@ KvDelegate::KvDelegate(const std::string &path, const std::shared_ptr executors_ = nullptr; ExecutorPool::TaskId taskId_ = ExecutorPool::INVALID_TASK_ID; bool hasChange_ = false; + int64_t absoluteWaitTime_ = 0; + int64_t waitTime_ = 6 * 3600; // 6 hours }; } // namespace OHOS::DataShare #endif // DATASHARESERVICE_KV_DELEGATE_H diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index e00ac7c17..9fca1eee9 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -599,7 +599,7 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) saveMeta.uid = IPCSkeleton::GetCallingUid(); saveMeta.storeType = DATA_SHARE_SINGLE_VERSION; saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); - KvDBDelegate::GetInstance(false, saveMeta.dataDir, binderInfo.executors); + KvDBDelegate::GetInstance(saveMeta.dataDir, binderInfo.executors); SchedulerManager::GetInstance().SetExecutorPool(binderInfo.executors); ExtensionAbilityManager::GetInstance().SetExecutorPool(binderInfo.executors); DBDelegate::SetExecutorPool(binderInfo.executors); diff --git a/services/distributeddataservice/service/data_share/dfx/hiview_fault_adapter.h b/services/distributeddataservice/service/data_share/dfx/hiview_fault_adapter.h index 3b001e62d..bb4910033 100644 --- a/services/distributeddataservice/service/data_share/dfx/hiview_fault_adapter.h +++ b/services/distributeddataservice/service/data_share/dfx/hiview_fault_adapter.h @@ -41,6 +41,7 @@ public: static constexpr const char* timeOut = "TIME_OUT"; static constexpr const char* resultsetFull = "RESULTSET_FULL"; static constexpr const char* curdFailed = "CURD_FAILED"; + static constexpr const char* kvDBCorrupt = "KVDB_CORRUPT"; static void ReportDataFault(const DataShareFaultInfo &faultInfo); static std::pair GetCallingName(uint32_t callingTokenid); }; diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 10c253d20..c15cb3295 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -1156,6 +1156,7 @@ ohos_unittest("DataShareServiceImplTest") { include_dirs = [ "${data_service_path}/service/config/include", "${data_service_path}/framework/include/metadata", + "${data_service_path}/service/data_share/common", ] sources = [ @@ -1261,7 +1262,6 @@ ohos_unittest("DataShareServiceImplTest") { "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddb", - "kv_store:distributeddb", "qos_manager:concurrent_task_client", "qos_manager:qos", "relational_store:native_rdb", diff --git a/services/distributeddataservice/service/test/data_share_scheduler_manager_test.cpp b/services/distributeddataservice/service/test/data_share_scheduler_manager_test.cpp index ba2cc75f1..60e6b8a3a 100644 --- a/services/distributeddataservice/service/test/data_share_scheduler_manager_test.cpp +++ b/services/distributeddataservice/service/test/data_share_scheduler_manager_test.cpp @@ -54,7 +54,7 @@ HWTEST_F(DataShareSchedulerManagerTest, EnableScheduler001, TestSize.Level1) tplt.scheduler_ = "scheduler test"; std::string dataDir = "/data/service/el1/public/database/distributeddata/kvdb"; std::shared_ptr executors = std::make_shared(1, 1); - auto kvDelegate = KvDBDelegate::GetInstance(false, dataDir, executors); + auto kvDelegate = KvDBDelegate::GetInstance(dataDir, executors); ASSERT_NE(kvDelegate, nullptr); TemplateData data(key.uri, key.bundleName, key.subscriberId, USER_TEST, tplt); auto ret = kvDelegate->Upsert(KvDBDelegate::TEMPLATE_TABLE, data); @@ -95,7 +95,7 @@ HWTEST_F(DataShareSchedulerManagerTest, DisableScheduler001, TestSize.Level1) tplt.scheduler_ = "scheduler test"; std::string dataDir = "/data/service/el1/public/database/distributeddata/kvdb"; std::shared_ptr executors = std::make_shared(1, 1); - auto kvDelegate = KvDBDelegate::GetInstance(false, dataDir, executors); + auto kvDelegate = KvDBDelegate::GetInstance(dataDir, executors); ASSERT_NE(kvDelegate, nullptr); TemplateData data(key.uri, key.bundleName, key.subscriberId, USER_TEST, tplt); auto ret = kvDelegate->Upsert(KvDBDelegate::TEMPLATE_TABLE, data); diff --git a/services/distributeddataservice/service/test/kv_dalegate_test.cpp b/services/distributeddataservice/service/test/kv_dalegate_test.cpp index 4920e91b2..cbdb329dd 100644 --- a/services/distributeddataservice/service/test/kv_dalegate_test.cpp +++ b/services/distributeddataservice/service/test/kv_dalegate_test.cpp @@ -16,19 +16,24 @@ #include #include +#include +#include +#include #include "data_share_profile_config.h" +#include "db_delegate.h" #include "executor_pool.h" -#include "grd_error.h" +#include "grd_base/grd_error.h" #include "kv_delegate.h" #include "log_print.h" +#include "proxy_data_manager.h" +#include "parameters.h" namespace OHOS::Test { using namespace testing::ext; using namespace OHOS::DataShare; class KvDelegateTest : public testing::Test { public: - static constexpr int64_t USER_TEST = 100; - static void SetUpTestCase(void){}; + static void SetUpTestCase(void); static void TearDownTestCase(void){}; void SetUp(){}; void TearDown(){}; @@ -42,6 +47,49 @@ const char* g_backupFiles[] = { }; const char* BACKUP_SUFFIX = ".backup"; std::shared_ptr executors = std::make_shared(5, 3); +bool g_isRK3568 = false; + +void KvDelegateTest::SetUpTestCase(void) +{ + static std::once_flag flag; + static std::string product; + const std::string invalidProduct { "default" }; + std::call_once(flag, []() { + product = OHOS::system::GetParameter("const.build.product", ""); + }); + if (product == invalidProduct) { + std::cout << "This test is not for " << invalidProduct << ", skip it." << std::endl; + g_isRK3568 = true; + return; + } +} + +bool FileComparison(const std::string& file1, const std::string& file2) +{ + std::ifstream f1(file1, std::ios::binary); + std::ifstream f2(file2, std::ios::binary); + + if (!f1.is_open() || !f2.is_open()) { + ZLOGI("fail to open files!"); + return false; // fail to open files + } + + // compare file size + f1.seekg(0, std::ios::end); + f2.seekg(0, std::ios::end); + if (f1.tellg() != f2.tellg()) { + ZLOGI("File size is different!"); + return false; + } + f1.seekg(0); + f2.seekg(0); + + return std::equal( + std::istreambuf_iterator(f1), + std::istreambuf_iterator(), + std::istreambuf_iterator(f2) + ); +} /** * @tc.name: RestoreIfNeedt001 @@ -398,6 +446,228 @@ HWTEST_F(KvDelegateTest, GetBatch002, TestSize.Level1) std::vector result; auto result1 = kvDelegate.GetBatch(collectionName, filter, projection, result); EXPECT_EQ(result1, GRD_INVALID_ARGS); - ZLOGI("GetBatch001 end"); + ZLOGI("GetBatch002 end"); +} + +/** +* @tc.name: KVDelegateGetInstanceTest001 +* @tc.desc: Test KvDelegate::GetInstance() function when both delegate and executors are null. +* @tc.type: FUNC +* @tc.require:issueICNFIF +* @tc.precon: None +* @tc.step: + 1.Call KvDBDelegate::GetInstance() to initialize kvDBDelegate. +* @tc.experct: Init failed. delegate is nullptr. +*/ +HWTEST_F(KvDelegateTest, KVDelegateGetInstanceTest001, TestSize.Level0) { + ZLOGI("KVDelegateGetInstanceTest001 start"); + auto delegate = KvDBDelegate::GetInstance("/data/test", nullptr); + EXPECT_EQ(delegate, nullptr); + ZLOGI("KVDelegateGetInstanceTest001 end"); +} + +/** +* @tc.name: KVDelegateGetInstanceTest002 +* @tc.desc: Test KvDelegate::GetInstance() function when delegate is null and executors is not null. +* @tc.type: FUNC +* @tc.require:issueICNFIF +* @tc.precon: None +* @tc.step: + 1.Call KvDBDelegate::GetInstance() to initialize kvDBDelegate. + 2.Call KvDBDelegate::GetInstance() to get kvDelegate when delegate is already initialized. +* @tc.experct: Init failed. delegate is nullptr. +*/ +HWTEST_F(KvDelegateTest, KVDelegateGetInstanceTest002, TestSize.Level0) { + ZLOGI("KVDelegateGetInstanceTest002 start"); + auto executors = std::make_shared(2, 1); + auto delegate = KvDBDelegate::GetInstance("/data/test", executors); + EXPECT_NE(delegate, nullptr); + delegate = KvDBDelegate::GetInstance("/data/test", executors); + EXPECT_NE(delegate, nullptr); + ZLOGI("KVDelegateGetInstanceTest002 end"); +} + +/** +* @tc.name: KVDelegateGetInstanceTest003 +* @tc.desc: Test KvDelegate::GetInstance() function when delegate is not null and executors is null. +* @tc.type: FUNC +* @tc.require:issueICNFIF +* @tc.precon: None +* @tc.step: + 1.Call KvDBDelegate::GetInstance() to initialize kvDBDelegate. + 2.Call KvDBDelegate::GetInstance() with empty executors to get kvDelegate when delegate is already initialized +* @tc.experct: Init failed. delegate is nullptr. +*/ +HWTEST_F(KvDelegateTest, KVDelegateGetInstanceTest003, TestSize.Level0) { + ZLOGI("KVDelegateGetInstanceTest003 start"); + auto executors = std::make_shared(2, 1); + auto delegate = KvDBDelegate::GetInstance("/data/test", executors); + EXPECT_NE(delegate, nullptr); + delegate = KvDBDelegate::GetInstance("/data/test", nullptr); + EXPECT_NE(delegate, nullptr); + ZLOGI("KVDelegateGetInstanceTest003 end"); +} + +/** +* @tc.name: KVDelegateResetBackupTest001 +* @tc.desc: Test KvDelegate::Init() when does not satisfy reset schedule conditions. Insert two datasets with the + second time waitTime_ set to 3600s. First scheduled backup waitTime is 1s. absoluteWaitTime_ is set + to 0ms to make sure backup schedule will not be reset to wait another 3600, First scheduled backup should be + done and not reset, and second inserted data should be included in the backup process, thus the backup + database should remain same as the original database with two dataset. +* @tc.type: FUNC +* @tc.require:issueICNFIF +* @tc.precon: None +* @tc.step: + 1.Initilize a KvDelegate object. + 2.set waitTime_ to 1s. + 3.call Upsert() to insert a dataset. + 4.Call NotifyBackup() to set hasChange_ condition to true to allow backup. + 5.Keep scheduled backup from being reset by setting absoluteWaitTime_ to 0ms. + 6.Set waitTime_ to 3600s to make sure if backup schedule resets, it will be reset to 3600s. + 7.call Upsert() to insert another dataset. + 8.Call NotifyBackup() to set hasChange_ condition to true to allow backup. +* @tc.experct: backup file should be the same as original file. +*/ +HWTEST_F(KvDelegateTest, KVDelegateResetBackupTest001, TestSize.Level0) { + if (g_isRK3568) { + GTEST_SKIP(); + } + ZLOGI("KVDelegateResetBackupTest001 start"); + auto executors = std::make_shared(2, 1); + auto delegate = new KvDelegate("/data/test", executors); + delegate->waitTime_ = 2; // 1s + std::vector proxyDataList = {"name", "age", "job"}; + std::vector proxyDataList1 = {"test", "hellow", "world"}; + auto value = ProxyDataList(ProxyDataListNode(proxyDataList, 24, 12)); + auto value1 = ProxyDataList(ProxyDataListNode(proxyDataList1, 10, 24)); + auto result = delegate->Upsert("proxydata_", value); + delegate->NotifyBackup(); + EXPECT_EQ(result.first, 0); + + // Set absoluteWaitTime_ to 0ms to make sure backup schedule will not be reset to wait another 3600s. + delegate->absoluteWaitTime_ = 0; + delegate->waitTime_ = 3600; + auto result1 = delegate->Upsert("proxydata_", value1); + delegate->NotifyBackup(); + EXPECT_EQ(result1.first, 0); + // First scheduled backup waitTime is 1s. Margin of error is 1s. + sleep(2); + // Backup shoud be done because schdule did not reset. + for (auto &fileName : g_backupFiles) { + std::string src = delegate->path_ + "/" + fileName; + std::string dst = src; + dst.append(BACKUP_SUFFIX); + EXPECT_TRUE(FileComparison(src, dst)); + } + ZLOGI("KVDelegateResetBackupTest001 end"); +} + +/** +* @tc.name: KVDelegateRestoreTest001 +* @tc.desc: Test RestoreIfNeed() after backup is done +* @tc.type: FUNC +* @tc.require:issueICNFIF +* @tc.precon: None +* @tc.step: + 1.Creat a KvDelegate object with an initialized executorPool. + 2.Set waitTime_ to 2s. + 3.Call Upsert() to insert a dataset. + 4.Get the dataset just inserted. + 5.Call NotifyBackup() to set hasChange_ condition to true to allow backup. + 6.Call FileComparison() to compare original database with backup database. + 7.Delete original database and call RestoreIfNeed() with GRD_REBUILD_DATABASE as input param. +* @tc.experct: Successfully Get the dataset previously inserted. +*/ +HWTEST_F(KvDelegateTest, KVDelegateRestoreTest001, TestSize.Level1) { + if (g_isRK3568) { + GTEST_SKIP(); + } + ZLOGI("KVDelegateRestoreTest001 start"); + auto executors = std::make_shared(2, 1); + auto delegate = new KvDelegate("/data/test", executors); + delegate->waitTime_ = 1; + std::vector proxyDataList = {"name", "age", "job"}; + auto value = ProxyDataList(ProxyDataListNode(proxyDataList, 24, 12)); + auto result = delegate->Upsert("proxydata_", value); + delegate->NotifyBackup(); + EXPECT_EQ(result.first, 0); + Id id = Id(std::to_string(12), 24); + std::string queryResult = ""; + + auto result1 = delegate->Get("proxydata_", id, queryResult); + + EXPECT_EQ(result1, 0); + // Scheduled backup waitTime is 1s, 1s for margin of error. + sleep(2); + for (auto &fileName : g_backupFiles) { + std::string src = delegate->path_ + "/" + fileName; + std::string dst = src; + dst.append(BACKUP_SUFFIX); + EXPECT_TRUE(FileComparison(src, dst)); + } + + EXPECT_EQ(std::remove("/data/test/dataShare.db"), 0); + bool restoreRet = delegate->RestoreIfNeed(GRD_REBUILD_DATABASE); + EXPECT_TRUE(restoreRet); + + std::string queryRetAfterRestore = ""; + result1 = delegate->Get("proxydata_", id, queryRetAfterRestore); + EXPECT_EQ(result1, 0); + ZLOGI("KVDelegateRestoreTest001 end"); +} + +/** +* @tc.name: KVDelegateInitTest001 +* @tc.desc: Test KvDelegate::Init() function when executors_ are null. +* @tc.type: FUNC +* @tc.require:issueICNFIF +* @tc.precon: None +* @tc.step: + 1.Initilize a KvDelegate object. + 2.Set executors_ to nullptr. + 3.Call Init() function. + 4.Call Init() function again. +* @tc.experct: Database init success, db_ is not nullptr. +*/ +HWTEST_F(KvDelegateTest, KVDelegateInitTest001, TestSize.Level0) { + ZLOGI("KVDelegateInitTest001 start"); + auto executors = std::make_shared(2, 1); + auto delegate = new KvDelegate("/data/test", executors); + EXPECT_NE(delegate, nullptr); + delegate->executors_ = nullptr; + bool result = delegate->Init(); + EXPECT_TRUE(result); + EXPECT_NE(delegate->db_, nullptr); + EXPECT_TRUE(delegate->isInitDone_); + EXPECT_EQ(delegate->absoluteWaitTime_, 0); + bool result1 = delegate->Init(); + EXPECT_TRUE(result1); + EXPECT_TRUE(delegate->isInitDone_); + ZLOGI("KVDelegateInitTest001 end"); +} + +/** +* @tc.name: KVDelegateInitTest002 +* @tc.desc: Test KvDelegate::Init() function when executors_ is not null. +* @tc.type: FUNC +* @tc.require:issueICNFIF +* @tc.precon: None +* @tc.step: + 1.Initilize a KvDelegate object. + 2.call Init() function. +* @tc.experct: Init success. Schedule success, taskId is not invalid. +*/ +HWTEST_F(KvDelegateTest, KVDelegateInitTest002, TestSize.Level0) { + ZLOGI("KVDelegateInitTest002 start"); + auto executors = std::make_shared(2, 1); + auto delegate = new KvDelegate("/data/test", executors); + bool result = delegate->Init(); + EXPECT_TRUE(result); + EXPECT_NE(delegate->db_, nullptr); + EXPECT_TRUE(delegate->isInitDone_); + EXPECT_NE(delegate->absoluteWaitTime_, 0); + EXPECT_NE(delegate->taskId_, ExecutorPool::INVALID_TASK_ID); + ZLOGI("KVDelegateInitTest002 end"); } } // namespace OHOS::Test \ No newline at end of file -- Gitee