1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "dms_mission_manager_test.h"
17 
18 #include <thread>
19 
20 #include "if_system_ability_manager.h"
21 #include "ipc_skeleton.h"
22 #include "iservice_registry.h"
23 #include "string_ex.h"
24 #include "system_ability_definition.h"
25 
26 #define private public
27 #define protected public
28 #include "distributed_sched_proxy.h"
29 #include "distributed_sched_service.h"
30 #include "distributed_sched_test_util.h"
31 #include "distributed_sched_utils.h"
32 #include "dtbschedmgr_device_info_storage.h"
33 #include "mission/distributed_sched_mission_manager.h"
34 #include "mission/mission_constant.h"
35 #include "mission/snapshot_converter.h"
36 #include "test_log.h"
37 #undef private
38 #undef protected
39 
40 using namespace std;
41 using namespace testing;
42 using namespace testing::ext;
43 using namespace OHOS::DistributedHardware;
44 
45 namespace OHOS {
46 namespace DistributedSchedule {
47 namespace {
48 const std::string DEVICE_NAME = "DEVICE_PHONE_001";
49 const std::string DEVICE_ID = "123456789ABCD";
50 const std::string DEVICE_ID_FALSE = "123456789ABCDF";
51 const std::string DEVICE_ID_FALSE_AGAIN = "123456789ABCDFA";
52 const std::u16string U16DEVICE_ID = u"123456789ABCD";
53 const std::string BUNDLE_NAME = "ohos.test.test";
54 constexpr int32_t TASK_ID = 11;
55 constexpr size_t BYTESTREAM_LENGTH = 100;
56 constexpr uint8_t ONE_BYTE = '6';
57 const int32_t NUM_MISSIONS = 100;
58 const int32_t NORMAL_NUM_MISSIONS = 10;
59 constexpr int32_t REQUEST_CODE_ERR = 305;
60 constexpr int32_t MAX_WAIT_TIME = 1000;
61 }
62 
63 bool DMSMissionManagerTest::isCaseDone_ = false;
64 std::mutex DMSMissionManagerTest::caseDoneLock_;
65 std::condition_variable DMSMissionManagerTest::caseDoneCondition_;
66 
SetUpTestCase()67 void DMSMissionManagerTest::SetUpTestCase()
68 {
69     if (!DistributedSchedUtil::LoadDistributedSchedService()) {
70         DTEST_LOG << "DMSMissionManagerTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
71     }
72     const std::string pkgName = "DBinderBus_" + std::to_string(getprocpid());
73     std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
74     DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
75 }
76 
TearDownTestCase()77 void DMSMissionManagerTest::TearDownTestCase()
78 {
79 }
80 
SetUp()81 void DMSMissionManagerTest::SetUp()
82 {
83     DistributedSchedUtil::MockPermission();
84     string localDeviceId;
85     if (!DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId)) {
86         DTEST_LOG << "getLocalDevicesId failed!" << std::endl;
87         return;
88     }
89     localDeviceId_ = localDeviceId;
90     u16localDeviceId_ = Str8ToStr16(localDeviceId);
91 }
92 
TearDown()93 void DMSMissionManagerTest::TearDown()
94 {
95 }
96 
OnRemoteDied()97 void DMSMissionManagerTest::DeviceInitCallBack::OnRemoteDied()
98 {
99 }
100 
GetDms()101 sptr<IDistributedSched> DMSMissionManagerTest::GetDms()
102 {
103     if (proxy_ != nullptr) {
104         return proxy_;
105     }
106     auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
107     EXPECT_TRUE(sm != nullptr);
108     if (sm == nullptr) {
109         DTEST_LOG << "DMSMissionManagerTest sm is nullptr" << std::endl;
110         return nullptr;
111     }
112     DTEST_LOG << "DMSMissionManagerTest sm is not nullptr" << std::endl;
113     auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
114     proxy_ = iface_cast<IDistributedSched>(distributedObject);
115     if (proxy_ == nullptr) {
116         DTEST_LOG << "DMSMissionManagerTest DistributedSched is nullptr" << std::endl;
117     } else {
118         DTEST_LOG << "DMSMissionManagerTest DistributedSched is not nullptr" << std::endl;
119     }
120     return proxy_;
121 }
122 
NotifyMissionsChanged(const std::string & deviceId)123 void RemoteMissionListenerTest::NotifyMissionsChanged(const std::string& deviceId)
124 {
125     DTEST_LOG << "NotifyMissionsChanged" << std::endl;
126 }
127 
NotifySnapshot(const std::string & deviceId,int32_t missionId)128 void RemoteMissionListenerTest::NotifySnapshot(const std::string& deviceId, int32_t missionId)
129 {
130     DTEST_LOG << "NotifySnapshot" << std::endl;
131 }
132 
NotifyNetDisconnect(const std::string & deviceId,int32_t state)133 void RemoteMissionListenerTest::NotifyNetDisconnect(const std::string& deviceId, int32_t state)
134 {
135     DTEST_LOG << "NotifyNetDisconnect" << std::endl;
136 }
137 
138 /**
139  * @tc.name: testGetRemoteMissionInfo001
140  * @tc.desc: get remote mission info
141  * @tc.type: FUNC
142  */
143 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionInfo001, TestSize.Level1)
144 {
145     std::vector<AAFwk::MissionInfo> infos;
146     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(DEVICE_ID, 0, infos);
147     EXPECT_TRUE(ret != ERR_NONE);
148 
149     ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(localDeviceId_, 0, infos);
150     EXPECT_TRUE(ret != ERR_NONE);
151 
152     ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos("", 0, infos);
153     EXPECT_TRUE(ret != ERR_NONE);
154 
155     ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(DEVICE_ID, -1, infos);
156     EXPECT_TRUE(ret != ERR_NONE);
157 
158     ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(localDeviceId_, -1, infos);
159     EXPECT_TRUE(ret != ERR_NONE);
160 }
161 
162 /**
163  * @tc.name: testGetRemoteMissionInfo002
164  * @tc.desc: get remote mission info
165  * @tc.type: FUNC
166  */
167 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionInfo002, TestSize.Level1)
168 {
169     sptr<IDistributedSched> proxy = GetDms();
170     if (proxy == nullptr) {
171         return;
172     }
173     std::vector<AAFwk::MissionInfo> infos;
174     auto ret = proxy->GetMissionInfos(DEVICE_ID, 0, infos);
175     EXPECT_TRUE(ret != ERR_NONE);
176 
177     ret = proxy->GetMissionInfos(localDeviceId_, 0, infos);
178     EXPECT_TRUE(ret != ERR_NONE);
179 
180     ret = proxy->GetMissionInfos("", 0, infos);
181     EXPECT_TRUE(ret != ERR_NONE);
182 
183     ret = proxy->GetMissionInfos(DEVICE_ID, -1, infos);
184     EXPECT_TRUE(ret != ERR_NONE);
185 
186     ret = proxy->GetMissionInfos(localDeviceId_, -1, infos);
187     EXPECT_TRUE(ret != ERR_NONE);
188 }
189 
190 /**
191  * @tc.name: testStartSyncRemoteMissions001
192  * @tc.desc: prepare and sync missions from remote
193  * @tc.type: FUNC
194  */
195 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions001, TestSize.Level1)
196 {
197     sptr<IDistributedSched> proxy = GetDms();
198     if (proxy == nullptr) {
199         return;
200     }
201     auto ret = proxy->StartSyncRemoteMissions(DEVICE_ID, false, 0);
202     EXPECT_NE(ret, ERR_NONE);
203 }
204 
205 /**
206  * @tc.name: testStartSyncRemoteMissions002
207  * @tc.desc: prepare and sync missions from remote
208  * @tc.type: FUNC
209  */
210 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions002, TestSize.Level1)
211 {
212     sptr<IDistributedSched> proxy = GetDms();
213     if (proxy == nullptr) {
214         return;
215     }
216     auto ret = proxy->StartSyncRemoteMissions("", false, 0);
217     EXPECT_NE(ret, ERR_NONE);
218 }
219 
220 /**
221  * @tc.name: testStartSyncRemoteMissions003
222  * @tc.desc: prepare and sync missions from remote
223  * @tc.type: FUNC
224  */
225 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions003, TestSize.Level1)
226 {
227     sptr<IDistributedSched> proxy = GetDms();
228     if (proxy == nullptr) {
229         return;
230     }
231     auto ret = proxy->StartSyncRemoteMissions(localDeviceId_, false, 0);
232     EXPECT_NE(ret, ERR_NONE);
233 }
234 
235 /**
236  * @tc.name: testStartSyncRemoteMissions004
237  * @tc.desc: prepare and sync missions from remote
238  * @tc.type: FUNC
239  */
240 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions004, TestSize.Level3)
241 {
242     DTEST_LOG << "testStartSyncRemoteMissions004 begin" << std::endl;
243     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
244     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
245     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, false, 0);
246     EXPECT_EQ(ret, ERR_NONE);
247     DTEST_LOG << "testStartSyncRemoteMissions004 end" << std::endl;
248 }
249 /**
250  * @tc.name: testStartSyncRemoteMissions005
251  * @tc.desc: prepare and sync missions from remote
252  * @tc.type: FUNC
253  */
254 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions005, TestSize.Level3)
255 {
256     DTEST_LOG << "testStartSyncRemoteMissions005 begin" << std::endl;
257     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions("", false, 0);
258     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
259     DTEST_LOG << "testStartSyncRemoteMissions005 end" << std::endl;
260 }
261 
262 /**
263  * @tc.name: testStartSyncRemoteMissions006
264  * @tc.desc: prepare and sync missions from remote
265  * @tc.type: FUNC
266  */
267 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions006, TestSize.Level3)
268 {
269     DTEST_LOG << "testStartSyncRemoteMissions006 begin" << std::endl;
270     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(localDeviceId_, false, 0);
271     EXPECT_NE(ret, ERR_NONE);
272     DTEST_LOG << "testStartSyncRemoteMissions006 end" << std::endl;
273 }
274 
275 /**
276  * @tc.name: testStartSyncRemoteMissions007
277  * @tc.desc: prepare and sync missions from remote
278  * @tc.type: FUNC
279  */
280 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions007, TestSize.Level3)
281 {
282     DTEST_LOG << "testStartSyncRemoteMissions007 begin" << std::endl;
283     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
284     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
285     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, true, 0);
286     EXPECT_EQ(ret, ERR_NONE);
287     DTEST_LOG << "testStartSyncRemoteMissions007 end" << std::endl;
288 }
289 
290 /**
291  * @tc.name: testStartSyncRemoteMissions008
292  * @tc.desc: prepare and sync missions from remote
293  * @tc.type: FUNC
294  */
295 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions008, TestSize.Level3)
296 {
297     DTEST_LOG << "testStartSyncRemoteMissions008 begin" << std::endl;
298     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions("", true, 0);
299     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
300     DTEST_LOG << "testStartSyncRemoteMissions008 end" << std::endl;
301 }
302 
303 /**
304  * @tc.name: testStartSyncRemoteMissions009
305  * @tc.desc: prepare and sync missions from remote
306  * @tc.type: FUNC
307  */
308 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions009, TestSize.Level3)
309 {
310     DTEST_LOG << "testStartSyncRemoteMissions009 begin" << std::endl;
311     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(localDeviceId_, true, 0);
312     EXPECT_NE(ret, ERR_NONE);
313     DTEST_LOG << "testStartSyncRemoteMissions009 end" << std::endl;
314 }
315 
316 /**
317  * @tc.name: testStartSyncRemoteMissions010
318  * @tc.desc: prepare and sync missions from remote
319  * @tc.type: FUNC
320  */
321 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions010, TestSize.Level3)
322 {
323     DTEST_LOG << "testStartSyncRemoteMissions010 begin" << std::endl;
324     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
325     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
326     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, true, 1);
327     EXPECT_EQ(ret, ERR_NONE);
328     DTEST_LOG << "testStartSyncRemoteMissions010 end" << std::endl;
329 }
330 
331 /**
332  * @tc.name: testStartSyncRemoteMissions011
333  * @tc.desc: prepare and sync missions from remote
334  * @tc.type: FUNC
335  */
336 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions011, TestSize.Level3)
337 {
338     DTEST_LOG << "testStartSyncRemoteMissions011 begin" << std::endl;
339     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions("", true, 1);
340     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
341     DTEST_LOG << "testStartSyncRemoteMissions011 end" << std::endl;
342 }
343 
344 /**
345  * @tc.name: testStartSyncRemoteMissions012
346  * @tc.desc: prepare and sync missions from remote
347  * @tc.type: FUNC
348  */
349 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions012, TestSize.Level3)
350 {
351     DTEST_LOG << "testStartSyncRemoteMissions012 begin" << std::endl;
352     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(localDeviceId_, true, 1);
353     EXPECT_NE(ret, ERR_NONE);
354     DTEST_LOG << "testStartSyncRemoteMissions012 end" << std::endl;
355 }
356 
357 /**
358  * @tc.name: testStartSyncRemoteMissions013
359  * @tc.desc: prepare and sync missions from remote
360  * @tc.type: FUNC
361  */
362 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions013, TestSize.Level3)
363 {
364     DTEST_LOG << "testStartSyncRemoteMissions013 begin" << std::endl;
365     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, localDeviceId_);
366     EXPECT_EQ(ret, ERR_NONE);
367     DTEST_LOG << "testStartSyncRemoteMissions013 end" << std::endl;
368 }
369 
370 /**
371  * @tc.name: testStartSyncRemoteMissions014
372  * @tc.desc: prepare and sync missions from remote
373  * @tc.type: FUNC
374  */
375 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions014, TestSize.Level3)
376 {
377     DTEST_LOG << "testStartSyncRemoteMissions014 begin" << std::endl;
378     sptr<IDistributedSched> proxy = GetDms();
379     if (proxy == nullptr) {
380         return;
381     }
382     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, proxy);
383     EXPECT_NE(ret, ERR_NONE);
384     DTEST_LOG << "testStartSyncRemoteMissions014 end" << std::endl;
385 }
386 
387 /**
388  * @tc.name: testNeedSyncDevice001
389  * @tc.desc: need sync device
390  * @tc.type: FUNC
391  */
392 HWTEST_F(DMSMissionManagerTest, testNeedSyncDevice001, TestSize.Level3)
393 {
394     DTEST_LOG << "testCleanMissionResources001 begin" << std::endl;
395     bool ret = DistributedSchedMissionManager::GetInstance().NeedSyncDevice(DEVICE_ID);
396     EXPECT_FALSE(ret);
397     DTEST_LOG << "testNeedSyncDevice001 end" << std::endl;
398 }
399 
400 /**
401  * @tc.name: testNeedSyncDevice002
402  * @tc.desc: need sync device
403  * @tc.type: FUNC
404  */
405 HWTEST_F(DMSMissionManagerTest, testNeedSyncDevice002, TestSize.Level3)
406 {
407     DTEST_LOG << "testNeedSyncDevice002 begin" << std::endl;
408     remoteSyncDeviceSet_.emplace(DEVICE_ID);
409     bool ret = DistributedSchedMissionManager::GetInstance().NeedSyncDevice(DEVICE_ID);
410     EXPECT_FALSE(ret);
411     DTEST_LOG << "testNeedSyncDevice002 end" << std::endl;
412 }
413 
414 /**
415  * @tc.name: testHasSyncListener001
416  * @tc.desc: need sync device
417  * @tc.type: FUNC
418  */
419 HWTEST_F(DMSMissionManagerTest, testHasSyncListener001, TestSize.Level3)
420 {
421     DTEST_LOG << "testHasSyncListener001 begin" << std::endl;
422     bool ret = DistributedSchedMissionManager::GetInstance().HasSyncListener(DEVICE_ID);
423     EXPECT_FALSE(ret);
424     DTEST_LOG << "testHasSyncListener001 end" << std::endl;
425 }
426 
427 /**
428  * @tc.name: testCleanMissionResources001
429  * @tc.desc: prepare and sync missions from remote
430  * @tc.type: FUNC
431  */
432 HWTEST_F(DMSMissionManagerTest, testCleanMissionResources001, TestSize.Level3)
433 {
434     DTEST_LOG << "testCleanMissionResources001 begin" << std::endl;
435     DistributedSchedMissionManager::GetInstance().CleanMissionResources(DEVICE_ID);
436     DTEST_LOG << "testCleanMissionResources001 end" << std::endl;
437 }
438 
439 /**
440  * @tc.name: testStopSyncRemoteMissions001
441  * @tc.desc: stop sync missions from remote with fake deviceId
442  * @tc.type: FUNC
443  */
444 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions001, TestSize.Level1)
445 {
446     sptr<IDistributedSched> proxy = GetDms();
447     if (proxy == nullptr) {
448         return;
449     }
450     auto ret = proxy->StopSyncRemoteMissions(DEVICE_ID);
451     EXPECT_NE(ret, ERR_NONE);
452 }
453 
454 /**
455  * @tc.name: testStopSyncRemoteMissions002
456  * @tc.desc: stop sync missions from remote with local deviceId
457  * @tc.type: FUNC
458  */
459 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions002, TestSize.Level1)
460 {
461     sptr<IDistributedSched> proxy = GetDms();
462     if (proxy == nullptr) {
463         return;
464     }
465     auto ret = proxy->StopSyncRemoteMissions(localDeviceId_);
466     EXPECT_NE(ret, ERR_NONE);
467 }
468 
469 /**
470  * @tc.name: testStopSyncRemoteMissions003
471  * @tc.desc: stop sync missions from remote with empty deviceId
472  * @tc.type: FUNC
473  */
474 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions003, TestSize.Level1)
475 {
476     sptr<IDistributedSched> proxy = GetDms();
477     if (proxy == nullptr) {
478         return;
479     }
480     auto ret = proxy->StopSyncRemoteMissions("");
481     EXPECT_NE(ret, ERR_NONE);
482 }
483 
484 /**
485  * @tc.name: testStopSyncRemoteMissions004
486  * @tc.desc: stop sync missions from remote with empty deviceId
487  * @tc.type: FUNC
488  */
489 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions004, TestSize.Level3)
490 {
491     DTEST_LOG << "testStopSyncRemoteMissions004 begin" << std::endl;
492     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions("", false, true);
493     EXPECT_NE(ret, ERR_NONE);
494     DTEST_LOG << "testStopSyncRemoteMissions004 end" << std::endl;
495 }
496 
497 /**
498  * @tc.name: testStopSyncRemoteMissions005
499  * @tc.desc: stop sync missions from remote with local deviceId
500  * @tc.type: FUNC
501  */
502 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions005, TestSize.Level3)
503 {
504     DTEST_LOG << "testStopSyncRemoteMissions005 begin" << std::endl;
505     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(localDeviceId_, false, true);
506     EXPECT_NE(ret, ERR_NONE);
507     DTEST_LOG << "testStopSyncRemoteMissions005 end" << std::endl;
508 }
509 
510 /**
511  * @tc.name: testStopSyncRemoteMissions006
512  * @tc.desc: stop sync missions from remote with deviceId
513  * @tc.type: FUNC
514  */
515 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions006, TestSize.Level3)
516 {
517     DTEST_LOG << "testStopSyncRemoteMissions006 begin" << std::endl;
518     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(DEVICE_ID, false, true);
519     EXPECT_NE(ret, ERR_NONE);
520     DTEST_LOG << "testStopSyncRemoteMissions006 end" << std::endl;
521 }
522 
523 /**
524  * @tc.name: testStopSyncRemoteMissions007
525  * @tc.desc: stop sync missions from remote with empty deviceId
526  * @tc.type: FUNC
527  */
528 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions007, TestSize.Level3)
529 {
530     DTEST_LOG << "testStopSyncRemoteMissions007 begin" << std::endl;
531     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions("", true, true);
532     EXPECT_EQ(ret, ERR_NONE);
533     DTEST_LOG << "testStopSyncRemoteMissions007 end" << std::endl;
534 }
535 
536 /**
537  * @tc.name: testStopSyncRemoteMissions008
538  * @tc.desc: stop sync missions from remote with local deviceId
539  * @tc.type: FUNC
540  */
541 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions008, TestSize.Level3)
542 {
543     DTEST_LOG << "testStopSyncRemoteMissions008 begin" << std::endl;
544     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(localDeviceId_, true, true);
545     EXPECT_EQ(ret, ERR_NONE);
546     DTEST_LOG << "testStopSyncRemoteMissions008 end" << std::endl;
547 }
548 
549 /**
550  * @tc.name: testStopSyncRemoteMissions009
551  * @tc.desc: stop sync missions from remote with deviceId
552  * @tc.type: FUNC
553  */
554 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions009, TestSize.Level3)
555 {
556     DTEST_LOG << "testStopSyncRemoteMissions009 begin" << std::endl;
557     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(DEVICE_ID, true, true);
558     EXPECT_EQ(ret, ERR_NONE);
559     DTEST_LOG << "testStopSyncRemoteMissions009 end" << std::endl;
560 }
561 
562 /**
563  * @tc.name: testStopSyncRemoteMissions010
564  * @tc.desc: stop sync missions from remote with empty deviceId
565  * @tc.type: FUNC
566  */
567 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions010, TestSize.Level3)
568 {
569     DTEST_LOG << "testStopSyncRemoteMissions010 begin" << std::endl;
570     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions("", true, false);
571     EXPECT_EQ(ret, ERR_NONE);
572     DTEST_LOG << "testStopSyncRemoteMissions010 end" << std::endl;
573 }
574 
575 /**
576  * @tc.name: testStopSyncRemoteMissions011
577  * @tc.desc: stop sync missions from remote with local deviceId
578  * @tc.type: FUNC
579  */
580 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions011, TestSize.Level3)
581 {
582     DTEST_LOG << "testStopSyncRemoteMissions011 begin" << std::endl;
583     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(localDeviceId_, true, false);
584     EXPECT_EQ(ret, ERR_NONE);
585     DTEST_LOG << "testStopSyncRemoteMissions011 end" << std::endl;
586 }
587 
588 /**
589  * @tc.name: testStopSyncRemoteMissions012
590  * @tc.desc: stop sync missions from remote with deviceId
591  * @tc.type: FUNC
592  */
593 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions012, TestSize.Level3)
594 {
595     DTEST_LOG << "testStopSyncRemoteMissions012 begin" << std::endl;
596     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(DEVICE_ID, true, false);
597     EXPECT_EQ(ret, ERR_NONE);
598     DTEST_LOG << "testStopSyncRemoteMissions012 end" << std::endl;
599 }
600 
601 /**
602  * @tc.name: testRegisterMissionListener001
603  * @tc.desc: register mission listener
604  * @tc.type: FUNC
605  */
606 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener001, TestSize.Level1)
607 {
608     sptr<IDistributedSched> proxy = GetDms();
609     if (proxy == nullptr) {
610         return;
611     }
612     auto ret = proxy->RegisterMissionListener(U16DEVICE_ID, nullptr);
613     EXPECT_TRUE(ret != ERR_NONE);
614 
615     ret = proxy->RegisterMissionListener(u16localDeviceId_, nullptr);
616     EXPECT_TRUE(ret != ERR_NONE);
617 
618     ret = proxy->RegisterMissionListener(u"", nullptr);
619     EXPECT_TRUE(ret != ERR_NONE);
620 }
621 
622 /**
623  * @tc.name: testRegisterMissionListener002
624  * @tc.desc: register mission listener
625  * @tc.type: FUNC
626  */
627 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener002, TestSize.Level1)
628 {
629     sptr<IDistributedSched> proxy = GetDms();
630     if (proxy == nullptr) {
631         return;
632     }
633     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
634     auto ret = proxy->RegisterMissionListener(U16DEVICE_ID, listener);
635     EXPECT_TRUE(ret != ERR_NONE);
636 
637     ret = proxy->RegisterMissionListener(u16localDeviceId_, listener);
638     EXPECT_TRUE(ret != ERR_NONE);
639 
640     ret = proxy->RegisterMissionListener(u"", listener);
641     EXPECT_TRUE(ret != ERR_NONE);
642 
643     ret = proxy->UnRegisterMissionListener(U16DEVICE_ID, listener);
644     EXPECT_TRUE(ret != ERR_NONE);
645 
646     ret = proxy->UnRegisterMissionListener(u16localDeviceId_, listener);
647     EXPECT_TRUE(ret != ERR_NONE);
648 
649     ret = proxy->UnRegisterMissionListener(u"", listener);
650     EXPECT_TRUE(ret != ERR_NONE);
651 }
652 
653 /**
654  * @tc.name: testRegisterMissionListener003
655  * @tc.desc: test register mission listener
656  * @tc.type: FUNC
657  */
658 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener003, TestSize.Level3)
659 {
660     DTEST_LOG << "testRegisterMissionListener003 begin" << std::endl;
661     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
662     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(u"", listener);
663     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
664     DTEST_LOG << "testRegisterMissionListener003 end" << std::endl;
665 }
666 
667 /**
668  * @tc.name: testRegisterMissionListener004
669  * @tc.desc: test register mission listener
670  * @tc.type: FUNC
671  */
672 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener004, TestSize.Level3)
673 {
674     DTEST_LOG << "testRegisterMissionListener004 begin" << std::endl;
675     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
676     DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_["1234567"] = DEVICE_ID;
677     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(U16DEVICE_ID, listener);
678     EXPECT_EQ(ret, ERR_NONE);
679     DTEST_LOG << "testRegisterMissionListener004 end" << std::endl;
680 }
681 
682 /**
683  * @tc.name: testRegisterMissionListener005
684  * @tc.desc: test register mission listener
685  * @tc.type: FUNC
686  */
687 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener005, TestSize.Level3)
688 {
689     DTEST_LOG << "testRegisterMissionListener005 begin" << std::endl;
690     sptr<IRemoteObject> listener = nullptr;
691     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(u"", listener);
692     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
693     DTEST_LOG << "testRegisterMissionListener005 end" << std::endl;
694 }
695 
696 /**
697  * @tc.name: testRegisterMissionListener006
698  * @tc.desc: test register mission listener
699  * @tc.type: FUNC
700  */
701 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener006, TestSize.Level3)
702 {
703     DTEST_LOG << "testRegisterMissionListener006 begin" << std::endl;
704     sptr<IRemoteObject> listener = nullptr;
705     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(U16DEVICE_ID, listener);
706     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
707     DTEST_LOG << "testRegisterMissionListener006 end" << std::endl;
708 }
709 
710 /**
711  * @tc.name: testRegisterMissionListener007
712  * @tc.desc: test register mission listener
713  * @tc.type: FUNC
714  */
715 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener007, TestSize.Level3)
716 {
717     DTEST_LOG << "testRegisterMissionListener007 begin" << std::endl;
718     u16string deviceId = Str8ToStr16(localDeviceId_);
719     sptr<IRemoteObject> listener = nullptr;
720     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(deviceId, listener);
721     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
722     DTEST_LOG << "testRegisterMissionListener007 end" << std::endl;
723 }
724 
725 /**
726  * @tc.name: testRegisterMissionListener008
727  * @tc.desc: test register mission listener
728  * @tc.type: FUNC
729  */
730 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener008, TestSize.Level3)
731 {
732     DTEST_LOG << "testRegisterMissionListener008 begin" << std::endl;
733     u16string deviceId = Str8ToStr16(localDeviceId_);
734     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
735     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(deviceId, listener);
736     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
737     DTEST_LOG << "testRegisterMissionListener008 end" << std::endl;
738 }
739 
740 /**
741  * @tc.name: testUnRegisterMissionListener001
742  * @tc.desc: register mission listener
743  * @tc.type: FUNC
744  */
745 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener001, TestSize.Level1)
746 {
747     sptr<IDistributedSched> proxy = GetDms();
748     if (proxy == nullptr) {
749         return;
750     }
751     auto ret = proxy->UnRegisterMissionListener(U16DEVICE_ID, nullptr);
752     EXPECT_TRUE(ret != ERR_NONE);
753 
754     ret = proxy->UnRegisterMissionListener(u16localDeviceId_, nullptr);
755     EXPECT_TRUE(ret != ERR_NONE);
756 
757     ret = proxy->UnRegisterMissionListener(u"", nullptr);
758     EXPECT_TRUE(ret != ERR_NONE);
759 }
760 
761 /**
762  * @tc.name: testUnRegisterMissionListener002
763  * @tc.desc: register mission listener
764  * @tc.type: FUNC
765  */
766 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener002, TestSize.Level3)
767 {
768     DTEST_LOG << "testUnRegisterMissionListener002 begin" << std::endl;
769     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
770     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(U16DEVICE_ID, listener);
771     EXPECT_EQ(ret, ERR_NONE);
772     DTEST_LOG << "testUnRegisterMissionListener002 end" << std::endl;
773 }
774 
775 /**
776  * @tc.name: testUnRegisterMissionListener003
777  * @tc.desc: register mission listener
778  * @tc.type: FUNC
779  */
780 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener003, TestSize.Level3)
781 {
782     DTEST_LOG << "testUnRegisterMissionListener003 begin" << std::endl;
783     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(U16DEVICE_ID, nullptr);
784     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
785     DTEST_LOG << "testUnRegisterMissionListener003 end" << std::endl;
786 }
787 
788 /**
789  * @tc.name: testUnRegisterMissionListener004
790  * @tc.desc: register mission listener
791  * @tc.type: FUNC
792  */
793 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener004, TestSize.Level3)
794 {
795     DTEST_LOG << "testUnRegisterMissionListener004 begin" << std::endl;
796     u16string deviceId = Str8ToStr16(localDeviceId_);
797     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(deviceId, nullptr);
798     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
799     DTEST_LOG << "testUnRegisterMissionListener004 end" << std::endl;
800 }
801 
802 /**
803  * @tc.name: testUnRegisterMissionListener005
804  * @tc.desc: register mission listener
805  * @tc.type: FUNC
806  */
807 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener005, TestSize.Level3)
808 {
809     DTEST_LOG << "testUnRegisterMissionListener005 begin" << std::endl;
810     u16string deviceId = Str8ToStr16(localDeviceId_);
811     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
812     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(deviceId, listener);
813     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
814     DTEST_LOG << "testUnRegisterMissionListener005 end" << std::endl;
815 }
816 
817 /**
818  * @tc.name: testIsDeviceIdValidated001
819  * @tc.desc: judging whether the deviceId is valid
820  * @tc.type: FUNC
821  */
822 HWTEST_F(DMSMissionManagerTest, testIsDeviceIdValidated001, TestSize.Level1)
823 {
824     std::string emptyDeviceId = "";
825     auto ret = DistributedSchedMissionManager::GetInstance().IsDeviceIdValidated(emptyDeviceId);
826     EXPECT_FALSE(ret);
827 
828     ret = DistributedSchedMissionManager::GetInstance().IsDeviceIdValidated(DEVICE_ID_FALSE);
829     EXPECT_FALSE(ret);
830 
831     ret = DistributedSchedMissionManager::GetInstance().IsDeviceIdValidated(DEVICE_ID_FALSE_AGAIN);
832     EXPECT_FALSE(ret);
833 }
834 
835 /**
836  * @tc.name: testGetMissionInfos001
837  * @tc.desc: get missions
838  * @tc.type: FUNC
839  */
840 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos001, TestSize.Level1)
841 {
842     std::string deviceid = DEVICE_ID;
843     int32_t numMissions = NUM_MISSIONS;
844     std::vector<AAFwk::MissionInfo> missionInfos;
845 
846     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
847     EXPECT_TRUE(ret != ERR_NONE);
848 }
849 
850 /**
851  * @tc.name: testGetMissionInfos002
852  * @tc.desc: get missions
853  * @tc.type: FUNC
854  */
855 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos002, TestSize.Level3)
856 {
857     DTEST_LOG << "testGetMissionInfos002 begin" << std::endl;
858     std::string deviceid = localDeviceId_;
859     int32_t numMissions = NUM_MISSIONS;
860     std::vector<AAFwk::MissionInfo> missionInfos;
861 
862     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
863     EXPECT_TRUE(ret != ERR_NONE);
864     DTEST_LOG << "testGetMissionInfos002 end" << std::endl;
865 }
866 
867 /**
868  * @tc.name: testGetMissionInfos003
869  * @tc.desc: get missions
870  * @tc.type: FUNC
871  */
872 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos003, TestSize.Level3)
873 {
874     DTEST_LOG << "testGetMissionInfos003 begin" << std::endl;
875     std::string deviceid = "";
876     int32_t numMissions = NUM_MISSIONS;
877     std::vector<AAFwk::MissionInfo> missionInfos;
878 
879     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
880     EXPECT_TRUE(ret != ERR_NONE);
881     DTEST_LOG << "testGetMissionInfos003 end" << std::endl;
882 }
883 
884 /**
885  * @tc.name: testGetMissionInfos004
886  * @tc.desc: get missions
887  * @tc.type: FUNC
888  */
889 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos004, TestSize.Level3)
890 {
891     DTEST_LOG << "testGetMissionInfos004 begin" << std::endl;
892     std::string deviceid = DEVICE_ID;
893     int32_t numMissions = -1;
894     std::vector<AAFwk::MissionInfo> missionInfos;
895     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
896     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
897     DTEST_LOG << "testGetMissionInfos004 end" << std::endl;
898 }
899 
900 /**
901  * @tc.name: testGetMissionInfos005
902  * @tc.desc: get missions
903  * @tc.type: FUNC
904  */
905 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos005, TestSize.Level3)
906 {
907     DTEST_LOG << "testGetMissionInfos005 begin" << std::endl;
908     std::string deviceid = "";
909     int32_t numMissions = NUM_MISSIONS;
910     std::vector<AAFwk::MissionInfo> missionInfos;
911     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
912     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
913     DTEST_LOG << "testGetMissionInfos005 end" << std::endl;
914 }
915 
916 /**
917  * @tc.name: testGetMissionInfos006
918  * @tc.desc: get missions
919  * @tc.type: FUNC
920  */
921 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos006, TestSize.Level3)
922 {
923     DTEST_LOG << "testGetMissionInfos006 begin" << std::endl;
924     std::string deviceid = "";
925     int32_t numMissions = 0;
926     std::vector<AAFwk::MissionInfo> missionInfos;
927     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
928     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
929     DTEST_LOG << "testGetMissionInfos006 end" << std::endl;
930 }
931 
932 /**
933  * @tc.name: testFetchCachedRemoteMissions001
934  * @tc.desc: test stop fake device, return error code
935  * @tc.type: FUNC
936  */
937 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions001, TestSize.Level1)
938 {
939     std::vector<DstbMissionInfo> infos;
940     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(DEVICE_ID, 0, infos);
941     EXPECT_TRUE(ret != ERR_NONE);
942 }
943 
944 /**
945  * @tc.name: testFetchCachedRemoteMissions002
946  * @tc.desc: test empty deviceId, return error code
947  * @tc.type: FUNC
948  */
949 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions002, TestSize.Level3)
950 {
951     DTEST_LOG << "testFetchCachedRemoteMissions002 begin" << std::endl;
952     std::vector<DstbMissionInfo> infos;
953     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions("", 0, infos);
954     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
955     DTEST_LOG << "testFetchCachedRemoteMissions002 end" << std::endl;
956 }
957 
958 /**
959  * @tc.name: testFetchCachedRemoteMissions003
960  * @tc.desc: test local deviceId, return error code
961  * @tc.type: FUNC
962  */
963 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions003, TestSize.Level3)
964 {
965     DTEST_LOG << "testFetchCachedRemoteMissions003 begin" << std::endl;
966     std::vector<DstbMissionInfo> infos;
967     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(localDeviceId_, 0, infos);
968     EXPECT_TRUE(ret == ERR_NULL_OBJECT);
969     DTEST_LOG << "testFetchCachedRemoteMissions003 end" << std::endl;
970 }
971 
972 /**
973  * @tc.name: testFetchCachedRemoteMissions004
974  * @tc.desc: test stop fake device, return error code
975  * @tc.type: FUNC
976  */
977 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions004, TestSize.Level3)
978 {
979     DTEST_LOG << "testFetchCachedRemoteMissions004 begin" << std::endl;
980     std::vector<DstbMissionInfo> infos;
981     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(DEVICE_ID, NUM_MISSIONS, infos);
982     EXPECT_TRUE(ret != ERR_NONE);
983     DTEST_LOG << "testFetchCachedRemoteMissions004 end" << std::endl;
984 }
985 
986 /**
987  * @tc.name: testFetchCachedRemoteMissions005
988  * @tc.desc: test empty deviceId, return error code
989  * @tc.type: FUNC
990  */
991 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions005, TestSize.Level3)
992 {
993     DTEST_LOG << "testFetchCachedRemoteMissions005 begin" << std::endl;
994     std::vector<DstbMissionInfo> infos;
995     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions("", NUM_MISSIONS, infos);
996     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
997     DTEST_LOG << "testFetchCachedRemoteMissions005 end" << std::endl;
998 }
999 
1000 /**
1001  * @tc.name: testFetchCachedRemoteMissions006
1002  * @tc.desc: test local deviceId, return error code
1003  * @tc.type: FUNC
1004  */
1005 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions006, TestSize.Level3)
1006 {
1007     DTEST_LOG << "testFetchCachedRemoteMissions006 begin" << std::endl;
1008     std::vector<DstbMissionInfo> infos;
1009     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(localDeviceId_,
1010         NUM_MISSIONS, infos);
1011     EXPECT_TRUE(ret == ERR_NULL_OBJECT);
1012     DTEST_LOG << "testFetchCachedRemoteMissions006 end" << std::endl;
1013 }
1014 
1015 /**
1016  * @tc.name: testFetchCachedRemoteMissions007
1017  * @tc.desc: test stop fake device, return error code
1018  * @tc.type: FUNC
1019  */
1020 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions007, TestSize.Level3)
1021 {
1022     DTEST_LOG << "testFetchCachedRemoteMissions007 begin" << std::endl;
1023     std::vector<DstbMissionInfo> infos;
1024     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(DEVICE_ID,
1025         NORMAL_NUM_MISSIONS, infos);
1026     EXPECT_TRUE(ret != ERR_NONE);
1027     DTEST_LOG << "testFetchCachedRemoteMissions007 end" << std::endl;
1028 }
1029 
1030 /**
1031  * @tc.name: testFetchCachedRemoteMissions008
1032  * @tc.desc: test empty deviceId, return error code
1033  * @tc.type: FUNC
1034  */
1035 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions008, TestSize.Level3)
1036 {
1037     DTEST_LOG << "testFetchCachedRemoteMissions008 begin" << std::endl;
1038     std::vector<DstbMissionInfo> infos;
1039     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions("", NORMAL_NUM_MISSIONS, infos);
1040     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
1041     DTEST_LOG << "testFetchCachedRemoteMissions008 end" << std::endl;
1042 }
1043 
1044 /**
1045  * @tc.name: testFetchCachedRemoteMissions009
1046  * @tc.desc: test local deviceId, return error code
1047  * @tc.type: FUNC
1048  */
1049 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions009, TestSize.Level3)
1050 {
1051     DTEST_LOG << "testFetchCachedRemoteMissions009 begin" << std::endl;
1052     std::vector<DstbMissionInfo> infos;
1053     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(localDeviceId_,
1054         NORMAL_NUM_MISSIONS, infos);
1055     EXPECT_TRUE(ret == ERR_NULL_OBJECT);
1056     DTEST_LOG << "testFetchCachedRemoteMissions009 end" << std::endl;
1057 }
1058 
1059 /**
1060  * @tc.name: testStopDataStorage001
1061  * @tc.desc: test stop data storage
1062  * @tc.type: FUNC
1063  */
1064 HWTEST_F(DMSMissionManagerTest, testStopDataStorage001, TestSize.Level3)
1065 {
1066     DTEST_LOG << "testStopDataStorage001 begin" << std::endl;
1067     auto ret = DistributedSchedMissionManager::GetInstance().StopDataStorage();
1068     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1069     DTEST_LOG << "testStopDataStorage001 end" << std::endl;
1070 }
1071 
1072 /**
1073  * @tc.name: testStoreSnapshotInfo001
1074  * @tc.desc: test store snapshot info
1075  * @tc.type: FUNC
1076  */
1077 HWTEST_F(DMSMissionManagerTest, testStoreSnapshotInfo001, TestSize.Level3)
1078 {
1079     DTEST_LOG << "testStoreSnapshotInfo001 begin" << std::endl;
1080     auto ret = DistributedSchedMissionManager::GetInstance().StoreSnapshotInfo(DEVICE_ID, 0, 0, 0);
1081     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1082     DTEST_LOG << "testStoreSnapshotInfo001 end" << std::endl;
1083 }
1084 
1085 /**
1086  * @tc.name: testRemoveSnapshotInfo001
1087  * @tc.desc: test remove snapshot info
1088  * @tc.type: FUNC
1089  */
1090 HWTEST_F(DMSMissionManagerTest, testRemoveSnapshotInfo001, TestSize.Level3)
1091 {
1092     DTEST_LOG << "testRemoveSnapshotInfo001 begin" << std::endl;
1093     auto ret = DistributedSchedMissionManager::GetInstance().RemoveSnapshotInfo(DEVICE_ID, 0);
1094     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1095     DTEST_LOG << "testRemoveSnapshotInfo001 end" << std::endl;
1096 }
1097 
1098 /**
1099  * @tc.name: testInitDataStorage001
1100  * @tc.desc: test init data storage
1101  * @tc.type: FUNC
1102  */
1103 HWTEST_F(DMSMissionManagerTest, testInitDataStorage001, TestSize.Level3)
1104 {
1105     DTEST_LOG << "testInitDataStorage001 begin" << std::endl;
1106     auto ret = DistributedSchedMissionManager::GetInstance().InitDataStorage();
1107     EXPECT_EQ(ret, ERR_NONE);
1108     DTEST_LOG << "testInitDataStorage001 end" << std::endl;
1109 }
1110 
1111 /**
1112  * @tc.name: testInitDataStorage002
1113  * @tc.desc: test init data storage
1114  * @tc.type: FUNC
1115  */
1116 HWTEST_F(DMSMissionManagerTest, testInitDataStorage002, TestSize.Level3)
1117 {
1118     DTEST_LOG << "testInitDataStorage002 begin" << std::endl;
1119     auto ret = DistributedSchedMissionManager::GetInstance().InitDataStorage();
1120     EXPECT_EQ(ret, ERR_NONE);
1121     DTEST_LOG << "testInitDataStorage002 end" << std::endl;
1122 }
1123 
1124 /**
1125  * @tc.name: testStoreSnapshotInfo002
1126  * @tc.desc: test store snapshot info
1127  * @tc.type: FUNC
1128  */
1129 HWTEST_F(DMSMissionManagerTest, testStoreSnapshotInfo002, TestSize.Level3)
1130 {
1131     DTEST_LOG << "testStoreSnapshotInfo002 begin" << std::endl;
1132     auto ret = DistributedSchedMissionManager::GetInstance().StoreSnapshotInfo(DEVICE_ID_FALSE, 0, 0, 0);
1133     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1134     DTEST_LOG << "testStoreSnapshotInfo002 end" << std::endl;
1135 }
1136 
1137 /**
1138  * @tc.name: testRemoveSnapshotInfo002
1139  * @tc.desc: test remove snapshot info
1140  * @tc.type: FUNC
1141  */
1142 HWTEST_F(DMSMissionManagerTest, testRemoveSnapshotInfo002, TestSize.Level3)
1143 {
1144     DTEST_LOG << "testRemoveSnapshotInfo002 begin" << std::endl;
1145     auto ret = DistributedSchedMissionManager::GetInstance().RemoveSnapshotInfo(DEVICE_ID_FALSE, 0);
1146     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1147     DTEST_LOG << "testRemoveSnapshotInfo002 end" << std::endl;
1148 }
1149 
1150 /**
1151  * @tc.name: testGetRemoteMissionSnapshotInfo001
1152  * @tc.desc: test get remote mission snapshot info
1153  * @tc.type: FUNC
1154  */
1155 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionSnapshotInfo001, TestSize.Level3)
1156 {
1157     DTEST_LOG << "testGetRemoteMissionSnapshotInfo001 begin" << std::endl;
1158     DistributedSchedMissionManager::GetInstance().NotifySnapshotChanged(DEVICE_ID, 0);
1159     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
1160     auto ret = DistributedSchedMissionManager::GetInstance().GetRemoteMissionSnapshotInfo("", 0, missionSnapshot);
1161     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1162     DTEST_LOG << "testGetRemoteMissionSnapshotInfo001 end" << std::endl;
1163 }
1164 
1165 /**
1166  * @tc.name: testDeviceOnlineNotify003
1167  * @tc.desc: test device online notify
1168  * @tc.type: FUNC
1169  */
1170 HWTEST_F(DMSMissionManagerTest, testDeviceOnlineNotify003, TestSize.Level3)
1171 {
1172     DTEST_LOG << "testDeviceOnlineNotify003 begin" << std::endl;
1173     DistributedSchedMissionManager::GetInstance().Init();
1174     DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify(DEVICE_ID);
1175     DTEST_LOG << "testDeviceOnlineNotify003 end" << std::endl;
1176 }
1177 
1178 /**
1179  * @tc.name: testDeviceOfflineNotify001
1180  * @tc.desc: test device offline notify
1181  * @tc.type: FUNC
1182  */
1183 HWTEST_F(DMSMissionManagerTest, testDeviceOfflineNotify001, TestSize.Level3)
1184 {
1185     DTEST_LOG << "testDeviceOfflineNotify001 begin" << std::endl;
1186     DistributedSchedMissionManager::GetInstance().DeviceOfflineNotify("");
1187     DTEST_LOG << "testDeviceOfflineNotify001 end" << std::endl;
1188 }
1189 
1190 /**
1191  * @tc.name: testDeviceOfflineNotify002
1192  * @tc.desc: test device offline notify
1193  * @tc.type: FUNC
1194  */
1195 HWTEST_F(DMSMissionManagerTest, testDeviceOfflineNotify002, TestSize.Level3)
1196 {
1197     DTEST_LOG << "testDeviceOfflineNotify002 begin" << std::endl;
1198     std::set<std::string> remoteSyncDeviceSet_ = set<std::string>();
1199     DistributedSchedMissionManager::GetInstance().DeviceOfflineNotify(DEVICE_ID);
1200     DTEST_LOG << "testDeviceOfflineNotify002 end" << std::endl;
1201 }
1202 
1203 /**
1204  * @tc.name: testOnRemoteDied001
1205  * @tc.desc: test on remote died
1206  * @tc.type: FUNC
1207  */
1208 HWTEST_F(DMSMissionManagerTest, testOnRemoteDied001, TestSize.Level3)
1209 {
1210     DTEST_LOG << "testOnRemoteDied001 begin" << std::endl;
1211     wptr<IRemoteObject> remote = nullptr;
1212     DistributedSchedMissionManager::GetInstance().OnRemoteDied(remote);
1213     DTEST_LOG << "testOnRemoteDied001 end" << std::endl;
1214 }
1215 
1216 /**
1217  * @tc.name: testOnRemoteDied002
1218  * @tc.desc: test on remote died
1219  * @tc.type: FUNC
1220  */
1221 HWTEST_F(DMSMissionManagerTest, testOnRemoteDied002, TestSize.Level3)
1222 {
1223     DTEST_LOG << "testOnRemoteDied002 begin" << std::endl;
1224     wptr<IRemoteObject> remote = new RemoteMissionListenerTest();
1225     DistributedSchedMissionManager::GetInstance().OnRemoteDied(remote);
1226     DTEST_LOG << "testOnRemoteDied002 end" << std::endl;
1227 }
1228 
1229 /**
1230  * @tc.name: testStartSyncMissionsFromRemote001
1231  * @tc.desc: prepare and sync missions from remote
1232  * @tc.type: FUNC
1233  */
1234 HWTEST_F(DMSMissionManagerTest, testStartSyncMissionsFromRemote001, TestSize.Level3)
1235 {
1236     DTEST_LOG << "testStartSyncMissionsFromRemote001 begin" << std::endl;
1237     DistributedSchedUtil::MockManageMissions();
1238     std::vector<DstbMissionInfo> missionInfos;
1239     CallerInfo callerInfo;
1240     DistributedSchedMissionManager::GetInstance().Init();
1241     DistributedSchedMissionManager::GetInstance().GenerateCallerInfo(callerInfo);
1242     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncMissionsFromRemote(callerInfo, missionInfos);
1243     EXPECT_EQ(ret, ERR_NONE);
1244     DTEST_LOG << "testStartSyncMissionsFromRemote001 end" << std::endl;
1245 }
1246 
1247 /**
1248  * @tc.name: testStopSyncMissionsFromRemote001
1249  * @tc.desc: stop sync missions from remote
1250  * @tc.type: FUNC
1251  */
1252 HWTEST_F(DMSMissionManagerTest, testStopSyncMissionsFromRemote001, TestSize.Level3)
1253 {
1254     DTEST_LOG << "testStopSyncMissionsFromRemote001 begin" << std::endl;
1255     std::vector<DstbMissionInfo> missionInfos;
1256     CallerInfo callerInfo;
1257     DistributedSchedMissionManager::GetInstance().Init();
1258     DistributedSchedMissionManager::GetInstance().StopSyncMissionsFromRemote("");
1259     DTEST_LOG << "testStopSyncMissionsFromRemote001 end" << std::endl;
1260 }
1261 
1262 /**
1263  * @tc.name: testStopSyncMissionsFromRemote002
1264  * @tc.desc: stop sync missions from remote
1265  * @tc.type: FUNC
1266  */
1267 HWTEST_F(DMSMissionManagerTest, testStopSyncMissionsFromRemote002, TestSize.Level3)
1268 {
1269     DTEST_LOG << "testStopSyncMissionsFromRemote002 begin" << std::endl;
1270     std::vector<DstbMissionInfo> missionInfos;
1271     CallerInfo callerInfo;
1272     DistributedSchedMissionManager::GetInstance().Init();
1273     DistributedSchedMissionManager::GetInstance().StopSyncMissionsFromRemote(DEVICE_ID);
1274     DTEST_LOG << "testStopSyncMissionsFromRemote002 end" << std::endl;
1275 }
1276 
1277 /**
1278  * @tc.name: testNotifyMissionsChangedFromRemote001
1279  * @tc.desc: notify missions changed from remote
1280  * @tc.type: FUNC
1281  */
1282 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedFromRemote001, TestSize.Level3)
1283 {
1284     DTEST_LOG << "testNotifyMissionsChangedFromRemote001 begin" << std::endl;
1285     CallerInfo callerInfo;
1286     callerInfo.sourceDeviceId = DEVICE_ID;
1287     callerInfo.uid = 0;
1288     callerInfo.pid = 0;
1289     callerInfo.dmsVersion = 0;
1290     std::vector<DstbMissionInfo> missionInfos;
1291     DistributedSchedMissionManager::GetInstance().Init();
1292     auto ret = DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedFromRemote(callerInfo, missionInfos);
1293     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1294     DTEST_LOG << "testNotifyMissionsChangedFromRemote001 end" << std::endl;
1295 }
1296 
1297 /**
1298  * @tc.name: testNotifyMissionsChangedFromRemote002
1299  * @tc.desc: notify missions changed from remote
1300  * @tc.type: FUNC
1301  */
1302 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedFromRemote002, TestSize.Level3)
1303 {
1304     DTEST_LOG << "testNotifyMissionsChangedFromRemote002 begin" << std::endl;
1305     CallerInfo callerInfo;
1306     callerInfo.sourceDeviceId = DEVICE_ID;
1307     callerInfo.uid = 0;
1308     callerInfo.pid = 0;
1309     callerInfo.dmsVersion = 0;
1310     std::vector<DstbMissionInfo> missionInfos;
1311     DistributedSchedMissionManager::GetInstance().Init();
1312     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
1313     auto& listenerInfo = DistributedSchedMissionManager::GetInstance().listenDeviceMap_[U16DEVICE_ID];
1314     EXPECT_EQ(listenerInfo.Emplace(listener), true);
1315     auto ret = DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedFromRemote(callerInfo, missionInfos);
1316     EXPECT_EQ(ret, ERR_NONE);
1317     DTEST_LOG << "testNotifyMissionsChangedFromRemote002 end" << std::endl;
1318 }
1319 
1320 /**
1321  * @tc.name: testNotifyLocalMissionsChanged001
1322  * @tc.desc: notify local missions changed
1323  * @tc.type: FUNC
1324  */
1325 HWTEST_F(DMSMissionManagerTest, testNotifyLocalMissionsChanged001, TestSize.Level3)
1326 {
1327     DTEST_LOG << "testNotifyLocalMissionsChanged001 begin" << std::endl;
1328     DistributedSchedMissionManager::GetInstance().Init();
1329     DistributedSchedMissionManager::GetInstance().NotifyLocalMissionsChanged();
1330     DTEST_LOG << "testNotifyLocalMissionsChanged001 end" << std::endl;
1331 }
1332 
1333 /**
1334  * @tc.name: testNotifyMissionSnapshotCreated001
1335  * @tc.desc: notify mission snapshot created
1336  * @tc.type: FUNC
1337  */
1338 HWTEST_F(DMSMissionManagerTest, testNotifyMissionSnapshotCreated001, TestSize.Level3)
1339 {
1340     DTEST_LOG << "testNotifyMissionSnapshotCreated001 begin" << std::endl;
1341     DistributedSchedMissionManager::GetInstance().Init();
1342     DistributedSchedMissionManager::GetInstance().NotifyMissionSnapshotCreated(1);
1343     DTEST_LOG << "testNotifyMissionSnapshotCreated001 end" << std::endl;
1344 }
1345 
1346 /**
1347  * @tc.name: testNotifyMissionSnapshotChanged001
1348  * @tc.desc: notify mission snapshot changed
1349  * @tc.type: FUNC
1350  */
1351 HWTEST_F(DMSMissionManagerTest, testNotifyMissionSnapshotChanged001, TestSize.Level3)
1352 {
1353     DTEST_LOG << "testNotifyMissionSnapshotChanged001 begin" << std::endl;
1354     DistributedSchedMissionManager::GetInstance().Init();
1355     DistributedSchedMissionManager::GetInstance().NotifyMissionSnapshotChanged(1);
1356     DTEST_LOG << "testNotifyMissionSnapshotChanged001 end" << std::endl;
1357 }
1358 
1359 /**
1360  * @tc.name: testNotifyMissionSnapshotDestroyed001
1361  * @tc.desc: notify mission snapshot destroyed
1362  * @tc.type: FUNC
1363  */
1364 HWTEST_F(DMSMissionManagerTest, testNotifyMissionSnapshotDestroyed001, TestSize.Level3)
1365 {
1366     DTEST_LOG << "testNotifyMissionSnapshotDestroyed001 begin" << std::endl;
1367     DistributedSchedMissionManager::GetInstance().Init();
1368     DistributedSchedMissionManager::GetInstance().NotifyMissionSnapshotDestroyed(1);
1369     DTEST_LOG << "testNotifyMissionSnapshotDestroyed001 end" << std::endl;
1370 }
1371 
1372 /**
1373  * @tc.name: testNotifyMissionsChangedToRemote001
1374  * @tc.desc: notify missions changed to remote
1375  * @tc.type: FUNC
1376  */
1377 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedToRemote001, TestSize.Level3)
1378 {
1379     DTEST_LOG << "testNotifyMissionsChangedToRemote001 begin" << std::endl;
1380     std::vector<DstbMissionInfo> missionInfos;
1381     auto ret = DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedToRemote(missionInfos);
1382     EXPECT_EQ(ret, ERR_NONE);
1383     DTEST_LOG << "testNotifyMissionsChangedToRemote001 end" << std::endl;
1384 }
1385 
1386 /**
1387  * @tc.name: testNotifyMissionsChangedToRemoteInner001
1388  * @tc.desc: notify missions changed to remote inner
1389  * @tc.type: FUNC
1390  */
1391 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedToRemoteInner001, TestSize.Level3)
1392 {
1393     DTEST_LOG << "testNotifyMissionsChangedToRemoteInner001 begin" << std::endl;
1394     CallerInfo callerInfo;
1395     std::vector<DstbMissionInfo> missionInfos;
1396     DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedToRemoteInner("", missionInfos, callerInfo);
1397     DTEST_LOG << "testNotifyMissionsChangedToRemoteInner001 end" << std::endl;
1398 }
1399 
1400 /**
1401  * @tc.name: testNotifyMissionsChangedToRemoteInner002
1402  * @tc.desc: notify missions changed to remote inner
1403  * @tc.type: FUNC
1404  */
1405 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedToRemoteInner002, TestSize.Level3)
1406 {
1407     DTEST_LOG << "testNotifyMissionsChangedToRemoteInner002 begin" << std::endl;
1408     CallerInfo callerInfo;
1409     std::vector<DstbMissionInfo> missionInfos;
1410     DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedToRemoteInner(
1411         DEVICE_ID, missionInfos, callerInfo);
1412     DTEST_LOG << "testNotifyMissionsChangedToRemoteInner002 end" << std::endl;
1413 }
1414 
1415 /**
1416  * @tc.name: testOnRemoteDmsDied001
1417  * @tc.desc: on remote dms died
1418  * @tc.type: FUNC
1419  */
1420 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied001, TestSize.Level3)
1421 {
1422     DTEST_LOG << "testOnRemoteDmsDied001 begin" << std::endl;
1423     wptr<IRemoteObject> remote = nullptr;
1424     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
1425     DTEST_LOG << "testOnRemoteDmsDied001 end" << std::endl;
1426 }
1427 
1428 /**
1429  * @tc.name: testOnRemoteDmsDied002
1430  * @tc.desc: on remote dms died
1431  * @tc.type: FUNC
1432  */
1433 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied002, TestSize.Level3)
1434 {
1435     DTEST_LOG << "testOnRemoteDmsDied002 begin" << std::endl;
1436     wptr<IRemoteObject> remote = wptr<IRemoteObject>();
1437     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
1438     DTEST_LOG << "testOnRemoteDmsDied002 end" << std::endl;
1439 }
1440 
1441 /**
1442  * @tc.name: testRetryStartSyncRemoteMissions001
1443  * @tc.desc: retry start sync remote missions
1444  * @tc.type: FUNC
1445  */
1446 HWTEST_F(DMSMissionManagerTest, testRetryStartSyncRemoteMissions001, TestSize.Level3)
1447 {
1448     DTEST_LOG << "testRetryStartSyncRemoteMissions001 begin" << std::endl;
1449     DistributedSchedMissionManager::GetInstance().Init();
1450     DistributedSchedMissionManager::GetInstance().RetryStartSyncRemoteMissions("", localDeviceId_, 1);
1451     DTEST_LOG << "testRetryStartSyncRemoteMissions001 end" << std::endl;
1452 }
1453 
1454 /**
1455  * @tc.name: testRetryStartSyncRemoteMissions002
1456  * @tc.desc: retry start sync remote missions
1457  * @tc.type: FUNC
1458  */
1459 HWTEST_F(DMSMissionManagerTest, testRetryStartSyncRemoteMissions002, TestSize.Level3)
1460 {
1461     DTEST_LOG << "testRetryStartSyncRemoteMissions002 begin" << std::endl;
1462     DistributedSchedMissionManager::GetInstance().Init();
1463     DistributedSchedMissionManager::GetInstance().RetryStartSyncRemoteMissions(DEVICE_ID, localDeviceId_, 1);
1464     DTEST_LOG << "testRetryStartSyncRemoteMissions002 end" << std::endl;
1465 }
1466 
1467 /**
1468  * @tc.name: testOnMissionListenerDied001
1469  * @tc.desc: on mission listener died
1470  * @tc.type: FUNC
1471  */
1472 HWTEST_F(DMSMissionManagerTest, testOnMissionListenerDied001, TestSize.Level3)
1473 {
1474     DTEST_LOG << "testOnMissionListenerDied001 begin" << std::endl;
1475     sptr<IRemoteObject> remote = nullptr;
1476     DistributedSchedMissionManager::GetInstance().OnMissionListenerDied(remote);
1477     DTEST_LOG << "testOnMissionListenerDied001 end" << std::endl;
1478 }
1479 
1480 /**
1481  * @tc.name: testOnMissionListenerDied002
1482  * @tc.desc: on mission listener died
1483  * @tc.type: FUNC
1484  */
1485 HWTEST_F(DMSMissionManagerTest, testOnMissionListenerDied002, TestSize.Level3)
1486 {
1487     DTEST_LOG << "testOnMissionListenerDied002 begin" << std::endl;
1488     sptr<IRemoteObject> remote = sptr<IRemoteObject>();
1489     DistributedSchedMissionManager::GetInstance().OnMissionListenerDied(remote);
1490     DTEST_LOG << "testOnMissionListenerDied002 end" << std::endl;
1491 }
1492 
1493 /**
1494  * @tc.name: testOnRemoteDmsDied003
1495  * @tc.desc: on remote dms died
1496  * @tc.type: FUNC
1497  */
1498 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied003, TestSize.Level3)
1499 {
1500     DTEST_LOG << "testOnRemoteDmsDied003 begin" << std::endl;
1501     sptr<IRemoteObject> remote = nullptr;
1502     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
1503     DTEST_LOG << "testOnRemoteDmsDied003 end" << std::endl;
1504 }
1505 
1506 /**
1507  * @tc.name: testOnRemoteDmsDied004
1508  * @tc.desc: on remote dms died
1509  * @tc.type: FUNC
1510  */
1511 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied004, TestSize.Level3)
1512 {
1513     DTEST_LOG << "testOnRemoteDmsDied004 begin" << std::endl;
1514     sptr<IRemoteObject> remote = sptr<IRemoteObject>();
1515     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
1516     DTEST_LOG << "testOnRemoteDmsDied004 end" << std::endl;
1517 }
1518 
1519 /**
1520  * @tc.name: testRetryRegisterMissionChange001
1521  * @tc.desc: retry register mission change
1522  * @tc.type: FUNC
1523  */
1524 HWTEST_F(DMSMissionManagerTest, testRetryRegisterMissionChange001, TestSize.Level3)
1525 {
1526     DTEST_LOG << "testRetryRegisterMissionChange001 begin" << std::endl;
1527     DistributedSchedMissionManager::GetInstance().Init();
1528     DistributedSchedMissionManager::GetInstance().RetryRegisterMissionChange(1);
1529     DTEST_LOG << "testRetryRegisterMissionChange001 end" << std::endl;
1530 }
1531 
1532 /**
1533  * @tc.name: testMissionSnapshotChanged001
1534  * @tc.desc: mission snapshot changed
1535  * @tc.type: FUNC
1536  */
1537 HWTEST_F(DMSMissionManagerTest, testMissionSnapshotChanged001, TestSize.Level3)
1538 {
1539     DTEST_LOG << "testMissionSnapshotChanged001 begin" << std::endl;
1540     DistributedSchedMissionManager::GetInstance().NotifyDmsProxyProcessDied();
1541     std::vector<DstbMissionInfo> missionInfos;
1542     DistributedSchedMissionManager::GetInstance().InitAllSnapshots(missionInfos);
1543     auto ret = DistributedSchedMissionManager::GetInstance().MissionSnapshotChanged(NUM_MISSIONS);
1544     EXPECT_NE(ret, ERR_NONE);
1545     DTEST_LOG << "testMissionSnapshotChanged001 end" << std::endl;
1546 }
1547 
1548 /**
1549  * @tc.name: testOnDnetDied001
1550  * @tc.desc: on dnet died
1551  * @tc.type: FUNC
1552  */
1553 HWTEST_F(DMSMissionManagerTest, testOnDnetDied001, TestSize.Level3)
1554 {
1555     DTEST_LOG << "testOnDnetDied001 begin" << std::endl;
1556     DistributedSchedMissionManager::GetInstance().Init();
1557     DistributedSchedMissionManager::GetInstance().OnDnetDied();
1558     DTEST_LOG << "testOnDnetDied001 end" << std::endl;
1559 }
1560 
1561 /**
1562  * @tc.name: ProxyCallStopSyncMissionsFromRemote001
1563  * @tc.desc: call dms proxy StopSyncMissionsFromRemote
1564  * @tc.type: FUNC
1565  * @tc.require: I5XDDS
1566  */
1567 HWTEST_F(DMSMissionManagerTest, ProxyCallStopSyncMissionsFromRemote001, TestSize.Level3)
1568 {
1569     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStopSyncMissionsFromRemote001 start" << std::endl;
1570     sptr<IDistributedSched> proxy = GetDms();
1571     if (proxy == nullptr) {
1572         return;
1573     }
1574     CallerInfo callerInfo;
1575     int32_t ret = proxy->StopSyncMissionsFromRemote(callerInfo);
1576     EXPECT_EQ(ret, REQUEST_CODE_ERR);
1577     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStopSyncMissionsFromRemote001 end" << std::endl;
1578 }
1579 
1580 /**
1581  * @tc.name: ProxyCallNotifyMissionsChangedFromRemote001
1582  * @tc.desc: call dms proxy NotifyMissionsChangedFromRemote
1583  * @tc.type: FUNC
1584  * @tc.require: I5XDDS
1585  */
1586 HWTEST_F(DMSMissionManagerTest, ProxyCallNotifyMissionsChangedFromRemote001, TestSize.Level3)
1587 {
1588     DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyMissionsChangedFromRemote001 start" << std::endl;
1589     sptr<IDistributedSched> proxy = GetDms();
1590     if (proxy == nullptr) {
1591         return;
1592     }
1593     CallerInfo callerInfo;
1594     std::vector<DstbMissionInfo> missionInfos;
1595     int32_t ret = proxy->NotifyMissionsChangedFromRemote(missionInfos, callerInfo);
1596     EXPECT_EQ(ret, REQUEST_CODE_ERR);
1597     DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyMissionsChangedFromRemote001 end" << std::endl;
1598 }
1599 
1600 /**
1601  * @tc.name: ProxyCallGetRemoteMissionSnapshotInfo001
1602  * @tc.desc: call dms proxy GetRemoteMissionSnapshotInfo
1603  * @tc.type: FUNC
1604  * @tc.require: I5XDDS
1605  */
1606 HWTEST_F(DMSMissionManagerTest, ProxyCallGetRemoteMissionSnapshotInfo001, TestSize.Level3)
1607 {
1608     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetRemoteMissionSnapshotInfo001 start" << std::endl;
1609     sptr<IDistributedSched> proxy = GetDms();
1610     if (proxy == nullptr) {
1611         return;
1612     }
1613     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
1614     int32_t ret = proxy->GetRemoteMissionSnapshotInfo("MockDevId", 1, missionSnapshot);
1615     EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1616     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetRemoteMissionSnapshotInfo001 end" << std::endl;
1617 }
1618 
1619 /**
1620  * @tc.name: ProxyCallGetRemoteMissionSnapshotInfo002
1621  * @tc.desc: call dms proxy GetRemoteMissionSnapshotInfo
1622  * @tc.type: FUNC
1623  * @tc.require: I5XDDS
1624  */
1625 HWTEST_F(DMSMissionManagerTest, ProxyCallGetRemoteMissionSnapshotInfo002, TestSize.Level3)
1626 {
1627     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetRemoteMissionSnapshotInfo002 start" << std::endl;
1628     sptr<IDistributedSched> proxy = GetDms();
1629     if (proxy == nullptr) {
1630         return;
1631     }
1632     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
1633     int32_t ret = proxy->GetRemoteMissionSnapshotInfo("", 1, missionSnapshot);
1634     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1635     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetRemoteMissionSnapshotInfo002 end" << std::endl;
1636 }
1637 
1638 /**
1639  * @tc.name: ProxyCallGetRemoteMissionSnapshotInfo003
1640  * @tc.desc: call dms proxy GetRemoteMissionSnapshotInfo
1641  * @tc.type: FUNC
1642  * @tc.require: I5XDDS
1643  */
1644 HWTEST_F(DMSMissionManagerTest, ProxyCallGetRemoteMissionSnapshotInfo003, TestSize.Level3)
1645 {
1646     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetRemoteMissionSnapshotInfo003 start" << std::endl;
1647     sptr<IDistributedSched> proxy = GetDms();
1648     if (proxy == nullptr) {
1649         return;
1650     }
1651     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
1652     int32_t ret = proxy->GetRemoteMissionSnapshotInfo("MockDevId", -1, missionSnapshot);
1653     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1654     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetRemoteMissionSnapshotInfo003 end" << std::endl;
1655 }
1656 
1657 /**
1658  * @tc.name: testDeleteDataStorage005
1659  * @tc.desc: test DeleteDataStorage
1660  * @tc.type: FUNC
1661  */
1662 HWTEST_F(DMSMissionManagerTest, testDeleteDataStorage005, TestSize.Level3)
1663 {
1664     DTEST_LOG << "testDeleteDataStorage005 begin" << std::endl;
1665     std::string uuid = "uuid for GetUuidByNetworkId";
1666     {
1667         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
1668         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
1669     }
1670     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1671         std::make_shared<DistributedDataStorage>();
1672     auto result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Init();
__anon03ffda660202() 1673     auto initDoneTask = []() {
1674         std::lock_guard<std::mutex> autoLock(caseDoneLock_);
1675         isCaseDone_ = true;
1676         caseDoneCondition_.notify_all();
1677     };
1678     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
1679         std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
1680             DistributedSchedMissionManager::GetInstance().distributedDataStorage_->dmsDataStorageHandler_;
1681         if (dmsDataStorageHandler != nullptr) {
1682             dmsDataStorageHandler->PostTask(initDoneTask);
1683         }
1684     }
1685     std::unique_lock<std::mutex> lock(caseDoneLock_);
1686     caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
__anon03ffda660302() 1687         [&] () { return isCaseDone_; });
1688     EXPECT_TRUE(result);
1689     isCaseDone_ = false;
1690     uint8_t* byteStream = new uint8_t[BYTESTREAM_LENGTH];
1691     for (size_t i = 0; i < BYTESTREAM_LENGTH; ++i) {
1692         byteStream[i] = ONE_BYTE;
1693     }
1694     result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Insert(localDeviceId_,
1695         TASK_ID, byteStream, BYTESTREAM_LENGTH);
1696     EXPECT_TRUE(result);
1697     DistributedSchedMissionManager::GetInstance().missionHandler_ = nullptr;
1698     DistributedSchedMissionManager::GetInstance().DeleteDataStorage(localDeviceId_, false);
1699     DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Stop();
1700     DTEST_LOG << "testDeleteDataStorage005 end" << std::endl;
1701 }
1702 
1703 /**
1704  * @tc.name: testDeleteDataStorage006
1705  * @tc.desc: test DeleteDataStorage
1706  * @tc.type: FUNC
1707  */
1708 HWTEST_F(DMSMissionManagerTest, testDeleteDataStorage006, TestSize.Level3)
1709 {
1710     DTEST_LOG << "testDeleteDataStorage006 begin" << std::endl;
1711     std::string uuid = "uuid for GetUuidByNetworkId";
1712     {
1713         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
1714         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
1715     }
1716     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1717         std::make_shared<DistributedDataStorage>();
1718     auto result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Init();
__anon03ffda660402() 1719     auto initDoneTask = []() {
1720         std::lock_guard<std::mutex> autoLock(caseDoneLock_);
1721         isCaseDone_ = true;
1722         caseDoneCondition_.notify_all();
1723     };
1724     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
1725         std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
1726             DistributedSchedMissionManager::GetInstance().distributedDataStorage_->dmsDataStorageHandler_;
1727         if (dmsDataStorageHandler != nullptr) {
1728             dmsDataStorageHandler->PostTask(initDoneTask);
1729         }
1730     }
1731     std::unique_lock<std::mutex> lock(caseDoneLock_);
1732     caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
__anon03ffda660502() 1733         [&] () { return isCaseDone_; });
1734     EXPECT_TRUE(result);
1735     isCaseDone_ = false;
1736     uint8_t* byteStream = new uint8_t[BYTESTREAM_LENGTH];
1737     for (size_t i = 0; i < BYTESTREAM_LENGTH; ++i) {
1738         byteStream[i] = ONE_BYTE;
1739     }
1740     result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Insert(localDeviceId_,
1741         TASK_ID, byteStream, BYTESTREAM_LENGTH);
1742     EXPECT_TRUE(result);
1743     DistributedSchedMissionManager::GetInstance().missionHandler_ = nullptr;
1744     DistributedSchedMissionManager::GetInstance().DeleteDataStorage(localDeviceId_, true);
1745     DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Stop();
1746     DTEST_LOG << "testDeleteDataStorage006 end" << std::endl;
1747 }
1748 
1749 /**
1750  * @tc.name: testRegisterMissionListener009
1751  * @tc.desc: test register mission listener
1752  * @tc.type: FUNC
1753  */
1754 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener009, TestSize.Level3)
1755 {
1756     DTEST_LOG << "testRegisterMissionListener009 begin" << std::endl;
1757     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
1758     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
1759     u16string deviceId = Str8ToStr16(localDeviceId_);
1760     std::string uuid = "uuid for GetUuidByNetworkId";
1761     {
1762         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
1763         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
1764     }
1765     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
1766     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(deviceId, listener);
1767     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1768     DTEST_LOG << "testRegisterMissionListener009 end" << std::endl;
1769 }
1770 
1771 /**
1772  * @tc.name: testRegisterMissionListener010
1773  * @tc.desc: test register mission listener
1774  * @tc.type: FUNC
1775  */
1776 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener010, TestSize.Level3)
1777 {
1778     DTEST_LOG << "testRegisterMissionListener010 begin" << std::endl;
1779     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
1780     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
1781     u16string deviceId = Str8ToStr16(DEVICE_ID);
1782     std::string uuid = "uuid for GetUuidByNetworkId";
1783     {
1784         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
1785         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = DEVICE_ID;
1786     }
1787     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
1788     {
1789         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
1790         ListenerInfo listenerInfo;
1791         listenerInfo.Emplace(listener);
1792         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
1793     }
1794     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(deviceId, listener);
1795     EXPECT_EQ(ret, ERR_NONE);
1796     DTEST_LOG << "testRegisterMissionListener010 end" << std::endl;
1797 }
1798 
1799 /**
1800  * @tc.name: testIsDeviceIdValidated002
1801  * @tc.desc: test IsDeviceIdValidated
1802  * @tc.type: FUNC
1803  */
1804 HWTEST_F(DMSMissionManagerTest, testIsDeviceIdValidated002, TestSize.Level1)
1805 {
1806     DTEST_LOG << "testIsDeviceIdValidated002 begin" << std::endl;
1807     {
1808         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1809         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
1810     }
1811 
1812     int32_t deviceType = 0;
1813     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
1814         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, localDeviceId_);
1815     {
1816         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1817         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[localDeviceId_] = dmsDeviceInfo;
1818     }
1819     auto ret = DistributedSchedMissionManager::GetInstance().IsDeviceIdValidated(localDeviceId_);
1820     EXPECT_TRUE(ret);
1821     DTEST_LOG << "testIsDeviceIdValidated002 end" << std::endl;
1822 }
1823 
1824 
1825 /**
1826  * @tc.name: testGetMissionInfos007
1827  * @tc.desc: get missions
1828  * @tc.type: FUNC
1829  */
1830 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos007, TestSize.Level3)
1831 {
1832     DTEST_LOG << "testGetMissionInfos007 begin" << std::endl;
1833     {
1834         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1835         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
1836     }
1837 
1838     int32_t deviceType = 0;
1839     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
1840         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
1841     {
1842         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1843         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = dmsDeviceInfo;
1844     }
1845     int32_t numMissions = 0;
1846     std::vector<AAFwk::MissionInfo> missionInfos;
1847     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(DEVICE_ID, numMissions, missionInfos);
1848     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1849     DTEST_LOG << "testGetMissionInfos007 end" << std::endl;
1850 }
1851 
1852 /**
1853  * @tc.name: testGetMissionInfos008
1854  * @tc.desc: get missions
1855  * @tc.type: FUNC
1856  */
1857 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos008, TestSize.Level3)
1858 {
1859     DTEST_LOG << "testGetMissionInfos008 begin" << std::endl;
1860     {
1861         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1862         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
1863     }
1864 
1865     int32_t deviceType = 0;
1866     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
1867         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
1868     {
1869         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1870         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = dmsDeviceInfo;
1871     }
1872     int32_t numMissions = NORMAL_NUM_MISSIONS;
1873     std::vector<AAFwk::MissionInfo> missionInfos;
1874     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(DEVICE_ID, numMissions, missionInfos);
1875     EXPECT_EQ(ret, ERR_OK);
1876     DTEST_LOG << "testGetMissionInfos008 end" << std::endl;
1877 }
1878 
1879 /**
1880  * @tc.name: testGetMissionInfos009
1881  * @tc.desc: get missions
1882  * @tc.type: FUNC
1883  */
1884 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos009, TestSize.Level3)
1885 {
1886     DTEST_LOG << "testGetMissionInfos009 begin" << std::endl;
1887     {
1888         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1889         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
1890     }
1891 
1892     int32_t deviceType = 0;
1893     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
1894         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
1895     {
1896         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1897         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[localDeviceId_] = dmsDeviceInfo;
1898     }
1899     int32_t numMissions = NORMAL_NUM_MISSIONS;
1900     std::vector<AAFwk::MissionInfo> missionInfos;
1901     std::string uuid = DtbschedmgrDeviceInfoStorage::GetInstance().GetUuidByNetworkId(localDeviceId_);
1902     {
1903         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteMissionInfosLock_);
1904         DistributedSchedMissionManager::GetInstance().deviceMissionInfos_.erase(uuid);
1905     }
1906     std::vector<DstbMissionInfo> dstbMissionInfos;
1907     {
1908         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteMissionInfosLock_);
1909         DistributedSchedMissionManager::GetInstance().deviceMissionInfos_[uuid] = dstbMissionInfos;
1910     }
1911     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(localDeviceId_, numMissions, missionInfos);
1912     EXPECT_EQ(ret, ERR_OK);
1913     DTEST_LOG << "testGetMissionInfos009 end" << std::endl;
1914 }
1915 
1916 /**
1917  * @tc.name: testInitDataStorage003
1918  * @tc.desc: test init data storage
1919  * @tc.type: FUNC
1920  */
1921 HWTEST_F(DMSMissionManagerTest, testInitDataStorage003, TestSize.Level3)
1922 {
1923     DTEST_LOG << "testInitDataStorage003 begin" << std::endl;
1924     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ == nullptr) {
1925         DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1926             std::make_shared<DistributedDataStorage>();
1927     }
1928     auto ret = DistributedSchedMissionManager::GetInstance().InitDataStorage();
1929     EXPECT_EQ(ret, ERR_NONE);
1930     ret = DistributedSchedMissionManager::GetInstance().StopDataStorage();
1931     DTEST_LOG << "testInitDataStorage003 end" << std::endl;
1932 }
1933 
1934 /**
1935  * @tc.name: testStopDataStorage003
1936  * @tc.desc: test stop data storage
1937  * @tc.type: FUNC
1938  */
1939 HWTEST_F(DMSMissionManagerTest, testStopDataStorage003, TestSize.Level3)
1940 {
1941     DTEST_LOG << "testStopDataStorage003 begin" << std::endl;
1942     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1943         std::make_shared<DistributedDataStorage>();
1944     auto result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Init();
__anon03ffda660602() 1945     auto initDoneTask = []() {
1946         std::lock_guard<std::mutex> autoLock(caseDoneLock_);
1947         isCaseDone_ = true;
1948         caseDoneCondition_.notify_all();
1949     };
1950     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
1951         std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
1952             DistributedSchedMissionManager::GetInstance().distributedDataStorage_->dmsDataStorageHandler_;
1953         if (dmsDataStorageHandler != nullptr) {
1954             dmsDataStorageHandler->PostTask(initDoneTask);
1955         }
1956     }
1957     std::unique_lock<std::mutex> lock(caseDoneLock_);
1958     caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
__anon03ffda660702() 1959         [&] () { return isCaseDone_; });
1960     EXPECT_TRUE(result);
1961     isCaseDone_ = false;
1962     auto ret = DistributedSchedMissionManager::GetInstance().StopDataStorage();
1963     EXPECT_EQ(ret, ERR_NONE);
1964     DTEST_LOG << "testStopDataStorage003 end" << std::endl;
1965 }
1966 
1967 /**
1968  * @tc.name: testStoreSnapshotInfo004
1969  * @tc.desc: test store snapshot info
1970  * @tc.type: FUNC
1971  */
1972 HWTEST_F(DMSMissionManagerTest, testStoreSnapshotInfo004, TestSize.Level3)
1973 {
1974     DTEST_LOG << "testStoreSnapshotInfo004 begin" << std::endl;
1975     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1976             std::make_shared<DistributedDataStorage>();
1977     auto ret = DistributedSchedMissionManager::GetInstance().StoreSnapshotInfo(DEVICE_ID, 0, 0, 0);
1978     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1979     DTEST_LOG << "testStoreSnapshotInfo004 end" << std::endl;
1980 }
1981 
1982 /**
1983  * @tc.name: testStoreSnapshotInfo003
1984  * @tc.desc: test store snapshot info
1985  * @tc.type: FUNC
1986  */
1987 HWTEST_F(DMSMissionManagerTest, testStoreSnapshotInfo003, TestSize.Level3)
1988 {
1989     DTEST_LOG << "testStoreSnapshotInfo003 begin" << std::endl;
1990     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1991         std::make_shared<DistributedDataStorage>();
1992     auto result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Init();
__anon03ffda660802() 1993     auto initDoneTask = []() {
1994         std::lock_guard<std::mutex> autoLock(caseDoneLock_);
1995         isCaseDone_ = true;
1996         caseDoneCondition_.notify_all();
1997     };
1998     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
1999         std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
2000             DistributedSchedMissionManager::GetInstance().distributedDataStorage_->dmsDataStorageHandler_;
2001         if (dmsDataStorageHandler != nullptr) {
2002             dmsDataStorageHandler->PostTask(initDoneTask);
2003         }
2004     }
2005     std::unique_lock<std::mutex> lock(caseDoneLock_);
2006     caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
__anon03ffda660902() 2007         [&] () { return isCaseDone_; });
2008     EXPECT_TRUE(result);
2009     isCaseDone_ = false;
2010     std::string uuid = "uuid for GetUuidByNetworkId";
2011     {
2012         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2013         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
2014     }
2015     uint8_t* byteStream = new uint8_t[BYTESTREAM_LENGTH];
2016     for (size_t i = 0; i < BYTESTREAM_LENGTH; ++i) {
2017         byteStream[i] = ONE_BYTE;
2018     }
2019     auto ret = DistributedSchedMissionManager::GetInstance().
2020         StoreSnapshotInfo(localDeviceId_, TASK_ID, byteStream, BYTESTREAM_LENGTH);
2021     EXPECT_EQ(ret, ERR_NONE);
2022     ret = DistributedSchedMissionManager::GetInstance().RemoveSnapshotInfo(localDeviceId_, TASK_ID);
2023     EXPECT_EQ(ret, ERR_NONE);
2024     DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Stop();
2025     DTEST_LOG << "testStoreSnapshotInfo003 end" << std::endl;
2026 }
2027 
2028 /**
2029  * @tc.name: testRemoveSnapshotInfo003
2030  * @tc.desc: test remove snapshot info
2031  * @tc.type: FUNC
2032  */
2033 HWTEST_F(DMSMissionManagerTest, testRemoveSnapshotInfo003, TestSize.Level3)
2034 {
2035     DTEST_LOG << "testRemoveSnapshotInfo003 begin" << std::endl;
2036     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
2037             std::make_shared<DistributedDataStorage>();
2038     auto ret = DistributedSchedMissionManager::GetInstance().RemoveSnapshotInfo(DEVICE_ID, 0);
2039     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2040     DTEST_LOG << "testRemoveSnapshotInfo003 end" << std::endl;
2041 }
2042 
2043 /**
2044  * @tc.name: testGetRemoteMissionSnapshotInfo002
2045  * @tc.desc: test get remote mission snapshot info
2046  * @tc.type: FUNC
2047  */
2048 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionSnapshotInfo002, TestSize.Level3)
2049 {
2050     DTEST_LOG << "testGetRemoteMissionSnapshotInfo002 begin" << std::endl;
2051     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
2052     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ = nullptr;
2053     std::string uuid = "uuid for GetUuidByNetworkId";
2054     {
2055         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2056         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
2057     }
2058     auto ret = DistributedSchedMissionManager::GetInstance().GetRemoteMissionSnapshotInfo(localDeviceId_,
2059         0, missionSnapshot);
2060     EXPECT_EQ(ret, ERR_NULL_OBJECT);
2061     DTEST_LOG << "testGetRemoteMissionSnapshotInfo002 end" << std::endl;
2062 }
2063 
2064 /**
2065  * @tc.name: testGetRemoteMissionSnapshotInfo004
2066  * @tc.desc: test get remote mission snapshot info
2067  * @tc.type: FUNC
2068  */
2069 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionSnapshotInfo004, TestSize.Level3)
2070 {
2071     DTEST_LOG << "testGetRemoteMissionSnapshotInfo004 begin" << std::endl;
2072     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
2073     std::string uuid = "uuid for GetUuidByNetworkId";
2074     {
2075         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2076         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
2077     }
2078     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
2079         std::make_shared<DistributedDataStorage>();
2080     auto ret = DistributedSchedMissionManager::GetInstance().GetRemoteMissionSnapshotInfo(localDeviceId_,
2081         TASK_ID, missionSnapshot);
2082     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2083     DTEST_LOG << "testGetRemoteMissionSnapshotInfo004 end" << std::endl;
2084 }
2085 
2086 /**
2087  * @tc.name: testGetRemoteMissionSnapshotInfo005
2088  * @tc.desc: test get remote mission snapshot info
2089  * @tc.type: FUNC
2090  */
2091 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionSnapshotInfo005, TestSize.Level3)
2092 {
2093     DTEST_LOG << "testGetRemoteMissionSnapshotInfo005 begin" << std::endl;
2094     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
2095     std::string uuid = "uuid for GetUuidByNetworkId";
2096     {
2097         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2098         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
2099     }
2100     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
2101         std::make_shared<DistributedDataStorage>();
2102     auto result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Init();
__anon03ffda660a02() 2103     auto initDoneTask = []() {
2104         std::lock_guard<std::mutex> autoLock(caseDoneLock_);
2105         isCaseDone_ = true;
2106         caseDoneCondition_.notify_all();
2107     };
2108     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
2109         std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
2110             DistributedSchedMissionManager::GetInstance().distributedDataStorage_->dmsDataStorageHandler_;
2111         if (dmsDataStorageHandler != nullptr) {
2112             dmsDataStorageHandler->PostTask(initDoneTask);
2113         }
2114     }
2115     std::unique_lock<std::mutex> lock(caseDoneLock_);
2116     caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
__anon03ffda660b02() 2117         [&] () { return isCaseDone_; });
2118     EXPECT_TRUE(result);
2119     isCaseDone_ = false;
2120     uint8_t* byteStream = new uint8_t[BYTESTREAM_LENGTH];
2121     for (size_t i = 0; i < BYTESTREAM_LENGTH; ++i) {
2122         byteStream[i] = ONE_BYTE;
2123     }
2124     result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Insert(localDeviceId_,
2125         TASK_ID, byteStream, BYTESTREAM_LENGTH);
2126     EXPECT_TRUE(result);
2127     auto ret = DistributedSchedMissionManager::GetInstance().GetRemoteMissionSnapshotInfo(localDeviceId_,
2128         TASK_ID, missionSnapshot);
2129     EXPECT_EQ(ret, ERR_NULL_OBJECT);
2130     DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Stop();
2131     DTEST_LOG << "testGetRemoteMissionSnapshotInfo005 end" << std::endl;
2132 }
2133 
2134 /**
2135  * @tc.name: testDeviceOfflineNotify003
2136  * @tc.desc: test device offline notify
2137  * @tc.type: FUNC
2138  */
2139 HWTEST_F(DMSMissionManagerTest, testDeviceOfflineNotify003, TestSize.Level3)
2140 {
2141     DTEST_LOG << "testDeviceOfflineNotify003 begin" << std::endl;
2142     DistributedSchedMissionManager::GetInstance().Init();
2143     DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify(DEVICE_ID);
2144     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2145     sptr<IDistributedSched> remoteDmsObj(new DistributedSchedProxy(listener));
2146     {
2147         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2148         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2149     }
2150     {
2151         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2152         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = remoteDmsObj;
2153     }
2154     DistributedSchedMissionManager::GetInstance().DeviceOfflineNotify(DEVICE_ID);
2155     DTEST_LOG << "testDeviceOfflineNotify003 end" << std::endl;
2156 }
2157 
2158 /**
2159  * @tc.name: testStartSyncRemoteMissions015
2160  * @tc.desc: prepare and sync missions from remote
2161  * @tc.type: FUNC
2162  */
2163 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions015, TestSize.Level3)
2164 {
2165     DTEST_LOG << "testStartSyncRemoteMissions015 begin" << std::endl;
2166     u16string deviceId = Str8ToStr16(DEVICE_ID);
2167     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2168     {
2169         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2170         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2171     }
2172     {
2173         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2174         ListenerInfo listenerInfo;
2175         listenerInfo.Emplace(listener);
2176         listenerInfo.called = true;
2177         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2178     }
2179     sptr<IDistributedSched> proxy = GetDms();
2180     if (proxy == nullptr) {
2181         return;
2182     }
2183     {
2184         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2185         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2186     }
2187     {
2188         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2189         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = proxy;
2190     }
2191     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, localDeviceId_);
2192     EXPECT_EQ(ret, ERR_NONE);
2193     DTEST_LOG << "testStartSyncRemoteMissions015 end" << std::endl;
2194 }
2195 
2196 /**
2197  * @tc.name: testStartSyncRemoteMissions016
2198  * @tc.desc: prepare and sync missions from remote
2199  * @tc.type: FUNC
2200  */
2201 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions016, TestSize.Level3)
2202 {
2203     DTEST_LOG << "testStartSyncRemoteMissions016 begin" << std::endl;
2204     u16string deviceId = Str8ToStr16(DEVICE_ID);
2205     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2206     {
2207         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2208         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2209     }
2210     {
2211         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2212         ListenerInfo listenerInfo;
2213         listenerInfo.Emplace(listener);
2214         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2215     }
2216     sptr<IDistributedSched> proxy = GetDms();
2217     if (proxy == nullptr) {
2218         return;
2219     }
2220     {
2221         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2222         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2223     }
2224     {
2225         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2226         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = proxy;
2227     }
2228     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, localDeviceId_);
2229     EXPECT_NE(ret, ERR_NONE);
2230     DTEST_LOG << "testStartSyncRemoteMissions016 end" << std::endl;
2231 }
2232 
2233 /**
2234  * @tc.name: testUnRegisterMissionListener006
2235  * @tc.desc: register mission listener
2236  * @tc.type: FUNC
2237  */
2238 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener006, TestSize.Level3)
2239 {
2240     DTEST_LOG << "testUnRegisterMissionListener006 begin" << std::endl;
2241     /**
2242      * @tc.steps: step1. test device online notify
2243      */
2244     DTEST_LOG << "testDeviceOnlineNotify001 begin" << std::endl;
2245     DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify("");
2246     DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify(DEVICE_ID);
2247     DTEST_LOG << "testDeviceOnlineNotify001 end" << std::endl;
2248 
2249     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2250     {
2251         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2252         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2253     }
2254     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
2255     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
2256     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(U16DEVICE_ID, listener);
2257     EXPECT_EQ(ret, ERR_NONE);
2258     DTEST_LOG << "testUnRegisterMissionListener006 end" << std::endl;
2259 }
2260 
2261 /**
2262  * @tc.name: testUnRegisterMissionListener007
2263  * @tc.desc: register mission listener
2264  * @tc.type: FUNC
2265  */
2266 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener007, TestSize.Level3)
2267 {
2268     DTEST_LOG << "testUnRegisterMissionListener007 begin" << std::endl;
2269     /**
2270      * @tc.steps: step1. test delete data storage
2271      */
2272     DTEST_LOG << "testDeleteDataStorage001 begin" << std::endl;
2273     DistributedSchedMissionManager::GetInstance().DeleteDataStorage("", false);
2274     DTEST_LOG << "testDeleteDataStorage001 end" << std::endl;
2275     DTEST_LOG << "testDeleteDataStorage002 begin" << std::endl;
2276     DistributedSchedMissionManager::GetInstance().DeleteDataStorage(DEVICE_ID, false);
2277     DTEST_LOG << "testDeleteDataStorage002 end" << std::endl;
2278     DTEST_LOG << "testDeleteDataStorage003 begin" << std::endl;
2279     DistributedSchedMissionManager::GetInstance().DeleteDataStorage("", true);
2280     DTEST_LOG << "testDeleteDataStorage003 end" << std::endl;
2281     DTEST_LOG << "testDeleteDataStorage004 begin" << std::endl;
2282     DistributedSchedMissionManager::GetInstance().DeleteDataStorage(DEVICE_ID, true);
2283     DTEST_LOG << "testDeleteDataStorage004 end" << std::endl;
2284 
2285     u16string deviceId = Str8ToStr16(DEVICE_ID);
2286     {
2287         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2288         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2289     }
2290     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2291     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
2292     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
2293     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(deviceId, listener);
2294     EXPECT_EQ(ret, ERR_NONE);
2295     DTEST_LOG << "testUnRegisterMissionListener007 end" << std::endl;
2296 }
2297 
2298 /**
2299  * @tc.name: testUnRegisterMissionListener008
2300  * @tc.desc: register mission listener
2301  * @tc.type: FUNC
2302  */
2303 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener008, TestSize.Level3)
2304 {
2305     DTEST_LOG << "testUnRegisterMissionListener008 begin" << std::endl;
2306     /**
2307      * @tc.steps: step1. enqueue cached snapshot info
2308      */
2309     DTEST_LOG << "testEnqueueCachedSnapshotInfo001 begin" << std::endl;
2310     DistributedSchedMissionManager::GetInstance().EnqueueCachedSnapshotInfo("", 1, nullptr);
2311     DTEST_LOG << "testEnqueueCachedSnapshotInfo001 end" << std::endl;
2312     DTEST_LOG << "testEnqueueCachedSnapshotInfo002 begin" << std::endl;
2313     DistributedSchedMissionManager::GetInstance().EnqueueCachedSnapshotInfo(DEVICE_ID, 1, nullptr);
2314     DTEST_LOG << "testEnqueueCachedSnapshotInfo002 end" << std::endl;
2315     DTEST_LOG << "testEnqueueCachedSnapshotInfo003 begin" << std::endl;
2316     unique_ptr<Snapshot> snapshot = make_unique<Snapshot>();
2317     DistributedSchedMissionManager::GetInstance().EnqueueCachedSnapshotInfo("", 1, std::move(snapshot));
2318     DTEST_LOG << "testEnqueueCachedSnapshotInfo003 end" << std::endl;
2319     DTEST_LOG << "testDequeueCachedSnapshotInfo001 begin" << std::endl;
2320     DistributedSchedMissionManager::GetInstance().DequeueCachedSnapshotInfo("", 1);
2321     DTEST_LOG << "testDequeueCachedSnapshotInfo001 end" << std::endl;
2322     DTEST_LOG << "testDequeueCachedSnapshotInfo002 begin" << std::endl;
2323     DistributedSchedMissionManager::GetInstance().DequeueCachedSnapshotInfo(DEVICE_ID, 1);
2324     DTEST_LOG << "testDequeueCachedSnapshotInfo002 end" << std::endl;
2325     /**
2326      * @tc.steps: step2. reborn mission cache
2327      */
2328     DTEST_LOG << "testRebornMissionCache001 begin" << std::endl;
2329     std::vector<DstbMissionInfo> missionInfos;
2330     DistributedSchedMissionManager::GetInstance().RebornMissionCache("", missionInfos);
2331     DTEST_LOG << "testRebornMissionCache001 end" << std::endl;
2332     DTEST_LOG << "testRebornMissionCache002 begin" << std::endl;
2333     DistributedSchedMissionManager::GetInstance().RebornMissionCache(DEVICE_ID, missionInfos);
2334     DTEST_LOG << "testRebornMissionCache002 end" << std::endl;
2335 
2336     u16string deviceId = Str8ToStr16(DEVICE_ID);
2337     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2338     {
2339         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2340         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2341     }
2342     {
2343         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2344         ListenerInfo listenerInfo;
2345         listenerInfo.Emplace(listener);
2346         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2347     }
2348     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
2349     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
2350     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(deviceId, listener);
2351     EXPECT_EQ(ret, ERR_NONE);
2352     DTEST_LOG << "testUnRegisterMissionListener008 end" << std::endl;
2353 }
2354 
2355 /**
2356  * @tc.name: testUnRegisterMissionListener009
2357  * @tc.desc: register mission listener
2358  * @tc.type: FUNC
2359  */
2360 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener009, TestSize.Level3)
2361 {
2362     DTEST_LOG << "testUnRegisterMissionListener009 begin" << std::endl;
2363     /**
2364      * @tc.steps: step1. fetch device handler
2365      */
2366     DTEST_LOG << "testFetchDeviceHandler001 begin" << std::endl;
2367     DistributedSchedMissionManager::GetInstance().FetchDeviceHandler("");
2368     DistributedSchedMissionManager::GetInstance().FetchDeviceHandler(DEVICE_ID);
2369     DTEST_LOG << "testFetchDeviceHandler001 end" << std::endl;
2370 
2371     u16string deviceId = Str8ToStr16(DEVICE_ID);
2372     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2373     sptr<IRemoteObject> nullListener = nullptr;
2374     {
2375         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2376         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2377     }
2378     {
2379         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2380         ListenerInfo listenerInfo;
2381         listenerInfo.Emplace(listener);
2382         listenerInfo.Emplace(nullListener);
2383         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2384     }
2385     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
2386     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
2387     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(deviceId, listener);
2388     EXPECT_EQ(ret, ERR_NONE);
2389     DTEST_LOG << "testUnRegisterMissionListener009 end" << std::endl;
2390 }
2391 
2392 /**
2393  * @tc.name: testCleanMissionResources002
2394  * @tc.desc: prepare and sync missions from remote
2395  * @tc.type: FUNC
2396  */
2397 HWTEST_F(DMSMissionManagerTest, testCleanMissionResources002, TestSize.Level3)
2398 {
2399     DTEST_LOG << "testCleanMissionResources002 begin" << std::endl;
2400     u16string deviceId = Str8ToStr16(DEVICE_ID);
2401     sptr<IRemoteObject> nullListener = nullptr;
2402     {
2403         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2404         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2405     }
2406     {
2407         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2408         ListenerInfo listenerInfo;
2409         listenerInfo.Emplace(nullListener);
2410         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2411     }
2412     DistributedSchedMissionManager::GetInstance().CleanMissionResources(DEVICE_ID);
2413     DTEST_LOG << "testCleanMissionResources002 end" << std::endl;
2414 }
2415 
2416 /**
2417  * @tc.name: testStopSyncRemoteMissions013
2418  * @tc.desc: stop sync missions from remote with deviceId
2419  * @tc.type: FUNC
2420  */
2421 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions013, TestSize.Level3)
2422 {
2423     DTEST_LOG << "testStopSyncRemoteMissions013 begin" << std::endl;
2424     /**
2425      * @tc.steps: step1. test GetRemoteDms
2426      */
2427     DTEST_LOG << "testGetRemoteDms001 begin" << std::endl;
2428     sptr<IDistributedSched> proxy = GetDms();
2429     if (proxy == nullptr) {
2430         return;
2431     }
2432     {
2433         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2434         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2435     }
2436     {
2437         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2438         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[localDeviceId_] = proxy;
2439     }
2440 
2441     DistributedSchedMissionManager::GetInstance().GetRemoteDms(localDeviceId_);
2442     DTEST_LOG << "testGetRemoteDms001 end" << std::endl;
2443 
2444     {
2445         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2446         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2447     }
2448     {
2449         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2450         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = proxy;
2451     }
2452     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(DEVICE_ID, false, false);
2453     EXPECT_NE(ret, ERR_NONE);
2454     DTEST_LOG << "testStopSyncRemoteMissions013 end" << std::endl;
2455 }
2456 
2457 /**
2458  * @tc.name: testStartSyncMissionsFromRemote002
2459  * @tc.desc: prepare and sync missions from remote
2460  * @tc.type: FUNC
2461  */
2462 HWTEST_F(DMSMissionManagerTest, testStartSyncMissionsFromRemote002, TestSize.Level3)
2463 {
2464     DTEST_LOG << "testStartSyncMissionsFromRemote002 begin" << std::endl;
2465     DistributedSchedUtil::MockManageMissions();
2466     /**
2467      * @tc.steps: step1. test GetRemoteDms
2468      */
2469     DTEST_LOG << "testGetRemoteDms002 begin" << std::endl;
2470     {
2471         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2472         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2473     }
2474     {
2475         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2476         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[localDeviceId_] = nullptr;
2477     }
2478 
2479     DistributedSchedMissionManager::GetInstance().GetRemoteDms(localDeviceId_);
2480     DTEST_LOG << "testGetRemoteDms002 end" << std::endl;
2481 
2482     std::vector<DstbMissionInfo> missionInfos;
2483     CallerInfo callerInfo;
2484     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
2485     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
2486     DistributedSchedMissionManager::GetInstance().missonChangeListener_ = new DistributedMissionChangeListener();
2487     DistributedSchedMissionManager::GetInstance().GenerateCallerInfo(callerInfo);
2488     DistributedSchedMissionManager::GetInstance().isRegMissionChange_ = true;
2489     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncMissionsFromRemote(callerInfo, missionInfos);
2490     EXPECT_EQ(ret, ERR_NONE);
2491     DTEST_LOG << "testStartSyncMissionsFromRemote002 end" << std::endl;
2492 }
2493 
2494 /**
2495  * @tc.name: testStartSyncMissionsFromRemote003
2496  * @tc.desc: prepare and sync missions from remote
2497  * @tc.type: FUNC
2498  */
2499 HWTEST_F(DMSMissionManagerTest, testStartSyncMissionsFromRemote003, TestSize.Level3)
2500 {
2501     DTEST_LOG << "testStartSyncMissionsFromRemote003 begin" << std::endl;
2502     DistributedSchedUtil::MockManageMissions();
2503     /**
2504      * @tc.steps: step1. test notify remote died
2505      */
2506     DTEST_LOG << "testNotifyRemoteDied002 begin" << std::endl;
2507     wptr<IRemoteObject> remote = new RemoteMissionListenerTest();
2508     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ == nullptr) {
2509         DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
2510             std::make_shared<DistributedDataStorage>();
2511     }
2512     DistributedSchedMissionManager::GetInstance().NotifyRemoteDied(remote);
2513     DTEST_LOG << "testNotifyRemoteDied002 end" << std::endl;
2514 
2515     std::vector<DstbMissionInfo> missionInfos;
2516     CallerInfo callerInfo;
2517     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
2518     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
2519     DistributedSchedMissionManager::GetInstance().missonChangeListener_ = nullptr;
2520     DistributedSchedMissionManager::GetInstance().GenerateCallerInfo(callerInfo);
2521     DistributedSchedMissionManager::GetInstance().isRegMissionChange_ = false;
2522     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncMissionsFromRemote(callerInfo, missionInfos);
2523     EXPECT_EQ(ret, ERR_NONE);
2524     DTEST_LOG << "testStartSyncMissionsFromRemote003 end" << std::endl;
2525 }
2526 
2527 /**
2528  * @tc.name: testStopSyncMissionsFromRemote003
2529  * @tc.desc: stop sync missions from remote
2530  * @tc.type: FUNC
2531  */
2532 HWTEST_F(DMSMissionManagerTest, testStopSyncMissionsFromRemote003, TestSize.Level3)
2533 {
2534     DTEST_LOG << "testStopSyncMissionsFromRemote003 begin" << std::endl;
2535     std::vector<DstbMissionInfo> missionInfos;
2536     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
2537     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
2538     DistributedSchedMissionManager::GetInstance().missonChangeListener_ = nullptr;
2539     DistributedSchedMissionManager::GetInstance().StopSyncMissionsFromRemote(DEVICE_ID);
2540     DTEST_LOG << "testStopSyncMissionsFromRemote003 end" << std::endl;
2541 }
2542 
2543 /**
2544  * @tc.name: testNeedSyncDevice003
2545  * @tc.desc: need sync device
2546  * @tc.type: FUNC
2547  */
2548 HWTEST_F(DMSMissionManagerTest, testNeedSyncDevice003, TestSize.Level3)
2549 {
2550     DTEST_LOG << "testNeedSyncDevice003 begin" << std::endl;
2551     /**
2552      * @tc.steps: step1. delete cached snapshot info
2553      */
2554     DTEST_LOG << "testDeleteCachedSnapshotInfo001 begin" << std::endl;
2555     u16string deviceId = Str8ToStr16(DEVICE_ID);
2556     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2557     {
2558         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2559         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2560     }
2561     {
2562         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2563         ListenerInfo listenerInfo;
2564         listenerInfo.Emplace(listener);
2565         listenerInfo.called = true;
2566         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2567     }
2568     DistributedSchedMissionManager::GetInstance().NotifySnapshotChanged(DEVICE_ID, 0);
2569     std::string uuid = "uuid for GetUuidByNetworkId";
2570     {
2571         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2572         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_.clear();
2573     }
2574     {
2575         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2576         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = DEVICE_ID;
2577     }
2578     std::unique_ptr<Snapshot> snapshot = make_unique<Snapshot>();
2579     std::string key = DistributedSchedMissionManager::GetInstance().GenerateKeyInfo(DEVICE_ID, 1);
2580     {
2581         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2582         DistributedSchedMissionManager::GetInstance().cachedSnapshotInfos_.clear();
2583     }
2584     {
2585         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2586         DistributedSchedMissionManager::GetInstance().cachedSnapshotInfos_[key] = std::move(snapshot);
2587     }
2588     DistributedSchedMissionManager::GetInstance().DeleteCachedSnapshotInfo(DEVICE_ID);
2589     DTEST_LOG << "testDeleteCachedSnapshotInfo001 end" << std::endl;
2590 
2591     {
2592         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteSyncDeviceLock_);
2593         DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.clear();
2594     }
2595     {
2596         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteSyncDeviceLock_);
2597         DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.emplace(DEVICE_ID);
2598     }
2599     bool ret = DistributedSchedMissionManager::GetInstance().NeedSyncDevice(DEVICE_ID);
2600     EXPECT_TRUE(ret);
2601     DTEST_LOG << "testNeedSyncDevice003 end" << std::endl;
2602 }
2603 
2604 /**
2605  * @tc.name: testHasSyncListener002
2606  * @tc.desc: need sync device
2607  * @tc.type: FUNC
2608  */
2609 HWTEST_F(DMSMissionManagerTest, testHasSyncListener002, TestSize.Level3)
2610 {
2611     DTEST_LOG << "testHasSyncListener002 begin" << std::endl;
2612     /**
2613      * @tc.steps: step1. reborn mission cache
2614      */
2615     DTEST_LOG << "testRebornMissionCache003 begin" << std::endl;
2616     std::string uuid = "uuid for GetUuidByNetworkId";
2617     {
2618         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2619         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_.clear();
2620     }
2621     {
2622         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2623         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = DEVICE_ID;
2624     }
2625     std::vector<DstbMissionInfo> missionInfos;
2626     DistributedSchedMissionManager::GetInstance().RebornMissionCache(DEVICE_ID, missionInfos);
2627     DTEST_LOG << "testRebornMissionCache003 end" << std::endl;
2628 
2629     u16string deviceId = Str8ToStr16(DEVICE_ID);
2630     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2631     {
2632         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2633         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2634     }
2635     {
2636         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2637         ListenerInfo listenerInfo;
2638         listenerInfo.Emplace(listener);
2639         listenerInfo.called = true;
2640         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2641     }
2642     bool ret = DistributedSchedMissionManager::GetInstance().HasSyncListener(DEVICE_ID);
2643     EXPECT_TRUE(ret);
2644     DTEST_LOG << "testHasSyncListener002 end" << std::endl;
2645 }
2646 
2647 /**
2648  * @tc.name: testOnRemoteDied003
2649  * @tc.desc: test on remote died
2650  * @tc.type: FUNC
2651  */
2652 HWTEST_F(DMSMissionManagerTest, testOnRemoteDied003, TestSize.Level3)
2653 {
2654     DTEST_LOG << "testOnRemoteDied003 begin" << std::endl;
2655     wptr<IRemoteObject> remote = new RemoteMissionListenerTest();
2656     DistributedSchedMissionManager::GetInstance().missionHandler_ = nullptr;
2657     DistributedSchedMissionManager::GetInstance().OnRemoteDied(remote);
2658     DTEST_LOG << "testOnRemoteDied003 end" << std::endl;
2659 }
2660 
2661 /**
2662  * @tc.name: testDequeueCachedSnapshotInfo003
2663  * @tc.desc: enqueue cached snapshot info
2664  * @tc.type: FUNC
2665  */
2666 HWTEST_F(DMSMissionManagerTest, testDequeueCachedSnapshotInfo003, TestSize.Level3)
2667 {
2668     DTEST_LOG << "testDequeueCachedSnapshotInfo003 begin" << std::endl;
2669     u16string deviceId = Str8ToStr16(DEVICE_ID);
2670     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2671     {
2672         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2673         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2674     }
2675     {
2676         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2677         ListenerInfo listenerInfo;
2678         listenerInfo.called = false;
2679         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2680     }
2681     DistributedSchedMissionManager::GetInstance().NotifySnapshotChanged(DEVICE_ID, 0);
2682     std::unique_ptr<Snapshot> snapshot = make_unique<Snapshot>();
2683     std::string key = DistributedSchedMissionManager::GetInstance().GenerateKeyInfo(DEVICE_ID, 1);
2684     {
2685         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2686         DistributedSchedMissionManager::GetInstance().cachedSnapshotInfos_.clear();
2687     }
2688     {
2689         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2690         DistributedSchedMissionManager::GetInstance().cachedSnapshotInfos_[key] = std::move(snapshot);
2691     }
2692     auto ret = DistributedSchedMissionManager::GetInstance().DequeueCachedSnapshotInfo(DEVICE_ID, 1);
2693     EXPECT_NE(ret, nullptr);
2694     DTEST_LOG << "testDequeueCachedSnapshotInfo003 end" << std::endl;
2695 }
2696 
2697 /**
2698  * @tc.name: testFetchCachedRemoteMissions010
2699  * @tc.desc: test FetchCachedRemoteMissions
2700  * @tc.type: FUNC
2701  */
2702 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions010, TestSize.Level3)
2703 {
2704     DTEST_LOG << "testFetchCachedRemoteMissions010 begin" << std::endl;
2705     std::string uuid = "uuid for GetUuidByNetworkId";
2706     {
2707         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2708         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_.clear();
2709     }
2710     {
2711         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2712         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = DEVICE_ID;
2713     }
2714     {
2715         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteMissionInfosLock_);
2716         DistributedSchedMissionManager::GetInstance().deviceMissionInfos_.clear();
2717     }
2718     std::vector<DstbMissionInfo> dstbMissionInfos;
2719     {
2720         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteMissionInfosLock_);
2721         DistributedSchedMissionManager::GetInstance().deviceMissionInfos_[uuid] = dstbMissionInfos;
2722     }
2723     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(DEVICE_ID,
2724         0, dstbMissionInfos);
2725     EXPECT_EQ(ret, ERR_NONE);
2726     DTEST_LOG << "testFetchCachedRemoteMissions010 end" << std::endl;
2727 }
2728 
2729 /**
2730  * @tc.name: testNotifyMissionsChangedFromRemote003
2731  * @tc.desc: notify missions changed from remote
2732  * @tc.type: FUNC
2733  */
2734 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedFromRemote003, TestSize.Level3)
2735 {
2736     DTEST_LOG << "testNotifyMissionsChangedFromRemote003 begin" << std::endl;
2737     CallerInfo callerInfo;
2738     callerInfo.sourceDeviceId = DEVICE_ID;
2739     callerInfo.uid = 0;
2740     callerInfo.pid = 0;
2741     callerInfo.dmsVersion = 0;
2742     std::vector<DstbMissionInfo> missionInfos;
2743     u16string deviceId = Str8ToStr16(DEVICE_ID);
2744     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2745     {
2746         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2747         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2748     }
2749     {
2750         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2751         ListenerInfo listenerInfo;
2752         listenerInfo.Emplace(listener);
2753         listenerInfo.called = true;
2754         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2755     }
2756     DistributedSchedMissionManager::GetInstance().missionHandler_ = nullptr;
2757     auto ret = DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedFromRemote(callerInfo, missionInfos);
2758     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2759     DTEST_LOG << "testNotifyMissionsChangedFromRemote003 end" << std::endl;
2760 }
2761 
2762 /**
2763  * @tc.name: testNotifyMissionSnapshotCreated002
2764  * @tc.desc: notify mission snapshot created
2765  * @tc.type: FUNC
2766  */
2767 HWTEST_F(DMSMissionManagerTest, testNotifyMissionSnapshotCreated002, TestSize.Level3)
2768 {
2769     DTEST_LOG << "testNotifyMissionSnapshotCreated002 begin" << std::endl;
2770     auto missionChangeRunner = AppExecFwk::EventRunner::Create("DistributedMissionChange");
2771     DistributedSchedMissionManager::GetInstance().missionChangeHandler_ =
2772         std::make_shared<AppExecFwk::EventHandler>(missionChangeRunner);
2773     DistributedSchedMissionManager::GetInstance().NotifyMissionSnapshotCreated(1);
2774     DTEST_LOG << "testNotifyMissionSnapshotCreated002 end" << std::endl;
2775 }
2776 
2777 /**
2778  * @tc.name: testNotifyMissionSnapshotCreated003
2779  * @tc.desc: notify mission snapshot created
2780  * @tc.type: FUNC
2781  */
2782 HWTEST_F(DMSMissionManagerTest, testNotifyMissionSnapshotCreated003, TestSize.Level3)
2783 {
2784     DTEST_LOG << "testNotifyMissionSnapshotCreated003 begin" << std::endl;
2785     auto missionChangeRunner = AppExecFwk::EventRunner::Create("DistributedMissionChange");
2786     DistributedSchedMissionManager::GetInstance().missionChangeHandler_ =
2787         std::make_shared<AppExecFwk::EventHandler>(missionChangeRunner);
2788     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ = nullptr;
2789     DistributedSchedMissionManager::GetInstance().NotifyMissionSnapshotCreated(1);
2790     DTEST_LOG << "testNotifyMissionSnapshotCreated003 end" << std::endl;
2791 }
2792 
2793 /**
2794  * @tc.name: testNotifyMissionsChangedToRemote002
2795  * @tc.desc: notify missions changed to remote
2796  * @tc.type: FUNC
2797  */
2798 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedToRemote002, TestSize.Level3)
2799 {
2800     DTEST_LOG << "testNotifyMissionsChangedToRemote002 begin" << std::endl;
2801     {
2802         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteSyncDeviceLock_);
2803         DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.clear();
2804     }
2805     std::vector<DstbMissionInfo> missionInfos;
2806     auto ret = DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedToRemote(missionInfos);
2807     EXPECT_EQ(ret, ERR_NONE);
2808     DTEST_LOG << "testNotifyMissionsChangedToRemote002 end" << std::endl;
2809 }
2810 
2811 /**
2812  * @tc.name: testNotifyMissionsChangedToRemote003
2813  * @tc.desc: notify missions changed to remote
2814  * @tc.type: FUNC
2815  */
2816 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedToRemote003, TestSize.Level3)
2817 {
2818     DTEST_LOG << "testNotifyMissionsChangedToRemote003 begin" << std::endl;
2819     {
2820         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteSyncDeviceLock_);
2821         DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.clear();
2822     }
2823     {
2824         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteSyncDeviceLock_);
2825         DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.emplace(localDeviceId_);
2826     }
2827     {
2828         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2829         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
2830     }
2831     int32_t deviceType = 0;
2832     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
2833         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
2834     {
2835         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2836         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[localDeviceId_] = dmsDeviceInfo;
2837     }
2838     std::string uuid = "uuid for GetUuidByNetworkId";
2839     {
2840         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2841         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_.clear();
2842     }
2843     {
2844         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2845         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
2846     }
2847     std::vector<DstbMissionInfo> missionInfos;
2848     auto ret = DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedToRemote(missionInfos);
2849     EXPECT_EQ(ret, ERR_NONE);
2850     DTEST_LOG << "testNotifyMissionsChangedToRemote003 end" << std::endl;
2851 }
2852 
2853 /**
2854  * @tc.name: testNotifyMissionsChangedToRemoteInner003
2855  * @tc.desc: notify missions changed to remote inner
2856  * @tc.type: FUNC
2857  */
2858 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedToRemoteInner003, TestSize.Level3)
2859 {
2860     DTEST_LOG << "testNotifyMissionsChangedToRemoteInner003 begin" << std::endl;
2861     sptr<IDistributedSched> proxy = GetDms();
2862     if (proxy == nullptr) {
2863         return;
2864     }
2865     {
2866         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2867         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2868     }
2869     {
2870         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2871         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = proxy;
2872     }
2873     CallerInfo callerInfo;
2874     std::vector<DstbMissionInfo> missionInfos;
2875     DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedToRemoteInner(
2876         DEVICE_ID, missionInfos, callerInfo);
2877     DTEST_LOG << "testNotifyMissionsChangedToRemoteInner003 end" << std::endl;
2878 }
2879 
2880 /**
2881  * @tc.name: testFetchDeviceHandler003
2882  * @tc.desc: fetch device handler
2883  * @tc.type: FUNC
2884  */
2885 HWTEST_F(DMSMissionManagerTest, testFetchDeviceHandler003, TestSize.Level3)
2886 {
2887     DTEST_LOG << "testFetchDeviceHandler003 begin" << std::endl;
2888     {
2889         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2890         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
2891     }
2892 
2893     int32_t deviceType = 0;
2894     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
2895         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
2896     {
2897         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2898         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = dmsDeviceInfo;
2899     }
2900     auto ret = DistributedSchedMissionManager::GetInstance().FetchDeviceHandler(DEVICE_ID);
2901     EXPECT_EQ(ret, nullptr);
2902     DTEST_LOG << "testFetchDeviceHandler003 end" << std::endl;
2903 }
2904 
2905 /**
2906  * @tc.name: testFetchDeviceHandler004
2907  * @tc.desc: fetch device handler
2908  * @tc.type: FUNC
2909  */
2910 HWTEST_F(DMSMissionManagerTest, testFetchDeviceHandler004, TestSize.Level3)
2911 {
2912     DTEST_LOG << "testFetchDeviceHandler004 begin" << std::endl;
2913     {
2914         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2915         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
2916     }
2917     int32_t deviceType = 0;
2918     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
2919         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
2920     {
2921         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2922         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = dmsDeviceInfo;
2923     }
2924 
2925     std::string uuid = "uuid for GetUuidByNetworkId";
2926     {
2927         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2928         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_.clear();
2929     }
2930     {
2931         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2932         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = DEVICE_ID;
2933     }
2934     auto ret = DistributedSchedMissionManager::GetInstance().FetchDeviceHandler(DEVICE_ID);
2935     EXPECT_NE(ret, nullptr);
2936     DTEST_LOG << "testFetchDeviceHandler004 end" << std::endl;
2937 }
2938 
2939 /**
2940  * @tc.name: testFetchDeviceHandler005
2941  * @tc.desc: fetch device handler
2942  * @tc.type: FUNC
2943  */
2944 HWTEST_F(DMSMissionManagerTest, testFetchDeviceHandler005, TestSize.Level3)
2945 {
2946     DTEST_LOG << "testFetchDeviceHandler005 begin" << std::endl;
2947     DistributedSchedMissionManager::GetInstance().isRegMissionChange_ = false;
2948     DistributedSchedMissionManager::GetInstance().NotifyDmsProxyProcessDied();
2949     {
2950         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2951         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
2952     }
2953     int32_t deviceType = 0;
2954     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
2955         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
2956     {
2957         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2958         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = dmsDeviceInfo;
2959     }
2960 
2961     std::string uuid = "uuid for GetUuidByNetworkId";
2962     {
2963         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2964         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_.clear();
2965     }
2966     {
2967         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2968         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = DEVICE_ID;
2969     }
2970     auto anonyUuid = GetAnonymStr(uuid);
2971     auto runner = AppExecFwk::EventRunner::Create(anonyUuid + "_MissionN");
2972     auto handler = std::make_shared<AppExecFwk::EventHandler>(runner);
2973     DistributedSchedMissionManager::GetInstance().deviceHandle_.emplace(uuid, handler);
2974     auto ret = DistributedSchedMissionManager::GetInstance().FetchDeviceHandler(DEVICE_ID);
2975     EXPECT_NE(ret, nullptr);
2976     DTEST_LOG << "testFetchDeviceHandler005 end" << std::endl;
2977 }
2978 
2979 /**
2980  * @tc.name: testOnRemoteDmsDied009
2981  * @tc.desc: on remote dms died
2982  * @tc.type: FUNC
2983  */
2984 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied009, TestSize.Level3)
2985 {
2986     DTEST_LOG << "testOnRemoteDmsDied009 begin" << std::endl;
2987     wptr<IRemoteObject> remote = new RemoteMissionListenerTest();
2988     DistributedSchedMissionManager::GetInstance().missionHandler_ = nullptr;
2989     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
2990     DTEST_LOG << "testOnRemoteDmsDied009 end" << std::endl;
2991 }
2992 
2993 /**
2994  * @tc.name: testOnRemoteDmsDied005
2995  * @tc.desc: on remote dms died
2996  * @tc.type: FUNC
2997  */
2998 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied005, TestSize.Level3)
2999 {
3000     DTEST_LOG << "testOnRemoteDmsDied005 begin" << std::endl;
3001     wptr<IRemoteObject> remote = new RemoteMissionListenerTest();
3002     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
3003     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
3004     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
3005     DTEST_LOG << "testOnRemoteDmsDied005 end" << std::endl;
3006 }
3007 
3008 /**
3009  * @tc.name: testRetryStartSyncRemoteMissions003
3010  * @tc.desc: retry start sync remote missions
3011  * @tc.type: FUNC
3012  */
3013 HWTEST_F(DMSMissionManagerTest, testRetryStartSyncRemoteMissions003, TestSize.Level3)
3014 {
3015     DTEST_LOG << "testRetryStartSyncRemoteMissions003 begin" << std::endl;
3016     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
3017     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
3018     DistributedSchedMissionManager::GetInstance().RetryStartSyncRemoteMissions(DEVICE_ID, localDeviceId_, 1);
3019     DTEST_LOG << "testRetryStartSyncRemoteMissions003 end" << std::endl;
3020 }
3021 
3022 /**
3023  * @tc.name: testRetryStartSyncRemoteMissions004
3024  * @tc.desc: retry start sync remote missions
3025  * @tc.type: FUNC
3026  */
3027 HWTEST_F(DMSMissionManagerTest, testRetryStartSyncRemoteMissions004, TestSize.Level3)
3028 {
3029     DTEST_LOG << "testRetryStartSyncRemoteMissions004 begin" << std::endl;
3030     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
3031     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
3032     u16string deviceId = Str8ToStr16(DEVICE_ID);
3033     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
3034     {
3035         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
3036         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
3037     }
3038     {
3039         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
3040         ListenerInfo listenerInfo;
3041         listenerInfo.Emplace(listener);
3042         listenerInfo.called = true;
3043         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
3044     }
3045     DistributedSchedMissionManager::GetInstance().RetryStartSyncRemoteMissions(DEVICE_ID, localDeviceId_, 1);
3046     DTEST_LOG << "testRetryStartSyncRemoteMissions004 end" << std::endl;
3047 }
3048 
3049 /**
3050  * @tc.name: testRetryStartSyncRemoteMissions005
3051  * @tc.desc: retry start sync remote missions
3052  * @tc.type: FUNC
3053  */
3054 HWTEST_F(DMSMissionManagerTest, testRetryStartSyncRemoteMissions005, TestSize.Level3)
3055 {
3056     DTEST_LOG << "testRetryStartSyncRemoteMissions005 begin" << std::endl;
3057     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
3058     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
3059     u16string deviceId = Str8ToStr16(DEVICE_ID);
3060     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
3061     {
3062         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
3063         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
3064     }
3065     {
3066         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
3067         ListenerInfo listenerInfo;
3068         listenerInfo.Emplace(listener);
3069         listenerInfo.called = true;
3070         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
3071     }
3072     sptr<IDistributedSched> proxy = GetDms();
3073     if (proxy == nullptr) {
3074         return;
3075     }
3076     {
3077         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
3078         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
3079     }
3080     {
3081         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
3082         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = proxy;
3083     }
3084     DistributedSchedMissionManager::GetInstance().RetryStartSyncRemoteMissions(DEVICE_ID, localDeviceId_, 1);
3085     DTEST_LOG << "testRetryStartSyncRemoteMissions005 end" << std::endl;
3086 }
3087 
3088 /**
3089  * @tc.name: testOnMissionListenerDied003
3090  * @tc.desc: on mission listener died
3091  * @tc.type: FUNC
3092  */
3093 HWTEST_F(DMSMissionManagerTest, testOnMissionListenerDied003, TestSize.Level3)
3094 {
3095     DTEST_LOG << "testOnMissionListenerDied003 begin" << std::endl;
3096     u16string deviceId = Str8ToStr16(DEVICE_ID);
3097     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
3098     {
3099         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
3100         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
3101     }
3102     {
3103         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
3104         ListenerInfo listenerInfo;
3105         listenerInfo.Emplace(listener);
3106         listenerInfo.called = true;
3107         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
3108     }
3109     DistributedSchedMissionManager::GetInstance().OnMissionListenerDied(listener);
3110     DTEST_LOG << "testOnMissionListenerDied003 end" << std::endl;
3111 }
3112 
3113 /**
3114  * @tc.name: testOnMissionListenerDied004
3115  * @tc.desc: on mission listener died
3116  * @tc.type: FUNC
3117  */
3118 HWTEST_F(DMSMissionManagerTest, testOnMissionListenerDied004, TestSize.Level3)
3119 {
3120     DTEST_LOG << "testOnMissionListenerDied004 begin" << std::endl;
3121     u16string deviceId = Str8ToStr16(DEVICE_ID);
3122     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
3123     {
3124         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
3125         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
3126     }
3127     sptr<IRemoteObject> remote = sptr<IRemoteObject>();
3128     {
3129         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
3130         ListenerInfo listenerInfo;
3131         listenerInfo.Emplace(listener);
3132         listenerInfo.called = true;
3133         listenerInfo.Emplace(remote);
3134         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
3135     }
3136     DistributedSchedMissionManager::GetInstance().OnMissionListenerDied(listener);
3137     DTEST_LOG << "testOnMissionListenerDied004 end" << std::endl;
3138 }
3139 
3140 /**
3141  * @tc.name: testOnMissionListenerDied005
3142  * @tc.desc: on mission listener died
3143  * @tc.type: FUNC
3144  */
3145 HWTEST_F(DMSMissionManagerTest, testOnMissionListenerDied005, TestSize.Level3)
3146 {
3147     DTEST_LOG << "testOnMissionListenerDied005 begin" << std::endl;
3148     u16string deviceId = Str8ToStr16(DEVICE_ID);
3149     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
3150     {
3151         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
3152         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
3153     }
3154     {
3155         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
3156         ListenerInfo listenerInfo;
3157         listenerInfo.Emplace(listener);
3158         listenerInfo.called = false;
3159         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
3160     }
3161     DistributedSchedMissionManager::GetInstance().OnMissionListenerDied(listener);
3162     DTEST_LOG << "testOnMissionListenerDied005 end" << std::endl;
3163 }
3164 
3165 /**
3166  * @tc.name: testOnRemoteDmsDied006
3167  * @tc.desc: on remote dms died
3168  * @tc.type: FUNC
3169  */
3170 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied006, TestSize.Level3)
3171 {
3172     DTEST_LOG << "testOnRemoteDmsDied006 begin" << std::endl;
3173     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
3174     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
3175     sptr<IRemoteObject> remote(new RemoteMissionListenerTest());
3176     sptr<IDistributedSched> remoteDmsObj(new DistributedSchedProxy(remote));
3177     {
3178         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
3179         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
3180     }
3181     {
3182         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
3183         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = remoteDmsObj;
3184     }
3185     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
3186     DTEST_LOG << "testOnRemoteDmsDied006 end" << std::endl;
3187 }
3188 
3189 /**
3190  * @tc.name: testOnRemoteDmsDied007
3191  * @tc.desc: on remote dms died
3192  * @tc.type: FUNC
3193  */
3194 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied007, TestSize.Level3)
3195 {
3196     DTEST_LOG << "testOnRemoteDmsDied007 begin" << std::endl;
3197     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
3198     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
3199     sptr<IRemoteObject> remote(new RemoteMissionListenerTest());
3200     sptr<IDistributedSched> proxy = GetDms();
3201     if (proxy == nullptr) {
3202         return;
3203     }
3204     {
3205         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
3206         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
3207     }
3208     {
3209         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
3210         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = proxy;
3211     }
3212     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
3213     DTEST_LOG << "testOnRemoteDmsDied007 end" << std::endl;
3214 }
3215 
3216 /**
3217  * @tc.name: testOnRemoteDmsDied008
3218  * @tc.desc: on remote dms died
3219  * @tc.type: FUNC
3220  */
3221 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied008, TestSize.Level3)
3222 {
3223     DTEST_LOG << "testOnRemoteDmsDied008 begin" << std::endl;
3224     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
3225     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
3226     sptr<IRemoteObject> remote(new RemoteMissionListenerTest());
3227     sptr<IDistributedSched> remoteDmsObj(new DistributedSchedProxy(remote));
3228     {
3229         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
3230         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
3231     }
3232     {
3233         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
3234         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = remoteDmsObj;
3235     }
3236     u16string deviceId = Str8ToStr16(DEVICE_ID);
3237     {
3238         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
3239         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
3240     }
3241     {
3242         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
3243         ListenerInfo listenerInfo;
3244         listenerInfo.Emplace(remote);
3245         listenerInfo.called = true;
3246         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
3247     }
3248     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
3249     DTEST_LOG << "testOnRemoteDmsDied008 end" << std::endl;
3250 }
3251 
3252 /**
3253  * @tc.name: testRetryRegisterMissionChange002
3254  * @tc.desc: retry register mission change
3255  * @tc.type: FUNC
3256  */
3257 HWTEST_F(DMSMissionManagerTest, testRetryRegisterMissionChange002, TestSize.Level3)
3258 {
3259     DTEST_LOG << "testRetryRegisterMissionChange002 begin" << std::endl;
3260     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
3261     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
3262     DistributedSchedMissionManager::GetInstance().RetryRegisterMissionChange(1);
3263     DTEST_LOG << "testRetryRegisterMissionChange002 end" << std::endl;
3264 }
3265 
3266 /**
3267  * @tc.name: testOnDnetDied002
3268  * @tc.desc: on dnet died
3269  * @tc.type: FUNC
3270  */
3271 HWTEST_F(DMSMissionManagerTest, testOnDnetDied002, TestSize.Level3)
3272 {
3273     DTEST_LOG << "testOnDnetDied002 begin" << std::endl;
3274     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
3275     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
3276     DistributedSchedMissionManager::GetInstance().isRegMissionChange_ = false;
3277     DistributedSchedMissionManager::GetInstance().OnDnetDied();
3278     DTEST_LOG << "testOnDnetDied002 end" << std::endl;
3279 }
3280 } // namespace DistributedSchedule
3281 } // namespace OHOS