From bab33143b9236e5acd4968cb38bb9713011190e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E5=87=AF=E5=9C=A3?= Date: Wed, 28 May 2025 16:11:09 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=AB=AF=E4=BA=91=E3=80=91=E3=80=90?= =?UTF-8?q?=E5=88=86=E5=B8=83=E5=BC=8FDB=E3=80=91=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=B5=84=E4=BA=A7=E5=BC=82=E6=AD=A5=E4=B8=8B=E8=BD=BD=E8=BF=87?= =?UTF-8?q?=E7=A8=8B=E4=B8=AD=E4=BF=AE=E6=94=B9=E6=9C=AC=E5=9C=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=97=A0=E6=B3=95=E6=9B=B4=E6=96=B0=E5=88=B0=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=A1=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 谭凯圣 --- .../relational/relational_sync_able_storage.h | 15 +- .../include/icloud_sync_storage_interface.h | 6 +- .../storage/include/storage_proxy.h | 6 +- .../relational_sync_able_storage.cpp | 15 +- .../relational_sync_able_storage_extend.cpp | 129 +++++++++++++----- .../src/sqlite/sqlite_cloud_kv_store.cpp | 75 +++++++++- .../src/sqlite/sqlite_cloud_kv_store.h | 13 +- .../storage/src/storage_proxy.cpp | 12 +- .../syncer/src/cloud/cloud_syncer.cpp | 2 +- .../syncer/src/cloud/cloud_syncer.h | 3 + .../src/cloud/cloud_syncer_extend_extend.cpp | 30 ++++ ...teddb_cloud_async_download_assets_test.cpp | 59 ++++++++ ...stributeddb_cloud_syncer_download_test.cpp | 58 ++++---- ...ddb_cloud_syncer_progress_manager_test.cpp | 12 +- ...distributeddb_cloud_syncer_upload_test.cpp | 66 ++++----- .../mock_icloud_sync_storage_interface.h | 6 +- 16 files changed, 380 insertions(+), 127 deletions(-) diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h b/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h index 777caa77ed..6f26873601 100644 --- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h +++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h @@ -139,11 +139,11 @@ public: // recycling the write handle void SetReusedHandle(StorageExecutor *handle); - int StartTransaction(TransactType type) override; + int StartTransaction(TransactType type, bool isAsyncDownload = false) override; - int Commit() override; + int Commit(bool isAsyncDownload = false) override; - int Rollback() override; + int Rollback(bool isAsyncDownload = false) override; int GetUploadCount(const QuerySyncObject &query, const Timestamp ×tamp, bool isCloudForcePush, bool isCompensatedTask, int64_t &count) override; @@ -300,6 +300,8 @@ private: OperatePerm perm = OperatePerm::NORMAL_PERM) const; SQLiteSingleVerRelationalStorageExecutor *GetHandleExpectTransaction(bool isWrite, int &errCode, OperatePerm perm = OperatePerm::NORMAL_PERM) const; + SQLiteSingleVerRelationalStorageExecutor *GetHandleExpectTransactionForAsyncDownload(bool isWrite, int &errCode, + OperatePerm perm = OperatePerm::NORMAL_PERM) const; void ReleaseHandle(SQLiteSingleVerRelationalStorageExecutor *&handle) const; // get @@ -342,6 +344,12 @@ private: void SaveCursorChange(const std::string &tableName, uint64_t currCursor); + int CommitForAsyncDownload(); + + int RollbackForAsyncDownload(); + + int StartTransactionForAsyncDownload(TransactType type); + // data std::shared_ptr storageEngine_ = nullptr; std::function onSchemaChanged_; @@ -365,6 +373,7 @@ private: mutable bool isCachedOption_; SQLiteSingleVerRelationalStorageExecutor *transactionHandle_ = nullptr; + SQLiteSingleVerRelationalStorageExecutor *asyncDownloadTransactionHandle_ = nullptr; mutable std::shared_mutex transactionMutex_; // used for transaction SchemaMgr schemaMgr_; diff --git a/frameworks/libs/distributeddb/storage/include/icloud_sync_storage_interface.h b/frameworks/libs/distributeddb/storage/include/icloud_sync_storage_interface.h index 3f56d25565..531b0dcaa1 100644 --- a/frameworks/libs/distributeddb/storage/include/icloud_sync_storage_interface.h +++ b/frameworks/libs/distributeddb/storage/include/icloud_sync_storage_interface.h @@ -116,11 +116,11 @@ public: virtual int GetCloudTableSchema(const TableName &tableName, TableSchema &tableSchema) = 0; - virtual int StartTransaction(TransactType type) = 0; + virtual int StartTransaction(TransactType type, bool isAsyncDownload = false) = 0; - virtual int Commit() = 0; + virtual int Commit(bool isAsyncDownload = false) = 0; - virtual int Rollback() = 0; + virtual int Rollback(bool isAsyncDownload = false) = 0; virtual int GetUploadCount(const QuerySyncObject &query, const Timestamp ×tamp, bool isCloudForcePush, bool isCompensatedTask, int64_t &count) = 0; diff --git a/frameworks/libs/distributeddb/storage/include/storage_proxy.h b/frameworks/libs/distributeddb/storage/include/storage_proxy.h index fd2c45e1c8..bbbffd0afe 100644 --- a/frameworks/libs/distributeddb/storage/include/storage_proxy.h +++ b/frameworks/libs/distributeddb/storage/include/storage_proxy.h @@ -51,11 +51,11 @@ public: int SetCloudWaterMark(const std::string &tableName, std::string &cloudMark); - int StartTransaction(TransactType type = TransactType::DEFERRED); + int StartTransaction(TransactType type = TransactType::DEFERRED, bool isAsyncDownload = false); - int Commit(); + int Commit(bool isAsyncDownload = false); - int Rollback(); + int Rollback(bool isAsyncDownload = false); int GetUploadCount(const std::string &tableName, const Timestamp ×tamp, const bool isCloudForcePush, int64_t &count); diff --git a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage.cpp b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage.cpp index b7da21ae83..7121e02cc2 100644 --- a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage.cpp +++ b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage.cpp @@ -1036,8 +1036,11 @@ StoreInfo RelationalSyncAbleStorage::GetStoreInfo() const return info; } -int RelationalSyncAbleStorage::StartTransaction(TransactType type) +int RelationalSyncAbleStorage::StartTransaction(TransactType type, bool isAsyncDownload) { + if (isAsyncDownload) { + return StartTransactionForAsyncDownload(type); + } if (storageEngine_ == nullptr) { return -E_INVALID_DB; } @@ -1062,8 +1065,11 @@ int RelationalSyncAbleStorage::StartTransaction(TransactType type) return errCode; } -int RelationalSyncAbleStorage::Commit() +int RelationalSyncAbleStorage::Commit(bool isAsyncDownload) { + if (isAsyncDownload) { + return CommitForAsyncDownload(); + } std::unique_lock lock(transactionMutex_); if (transactionHandle_ == nullptr) { LOGE("relation database is null or the transaction has not been started"); @@ -1076,8 +1082,11 @@ int RelationalSyncAbleStorage::Commit() return errCode; } -int RelationalSyncAbleStorage::Rollback() +int RelationalSyncAbleStorage::Rollback(bool isAsyncDownload) { + if (isAsyncDownload) { + return RollbackForAsyncDownload(); + } std::unique_lock lock(transactionMutex_); if (transactionHandle_ == nullptr) { LOGE("Invalid handle for rollback or the transaction has not been started."); diff --git a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage_extend.cpp b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage_extend.cpp index 4e98a047c6..0642594528 100644 --- a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage_extend.cpp +++ b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage_extend.cpp @@ -181,68 +181,61 @@ int RelationalSyncAbleStorage::FillCloudAssetForAsyncDownload(const std::string LOGE("[RelationalSyncAbleStorage]storage is null when fill asset for async download"); return -E_INVALID_DB; } - int errCode = E_OK; - auto *handle = GetHandle(true, errCode); - if (handle == nullptr) { - LOGE("executor is null when fill asset for async download."); - return errCode; + if (asyncDownloadTransactionHandle_ == nullptr) { + LOGE("the transaction has not been started when fill asset for async download."); + return -E_INVALID_DB; } TableSchema tableSchema; - errCode = GetCloudTableSchema(tableName, tableSchema); + int errCode = GetCloudTableSchema(tableName, tableSchema); if (errCode != E_OK) { - ReleaseHandle(handle); - LOGE("Get cloud schema failed when fill cloud asset, %d, tableName:%s, length:%zu", - errCode, DBCommon::StringMiddleMasking(tableName).c_str(), tableName.size()); + LOGE("Get cloud schema failed when fill cloud asset, %d", errCode); return errCode; } uint64_t currCursor = DBConstant::INVALID_CURSOR; - errCode = handle->FillCloudAssetForDownload(tableSchema, asset, isDownloadSuccess, currCursor); + errCode = asyncDownloadTransactionHandle_->FillCloudAssetForDownload( + tableSchema, asset, isDownloadSuccess, currCursor); if (errCode != E_OK) { - LOGE("fill cloud asset for download failed:%d, tableName:%s, length:%zu", - errCode, DBCommon::StringMiddleMasking(tableName).c_str(), tableName.size()); + LOGE("fill cloud asset for async download failed.%d", errCode); } - SaveCursorChange(tableName, currCursor); - ReleaseHandle(handle); return errCode; } int RelationalSyncAbleStorage::UpdateRecordFlagForAsyncDownload(const std::string &tableName, bool recordConflict, const LogInfo &logInfo) { - int errCode = E_OK; - auto *handle = GetHandle(true, errCode); - if (handle == nullptr) { - LOGE("executor is null when update flag for async download."); + if (asyncDownloadTransactionHandle_ == nullptr) { + LOGE("[RelationalSyncAbleStorage] the transaction has not been started"); + return -E_INVALID_DB; + } + TableSchema tableSchema; + GetCloudTableSchema(tableName, tableSchema); + std::vector assets; + int errCode = asyncDownloadTransactionHandle_->GetDownloadAssetRecordsByGid(tableSchema, logInfo.cloudGid, assets); + if (errCode != E_OK) { + LOGE("[RelationalSyncAbleStorage] get download asset by gid %s failed %d", logInfo.cloudGid.c_str(), errCode); return errCode; } + bool isInconsistency = !assets.empty(); UpdateRecordFlagStruct updateRecordFlag = { .tableName = tableName, .isRecordConflict = recordConflict, - .isInconsistency = false + .isInconsistency = isInconsistency }; std::string sql = CloudStorageUtils::GetUpdateRecordFlagSql(updateRecordFlag, logInfo); - errCode = handle->UpdateRecordFlag(tableName, sql, logInfo); - if (errCode != E_OK) { - LOGE("update flag for async download failed:%d, tableName:%s, length:%zu", - errCode, DBCommon::StringMiddleMasking(tableName).c_str(), tableName.size()); - } - ReleaseHandle(handle); - return errCode; + return asyncDownloadTransactionHandle_->UpdateRecordFlag(tableName, sql, logInfo); } int RelationalSyncAbleStorage::SetLogTriggerStatusForAsyncDownload(bool status) { int errCode = E_OK; - auto *handle = GetHandle(false, errCode); + auto *handle = GetHandleExpectTransactionForAsyncDownload(false, errCode); if (handle == nullptr) { - LOGE("executor is null when set trigger status for async download."); return errCode; } errCode = handle->SetLogTriggerStatus(status); - if (errCode != E_OK) { - LOGE("set trigger status for async download failed:%d"); + if (asyncDownloadTransactionHandle_ == nullptr) { + ReleaseHandle(handle); } - ReleaseHandle(handle); return errCode; } @@ -330,5 +323,79 @@ bool RelationalSyncAbleStorage::IsSetDistributedSchema(const std::string &tableN } return true; } + +int RelationalSyncAbleStorage::CommitForAsyncDownload() +{ + std::unique_lock lock(transactionMutex_); + if (asyncDownloadTransactionHandle_ == nullptr) { + LOGE("relation database is null or the transaction has not been started"); + return -E_INVALID_DB; + } + int errCode = asyncDownloadTransactionHandle_->Commit(); + ReleaseHandle(asyncDownloadTransactionHandle_); + asyncDownloadTransactionHandle_ = nullptr; + LOGD("connection commit transaction!"); + return errCode; +} + +int RelationalSyncAbleStorage::RollbackForAsyncDownload() +{ + std::unique_lock lock(transactionMutex_); + if (asyncDownloadTransactionHandle_ == nullptr) { + LOGE("Invalid handle for rollback or the transaction has not been started."); + return -E_INVALID_DB; + } + + int errCode = asyncDownloadTransactionHandle_->Rollback(); + ReleaseHandle(asyncDownloadTransactionHandle_); + asyncDownloadTransactionHandle_ = nullptr; + LOGI("connection rollback transaction!"); + return errCode; +} + +SQLiteSingleVerRelationalStorageExecutor *RelationalSyncAbleStorage::GetHandleExpectTransactionForAsyncDownload( + bool isWrite, int &errCode, OperatePerm perm) const +{ + if (storageEngine_ == nullptr) { + errCode = -E_INVALID_DB; + return nullptr; + } + if (asyncDownloadTransactionHandle_ != nullptr) { + return asyncDownloadTransactionHandle_; + } + auto handle = static_cast( + storageEngine_->FindExecutor(isWrite, perm, errCode)); + if (errCode != E_OK) { + ReleaseHandle(handle); + handle = nullptr; + } + return handle; +} + +int RelationalSyncAbleStorage::StartTransactionForAsyncDownload(TransactType type) +{ + if (storageEngine_ == nullptr) { + return -E_INVALID_DB; + } + std::unique_lock lock(transactionMutex_); + if (asyncDownloadTransactionHandle_ != nullptr) { + LOGD("async download transaction started already."); + return -E_TRANSACT_STATE; + } + int errCode = E_OK; + auto *handle = static_cast( + storageEngine_->FindExecutor(type == TransactType::IMMEDIATE, OperatePerm::NORMAL_PERM, errCode)); + if (handle == nullptr) { + ReleaseHandle(handle); + return errCode; + } + errCode = handle->StartTransaction(type); + if (errCode != E_OK) { + ReleaseHandle(handle); + return errCode; + } + asyncDownloadTransactionHandle_ = handle; + return errCode; +} } #endif diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.cpp index 48e9c3eb91..ebdd26f5be 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.cpp @@ -86,8 +86,11 @@ int SqliteCloudKvStore::GetCloudTableSchema(const TableName &tableName, return -E_NOT_FOUND; } -int SqliteCloudKvStore::StartTransaction(TransactType type) +int SqliteCloudKvStore::StartTransaction(TransactType type, bool isAsyncDownload) { + if (isAsyncDownload) { + return StartTransactionForAsyncDownload(type); + } { std::lock_guard autoLock(transactionMutex_); if (transactionHandle_ != nullptr) { @@ -110,8 +113,11 @@ int SqliteCloudKvStore::StartTransaction(TransactType type) return errCode; } -int SqliteCloudKvStore::Commit() +int SqliteCloudKvStore::Commit(bool isAsyncDownload) { + if (isAsyncDownload) { + return CommitForAsyncDownload(); + } SQLiteSingleVerStorageExecutor *handle; { std::lock_guard autoLock(transactionMutex_); @@ -128,8 +134,11 @@ int SqliteCloudKvStore::Commit() return errCode; } -int SqliteCloudKvStore::Rollback() +int SqliteCloudKvStore::Rollback(bool isAsyncDownload) { + if (isAsyncDownload) { + return RollbackForAsyncDownload(); + } SQLiteSingleVerStorageExecutor *handle; { std::lock_guard autoLock(transactionMutex_); @@ -146,6 +155,66 @@ int SqliteCloudKvStore::Rollback() return errCode; } +int SqliteCloudKvStore::StartTransactionForAsyncDownload(TransactType type) +{ + { + std::lock_guard autoLock(transactionMutex_); + if (asyncDownloadTransactionHandle_ != nullptr) { + LOGW("[SqliteCloudKvStore] async download transaction has been started"); + return E_OK; + } + } + auto [errCode, handle] = storageHandle_->GetStorageExecutor(type == TransactType::IMMEDIATE); + if (errCode != E_OK) { + return errCode; + } + if (handle == nullptr) { + LOGE("[SqliteCloudKvStore] get handle return null"); + return -E_INTERNAL_ERROR; + } + errCode = handle->StartTransaction(type); + std::lock_guard autoLock(transactionMutex_); + asyncDownloadTransactionHandle_ = handle; + LOGD("[SqliteCloudKvStore] start async download transaction!"); + return errCode; +} + +int SqliteCloudKvStore::CommitForAsyncDownload() +{ + SQLiteSingleVerStorageExecutor *handle; + { + std::lock_guard autoLock(transactionMutex_); + if (asyncDownloadTransactionHandle_ == nullptr) { + LOGW("[SqliteCloudKvStore] no need to commit, transaction has not been started"); + return E_OK; + } + handle = asyncDownloadTransactionHandle_; + asyncDownloadTransactionHandle_ = nullptr; + } + int errCode = handle->Commit(); + storageHandle_->RecycleStorageExecutor(handle); + LOGD("[SqliteCloudKvStore] commit transaction!"); + return errCode; +} + +int SqliteCloudKvStore::RollbackForAsyncDownload() +{ + SQLiteSingleVerStorageExecutor *handle; + { + std::lock_guard autoLock(transactionMutex_); + if (asyncDownloadTransactionHandle_ == nullptr) { + LOGW("[SqliteCloudKvStore] no need to rollback, transaction has not been started"); + return E_OK; + } + handle = asyncDownloadTransactionHandle_; + asyncDownloadTransactionHandle_ = nullptr; + } + int errCode = handle->Rollback(); + storageHandle_->RecycleStorageExecutor(handle); + LOGD("[SqliteCloudKvStore] rollback transaction!"); + return errCode; +} + int SqliteCloudKvStore::GetUploadCount([[gnu::unused]] const QuerySyncObject &query, const Timestamp ×tamp, bool isCloudForcePush, [[gnu::unused]] bool isCompensatedTask, int64_t &count) diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.h index b1a478d62b..9e0841d390 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.h @@ -37,11 +37,11 @@ public: int GetCloudTableSchema(const TableName &tableName, TableSchema &tableSchema) override; - int StartTransaction(TransactType type) override; + int StartTransaction(TransactType type, bool isAsyncDownload = false) override; - int Commit() override; + int Commit(bool isAsyncDownload = false) override; - int Rollback() override; + int Rollback(bool isAsyncDownload = false) override; int GetUploadCount(const QuerySyncObject &query, const Timestamp ×tamp, bool isCloudForcePush, bool isCompensatedTask, int64_t &count) override; @@ -137,6 +137,12 @@ private: int OperateDataStatusInner(SQLiteSingleVerStorageExecutor *handle, const std::string ¤tVirtualTime, const std::string ¤tTime, uint32_t dataOperator); + int CommitForAsyncDownload(); + + int RollbackForAsyncDownload(); + + int StartTransactionForAsyncDownload(TransactType type); + KvStorageHandle *storageHandle_; std::mutex schemaMutex_; @@ -144,6 +150,7 @@ private: mutable std::mutex transactionMutex_; SQLiteSingleVerStorageExecutor *transactionHandle_; + SQLiteSingleVerStorageExecutor *asyncDownloadTransactionHandle_ = nullptr; std::string user_; diff --git a/frameworks/libs/distributeddb/storage/src/storage_proxy.cpp b/frameworks/libs/distributeddb/storage/src/storage_proxy.cpp index a2c001b5b2..a66d131b4d 100644 --- a/frameworks/libs/distributeddb/storage/src/storage_proxy.cpp +++ b/frameworks/libs/distributeddb/storage/src/storage_proxy.cpp @@ -118,13 +118,13 @@ int StorageProxy::SetCloudWaterMark(const std::string &tableName, std::string &c return cloudMetaData_->SetCloudWaterMark(AppendWithUserIfNeed(tableName), cloudMark); } -int StorageProxy::StartTransaction(TransactType type) +int StorageProxy::StartTransaction(TransactType type, bool isAsyncDownload) { std::shared_lock readLock(storeMutex_); if (store_ == nullptr) { return -E_INVALID_DB; } - int errCode = store_->StartTransaction(type); + int errCode = store_->StartTransaction(type, isAsyncDownload); if (errCode == E_OK) { transactionExeFlag_.store(true); isWrite_.store(type == TransactType::IMMEDIATE); @@ -132,26 +132,26 @@ int StorageProxy::StartTransaction(TransactType type) return errCode; } -int StorageProxy::Commit() +int StorageProxy::Commit(bool isAsyncDownload) { std::shared_lock readLock(storeMutex_); if (store_ == nullptr) { return -E_INVALID_DB; } - int errCode = store_->Commit(); + int errCode = store_->Commit(isAsyncDownload); if (errCode == E_OK) { transactionExeFlag_.store(false); } return errCode; } -int StorageProxy::Rollback() +int StorageProxy::Rollback(bool isAsyncDownload) { std::shared_lock readLock(storeMutex_); if (store_ == nullptr) { return -E_INVALID_DB; } - int errCode = store_->Rollback(); + int errCode = store_->Rollback(isAsyncDownload); if (errCode == E_OK) { transactionExeFlag_.store(false); } diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.cpp b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.cpp index e14a2dad11..f1265fe09a 100644 --- a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.cpp +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.cpp @@ -1749,7 +1749,7 @@ int CloudSyncer::CommitDownloadResult(const DownloadItem &downloadItem, InnerPro uint32_t successCount = 0u; int ret = E_OK; if (info.isAsyncDownload) { - ret = CommitDownloadAssetsForAsyncDownload(downloadItem, info, commitList, successCount); + ret = HandleDownloadResultForAsyncDownload(downloadItem, info, commitList, successCount); } else { ret = HandleDownloadResult(downloadItem, info, commitList, successCount); } diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.h b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.h index 5685c6cfc4..b22cd84613 100644 --- a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.h +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer.h @@ -283,6 +283,9 @@ protected: int HandleDownloadResult(const DownloadItem &downloadItem, InnerProcessInfo &info, DownloadCommitList &commitList, uint32_t &successCount); + int HandleDownloadResultForAsyncDownload(const DownloadItem &downloadItem, InnerProcessInfo &info, + DownloadCommitList &commitList, uint32_t &successCount); + int FillDownloadExtend(TaskId taskId, const std::string &tableName, const std::string &cloudWaterMark, VBucket &extend); diff --git a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer_extend_extend.cpp b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer_extend_extend.cpp index d7fccdf374..ae079b0c46 100644 --- a/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer_extend_extend.cpp +++ b/frameworks/libs/distributeddb/syncer/src/cloud/cloud_syncer_extend_extend.cpp @@ -46,4 +46,34 @@ int CloudSyncer::StopTaskBeforeSetReference(std::function &setReferen std::lock_guard lock(syncMutex_); return setReferenceFunc(); } + +int CloudSyncer::HandleDownloadResultForAsyncDownload(const DownloadItem &downloadItem, InnerProcessInfo &info, + DownloadCommitList &commitList, uint32_t &successCount) +{ + int errCode = storageProxy_->StartTransaction(TransactType::IMMEDIATE, true); + if (errCode != E_OK) { + LOGE("[CloudSyncer] start transaction Failed before handle async download."); + return errCode; + } + errCode = CommitDownloadAssetsForAsyncDownload(downloadItem, info, commitList, successCount); + if (errCode != E_OK) { + successCount = 0; + int ret = E_OK; + if (errCode == -E_REMOVE_ASSETS_FAILED) { + // remove assets failed no effect to asset status, just commit + ret = storageProxy_->Commit(true); + LOGE("[CloudSyncer] commit async download assets failed %d commit ret %d", errCode, ret); + } else { + ret = storageProxy_->Rollback(true); + LOGE("[CloudSyncer] commit async download assets failed %d rollback ret %d", errCode, ret); + } + return errCode; + } + errCode = storageProxy_->Commit(true); + if (errCode != E_OK) { + successCount = 0; + LOGE("[CloudSyncer] commit async download assets failed %d", errCode); + } + return errCode; +} } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_async_download_assets_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_async_download_assets_test.cpp index 923e725b15..a3280b6363 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_async_download_assets_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_async_download_assets_test.cpp @@ -63,6 +63,8 @@ protected: void CloseDb(); void DoSkipAssetDownload(SkipAssetTestParamT param); void UpdateLocalData(sqlite3 *&db, const std::string &tableName, int32_t begin, int32_t end); + void DeleteLocalData(sqlite3 *&db, const std::string &tableName); + void CheckLogTable(sqlite3 *&db, const std::string &tableName, int count); void UpdateLocalAndCheckUploadCount(const bool &isAsync, const int &dataCount, const int &expectCount); std::string storePath_; sqlite3 *db_ = nullptr; @@ -1067,6 +1069,21 @@ void DistributedDBCloudAsyncDownloadAssetsTest::UpdateLocalData( LOGW("update local data finished"); } +void DistributedDBCloudAsyncDownloadAssetsTest::DeleteLocalData(sqlite3 *&db, const std::string &tableName) +{ + const string sql = "delete from " + tableName + " where pk >= 0;"; + EXPECT_EQ(sqlite3_exec(db, sql.c_str(), nullptr, nullptr, nullptr), SQLITE_OK); + LOGW("delete local data finished"); +} + +void DistributedDBCloudAsyncDownloadAssetsTest::CheckLogTable(sqlite3 *&db, const std::string &tableName, int count) +{ + const string sql = "select COUNT(*) from " + DBCommon::GetLogTableName(tableName) + " where data_key>0;"; + EXPECT_EQ(sqlite3_exec(db, sql.c_str(), CloudDBSyncUtilsTest::QueryCountCallback, + reinterpret_cast(count), nullptr), SQLITE_OK); + LOGW("check log table finished"); +} + void DistributedDBCloudAsyncDownloadAssetsTest::UpdateLocalAndCheckUploadCount(const bool &isAsync, const int &dataCount, const int &expectCount) { @@ -1348,4 +1365,46 @@ HWTEST_F(DistributedDBCloudAsyncDownloadAssetsTest, AsyncAbnormalDownload008, Te EXPECT_EQ(downloadCount, cloudCount); virtualAssetLoader_->ForkBatchDownload(nullptr); } + +/** + * @tc.name: AsyncAbnormalDownload010 + * @tc.desc: Test assets is async downloading when delete local data. + * @tc.type: FUNC + * @tc.require: + * @tc.author: tankaisheng + */ +HWTEST_F(DistributedDBCloudAsyncDownloadAssetsTest, AsyncAbnormalDownload010, TestSize.Level1) +{ + /** + * @tc.steps: step1. Set max download task 1 + * @tc.expected: step1. ok + */ + AsyncDownloadAssetsConfig config; + config.maxDownloadTask = 1; + config.maxDownloadAssetsCount = 2; + EXPECT_EQ(RuntimeConfig::SetAsyncDownloadAssetsConfig(config), OK); + /** + * @tc.steps: step2. Insert cloud data + * @tc.expected: step2. ok + */ + const int cloudCount = 2000; + auto schema = GetSchema(); + EXPECT_EQ(RDBDataGenerator::InsertCloudDBData(0, cloudCount, 0, schema, virtualCloudDb_), OK); + /** + * @tc.steps: step3. Sync + * @tc.expected: step3. ok + */ + CloudSyncOption option = GetAsyncCloudSyncOption(); + RelationalTestUtils::CloudBlockSync(option, delegate_); + /** + * @tc.steps: step4. Delete local data. + * @tc.expected: step4. ok + */ + DeleteLocalData(db_, "AsyncDownloadAssetsTest"); + /** + * @tc.steps: step5. Check log table. + * @tc.expected: step5. ok + */ + CheckLogTable(db_, "AsyncDownloadAssetsTest", 0); +} } \ No newline at end of file diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_download_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_download_test.cpp index af0442cd21..2736b6bc95 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_download_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_download_test.cpp @@ -236,9 +236,9 @@ static void Expect2GetInfoByPrimaryKeyOrGidCall() HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockTest001, TestSize.Level1) { TaskId taskId = 1u; - EXPECT_CALL(*g_iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Commit()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetCloudTableSchema(_, _)).WillRepeatedly(Return(E_OK)); @@ -288,10 +288,10 @@ HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockTest001, TestSize.Lev HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockTest002, TestSize.Level1) { TaskId taskId = 6u; - EXPECT_CALL(*g_iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetCloudTableSchema(_, _)).WillRepeatedly(Return(E_OK)); @@ -334,10 +334,10 @@ HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockTest002, TestSize.Lev HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockQueryTest002, TestSize.Level1) { TaskId taskId = 1u; - EXPECT_CALL(*g_iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); @@ -367,10 +367,10 @@ HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockQueryTest002, TestSiz HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockQueryTest003, TestSize.Level1) { TaskId taskId = 1u; - EXPECT_CALL(*g_iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); @@ -425,10 +425,10 @@ HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockQueryTest003, TestSiz HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockQueryTest00302, TestSize.Level1) { TaskId taskId = 4u; - EXPECT_CALL(*g_iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); @@ -469,10 +469,10 @@ HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockQueryTest00302, TestS HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockQueryTest004, TestSize.Level1) { TaskId taskId = 1u; - EXPECT_CALL(*g_iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); @@ -514,10 +514,10 @@ HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockQueryTest004, TestSiz HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockQueryTest00402, TestSize.Level1) { TaskId taskId = 3u; - EXPECT_CALL(*g_iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); @@ -570,10 +570,10 @@ HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockQueryTest00402, TestS HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockQueryTest005, TestSize.Level1) { TaskId taskId = 1u; - EXPECT_CALL(*g_iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); @@ -602,10 +602,10 @@ HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockQueryTest005, TestSiz HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockTest006, TestSize.Level1) { TaskId taskId = 1u; - EXPECT_CALL(*g_iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); @@ -720,14 +720,14 @@ static void ExpectGetInfoByPrimaryKeyOrGidCall() HWTEST_F(DistributedDBCloudSyncerDownloadTest, DownloadMockTest007, TestSize.Level1) { TaskId taskId = 1u; - EXPECT_CALL(*g_iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly([](const QuerySyncObject &, const Timestamp &, bool, bool, int64_t &count) { count = 1; return E_OK; }); - EXPECT_CALL(*g_iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*g_iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*g_iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*g_iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_progress_manager_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_progress_manager_test.cpp index 26a8f7fca6..17de7d591f 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_progress_manager_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_progress_manager_test.cpp @@ -77,11 +77,11 @@ HWTEST_F(DistributedDBCloudSyncerProgressManagerTest, SyncerMgrCheck001, TestSiz EXPECT_CALL(*idb, HeartBeat()).WillRepeatedly(Return(OK)); EXPECT_CALL(*idb, Lock()).WillRepeatedly(Return(std::pair(OK, 10))); EXPECT_CALL(*idb, UnLock()).WillRepeatedly(Return(OK)); - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudTableSchema(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudData).WillRepeatedly(Return(E_OK)); @@ -134,11 +134,11 @@ HWTEST_F(DistributedDBCloudSyncerProgressManagerTest, SyncerMgrCheck002, TestSiz EXPECT_CALL(*idb, HeartBeat()).WillRepeatedly(Return(OK)); EXPECT_CALL(*idb, Lock()).WillRepeatedly(Return(std::pair(OK, 10))); EXPECT_CALL(*idb, UnLock()).WillRepeatedly(Return(OK)); - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudTableSchema(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudData).WillRepeatedly(Return(E_OK)); @@ -191,11 +191,11 @@ HWTEST_F(DistributedDBCloudSyncerProgressManagerTest, SyncerMgrCheck003, TestSiz EXPECT_CALL(*idb, HeartBeat()).WillRepeatedly(Return(OK)); EXPECT_CALL(*idb, Lock()).WillRepeatedly(Return(std::pair(OK, 10))); EXPECT_CALL(*idb, UnLock()).WillRepeatedly(Return(OK)); - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, PutCloudSyncData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudTableSchema(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudData).WillRepeatedly(Return(E_OK)); diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_upload_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_upload_test.cpp index 04ac306c2f..892c099b49 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_upload_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_upload_test.cpp @@ -43,12 +43,12 @@ const int COUNT = 1000; static void CommonExpectCall(MockICloudSyncStorageInterface *iCloud) { - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudTableSchema(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ReleaseCloudDataToken(_)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudDataNext(_, _)).WillRepeatedly(Return(E_OK)); @@ -165,10 +165,10 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck001, TestSize.Level1 EXPECT_CALL(*iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudTableSchema(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudData(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); @@ -222,10 +222,10 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck002, TestSize.Level1 cloudSyncer->SetMockICloudDB(idb); TaskId taskId = 2u; - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudTableSchema(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudData(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); @@ -258,10 +258,10 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck003, TestSize.Level1 std::shared_ptr idb = std::make_shared(); cloudSyncer->SetMockICloudDB(idb); - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetUploadCount(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudTableSchema(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudData(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); @@ -296,10 +296,10 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck004, TestSize.Level1 cloudSyncer->SetMockICloudDB(idb); cloudSyncer->InitCloudSyncer(3u, SYNC_MODE_CLOUD_FORCE_PUSH); - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); // 1. Failed to get total data count @@ -331,10 +331,10 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck005, TestSize.Level1 cloudSyncer->SetMockICloudDB(idb); cloudSyncer->InitCloudSyncer(3u, SYNC_MODE_CLOUD_FORCE_PUSH); - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudTableSchema(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudData(_, _, _, _, _)).WillRepeatedly(Return(E_OK)); @@ -384,12 +384,12 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck006, TestSize.Level1 EXPECT_CALL(*idb, BatchInsert(_, _, _)).WillRepeatedly(Return(OK)); - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudTableSchema(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ReleaseCloudDataToken(_)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetAllUploadCount(_, _, _, _, _)) .WillRepeatedly([](const QuerySyncObject &, const std::vector &, bool, bool, int64_t & count) { @@ -505,12 +505,12 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck008, TestSize.Level1 EXPECT_CALL(*idb, BatchInsert(_, _, _)).WillRepeatedly(Return(OK)); - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudTableSchema(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ReleaseCloudDataToken(_)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetAllUploadCount(_, _, _, _, _)) .WillRepeatedly([](const QuerySyncObject &, const std::vector &, bool, bool, int64_t & count) { @@ -683,7 +683,7 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck010, TestSize.Level1 cloudDataResult = uploadData; return E_OK; }); - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetAllUploadCount(_, _, _, _, _)) @@ -691,8 +691,8 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck010, TestSize.Level1 count = 3000; return E_OK; }); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudDataNext(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudDbSchema(_)).WillRepeatedly(Return(E_OK)); @@ -732,7 +732,7 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck011, TestSize.Level1 PrepareRecord(tmp, assets); cloudSyncer->InitCloudSyncer(6u, SYNC_MODE_CLOUD_FORCE_PUSH); - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetAllUploadCount(_, _, _, _, _)) @@ -740,8 +740,8 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck011, TestSize.Level1 count = 3000; return E_OK; }); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudDataNext(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudDbSchema(_)).WillRepeatedly(Return(E_OK)); @@ -789,7 +789,7 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck012, TestSize.Level1 cloudSyncer->SetMockICloudDB(idb); cloudSyncer->InitCloudSyncer(6u, SYNC_MODE_CLOUD_FORCE_PUSH); - EXPECT_CALL(*iCloud, StartTransaction(_)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, StartTransaction(_, false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, ChkSchema(_)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetAllUploadCount(_, _, _, _, _)) @@ -797,8 +797,8 @@ HWTEST_F(DistributedDBCloudSyncerUploadTest, UploadModeCheck012, TestSize.Level1 count = 3000; return E_OK; }); - EXPECT_CALL(*iCloud, Commit()).WillRepeatedly(Return(E_OK)); - EXPECT_CALL(*iCloud, Rollback()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Commit(false)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*iCloud, Rollback(false)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, PutMetaData(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudDataNext(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*iCloud, GetCloudDbSchema(_)).WillRepeatedly(Return(E_OK)); diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/mock_icloud_sync_storage_interface.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/mock_icloud_sync_storage_interface.h index 0c41d70425..1cb9a613f3 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/mock_icloud_sync_storage_interface.h +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/mock_icloud_sync_storage_interface.h @@ -27,9 +27,9 @@ public: MOCK_METHOD1(SetCloudDbSchema, int(const DataBaseSchema &)); MOCK_METHOD1(GetCloudDbSchema, int(std::shared_ptr &)); MOCK_METHOD2(GetCloudTableSchema, int(const TableName &, TableSchema &)); - MOCK_METHOD1(StartTransaction, int(TransactType)); - MOCK_METHOD0(Commit, int(void)); - MOCK_METHOD0(Rollback, int(void)); + MOCK_METHOD2(StartTransaction, int(TransactType, bool)); + MOCK_METHOD1(Commit, int(bool)); + MOCK_METHOD1(Rollback, int(bool)); MOCK_METHOD5(GetUploadCount, int(const QuerySyncObject &, const Timestamp &, bool, bool, int64_t &)); MOCK_METHOD5(GetAllUploadCount, int(const QuerySyncObject &, const std::vector &, bool, bool, int64_t &)); -- Gitee