添加端端同步兜底方案

Signed-off-by: m30043719 <maxiaodong25@huawei.com>
This commit is contained in:
m30043719 2024-08-08 20:35:19 +08:00
parent 360c22962a
commit 4ea11240d1
13 changed files with 565 additions and 15 deletions

View File

@ -218,6 +218,7 @@ ohos_shared_library("distributedschedsvr") {
"src/mission/distributed_sched_mission_manager.cpp",
"src/mission/dms_continue_recv_manager.cpp",
"src/mission/dms_continue_send_manager.cpp",
"src/mission/dsched_sync_e2e.cpp",
"src/mission/kvstore_death_recipient.cpp",
"src/mission/mission_changed_notify.cpp",
"src/mission/mission_info_converter.cpp",

View File

@ -290,6 +290,7 @@ private:
void RemoveConnectAbilityInfo(const std::string& deviceId);
void InitWifiStateListener();
void NotifyContinuateEventResult(int32_t resultCode, const EventNotify& event);
void InitDeviceCfg();
void NotifyCollaborateEventResult(int32_t resultCode, const EventNotify& event);
void GetContinueEventInfo(int32_t callingUid, std::vector<EventNotify> &events);
void GetCollaborateEventInfo(int32_t callingUid, std::vector<EventNotify> &events);

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DSCHED_SYNC_E2E_H
#define DSCHED_SYNC_E2E_H
#include "distributed_sched_utils.h"
#include "dtbschedmgr_device_info_storage.h"
#include "mission/distributed_bm_storage.h"
namespace OHOS {
namespace DistributedSchedule {
using namespace AppExecFwk;
using namespace DistributedKv;
class DmsKvSyncCB : public OHOS::DistributedKv::KvStoreSyncCallback {
public:
DmsKvSyncCB();
virtual ~DmsKvSyncCB();
void SyncCompleted(const std::map<std::string, DistributedKv::Status> &result) override;
};
class DmsKvSyncE2E {
public:
DmsKvSyncE2E();
~DmsKvSyncE2E();
static std::shared_ptr<DmsKvSyncE2E> GetInstance();
bool PushAndPullData();
bool PushAndPullData(const std::string &networkId);
void SetDeviceCfg();
bool CheckDeviceCfg();
void SetSyncRecord(const std::string &networkId);
void ClearSyncRecord(const std::string &networkId);
bool IsSynchronized(const std::string &networkId);
private:
void TryTwice(const std::function<DistributedKv::Status()> &func) const;
bool CheckKvStore();
DistributedKv::Status GetKvStore();
static std::mutex mutex_;
static std::shared_ptr<DmsKvSyncE2E> instance_;
const DistributedKv::AppId appId_ {DMS_BM_APP_ID};
const DistributedKv::StoreId storeId_ {DISTRIBUTE_BM_STORE_ID};
DistributedKv::DistributedKvDataManager dataManager_;
std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_;
mutable std::mutex kvStorePtrMutex_;
std::atomic<bool> isCfgDevices_ = false;
std::map<std::string, bool> deviceSyncRecord_;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // DSCHED_SYNC_E2E_H

View File

@ -26,6 +26,7 @@
#include "distributed_sched_utils.h"
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "mission/dsched_sync_e2e.h"
namespace OHOS {
namespace DistributedSchedule {
@ -67,8 +68,12 @@ void DnetworkAdapter::DeviceInitCallBack::OnRemoteDied()
void DnetworkAdapter::DmsDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo& deviceInfo)
{
std::string networkId = deviceInfo.networkId;
HILOGI("OnNodeOnline netwokId: %{public}s.", GetAnonymStr(networkId).c_str());
HILOGI("OnNodeOnline netwokId: %{public}s.", GetAnonymStr(deviceInfo.networkId).c_str());
if (DmsKvSyncE2E::GetInstance()->CheckDeviceCfg()) {
DmsKvSyncE2E::GetInstance()->PushAndPullData(deviceInfo.networkId);
}
DmsKvSyncE2E::GetInstance()->ClearSyncRecord(deviceInfo.networkId);
auto onlineNotifyTask = [deviceInfo]() {
std::lock_guard<std::mutex> autoLock(listenerSetMutex_);
for (auto& listener : listenerSet_) {
@ -86,6 +91,7 @@ void DnetworkAdapter::DmsDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo&
void DnetworkAdapter::DmsDeviceStateCallback::OnDeviceOffline(const DmDeviceInfo& deviceInfo)
{
HILOGI("OnNodeOffline networkId: %{public}s.", GetAnonymStr(deviceInfo.networkId).c_str());
DmsKvSyncE2E::GetInstance()->ClearSyncRecord(deviceInfo.networkId);
auto offlineNotifyTask = [deviceInfo]() {
std::lock_guard<std::mutex> autoLock(listenerSetMutex_);
for (auto& listener : listenerSet_) {

View File

@ -19,6 +19,7 @@
#include "distributed_sched_adapter.h"
#include "distributed_sched_utils.h"
#include "dtbschedmgr_log.h"
#include "mission/dsched_sync_e2e.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "os_account_manager.h"
@ -395,7 +396,8 @@ int32_t BundleManagerInternal::GetBundleNameById(const std::string& networkId,
HILOGD("called.");
bool result = DmsBmStorage::GetInstance()->GetDistributedBundleName(networkId, bundleNameId, bundleName);
if (!result) {
HILOGE("failed to get bundleName by bundleNameId");
HILOGE("failed to get bundleName by bundleNameId, try syncing");
DmsKvSyncE2E::GetInstance()->PushAndPullData(networkId);
return CAN_NOT_FOUND_ABILITY_ERR;
}
HILOGD("end.");

View File

@ -66,7 +66,6 @@ void CommonEventListener::OnReceiveEvent(const EventFwk::CommonEventData &eventD
break;
case USER_SWITCHED :
HILOGI("USER_SWITCHED");
DmsBmStorage::GetInstance()->UpdateDistributedData();
break;
case PACKAGE_ADDED :
HILOGI("PACKAGE_ADDED: %{public}s", want.GetElement().GetBundleName().c_str());

View File

@ -74,6 +74,7 @@
#include "mission/dms_continue_send_manager.h"
#include "mission/dms_continue_recv_manager.h"
#include "mission/distributed_sched_mission_manager.h"
#include "mission/dsched_sync_e2e.h"
#include "mission/wifi_state_listener.h"
#endif
@ -277,6 +278,7 @@ void DistributedSchedService::DeviceOfflineNotify(const std::string& networkId)
bool DistributedSchedService::Init()
{
HILOGD("ready to init.");
InitDeviceCfg();
int32_t ret = LoadContinueConfig();
if (ret != ERR_OK) {
HILOGE("Load continue config fail, ret %{public}d.", ret);
@ -367,6 +369,9 @@ void DistributedSchedService::InitCommonEventListener()
auto applyMonitor = std::make_shared<CommonEventListener>(subscribeInfo);
EventFwk::CommonEventManager::SubscribeCommonEvent(applyMonitor);
DmsBmStorage::GetInstance()->UpdateDistributedData();
if (DmsKvSyncE2E::GetInstance()->CheckDeviceCfg()) {
DmsKvSyncE2E::GetInstance()->PushAndPullData();
}
#endif
}
@ -384,6 +389,12 @@ void DistributedSchedService::InitWifiStateListener()
}
}
void DistributedSchedService::InitDeviceCfg()
{
HILOGI("called");
DmsKvSyncE2E::GetInstance()->SetDeviceCfg();
}
void DistributedSchedService::DurationStart(const std::string srcDeviceId, const std::string dstDeviceId)
{
DmsContinueTime::GetInstance().Init();

View File

@ -24,6 +24,7 @@
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "mission/distributed_sched_mission_manager.h"
#include "mission/dsched_sync_e2e.h"
using namespace OHOS::DistributedKv;
@ -97,9 +98,7 @@ bool DmsBmStorage::SaveStorageDistributeInfo(const std::string &bundleName, bool
AppExecFwk::BundleInfo bundleInfo;
bool ret = bundleMgr->GetBundleInfo(bundleName, FLAGS, bundleInfo, AppExecFwk::Constants::ALL_USERID);
if (!ret || !IsContinuable(bundleInfo)) {
HILOGW("GetBundleInfo of %{public}s failed:%{public}d or cannot be continued",
bundleName.c_str(), ret);
DeleteStorageDistributeInfo(bundleName);
HILOGW("GetBundleInfo of %{public}s failed:%{public}d or cannot be continued", bundleName.c_str(), ret);
return false;
}
std::string localUdid;
@ -385,12 +384,8 @@ bool DmsBmStorage::GetDistributedBundleName(const std::string &networkId, const
return false;
}
bool ret = DealGetBundleName(networkId, bundleNameId, bundleName);
if (!ret) {
HILOGW("get bundleName failed and try to call again");
ret = DealGetBundleName(networkId, bundleNameId, bundleName);
}
if (bundleName == "") {
HILOGE("GetBundleName fail");
if (!ret || bundleName == "") {
HILOGE("get bundleName failed: %{public}d", ret);
return false;
}
HILOGI("end.");

View File

@ -39,8 +39,8 @@ constexpr int32_t ACTIVE = 0;
constexpr int32_t INACTIVE = 1;
constexpr int32_t INDEX_2 = 2;
constexpr int32_t INDEX_3 = 3;
constexpr int32_t DBMS_RETRY_MAX_TIME = 0;
constexpr int32_t DBMS_RETRY_DELAY = 1000;
constexpr int32_t DBMS_RETRY_MAX_TIME = 5;
constexpr int32_t DBMS_RETRY_DELAY = 2000;
const std::string TAG = "DMSContinueRecvMgr";
const std::string DBMS_RETRY_TASK = "retry_on_boradcast_task";
const std::u16string DESCRIPTOR = u"ohos.aafwk.RemoteOnListener";

View File

@ -0,0 +1,233 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mission/dsched_sync_e2e.h"
#include <parameter.h>
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "DmsKvSyncE2E";
const std::string BMS_KV_BASE_DIR = "/data/service/el1/public/database/DistributedSchedule";
const int32_t SLEEP_INTERVAL = 100 * 1000; // 100ms
const int32_t EL1 = 1;
const int32_t MAX_TIMES = 600; // 1min
const char DETERMINE_DEVICE_TYPE_KEY[] = "persist.distributed_scene.sys_settings_data_sync";
} // namespace
std::shared_ptr<DmsKvSyncE2E> DmsKvSyncE2E::instance_ = nullptr;
std::mutex DmsKvSyncE2E::mutex_;
DmsKvSyncE2E::DmsKvSyncE2E()
{
HILOGD("called.");
TryTwice([this] { return GetKvStore(); });
HILOGD("end.");
}
DmsKvSyncE2E::~DmsKvSyncE2E()
{
HILOGD("called.");
dataManager_.CloseKvStore(appId_, storeId_);
HILOGD("end.");
}
std::shared_ptr<DmsKvSyncE2E> DmsKvSyncE2E::GetInstance()
{
HILOGD("called.");
std::lock_guard<std::mutex> lock(mutex_);
if (instance_ == nullptr) {
instance_ = std::make_shared<DmsKvSyncE2E>();
}
HILOGD("end.");
return instance_;
}
void DmsKvSyncE2E::SetDeviceCfg()
{
HILOGI("called.");
const char *syncType = "1";
const int bufferLen = 10;
char paramOutBuf[bufferLen] = {0};
int ret = GetParameter(DETERMINE_DEVICE_TYPE_KEY, "", paramOutBuf, bufferLen);
HILOGI("paramOutBuf: %{public}s, ret: %{public}d", paramOutBuf, ret);
if (ret > 0 && strncmp(paramOutBuf, syncType, strlen(syncType)) == 0) {
HILOGI("Determining the e2e device succeeded.");
isCfgDevices_ = true;
}
}
bool DmsKvSyncE2E::CheckDeviceCfg()
{
HILOGI("called.");
return isCfgDevices_;
}
bool DmsKvSyncE2E::PushAndPullData()
{
HILOGI("called.");
std::vector<std::string> networkIdList = DtbschedmgrDeviceInfoStorage::GetInstance().GetNetworkIdList();
if (networkIdList.empty()) {
HILOGE("GetNetworkIdList failed");
return false;
}
if (!CheckKvStore()) {
HILOGE("kvStore is nullptr");
return false;
}
DistributedKv::DataQuery dataQuery;
std::shared_ptr<DmsKvSyncCB> syncCallback = std::make_shared<DmsKvSyncCB>();
Status status = kvStorePtr_->Sync(networkIdList, DistributedKv::SyncMode::PUSH_PULL, dataQuery, syncCallback);
if (status != Status::SUCCESS) {
HILOGE("sync error: %{public}d", status);
return false;
}
HILOGI("Synchronizing");
return true;
}
bool DmsKvSyncE2E::PushAndPullData(const std::string &networkId)
{
HILOGI("called.");
if (!CheckDeviceCfg() && IsSynchronized(networkId)) {
HILOGW("The normal device been synchronized : %{public}s", GetAnonymStr(networkId).c_str());
return false;
}
std::vector<std::string> networkIdList = {networkId};
if (!CheckKvStore()) {
HILOGE("kvStore is nullptr");
return false;
}
SetSyncRecord(networkId);
DistributedKv::DataQuery dataQuery;
std::shared_ptr<DmsKvSyncCB> syncCallback = std::make_shared<DmsKvSyncCB>();
Status status = kvStorePtr_->Sync(networkIdList, DistributedKv::SyncMode::PUSH_PULL, dataQuery, syncCallback);
if (status != Status::SUCCESS) {
HILOGE("sync error: %{public}d", status);
return false;
}
HILOGI("Synchronizing");
return true;
}
void DmsKvSyncE2E::SetSyncRecord(const std::string &networkId)
{
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
deviceSyncRecord_.insert(std::make_pair(networkId, true));
}
void DmsKvSyncE2E::ClearSyncRecord(const std::string &networkId)
{
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
auto it = deviceSyncRecord_.find(networkId);
if (it != deviceSyncRecord_.end()) {
deviceSyncRecord_.erase(it);
HILOGI("Successfully cleared synchronization records for: %{public}s", GetAnonymStr(networkId).c_str());
} else {
HILOGI("No need to clean up for: %{public}s", GetAnonymStr(networkId).c_str());
}
}
bool DmsKvSyncE2E::IsSynchronized(const std::string &networkId)
{
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
if (deviceSyncRecord_.find(networkId) != deviceSyncRecord_.end() && deviceSyncRecord_[networkId]) {
return true;
}
return false;
}
bool DmsKvSyncE2E::CheckKvStore()
{
HILOGD("called.");
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
if (kvStorePtr_ != nullptr) {
return true;
}
int32_t tryTimes = MAX_TIMES;
while (tryTimes > 0) {
Status status = GetKvStore();
if (status == Status::SUCCESS && kvStorePtr_ != nullptr) {
return true;
}
HILOGW("CheckKvStore, Times: %{public}d", tryTimes);
usleep(SLEEP_INTERVAL);
tryTimes--;
}
HILOGD("end.");
return kvStorePtr_ != nullptr;
}
Status DmsKvSyncE2E::GetKvStore()
{
HILOGI("called.");
Options options = {
.createIfMissing = true,
.encrypt = false,
.autoSync = false,
.isPublic = true,
.securityLevel = SecurityLevel::S1,
.area = EL1,
.kvStoreType = KvStoreType::SINGLE_VERSION,
.baseDir = BMS_KV_BASE_DIR,
.dataType = DataType::TYPE_DYNAMICAL,
.cloudConfig = {
.enableCloud = true,
.autoSync = true
},
};
Status status = dataManager_.GetSingleKvStore(options, appId_, storeId_, kvStorePtr_);
if (status == Status::SUCCESS) {
HILOGI("get kvStore success");
} else if (status == DistributedKv::Status::STORE_META_CHANGED) {
HILOGE("This db meta changed, remove and rebuild it");
dataManager_.DeleteKvStore(appId_, storeId_, BMS_KV_BASE_DIR + appId_.appId);
}
HILOGI("end.");
return status;
}
void DmsKvSyncE2E::TryTwice(const std::function<Status()> &func) const
{
HILOGD("called.");
Status status = func();
if (status != Status::SUCCESS) {
status = func();
HILOGW("error and try to call again, result = %{public}d", status);
}
HILOGD("end.");
}
DmsKvSyncCB::DmsKvSyncCB()
{
HILOGD("create");
}
DmsKvSyncCB::~DmsKvSyncCB()
{
HILOGD("destroy");
}
void DmsKvSyncCB::SyncCompleted(const std::map<std::string, DistributedKv::Status> &result)
{
HILOGI("kvstore sync completed.");
for (auto ele : result) {
HILOGI("uuid: %{public}s , result: %{public}d", GetAnonymStr(ele.first).c_str(), ele.second);
}
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -328,6 +328,7 @@ ohos_unittest("dschedmissionmanagertest") {
"unittest/mission/distributed_mission_info_test.cpp",
"unittest/mission/dms_continue_manager_test.cpp",
"unittest/mission/dms_mission_manager_test.cpp",
"unittest/mission/dsched_sync_e2e_test.cpp",
"unittest/mission/mission_info_converter_test.cpp",
"unittest/mission/snapshot_test.cpp",
"unittest/mock_remote_stub.cpp",

View File

@ -0,0 +1,198 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dsched_sync_e2e_test.h"
#include <thread>
#include "distributed_sched_test_util.h"
#include "dtbschedmgr_device_info_storage.h"
#include "test_log.h"
namespace OHOS {
namespace DistributedSchedule {
using namespace std;
using namespace testing;
using namespace testing::ext;
using namespace OHOS::DistributedKv;
using namespace OHOS::DistributedHardware;
namespace {
const std::string BASEDIR = "/data/service/el1/public/database/DistributedSchedule";
constexpr int32_t TASK_ID_1 = 11;
constexpr int32_t TASK_ID_2 = 12;
constexpr size_t BYTESTREAM_LENGTH = 100;
constexpr uint8_t ONE_BYTE = '6';
}
void DmsKvSyncE2ETest::SetUpTestCase()
{
mkdir(BASEDIR.c_str(), (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
DTEST_LOG << "DmsKvSyncE2ETest::SetUpTestCase" << std::endl;
}
void DmsKvSyncE2ETest::TearDownTestCase()
{
(void)remove(BASEDIR.c_str());
DTEST_LOG << "DmsKvSyncE2ETest::TearDownTestCase" << std::endl;
}
void DmsKvSyncE2ETest::SetUp()
{
DistributedSchedUtil::MockPermission();
dmsKvSyncE2E_ = std::make_shared<DmsKvSyncE2E>();
DTEST_LOG << "DmsKvSyncE2ETest::SetUp" << std::endl;
}
void DmsKvSyncE2ETest::TearDown()
{
DTEST_LOG << "DmsKvSyncE2ETest::TearDown" << std::endl;
}
std::shared_ptr<DmsKvSyncE2E> DmsKvSyncE2ETest::GetDmsKvSyncE2E()
{
if (dmsKvSyncE2E_ == nullptr) {
dmsKvSyncE2E_ = std::make_unique<DmsKvSyncE2E>();
}
return dmsKvSyncE2E_;
}
/**
* @tc.name: PushAndPullDataTest_001
* @tc.desc: test insert DmsKvSyncE2E
* @tc.type: FUNC
*/
HWTEST_F(DmsKvSyncE2ETest, PushAndPullDataTest_001, TestSize.Level1)
{
DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_001 start" << std::endl;
ASSERT_NE(dmsKvSyncE2E_, nullptr);
auto dmsKvSyncE2E = GetDmsKvSyncE2E();
EXPECT_NE(dmsKvSyncE2E, nullptr);
if (dmsKvSyncE2E != nullptr) {
bool ret = dmsKvSyncE2E_->GetInstance()->PushAndPullData();
EXPECT_EQ(ret, false);
}
DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_001 end" << std::endl;
}
/**
* @tc.name: PushAndPullDataTest_002
* @tc.desc: test insert DmsKvSyncE2E
* @tc.type: FUNC
*/
HWTEST_F(DmsKvSyncE2ETest, PushAndPullDataTest_002, TestSize.Level1)
{
DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_002 start" << std::endl;
ASSERT_NE(dmsKvSyncE2E_, nullptr);
auto dmsKvSyncE2E = GetDmsKvSyncE2E();
EXPECT_NE(dmsKvSyncE2E, nullptr);
if (dmsKvSyncE2E != nullptr) {
const std::string networkId = "123";
bool ret = dmsKvSyncE2E_->GetInstance()->PushAndPullData(networkId);
EXPECT_EQ(ret, false);
}
DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_002 end" << std::endl;
}
/**
* @tc.name: SetDeviceCfgTest_001
* @tc.desc: test insert DmsKvSyncE2E
* @tc.type: FUNC
*/
HWTEST_F(DmsKvSyncE2ETest, SetDeviceCfgTest_001, TestSize.Level1)
{
DTEST_LOG << "DmsKvSyncE2ETest SetDeviceCfgTest_001 start" << std::endl;
ASSERT_NE(dmsKvSyncE2E_, nullptr);
auto dmsKvSyncE2E = GetDmsKvSyncE2E();
EXPECT_NE(dmsKvSyncE2E, nullptr);
if (dmsKvSyncE2E != nullptr) {
dmsKvSyncE2E_->GetInstance()->SetDeviceCfg();
}
DTEST_LOG << "DmsKvSyncE2ETest SetDeviceCfgTest_001 end" << std::endl;
}
/**
* @tc.name: CheckDeviceCfgTest_001
* @tc.desc: test insert DmsKvSyncE2E
* @tc.type: FUNC
*/
HWTEST_F(DmsKvSyncE2ETest, CheckDeviceCfgTest_001, TestSize.Level1)
{
DTEST_LOG << "DmsKvSyncE2ETest CheckDeviceCfgTest_001 start" << std::endl;
ASSERT_NE(dmsKvSyncE2E_, nullptr);
auto dmsKvSyncE2E = GetDmsKvSyncE2E();
EXPECT_NE(dmsKvSyncE2E, nullptr);
if (dmsKvSyncE2E != nullptr) {
bool ret = dmsKvSyncE2E_->GetInstance()->CheckDeviceCfg();
EXPECT_EQ(ret, false);
}
DTEST_LOG << "DmsKvSyncE2ETest CheckDeviceCfgTest_001 end" << std::endl;
}
/**
* @tc.name: SetSyncRecordTest_001
* @tc.desc: test insert DmsKvSyncE2E
* @tc.type: FUNC
*/
HWTEST_F(DmsKvSyncE2ETest, SetSyncRecordTest_001, TestSize.Level1)
{
DTEST_LOG << "DmsKvSyncE2ETest SetSyncRecordTest_001 start" << std::endl;
ASSERT_NE(dmsKvSyncE2E_, nullptr);
auto dmsKvSyncE2E = GetDmsKvSyncE2E();
EXPECT_NE(dmsKvSyncE2E, nullptr);
if (dmsKvSyncE2E != nullptr) {
const std::string networkId = "123";
dmsKvSyncE2E_->GetInstance()->SetSyncRecord(networkId);
}
DTEST_LOG << "DmsKvSyncE2ETest SetSyncRecordTest_001 end" << std::endl;
}
/**
* @tc.name: ClearSyncRecordTest_001
* @tc.desc: test insert DmsKvSyncE2E
* @tc.type: FUNC
*/
HWTEST_F(DmsKvSyncE2ETest, ClearSyncRecordTest_001, TestSize.Level1)
{
DTEST_LOG << "DmsKvSyncE2ETest ClearSyncRecordTest_001 start" << std::endl;
ASSERT_NE(dmsKvSyncE2E_, nullptr);
auto dmsKvSyncE2E = GetDmsKvSyncE2E();
EXPECT_NE(dmsKvSyncE2E, nullptr);
if (dmsKvSyncE2E != nullptr) {
const std::string networkId = "123";
dmsKvSyncE2E_->GetInstance()->ClearSyncRecord(networkId);
}
DTEST_LOG << "DmsKvSyncE2ETest ClearSyncRecordTest_001 end" << std::endl;
}
/**
* @tc.name: IsSynchronizedTest_001
* @tc.desc: test insert DmsKvSyncE2E
* @tc.type: FUNC
*/
HWTEST_F(DmsKvSyncE2ETest, IsSynchronizedTest_001, TestSize.Level1)
{
DTEST_LOG << "DmsKvSyncE2ETest IsSynchronizedTest_001 start" << std::endl;
ASSERT_NE(dmsKvSyncE2E_, nullptr);
auto dmsKvSyncE2E = GetDmsKvSyncE2E();
EXPECT_NE(dmsKvSyncE2E, nullptr);
if (dmsKvSyncE2E != nullptr) {
const std::string networkId = "123";
bool ret = dmsKvSyncE2E_->GetInstance()->IsSynchronized(networkId);
EXPECT_EQ(ret, true);
}
DTEST_LOG << "DmsKvSyncE2ETest IsSynchronizedTest_001 end" << std::endl;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DSCHED_SYNC_E2E_TEST_H
#define DSCHED_SYNC_E2E_TEST_H
#include "gtest/gtest.h"
#include "device_manager.h"
#include "mission/dsched_sync_e2e.h"
namespace OHOS {
namespace DistributedSchedule {
class DmsKvSyncE2ETest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
std::shared_ptr<DmsKvSyncE2E> GetDmsKvSyncE2E();
protected:
std::shared_ptr<DmsKvSyncE2E> dmsKvSyncE2E_;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif /* DSCHED_SYNC_E2E_TEST_H */