diff --git a/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp b/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp index 99f347cf56e318515d6c6b361694c37a8ecb5b20..962adbcbfac4c5876b010604437a81118e42c084 100644 --- a/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp +++ b/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp @@ -670,5 +670,54 @@ HWTEST_F(UdmfRunTimeStoreTest, GetSummary, TestSize.Level1) auto status = store->GetSummary(key, summary); ASSERT_EQ(status, E_DB_ERROR); } + +/** +* @tc.name: GetRuntime001 +* @tc.desc: Normal testcase of GetRuntime +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(UdmfRunTimeStoreTest, GetRuntime001, TestSize.Level1) +{ + UnifiedData inputData; + CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; + auto status = PreProcessUtils::RuntimeDataImputation(inputData, option); + EXPECT_EQ(status, E_OK); + auto key = inputData.GetRuntime()->key.GetUnifiedKey(); + + auto store = std::make_shared(STORE_ID); + bool result = store->Init(); + EXPECT_TRUE(result); + status = store->PutRuntime(key, *inputData.GetRuntime()); + EXPECT_EQ(status, E_OK); + + Runtime outRuntime; + status = store->GetRuntime(key, outRuntime); + EXPECT_EQ(status, E_OK); + EXPECT_EQ(inputData.GetRuntime()->createTime, outRuntime.createTime); +} + +/** +* @tc.name: GetRuntime002 +* @tc.desc: Abnormal testcase of GetRuntime +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(UdmfRunTimeStoreTest, GetRuntime002, TestSize.Level1) +{ + UnifiedData inputData; + CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; + auto status = PreProcessUtils::RuntimeDataImputation(inputData, option); + EXPECT_EQ(status, E_OK); + auto key = inputData.GetRuntime()->key.GetUnifiedKey(); + + auto store = std::make_shared(STORE_ID); + bool result = store->Init(); + EXPECT_TRUE(result); + + Runtime outRuntime; + status = store->GetRuntime(key, outRuntime); + EXPECT_EQ(status, E_NOT_FOUND); +} }; // namespace DistributedDataTest }; // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/store/runtime_store.cpp b/services/distributeddataservice/service/udmf/store/runtime_store.cpp index da14366c4cbaf908ff8ad7d93f6fdec860c2f27f..fa6f511e98b815d45800cf80844c12ecfaf13649 100644 --- a/services/distributeddataservice/service/udmf/store/runtime_store.cpp +++ b/services/distributeddataservice/service/udmf/store/runtime_store.cpp @@ -198,6 +198,10 @@ Status RuntimeStore::GetRuntime(const std::string &key, Runtime &runtime) UpdateTime(); Value value; auto res = kvStore_->Get({key.begin(), key.end()}, value); + if (res == NOT_FOUND) { + ZLOGW("Runtime not found, key: %{public}s", key.c_str()); + return E_NOT_FOUND; + } if (res != OK || value.empty()) { ZLOGE("Get failed, key: %{public}s, status:%{public}d", key.c_str(), res); return E_DB_ERROR;