代码拉取完成,页面将自动刷新
diff --git a/frameworks/libs/distributeddb/interfaces/include/store_types.h b/frameworks/libs/distributeddb/interfaces/include/store_types.h
index a5dd8fd81..279897a61 100644
--- a/frameworks/libs/distributeddb/interfaces/include/store_types.h
+++ b/frameworks/libs/distributeddb/interfaces/include/store_types.h
@@ -319,5 +319,17 @@ enum class DataOperator : uint32_t {
UPDATE_TIME = 0x01,
RESET_UPLOAD_CLOUD = 0x02
};
+
+struct DeviceSyncTarget {
+ std::string device;
+ std::string userId;
+ bool operator<(const DeviceSyncTarget &other) const
+ {
+ if (device == other.device) {
+ return userId < other.userId;
+ }
+ return device < other.device;
+ }
+};
} // namespace DistributedDB
#endif // KV_STORE_TYPE_H
diff --git a/frameworks/libs/distributeddb/syncer/src/device/isync_task_context.h b/frameworks/libs/distributeddb/syncer/src/device/isync_task_context.h
index 62a84de9c..2ef33d7d5 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/isync_task_context.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/isync_task_context.h
@@ -35,7 +35,7 @@ public:
enum TASK_EXEC_STATUS { INIT, RUNNING, FAILED, FINISHED };
// Initialize the context
- virtual int Initialize(const std::string &deviceId, ISyncInterface *syncInterface,
+ virtual int Initialize(const DeviceSyncTarget &target, ISyncInterface *syncInterface,
const std::shared_ptr<Metadata> &metadata, ICommunicator *communicator) = 0;
// Add a sync task target with the operation to the queue
diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.cpp b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.cpp
index 9ef639894..6115d8cbb 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.cpp
@@ -39,10 +39,10 @@ SingleVerSyncTaskContext::~SingleVerSyncTaskContext()
subManager_ = nullptr;
}
-int SingleVerSyncTaskContext::Initialize(const std::string &deviceId, ISyncInterface *syncInterface,
+int SingleVerSyncTaskContext::Initialize(const DeviceSyncTarget &target, ISyncInterface *syncInterface,
const std::shared_ptr<Metadata> &metadata, ICommunicator *communicator)
{
- if (deviceId.empty() || syncInterface == nullptr || metadata == nullptr ||
+ if (target.device.empty() || syncInterface == nullptr || metadata == nullptr ||
communicator == nullptr) {
LOGE("[SingleVerSyncTaskContext] [Initialize] parameter is invalid.");
return -E_INVALID_ARGS;
@@ -52,7 +52,8 @@ int SingleVerSyncTaskContext::Initialize(const std::string &deviceId, ISyncInter
LOGE("[SingleVerSyncTaskContext] [Initialize] stateMachine_ is nullptr.");
return -E_OUT_OF_MEMORY;
}
- deviceId_ = deviceId;
+ deviceId_ = target.device;
+ targetUserId_ = target.userId;
std::vector<uint8_t> dbIdentifier = syncInterface->GetIdentifier();
dbIdentifier.resize(3); // only show 3 bytes
syncActionName_ = DBDfxAdapter::SYNC_ACTION + "_" +
diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.h b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.h
index 0cb30f516..66efa6acf 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.h
@@ -40,7 +40,7 @@ public:
DISABLE_COPY_ASSIGN_MOVE(SingleVerSyncTaskContext);
// Init SingleVerSyncTaskContext
- int Initialize(const std::string &deviceId, ISyncInterface *syncInterface,
+ int Initialize(const DeviceSyncTarget &target, ISyncInterface *syncInterface,
const std::shared_ptr<Metadata> &metadata, ICommunicator *communicator) override;
// Add a sync task target with the operation to the queue
diff --git a/frameworks/libs/distributeddb/syncer/src/device/sync_engine.cpp b/frameworks/libs/distributeddb/syncer/src/device/sync_engine.cpp
index 08a28ff5d..6c9085656 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/sync_engine.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/sync_engine.cpp
@@ -323,13 +323,14 @@ int SyncEngine::InitComunicator(const ISyncInterface *syncInterface)
int SyncEngine::AddSyncOperForContext(const std::string &deviceId, SyncOperation *operation)
{
int errCode = E_OK;
+ std::string targetUserId = GetTargetUserId(deviceId);
ISyncTaskContext *context = nullptr;
{
std::lock_guard<std::mutex> lock(contextMapLock_);
- context = FindSyncTaskContext(deviceId);
+ context = FindSyncTaskContext({deviceId, targetUserId});
if (context == nullptr) {
if (!IsKilled()) {
- context = GetSyncTaskContext(deviceId, errCode);
+ context = GetSyncTaskContext({deviceId, targetUserId}, errCode);
}
if (context == nullptr) {
return errCode;
@@ -342,8 +343,6 @@ int SyncEngine::AddSyncOperForContext(const std::string &deviceId, SyncOperation
RefObject::IncObjRef(context);
}
- std::string targetUserId = GetTargetUserId(context->GetDeviceId());
- context->SetTargetUserId(targetUserId);
errCode = context->AddSyncOperation(operation);
if (operation != nullptr) {
operation->SetSyncContext(context); // make the life cycle of context and operation are same
@@ -419,11 +418,10 @@ int SyncEngine::DealMsgUtilQueueEmpty()
// it will deal with the first message in queue, we should increase object reference counts and sure that resources
// could be prevented from destroying by other threads.
do {
- ISyncTaskContext *nextContext = GetContextForMsg(inMsg->GetTarget(), errCode);
+ ISyncTaskContext *nextContext = GetContextForMsg({inMsg->GetTarget(), inMsg->GetSenderUserId()}, errCode);
if (errCode != E_OK) {
break;
}
- nextContext->SetTargetUserId(inMsg->GetSenderUserId());
errCode = ScheduleDealMsg(nextContext, inMsg);
if (errCode != E_OK) {
RefObject::DecObjRef(nextContext);
@@ -437,12 +435,12 @@ int SyncEngine::DealMsgUtilQueueEmpty()
return errCode;
}
-ISyncTaskContext *SyncEngine::GetContextForMsg(const std::string &targetDev, int &errCode)
+ISyncTaskContext *SyncEngine::GetContextForMsg(const DeviceSyncTarget &target, int &errCode)
{
ISyncTaskContext *context = nullptr;
{
std::lock_guard<std::mutex> lock(contextMapLock_);
- context = FindSyncTaskContext(targetDev);
+ context = FindSyncTaskContext(target);
if (context != nullptr) { // LCOV_EXCL_BR_LINE
if (context->IsKilled()) {
errCode = -E_OBJ_IS_KILLED;
@@ -453,7 +451,7 @@ ISyncTaskContext *SyncEngine::GetContextForMsg(const std::string &targetDev, int
errCode = -E_OBJ_IS_KILLED;
return nullptr;
}
- context = GetSyncTaskContext(targetDev, errCode);
+ context = GetSyncTaskContext(target, errCode);
if (context == nullptr) {
return nullptr;
}
@@ -547,11 +545,10 @@ int SyncEngine::MessageReciveCallbackInner(const std::string &targetDev, Message
}
int errCode = E_OK;
- ISyncTaskContext *nextContext = GetContextForMsg(targetDev, errCode);
+ ISyncTaskContext *nextContext = GetContextForMsg({targetDev, inMsg->GetSenderUserId()}, errCode);
if (errCode != E_OK) {
return errCode;
}
- nextContext->SetTargetUserId(inMsg->GetSenderUserId());
LOGD("[SyncEngine] MessageReciveCallback MSG ID = %d", inMsg->GetMessageId());
return ScheduleDealMsg(nextContext, inMsg);
}
@@ -602,9 +599,9 @@ int SyncEngine::GetMsgSize(const Message *inMsg) const
}
}
-ISyncTaskContext *SyncEngine::FindSyncTaskContext(const std::string &deviceId)
+ISyncTaskContext *SyncEngine::FindSyncTaskContext(const DeviceSyncTarget &target)
{
- auto iter = syncTaskContextMap_.find(deviceId);
+ auto iter = syncTaskContextMap_.find(target);
if (iter != syncTaskContextMap_.end()) {
ISyncTaskContext *context = iter->second;
return context;
@@ -612,24 +609,29 @@ ISyncTaskContext *SyncEngine::FindSyncTaskContext(const std::string &deviceId)
return nullptr;
}
-ISyncTaskContext *SyncEngine::GetSyncTaskContextAndInc(const std::string &deviceId)
+std::vector<ISyncTaskContext *> SyncEngine::GetSyncTaskContextAndInc(const std::string &deviceId)
{
- ISyncTaskContext *context = nullptr;
+ std::vector<ISyncTaskContext *> contexts;
std::lock_guard<std::mutex> lock(contextMapLock_);
- context = FindSyncTaskContext(deviceId);
- if (context == nullptr) {
- LOGI("[SyncEngine] dev=%s, context is null, no need to clear sync operation", STR_MASK(deviceId));
- return nullptr;
- }
- if (context->IsKilled()) { // LCOV_EXCL_BR_LINE
- LOGI("[SyncEngine] context is killing");
- return nullptr;
+ for (const auto &iter : syncTaskContextMap_) {
+ if (iter.first.device != deviceId) {
+ continue;
+ }
+ if (iter.second == nullptr) {
+ LOGI("[SyncEngine] dev=%s, context is null, no need to clear sync operation", STR_MASK(deviceId));
+ return {};
+ }
+ if (iter.second->IsKilled()) { // LCOV_EXCL_BR_LINE
+ LOGI("[SyncEngine] context is killing");
+ return {};
+ }
+ RefObject::IncObjRef(iter.second);
+ contexts.push_back(iter.second);
}
- RefObject::IncObjRef(context);
- return context;
+ return contexts;
}
-ISyncTaskContext *SyncEngine::GetSyncTaskContext(const std::string &deviceId, int &errCode)
+ISyncTaskContext *SyncEngine::GetSyncTaskContext(const DeviceSyncTarget &target, int &errCode)
{
auto storage = GetAndIncSyncInterface();
if (storage == nullptr) {
@@ -643,19 +645,19 @@ ISyncTaskContext *SyncEngine::GetSyncTaskContext(const std::string &deviceId, in
LOGE("[SyncEngine] SyncTaskContext alloc failed, may be no memory available!");
return nullptr;
}
- errCode = context->Initialize(deviceId, storage, metadata_, communicatorProxy_);
+ errCode = context->Initialize(target, storage, metadata_, communicatorProxy_);
if (errCode != E_OK) {
- LOGE("[SyncEngine] context init failed err %d, dev %s", errCode, STR_MASK(deviceId));
+ LOGE("[SyncEngine] context init failed err %d, dev %s", errCode, STR_MASK(target.device));
RefObject::DecObjRef(context);
storage->DecRefCount();
context = nullptr;
return nullptr;
}
- syncTaskContextMap_.insert(std::pair<std::string, ISyncTaskContext *>(deviceId, context));
+ syncTaskContextMap_.insert(std::pair<DeviceSyncTarget, ISyncTaskContext *>(target, context));
// IncRef for SyncEngine to make sure SyncEngine is valid when context access
RefObject::IncObjRef(this);
- context->OnLastRef([this, deviceId, storage]() {
- LOGD("[SyncEngine] SyncTaskContext for id %s finalized", STR_MASK(deviceId));
+ context->OnLastRef([this, target, storage]() {
+ LOGD("[SyncEngine] SyncTaskContext for id %s finalized", STR_MASK(target.device));
RefObject::DecObjRef(this);
storage->DecRefCount();
});
@@ -871,33 +873,37 @@ void SyncEngine::OfflineHandleByDevice(const std::string &deviceId, ISyncInterfa
static_cast<SyncGenericInterface *>(storage)->GetDBInfo(dbInfo);
RuntimeContext::GetInstance()->RemoveRemoteSubscribe(dbInfo, deviceId);
// get context and Inc context if context is not nullptr
- ISyncTaskContext *context = GetSyncTaskContextAndInc(deviceId);
- {
- std::lock_guard<std::mutex> lock(communicatorProxyLock_);
- if (communicatorProxy_ == nullptr) {
- return;
+ std::vector<ISyncTaskContext *> contexts = GetSyncTaskContextAndInc(deviceId);
+ for (const auto &context : contexts) {
+ {
+ std::lock_guard<std::mutex> lock(communicatorProxyLock_);
+ if (communicatorProxy_ == nullptr) {
+ return;
+ }
+ if (communicatorProxy_->IsDeviceOnline(deviceId)) { // LCOV_EXCL_BR_LINE
+ LOGI("[SyncEngine] target dev=%s is online, no need to clear task.", STR_MASK(deviceId));
+ RefObject::DecObjRef(context);
+ return;
+ }
}
- if (communicatorProxy_->IsDeviceOnline(deviceId)) { // LCOV_EXCL_BR_LINE
- LOGI("[SyncEngine] target dev=%s is online, no need to clear task.", STR_MASK(deviceId));
+ // means device is offline, clear local subscribe
+ subManager_->ClearLocalSubscribeQuery(deviceId);
+ // clear sync task
+ if (context != nullptr) {
+ context->ClearAllSyncTask();
RefObject::DecObjRef(context);
- return;
}
}
- // means device is offline, clear local subscribe
- subManager_->ClearLocalSubscribeQuery(deviceId);
- // clear sync task
- if (context != nullptr) {
- context->ClearAllSyncTask();
- RefObject::DecObjRef(context);
- }
}
void SyncEngine::ClearAllSyncTaskByDevice(const std::string &deviceId)
{
- ISyncTaskContext *context = GetSyncTaskContextAndInc(deviceId);
- if (context != nullptr) {
- context->ClearAllSyncTask();
- RefObject::DecObjRef(context);
+ std::vector<ISyncTaskContext *> contexts = GetSyncTaskContextAndInc(deviceId);
+ for (const auto &context : contexts) {
+ if (context != nullptr) {
+ context->ClearAllSyncTask();
+ RefObject::DecObjRef(context);
+ }
}
}
diff --git a/frameworks/libs/distributeddb/syncer/src/device/sync_engine.h b/frameworks/libs/distributeddb/syncer/src/device/sync_engine.h
index f81b7a474..cbed36ed9 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/sync_engine.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/sync_engine.h
@@ -142,8 +142,8 @@ protected:
virtual ISyncTaskContext *CreateSyncTaskContext(const ISyncInterface &syncInterface) = 0;
// Find SyncTaskContext from the map
- ISyncTaskContext *FindSyncTaskContext(const std::string &deviceId);
- ISyncTaskContext *GetSyncTaskContextAndInc(const std::string &deviceId);
+ ISyncTaskContext *FindSyncTaskContext(const DeviceSyncTarget &target);
+ std::vector<ISyncTaskContext *> GetSyncTaskContextAndInc(const std::string &deviceId);
void GetQueryAutoSyncParam(const std::string &device, const QuerySyncObject &query, InternalSyncParma &outParam);
void GetSubscribeSyncParam(const std::string &device, const QuerySyncObject &query, InternalSyncParma &outParam);
@@ -151,12 +151,12 @@ protected:
ISyncInterface *GetAndIncSyncInterface();
void SetSyncInterface(ISyncInterface *syncInterface);
- ISyncTaskContext *GetSyncTaskContext(const std::string &deviceId, int &errCode);
+ ISyncTaskContext *GetSyncTaskContext(const DeviceSyncTarget &target, int &errCode);
std::mutex storageMutex_;
ISyncInterface *syncInterface_;
// Used to store all send sync task infos (such as pull sync response, and push sync request)
- std::map<std::string, ISyncTaskContext *> syncTaskContextMap_;
+ std::map<DeviceSyncTarget, ISyncTaskContext *> syncTaskContextMap_;
std::mutex contextMapLock_;
std::shared_ptr<SubscribeManager> subManager_;
std::function<void(const InternalSyncParma ¶m)> queryAutoSyncCallback_;
@@ -201,7 +201,7 @@ private:
// Handle message in order.
int ScheduleDealMsg(ISyncTaskContext *context, Message *inMsg);
- ISyncTaskContext *GetContextForMsg(const std::string &targetDev, int &errCode);
+ ISyncTaskContext *GetContextForMsg(const DeviceSyncTarget &target, int &errCode);
ICommunicator *AllocCommunicator(const std::string &identifier, int &errCode, std::string userId = "");
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_mock_sync_module_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_mock_sync_module_test.cpp
index 827a7b8e5..ec92de554 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_mock_sync_module_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_mock_sync_module_test.cpp
@@ -108,7 +108,7 @@ void Init(MockSingleVerStateMachine &stateMachine, MockSyncTaskContext &syncTask
{
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
ASSERT_EQ(metadata->Initialize(&dbSyncInterface), E_OK);
- (void)syncTaskContext.Initialize("device", &dbSyncInterface, metadata, &communicator);
+ (void)syncTaskContext.Initialize({"device", ""}, &dbSyncInterface, metadata, &communicator);
(void)stateMachine.Initialize(&syncTaskContext, &dbSyncInterface, metadata, &communicator);
}
@@ -117,7 +117,7 @@ void Init(MockSingleVerStateMachine &stateMachine, MockSyncTaskContext *syncTask
{
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
ASSERT_EQ(metadata->Initialize(dbSyncInterface), E_OK);
- (void)syncTaskContext->Initialize("device", dbSyncInterface, metadata, &communicator);
+ (void)syncTaskContext->Initialize({"device", ""}, dbSyncInterface, metadata, &communicator);
(void)stateMachine.Initialize(syncTaskContext, dbSyncInterface, metadata, &communicator);
}
@@ -907,7 +907,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncDataSync003, TestSize.Level1)
const std::string deviceId = "deviceId";
dataSync.Initialize(&storage, &communicator, metadata, deviceId);
syncTaskContext.SetRemoteSoftwareVersion(SOFTWARE_VERSION_CURRENT);
- syncTaskContext.Initialize(deviceId, &storage, metadata, &communicator);
+ syncTaskContext.Initialize({deviceId, ""}, &storage, metadata, &communicator);
syncTaskContext.EnableClearRemoteStaleData(true);
/**
@@ -1383,7 +1383,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncEngineTest004, TestSize.Level0)
auto *enginePtr = new (std::nothrow) MockSyncEngine();
ASSERT_NE(enginePtr, nullptr);
int errCode = E_OK;
- auto *context = enginePtr->CallGetSyncTaskContext("dev", errCode);
+ auto *context = enginePtr->CallGetSyncTaskContext({"dev", "user"}, errCode);
EXPECT_EQ(context, nullptr);
EXPECT_EQ(errCode, -E_INVALID_DB);
RefObject::KillAndDecObjRef(enginePtr);
@@ -1700,7 +1700,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncTaskContextCheck001, TestSize.Leve
MockCommunicator communicator;
VirtualSingleVerSyncDBInterface dbSyncInterface;
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
- (void)syncTaskContext.Initialize("device", &dbSyncInterface, metadata, &communicator);
+ (void)syncTaskContext.Initialize({"device", ""}, &dbSyncInterface, metadata, &communicator);
syncTaskContext.SetLastFullSyncTaskStatus(SyncOperation::Status::OP_FINISHED_ALL);
syncTaskContext.CallSetSyncMode(static_cast<int>(SyncModeType::PUSH));
EXPECT_EQ(syncTaskContext.CallIsCurrentSyncTaskCanBeSkipped(), true);
@@ -1853,7 +1853,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncTaskContextCheck005, TestSize.Leve
VirtualSingleVerSyncDBInterface dbSyncInterface;
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
ASSERT_EQ(metadata->Initialize(&dbSyncInterface), E_OK);
- (void)context->Initialize("device", &dbSyncInterface, metadata, &communicator);
+ (void)context->Initialize({"device", ""}, &dbSyncInterface, metadata, &communicator);
(void)stateMachine.Initialize(context, &dbSyncInterface, metadata, &communicator);
for (int i = 0; i < 100; ++i) { // 100 sync target
@@ -1909,7 +1909,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncTaskContextCheck006, TestSize.Leve
VirtualSingleVerSyncDBInterface dbSyncInterface;
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
ASSERT_EQ(metadata->Initialize(&dbSyncInterface), E_OK);
- (void)context->Initialize("device", &dbSyncInterface, metadata, communicator);
+ (void)context->Initialize({"device", ""}, &dbSyncInterface, metadata, communicator);
/**
* @tc.steps: step2. add sync target into context
*/
@@ -1949,7 +1949,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncTaskContextCheck007, TestSize.Leve
VirtualRelationalVerSyncDBInterface dbSyncInterface;
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
ASSERT_EQ(metadata->Initialize(&dbSyncInterface), E_OK);
- (void)context->Initialize("device", &dbSyncInterface, metadata, &communicator);
+ (void)context->Initialize({"device", ""}, &dbSyncInterface, metadata, &communicator);
(void)stateMachine.Initialize(context, &dbSyncInterface, metadata, &communicator);
/**
* @tc.steps: step2. prepare table and query
@@ -2371,7 +2371,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SingleVerDataSyncUtils001, TestSize.Le
MockCommunicator communicator;
VirtualSingleVerSyncDBInterface dbSyncInterface;
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
- (void)context.Initialize("device", &dbSyncInterface, metadata, &communicator);
+ (void)context.Initialize({"device", ""}, &dbSyncInterface, metadata, &communicator);
std::vector<SendDataItem> data;
for (int i = 0; i < 2; ++i) { // loop 2 times
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_time_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_time_sync_test.cpp
index 245e10744..e85470ff5 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_time_sync_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_time_sync_test.cpp
@@ -163,7 +163,7 @@ HWTEST_F(DistributedDBTimeSyncTest, NormalSync001, TestSize.Level0)
/**
* @tc.steps: step3. Register the OnMessageCallback to virtual communicator
*/
- g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ g_syncTaskContext->Initialize({DEVICE_B, ""}, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
g_virtualCommunicator->SetTimeSync(g_timeSyncA.get(), g_timeSyncB.get(), DEVICE_A, g_syncTaskContext);
/**
@@ -203,7 +203,7 @@ HWTEST_F(DistributedDBTimeSyncTest, NormalSync002, TestSize.Level0)
/**
* @tc.steps: step2. Register the OnMessageCallback to virtual communicator
*/
- g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ g_syncTaskContext->Initialize({DEVICE_B, ""}, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
g_virtualCommunicator->SetTimeSync(g_timeSyncA.get(), g_timeSyncB.get(), DEVICE_A, g_syncTaskContext);
/**
* @tc.steps: step3. Fetch timeOffset value
@@ -253,7 +253,7 @@ HWTEST_F(DistributedDBTimeSyncTest, NormalSync003, TestSize.Level0)
/**
* @tc.steps: step3. Register the OnMessageCallback to virtual communicator
*/
- g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ g_syncTaskContext->Initialize({DEVICE_B, ""}, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
g_virtualCommunicator->SetTimeSync(g_timeSyncA.get(), g_timeSyncB.get(), DEVICE_A, g_syncTaskContext);
/**
* @tc.steps: step4. Fetch timeOffset value
@@ -290,7 +290,7 @@ HWTEST_F(DistributedDBTimeSyncTest, NetDisconnetSyncTest001, TestSize.Level0)
errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A);
EXPECT_TRUE(errCode == E_OK);
- g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ g_syncTaskContext->Initialize({DEVICE_B, ""}, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
g_virtualCommunicator->SetTimeSync(g_timeSyncA.get(), g_timeSyncB.get(), DEVICE_A, g_syncTaskContext);
/**
* @tc.steps: step2. Disable the virtual communicator
@@ -395,7 +395,7 @@ HWTEST_F(DistributedDBTimeSyncTest, InvalidMessgeTest002, TestSize.Level0)
// initialize timeSyncB
errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A);
EXPECT_TRUE(errCode == E_OK);
- g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ g_syncTaskContext->Initialize({DEVICE_B, ""}, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
g_virtualCommunicator->SetTimeSync(g_timeSyncA.get(), g_timeSyncB.get(), DEVICE_A, g_syncTaskContext);
Message *msg = new (std::nothrow) Message();
@@ -459,7 +459,7 @@ HWTEST_F(DistributedDBTimeSyncTest, SyncTimeout001, TestSize.Level2)
* @tc.steps: step1. Initialize the syncTaskContext
* @tc.expected: step1. Initialize syncTaskContext successfully
*/
- errCode = g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ errCode = g_syncTaskContext->Initialize({DEVICE_B, ""}, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
EXPECT_TRUE(errCode == E_OK);
/**
* @tc.steps: step2. Start the time syc task invoking StartSync() method
@@ -488,7 +488,7 @@ HWTEST_F(DistributedDBTimeSyncTest, CheckRemoteVersion001, TestSize.Level0)
* @tc.steps: step1. Initialize the syncTaskContext
* @tc.expected: step1. Initialize syncTaskContext successfully
*/
- errCode = g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ errCode = g_syncTaskContext->Initialize({DEVICE_B, ""}, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
EXPECT_EQ(errCode, E_OK);
/**
* @tc.steps: step2. Check remote version
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.cpp
index b68cae6e7..fc2806f7f 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.cpp
@@ -27,6 +27,7 @@ GenericVirtualDevice::GenericVirtualDevice(std::string deviceId)
metadata_(nullptr),
deviceId_(std::move(deviceId)),
remoteDeviceId_("real_device"),
+ targetUserId_("targetUser"),
context_(nullptr),
onRemoteDataChanged_(nullptr),
subManager_(nullptr),
@@ -110,7 +111,7 @@ int GenericVirtualDevice::Initialize(VirtualCommunicatorAggregator *comAggregato
}
communicateHandle_->RegOnMessageCallback(
std::bind(&GenericVirtualDevice::MessageCallback, this, std::placeholders::_1, std::placeholders::_2), []() {});
- context_->Initialize(remoteDeviceId_, storage_, metadata_, communicateHandle_);
+ context_->Initialize({remoteDeviceId_, targetUserId_}, storage_, metadata_, communicateHandle_);
context_->SetRetryStatus(SyncTaskContext::NO_NEED_RETRY);
context_->RegOnSyncTask(std::bind(&GenericVirtualDevice::StartResponseTask, this));
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.h
index 462dd6948..62dd59893 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.h
@@ -56,6 +56,7 @@ protected:
std::shared_ptr<Metadata> metadata_;
std::string deviceId_;
std::string remoteDeviceId_;
+ std::string targetUserId_;
SyncTaskContext *context_;
std::function<void(const std::string &)> onRemoteDataChanged_;
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_sync_engine.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_sync_engine.h
index 1545ea636..72a537b95 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_sync_engine.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_sync_engine.h
@@ -29,9 +29,9 @@ public:
subManager_ = std::make_shared<SubscribeManager>();
}
- ISyncTaskContext *CallGetSyncTaskContext(const std::string &deviceId, int &errCode)
+ ISyncTaskContext * CallGetSyncTaskContext(const DeviceSyncTarget &target, int &errCode)
{
- return SyncEngine::GetSyncTaskContext(deviceId, errCode);
+ return SyncEngine::GetSyncTaskContext(target, errCode);
}
};
} // namespace DistributedDB
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。