diff --git a/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h b/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h index b5e91e689c7acc9187915aa5615956cdfeba7651..e4940b91999f5be44fac8027941eb77cde54717f 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h +++ b/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h @@ -48,6 +48,8 @@ public: API_EXPORT void CloseStore(uint32_t tokenId, const std::string &storeId); + API_EXPORT void CloseStore(uint32_t tokenId); + API_EXPORT void CloseExcept(const std::set &users); API_EXPORT void SetObserver(uint32_t tokenId, const std::string &storeId, const Watchers &watchers); diff --git a/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp b/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp index ec9dea51e722ed94012a4ecf30873597a471fb4a..381c9cb7560c795466568a01f743e86c9f69c7d6 100644 --- a/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp @@ -94,6 +94,11 @@ void AutoCache::CloseStore(uint32_t tokenId, const std::string &storeId) }); } +void AutoCache::CloseStore(uint32_t tokenId) +{ + stores_.Erase(tokenId); +} + void AutoCache::CloseExcept(const std::set &users) { stores_.EraseIf([&users](const auto &tokenId, std::map &delegates) { diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.cpp index ff138986ac947a09bccd7698c743381b9c7941ce..1d1d9cf550308073ef8b8cfcd92074a2028f82e2 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -65,7 +65,7 @@ RdbGeneralStore::RdbGeneralStore(const StoreMetaData &meta) : manager_(meta.appI option.iterateTimes = ITERATE_TIMES; option.cipher = CipherType::AES_256_GCM; } - option.observer = nullptr; + option.observer = &observer_; manager_.OpenStore(meta.dataDir, meta.storeId, option, delegate_); RdbStoreConfig config(meta.dataDir); config.SetCreateNecessary(false); diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 84d6f34521edadb2d04f192c1c133ef1d5b17035..187e7874df15e572875b6b3287002781bda90bf3 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -143,6 +143,7 @@ int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, Distrib int32_t RdbServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) { OnClientDied(pid); + AutoCache::GetInstance().CloseStore(tokenId); return E_OK; } @@ -248,7 +249,7 @@ void RdbServiceImpl::SyncerTimeout(std::shared_ptr syncer) return; } auto storeId = syncer->GetStoreId(); - ZLOGI("%{public}s", storeId.c_str()); + ZLOGI("%{public}s", Anonymous::Change(storeId).c_str()); syncers_.ComputeIfPresent(syncer->GetPid(), [this, storeId](const auto& key, StoreSyncersType& syncers) { syncers.erase(storeId); syncerNum_--; @@ -342,7 +343,7 @@ std::pair RdbServiceImpl::DoSync(const RdbSyncerParam ¶m, void RdbServiceImpl::OnAsyncComplete(uint32_t tokenId, uint32_t seqNum, Details &&result) { - ZLOGI("pid=%{public}x seqnum=%{public}u", tokenId, seqNum); + ZLOGI("Sync complete, pid=%{public}x seqnum=%{public}u", tokenId, seqNum); auto [success, agent] = syncAgents_.Find(tokenId); if (success && agent.notifier_ != nullptr) { agent.notifier_->OnComplete(seqNum, std::move(result)); @@ -450,7 +451,9 @@ int32_t RdbServiceImpl::Sync(const RdbSyncerParam ¶m, const Option &option, { if (!option.isAsync) { auto [status, details] = DoSync(param, option, predicates); - async(std::move(details)); + if (async != nullptr) { + async(std::move(details)); + } return status; } return DoAsync(param, option, predicates); diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index cee088b0f18d5bee8340295f18b15be70cbd5e99..f2a611a5a39b0a22648422800fd458699a9ec151 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -22,13 +22,13 @@ #include "utils/anonymous.h" namespace OHOS::DistributedRdb { +using Anonymous = DistributedData::Anonymous; int32_t RdbServiceStub::OnRemoteObtainDistributedTableName(MessageParcel &data, MessageParcel &reply) { std::string device; std::string table; if (!ITypesUtil::Unmarshal(data, device, table)) { - ZLOGE("Unmarshal device:%{public}s table:%{public}s", DistributedData::Anonymous::Change(device).c_str(), - table.c_str()); + ZLOGE("Unmarshal device:%{public}s table:%{public}s", Anonymous::Change(device).c_str(), table.c_str()); return IPC_STUB_INVALID_DATA_ERR; } @@ -45,7 +45,7 @@ int32_t RdbServiceStub::OnGetSchema(MessageParcel &data, MessageParcel &reply) RdbSyncerParam param; if (!ITypesUtil::Unmarshal(data, param)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", param.bundleName_.c_str(), - param.storeName_.c_str()); + Anonymous::Change(param.storeName_).c_str()); return IPC_STUB_INVALID_DATA_ERR; } auto status = GetSchema(param); @@ -62,7 +62,7 @@ int32_t RdbServiceStub::OnRemoteInitNotifier(MessageParcel &data, MessageParcel sptr notifier; if (!ITypesUtil::Unmarshal(data, param, notifier) || notifier == nullptr) { ZLOGE("Unmarshal bundleName:%{public}s storeName_:%{public}s notifier is nullptr:%{public}d", - param.bundleName_.c_str(), param.storeName_.c_str(), notifier == nullptr); + param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str(), notifier == nullptr); return IPC_STUB_INVALID_DATA_ERR; } auto status = InitNotifier(param, notifier); @@ -79,7 +79,7 @@ int32_t RdbServiceStub::OnRemoteSetDistributedTables(MessageParcel &data, Messag std::vector tables; if (!ITypesUtil::Unmarshal(data, param, tables)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s tables size:%{public}zu", - param.bundleName_.c_str(), param.storeName_.c_str(), tables.size()); + param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str(), tables.size()); return IPC_STUB_INVALID_DATA_ERR; } @@ -98,7 +98,7 @@ int32_t RdbServiceStub::OnRemoteDoSync(MessageParcel &data, MessageParcel &reply PredicatesMemo predicates; if (!ITypesUtil::Unmarshal(data, param, option, predicates)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s tables:%{public}zu", param.bundleName_.c_str(), - param.storeName_.c_str(), predicates.tables_.size()); + Anonymous::Change(param.storeName_).c_str(), predicates.tables_.size()); return IPC_STUB_INVALID_DATA_ERR; } @@ -117,9 +117,9 @@ int32_t RdbServiceStub::OnRemoteDoAsync(MessageParcel &data, MessageParcel &repl Option option {}; PredicatesMemo predicates; if (!ITypesUtil::Unmarshal(data, param, option, predicates)) { - ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s seqNum:%{public}u tables:%{public}s", - param.bundleName_.c_str(), param.storeName_.c_str(), option.seqNum, - (*(predicates.tables_.begin())).c_str()); + ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s seqNum:%{public}u table:%{public}s", + param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str(), option.seqNum, + predicates.tables_.empty() ? "null" : predicates.tables_.begin()->c_str()); return IPC_STUB_INVALID_DATA_ERR; } auto status = Sync(param, option, predicates, nullptr); @@ -136,7 +136,7 @@ int32_t RdbServiceStub::OnRemoteDoSubscribe(MessageParcel &data, MessageParcel & SubscribeOption option; if (!ITypesUtil::Unmarshal(data, param, option)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", param.bundleName_.c_str(), - param.storeName_.c_str()); + Anonymous::Change(param.storeName_).c_str()); return IPC_STUB_INVALID_DATA_ERR; } @@ -154,7 +154,7 @@ int32_t RdbServiceStub::OnRemoteDoUnSubscribe(MessageParcel &data, MessageParcel SubscribeOption option; if (!ITypesUtil::Unmarshal(data, param)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", param.bundleName_.c_str(), - param.storeName_.c_str()); + Anonymous::Change(param.storeName_).c_str()); return IPC_STUB_INVALID_DATA_ERR; } @@ -174,9 +174,9 @@ int32_t RdbServiceStub::OnRemoteDoRemoteQuery(MessageParcel& data, MessageParcel std::vector selectionArgs; if (!ITypesUtil::Unmarshal(data, param, device, sql, selectionArgs)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s device:%{public}s sql:%{public}s " - "selectionArgs size:%{public}zu", param.bundleName_.c_str(), param.storeName_.c_str(), - DistributedData::Anonymous::Change(device).c_str(), - DistributedData::Anonymous::Change(sql).c_str(), selectionArgs.size()); + "selectionArgs size:%{public}zu", param.bundleName_.c_str(), + Anonymous::Change(param.storeName_).c_str(), Anonymous::Change(device).c_str(), + Anonymous::Change(sql).c_str(), selectionArgs.size()); return IPC_STUB_INVALID_DATA_ERR; } diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.cpp index c8d3c9665bb1373cc02f6726b7febe03e4c04156..d620126d47080d273214190ee6b711727f2a9a71 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -366,7 +366,9 @@ int32_t RdbSyncer::DoSync(const Option &option, const PredicatesMemo &predicates return delegate->Sync( devices, static_cast(option.mode), MakeQuery(predicates), [async](const std::map> &syncStatus) { - async(HandleSyncStatus(syncStatus)); + if (async != nullptr) { + async(HandleSyncStatus(syncStatus)); + } }, !option.isAsync); } else if ( DistributedData::GeneralStore::CLOUD_BEGIN <= option.mode && option.mode < DistributedData::GeneralStore::CLOUD_END) { diff --git a/kv_store/test/unittest/distributedKVStore/DeviceKvStoreKVCallbackJsTest.js b/kv_store/test/unittest/distributedKVStore/DeviceKvStoreKVCallbackJsTest.js index 11bc52a6d1086e0946304aadc4e0a69ee8b6e0bc..b8c68db7803773d9c8bdd5a96b2b06bab44b9e43 100644 --- a/kv_store/test/unittest/distributedKVStore/DeviceKvStoreKVCallbackJsTest.js +++ b/kv_store/test/unittest/distributedKVStore/DeviceKvStoreKVCallbackJsTest.js @@ -138,7 +138,7 @@ describe('DeviceKvStoreCallbackTest', function () { }); }); kvStore = null; - } catch (e) { + } catch (err) { console.error('afterEach closeKVStore err ' + `, error code is ${err.code}, message is ${err.message}`); } }) diff --git a/mock/sqlite/include/sqlite3.h b/mock/sqlite/include/sqlite3.h index 020b3ad8be94f01e465fd5fa8022dfef9aa75b8c..c0a5e352dc613cb847bb08774590bf920b905ea6 100644 --- a/mock/sqlite/include/sqlite3.h +++ b/mock/sqlite/include/sqlite3.h @@ -441,38 +441,38 @@ SQLITE_API int sqlite3_exec( ** ** See also: [extended result code definitions] */ -#define SQLITE_OK 0 /* Successful result */ -/* beginning-of-error-codes */ -#define SQLITE_ERROR 1 /* Generic error */ -#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ -#define SQLITE_PERM 3 /* Access permission denied */ -#define SQLITE_ABORT 4 /* Callback routine requested an abort */ -#define SQLITE_BUSY 5 /* The database file is locked */ -#define SQLITE_LOCKED 6 /* A table in the database is locked */ -#define SQLITE_NOMEM 7 /* A malloc() failed */ -#define SQLITE_READONLY 8 /* Attempt to write a readonly database */ -#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ -#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ -#define SQLITE_CORRUPT 11 /* The database disk image is malformed */ -#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ -#define SQLITE_FULL 13 /* Insertion failed because database is full */ -#define SQLITE_CANTOPEN 14 /* Unable to open the database file */ -#define SQLITE_PROTOCOL 15 /* Database lock protocol error */ -#define SQLITE_EMPTY 16 /* Internal use only */ -#define SQLITE_SCHEMA 17 /* The database schema changed */ -#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ -#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ -#define SQLITE_MISMATCH 20 /* Data type mismatch */ -#define SQLITE_MISUSE 21 /* Library used incorrectly */ -#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ -#define SQLITE_AUTH 23 /* Authorization denied */ -#define SQLITE_FORMAT 24 /* Not used */ -#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ -#define SQLITE_NOTADB 26 /* File opened that is not a database file */ +#define SQLITE_OK 0 /* 成功 | Successful result */ +/* 错误码开始 */ +#define SQLITE_ERROR 1 /* SQL错误 或 丢失数据库 | SQL error or missing database */ +#define SQLITE_INTERNAL 2 /* SQLite 内部逻辑错误 | Internal logic error in SQLite */ +#define SQLITE_PERM 3 /* 拒绝访问 | Access permission denied */ +#define SQLITE_ABORT 4 /* 回调函数请求取消操作 | Callback routine requested an abort */ +#define SQLITE_BUSY 5 /* 数据库文件被锁定 | The database file is locked */ +#define SQLITE_LOCKED 6 /* 数据库中的一个表被锁定 | A table in the database is locked */ +#define SQLITE_NOMEM 7 /* 某次 malloc() 函数调用失败 | A malloc() failed */ +#define SQLITE_READONLY 8 /* 尝试写入一个只读数据库 | Attempt to write a readonly database */ +#define SQLITE_INTERRUPT 9 /* 操作被 sqlite3_interupt() 函数中断 | Operation terminated by sqlite3_interrupt() */ +#define SQLITE_IOERR 10 /* 发生某些磁盘 I/O 错误 | Some kind of disk I/O error occurred */ +#define SQLITE_CORRUPT 11 /* 数据库磁盘映像不正确 | The database disk image is malformed */ +#define SQLITE_NOTFOUND 12 /* sqlite3_file_control() 中出现未知操作数 | Unknown opcode in sqlite3_file_control() */ +#define SQLITE_FULL 13 /* 因为数据库满导致插入失败 | Insertion failed because database is full */ +#define SQLITE_CANTOPEN 14 /* 无法打开数据库文件 | Unable to open the database file */ +#define SQLITE_PROTOCOL 15 /* 数据库锁定协议错误 | Database lock protocol error */ +#define SQLITE_EMPTY 16 /* 数据库为空 | Database is empty */ +#define SQLITE_SCHEMA 17 /* 数据结构发生改变 | The database schema changed */ +#define SQLITE_TOOBIG 18 /* 字符串或二进制数据超过大小限制 | String or BLOB exceeds size limit */ +#define SQLITE_CONSTRAINT 19 /* 由于约束违例而取消 | Abort due to constraint violation */ +#define SQLITE_MISMATCH 20 /* 数据类型不匹配 | Data type mismatch */ +#define SQLITE_MISUSE 21 /* 不正确的库使用 | Library used incorrectly */ +#define SQLITE_NOLFS 22 /* 使用了操作系统不支持的功能 | Uses OS features not supported on host */ +#define SQLITE_AUTH 23 /* 授权失败 | Authorization denied */ +#define SQLITE_FORMAT 24 /* 附加数据库格式错误 | Auxiliary database format error */ +#define SQLITE_RANGE 25 /* 传递给sqlite3_bind()的第二个参数超出范围 | 2nd parameter to sqlite3_bind out of range */ +#define SQLITE_NOTADB 26 /* 被打开的文件不是一个数据库文件 | File opened that is not a database file */ #define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */ #define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */ -#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ -#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ +#define SQLITE_ROW 100 /* sqlite3_step() 已经产生一个行结果 | sqlite3_step() has another row ready */ +#define SQLITE_DONE 101 /* sqlite3_step() 完成执行操作 | sqlite3_step() has finished executing */ /* end-of-error-codes */ /* diff --git a/relational_store/frameworks/js/napi/cloud_data/src/js_config.cpp b/relational_store/frameworks/js/napi/cloud_data/src/js_config.cpp index cb0dbd999d8dc785f0a29ef02f106af45ede81ed..6c4309f2278da08d4dda9f7754f6670a60c3fd34 100644 --- a/relational_store/frameworks/js/napi/cloud_data/src/js_config.cpp +++ b/relational_store/frameworks/js/napi/cloud_data/src/js_config.cpp @@ -176,7 +176,8 @@ napi_value JsConfig::ChangeAppCloudSwitch(napi_env env, napi_callback_info info) : napi_generic_failure; return; } - int32_t cStatus = proxy->ChangeAppSwitch(ctxt->accountId, ctxt->bundleName, ctxt->state); + int32_t cStatus = + proxy->ChangeAppSwitch(ctxt->accountId, ctxt->bundleName, ctxt->state ? CloudService::SWITCH_ON : CloudService::SWITCH_OFF); ZLOGD("ChangeAppCloudSwitch return %{public}d", cStatus); ctxt->status = (GenerateNapiError(cStatus, ctxt->jsCode, ctxt->error) == Status::SUCCESS) ? napi_ok diff --git a/relational_store/frameworks/js/napi/relationalstore/include/napi_async_call.h b/relational_store/frameworks/js/napi/relationalstore/include/napi_async_call.h index 408f3a8780a94eb14e2a2b7ab274e933a82fb902..c1fa3427560e9aa4870b6353193acb720c9ac37e 100644 --- a/relational_store/frameworks/js/napi/relationalstore/include/napi_async_call.h +++ b/relational_store/frameworks/js/napi/relationalstore/include/napi_async_call.h @@ -34,6 +34,7 @@ using ExecuteAction = std::function; class Context { public: void SetAction(napi_env env, napi_callback_info info, InputAction input, ExecuteAction exec, OutputAction output); + void SetAll(napi_env env, napi_callback_info info, InputAction input, ExecuteAction exec, OutputAction output); void SetError(std::shared_ptr error); virtual ~Context(); diff --git a/relational_store/frameworks/js/napi/relationalstore/include/napi_rdb_js_utils.h b/relational_store/frameworks/js/napi/relationalstore/include/napi_rdb_js_utils.h index 9ab3afe9fe3c5517cc865d671867e54a040a4d5d..6dc85b29a8b06d0e676478038e0b7bd1ea682fb4 100644 --- a/relational_store/frameworks/js/napi/relationalstore/include/napi_rdb_js_utils.h +++ b/relational_store/frameworks/js/napi/relationalstore/include/napi_rdb_js_utils.h @@ -18,6 +18,7 @@ #include "asset_value.h" #include "js_utils.h" #include "napi_rdb_store_observer.h" +#include "rdb_types.h"e13b522 #include "result_set.h" #include "value_object.h" #include "rdb_types.h" @@ -29,6 +30,9 @@ using JSChangeInfo = OHOS::RelationalStoreJsKit::NapiRdbStoreObserver::JSChangeI template<> int32_t Convert2Value(napi_env env, napi_value input, Asset &output); +template<> +int32_t Convert2Value(napi_env env, napi_value input, DistributedRdb::DistributedConfig &output); + template<> napi_value Convert2JSValue(napi_env env, const Asset &value); @@ -40,11 +44,8 @@ napi_value Convert2JSValue(napi_env env, const DistributedRdb::Statistic &statis template<> napi_value Convert2JSValue(napi_env env, const DistributedRdb::TableDetail &tableDetail); template<> -napi_value Convert2JSValue(napi_env env, const DistributedRdb::TableDetails &tableDetails); -template<> napi_value Convert2JSValue(napi_env env, const DistributedRdb::ProgressDetail &progressDetail); -template<> -napi_value Convert2JSValue(napi_env env, const DistributedRdb::Details &details); + template<> napi_value Convert2JSValue(napi_env env, const JSChangeInfo &value); }; // namespace JSUtils diff --git a/relational_store/frameworks/js/napi/relationalstore/include/napi_rdb_store.h b/relational_store/frameworks/js/napi/relationalstore/include/napi_rdb_store.h index 5eac78f1f3d43545fe28d0747d09ef7abebfc69d..5a9eed6067e0f25ae0b1b98554cb0de8ead4d067 100644 --- a/relational_store/frameworks/js/napi/relationalstore/include/napi_rdb_store.h +++ b/relational_store/frameworks/js/napi/relationalstore/include/napi_rdb_store.h @@ -81,7 +81,7 @@ private: explicit NapiCoudSyncCallback(napi_env env, napi_value callback) : NapiUvQueue(env, callback){} virtual ~NapiCoudSyncCallback() = default; - void OnSyncCompelete(const DistributedRdb::Details &details); + void OnSyncComplete(const DistributedRdb::Details &details); }; napi_value OnDataChangeEvent(napi_env env, size_t argc, napi_value *argv); diff --git a/relational_store/frameworks/js/napi/relationalstore/src/napi_async_call.cpp b/relational_store/frameworks/js/napi/relationalstore/src/napi_async_call.cpp index 4d71d664ec37c9c810e1c83def0540c7790338e5..9f33230a8c890333e71046e7d651008cecbf1b27 100644 --- a/relational_store/frameworks/js/napi/relationalstore/src/napi_async_call.cpp +++ b/relational_store/frameworks/js/napi/relationalstore/src/napi_async_call.cpp @@ -48,6 +48,25 @@ void Context::SetAction( napi_create_reference(env, self, 1, &self_); } +void Context::SetAll( + napi_env env, napi_callback_info info, InputAction input, ExecuteAction exec, OutputAction output) +{ + env_ = env; + size_t argc = MAX_INPUT_COUNT; + napi_value self = nullptr; + napi_value argv[MAX_INPUT_COUNT] = { nullptr }; + NAPI_CALL_RETURN_VOID(env, napi_get_cb_info(env, info, &argc, argv, &self, nullptr)); + + // int -->input_(env, argc, argv, self) + input(env, argc, argv, self); + + // if input return is not ok, then napi_throw_error context error + RDB_NAPI_ASSERT_BASE(env, error == nullptr, error, NAPI_RETVAL_NOTHING); + output_ = std::move(output); + exec_ = std::move(exec); + napi_create_reference(env, self, 1, &self_); +} + void Context::SetError(std::shared_ptr err) { error = err; diff --git a/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_js_utils.cpp b/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_js_utils.cpp index 06b7af7009bb532eead979a001b79e6835890548..ab10eeba68588f9c1a7ca49956f14faa62412351 100644 --- a/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_js_utils.cpp +++ b/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_js_utils.cpp @@ -66,6 +66,23 @@ int32_t Convert2Value(napi_env env, napi_value jsValue, Asset &output) return napi_ok; } +template<> +int32_t Convert2Value(napi_env env, napi_value input, DistributedRdb::DistributedConfig &output) +{ + napi_valuetype type; + napi_status status = napi_typeof(env, input, &type); + if (status != napi_ok || type != napi_object) { + LOG_DEBUG("napi_typeof failed status = %{public}d type = %{public}d", status, type); + return napi_invalid_arg; + } + + auto ret = Convert2Value(env, GetNamedProperty(env, input, "autoSync"), output.autoSync); + if (ret != napi_ok) { + return napi_invalid_arg; + } + return ret; +} + template<> napi_value Convert2JSValue(napi_env env, const Asset &value) { @@ -135,29 +152,6 @@ napi_value Convert2JSValue(napi_env env, const DistributedRdb::TableDetail &tabl return jsValue; } -template<> -napi_value Convert2JSValue(napi_env env, const DistributedRdb::TableDetails &tableDetails) -{ - napi_value jsValue; - napi_status status = napi_create_array_with_length(env, tableDetails.size(), &jsValue); - if (status != napi_ok) { - return nullptr; - } - - int index = 0; - for (const auto &[device, result] : tableDetails) { - napi_value jsElement; - status = napi_create_array_with_length(env, 2, &jsElement); - if (status != napi_ok) { - return nullptr; - } - napi_set_element(env, jsElement, 0, Convert2JSValue(env, device)); - napi_set_element(env, jsElement, 1, Convert2JSValue(env, result)); - napi_set_element(env, jsValue, index++, jsElement); - } - return jsValue; -} - template<> napi_value Convert2JSValue(napi_env env, const DistributedRdb::ProgressDetail &progressDetail) { @@ -178,12 +172,6 @@ napi_value Convert2JSValue(napi_env env, const DistributedRdb::ProgressDetail &p return jsValue; } -template<> -napi_value Convert2JSValue(napi_env env, const DistributedRdb::Details &details) -{ - return nullptr; -} - template<> napi_value Convert2JSValue(napi_env env, const JSChangeInfo &value) { diff --git a/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp b/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp index f2d21e03e7426fbfd425e122d9c6dd6ca3ffbff8..080d5c18a6a07f8a5b65c22cd938c33be5d2eee1 100644 --- a/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp +++ b/relational_store/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp @@ -74,9 +74,15 @@ struct RdbStoreContext : public Context { std::string pathName; std::string destName; std::string srcName; - int32_t enumArg; - int32_t distributedType; - int32_t syncMode; + union { + int32_t enumArg; + int32_t distributedType; + int32_t syncMode; + }; + + DistributedRdb::DistributedConfig distributedConfig; + Details details; + NativeRdb::ConflictResolution conflictResolution; #if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) DistributedRdb::SyncResult syncResult; @@ -290,6 +296,17 @@ int ParseDistributedTableArg(const napi_env &env, size_t argc, napi_value * argv return OK; } +int ParseDistributedConfigArg(const napi_env &env, size_t argc, napi_value * argv, std::shared_ptr context) +{ + context->distributedConfig = { false }; + if (argc > 2) { + auto status = JSUtils::Convert2Value(env, argv[2], context->distributedConfig); + CHECK_RETURN_SET(status == napi_ok, std::make_shared("distributedConfig", "a DistributedConfig type")); + } + LOG_DEBUG("ParseDistributedConfigArg end"); + return OK; +} + int ParseCloudSyncModeArg(const napi_env &env, const napi_value &arg, std::shared_ptr context) { auto status = JSUtils::Convert2ValueExt(env, arg, context->syncMode); @@ -1050,15 +1067,17 @@ napi_value RdbStoreProxy::SetDistributedTables(napi_env env, napi_callback_info LOG_DEBUG("RdbStoreProxy::SetDistributedTables start"); auto context = std::make_shared(); auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) { - CHECK_RETURN_SET_E(argc == 1 || argc == 2, std::make_shared("1 - 3")); + CHECK_RETURN_SET_E(1 <= argc && argc <= 3, std::make_shared("1 - 4")); CHECK_RETURN(OK == ParserThis(env, self, context)); CHECK_RETURN(OK == ParseTablesName(env, argv[0], context)); CHECK_RETURN(OK == ParseDistributedTableArg(env, argc, argv, context)); + CHECK_RETURN(OK == ParseDistributedConfigArg(env, argc, argv, context)); }; auto exec = [context]() -> int { LOG_DEBUG("RdbStoreProxy::SetDistributedTables Async"); RdbStoreProxy *obj = reinterpret_cast(context->boundObj); - return obj->rdbStore_->SetDistributedTables(context->tablesNames, context->distributedType); + return obj->rdbStore_->SetDistributedTables( + context->tablesNames, context->distributedType, context->distributedConfig); }; auto output = [context](napi_env env, napi_value &result) { napi_status status = napi_get_undefined(env, &result); @@ -1135,7 +1154,7 @@ napi_value RdbStoreProxy::CloudSync(napi_env env, napi_callback_info info) LOG_DEBUG("RdbStoreProxy::CloudSync start"); auto context = std::make_shared(); auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) { - CHECK_RETURN_SET_E(argc == 2 || argc == 3, std::make_shared("2 - 4")); + CHECK_RETURN_SET_E(1 < argc && argc < 5, std::make_shared("2 - 4")); CHECK_RETURN(OK == ParserThis(env, self, context)); CHECK_RETURN(OK == ParseCloudSyncModeArg(env, argv[0], context)); uint32_t index = 1; @@ -1145,7 +1164,17 @@ napi_value RdbStoreProxy::CloudSync(napi_env env, napi_callback_info info) CHECK_RETURN(OK == ParseTablesName(env, argv[index], context)); index++; } - CHECK_RETURN(OK == ParseCloudSyncCallback(env, argv[index], context)); + CHECK_RETURN(OK == ParseCloudSyncCallback(env, argv[index++], context)); + CHECK_RETURN_SET_E(index == argc - 1 || index == argc, std::make_shared("2 - 4")); + if(index == argc - 1){ + //get callback + napi_valuetype valueType = napi_undefined; + napi_typeof(env, argv[index], &valueType); + if (valueType == napi_function) { + LOG_INFO("asyncCall set callback"); + NAPI_CALL_RETURN_VOID(env, napi_create_reference(env, argv[index], 1, &context->callback_)); + } + } }; auto exec = [context]() -> int { LOG_DEBUG("RdbStoreProxy::CloudSync Async"); @@ -1156,7 +1185,7 @@ napi_value RdbStoreProxy::CloudSync(napi_env env, napi_callback_info info) return obj->rdbStore_->Sync(option, context->tablesNames, [context](const Details &details) { auto callback = std::make_shared(context->env_, context->cloudSyncCallback); - callback->OnSyncCompelete(details); + callback->OnSyncComplete(context->details); }); }; @@ -1166,7 +1195,7 @@ napi_value RdbStoreProxy::CloudSync(napi_env env, napi_callback_info info) CHECK_RETURN_SET_E(status == napi_ok, std::make_shared(E_ERROR)); }; - context->SetAction(env, info, input, exec, output); + context->SetAll(env, info, input, exec, output); CHECK_RETURN_NULL(context->error == nullptr || context->error->GetCode() == OK); return AsyncCall::Call(env, context); @@ -1270,7 +1299,7 @@ napi_value RdbStoreProxy::OffEvent(napi_env env, napi_callback_info info) return nullptr; } -void RdbStoreProxy::NapiCoudSyncCallback::OnSyncCompelete(const DistributedRdb::Details &details) +void RdbStoreProxy::NapiCoudSyncCallback::OnSyncComplete(const DistributedRdb::Details &details) { LOG_DEBUG("NapiCoudSyncCallback::OnSyncCompelete begin"); CallFunction([details](napi_env env, int &argc, napi_value *argv) { diff --git a/relational_store/frameworks/native/rdb/include/rdb_store_impl.h b/relational_store/frameworks/native/rdb/include/rdb_store_impl.h index 7b39ebe172c0fca57c25cd4cb0df98faac52e1dc..3096b6ba93b92647d7f989773184127352b7e778 100644 --- a/relational_store/frameworks/native/rdb/include/rdb_store_impl.h +++ b/relational_store/frameworks/native/rdb/include/rdb_store_impl.h @@ -21,6 +21,7 @@ #include #include #include +#include #include "rdb_store.h" #include "rdb_store_config.h" @@ -103,7 +104,8 @@ public: std::shared_ptr RemoteQuery(const std::string &device, const AbsRdbPredicates &predicates, const std::vector &columns, int &errCode) override; - int SetDistributedTables(const std::vector& tables, int32_t type) override; + int SetDistributedTables(const std::vector &tables, int32_t type, + const DistributedRdb::DistributedConfig &distributedConfig) override; std::string ObtainDistributedTableName(const std::string& device, const std::string& table, int &errCode) override; @@ -128,6 +130,7 @@ private: int GetDataBasePath(const std::string &databasePath, std::string &backupFilePath); int ExecuteSqlInner(const std::string &sql, std::vector &&bindArgs); int ExecuteGetLongInner(const std::string &sql, std::vector &&bindArgs); + void DoCloudSync(const std::string &table); const RdbStoreConfig rdbStoreConfig; SqliteConnectionPool *connectionPool; @@ -141,6 +144,13 @@ private: DistributedRdb::RdbSyncerParam syncerParam_; bool isEncrypt_; std::shared_ptr pool_; + + mutable std::shared_mutex rwMutex_; + static inline constexpr uint32_t INTERVAL = 500; + std::set cloudTables_; + + std::mutex mutex_; + std::shared_ptr> syncTables_; }; } // namespace OHOS::NativeRdb #endif diff --git a/relational_store/frameworks/native/rdb/mock/include/rdb_store_impl.h b/relational_store/frameworks/native/rdb/mock/include/rdb_store_impl.h index ca36024f20029a07948846745526e8cca62c096e..0a066284dc1d35dceb8625efdf7e52641ae9db17 100644 --- a/relational_store/frameworks/native/rdb/mock/include/rdb_store_impl.h +++ b/relational_store/frameworks/native/rdb/mock/include/rdb_store_impl.h @@ -104,6 +104,7 @@ private: int GetDataBasePath(const std::string &databasePath, std::string &backupFilePath); int ExecuteSqlInner(const std::string &sql, const std::vector &bindArgs); int ExecuteGetLongInner(const std::string &sql, const std::vector &bindArgs); + void DoCloudSync(const std::string &table); const RdbStoreConfig rdbStoreConfig; SqliteConnectionPool *connectionPool; diff --git a/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp b/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp index 1405940c7b5c0a3a724c26d3756f2f263a009e5e..495a481e42cb0cdd3323dc92b66f92aa9385fb0c 100644 --- a/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp +++ b/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp @@ -212,8 +212,11 @@ int RdbStoreImpl::BatchInsert(int64_t &outInsertNum, const std::string &table, s return FreeTransaction(connection, transaction.GetRollbackStr()); } } - - return FreeTransaction(connection, transaction.GetCommitStr()); + auto status = FreeTransaction(connection, transaction.GetCommitStr()); + if (status == E_OK) { + DoCloudSync(table); + } + return status; } std::pair> RdbStoreImpl::GetInsertParams( @@ -286,7 +289,9 @@ int RdbStoreImpl::InsertWithConflictResolution(int64_t &outRowId, const std::str errCode = connection->ExecuteForLastInsertedRowId(outRowId, sql.str(), std::move(bindArgs)); connectionPool->ReleaseConnection(connection); - + if (errCode == E_OK) { + DoCloudSync(table); + } return errCode; } @@ -348,7 +353,9 @@ int RdbStoreImpl::UpdateWithConflictResolution(int &changedRows, const std::stri errCode = connection->ExecuteForChangedRowCount(changedRows, sql.str(), std::move(bindArgs)); connectionPool->ReleaseConnection(connection); - + if (errCode == E_OK) { + DoCloudSync(table); + } return errCode; } @@ -383,7 +390,9 @@ int RdbStoreImpl::Delete(int &deletedRows, const std::string &table, const std:: int errCode = connection->ExecuteForChangedRowCount(deletedRows, sql.str(), std::move(bindArgs)); connectionPool->ReleaseConnection(connection); - + if (errCode == E_OK) { + DoCloudSync(table); + } return errCode; } @@ -406,7 +415,9 @@ int RdbStoreImpl::Delete(const std::string &table, const std::string &where, std int changedRows = 0; int errCode = connection->ExecuteForChangedRowCount(changedRows, sql.str(), std::move(args)); connectionPool->ReleaseConnection(connection); - + if (errCode == E_OK) { + DoCloudSync(table); + } return errCode == E_OK ? changedRows : -errCode; } @@ -523,6 +534,10 @@ int RdbStoreImpl::ExecuteSql(const std::string &sql, std::vector bi if (sqlType == SqliteUtils::STATEMENT_DDL) { errCode = connectionPool->ReOpenAvailableReadConnections(); } + + if (errCode == E_OK) { + DoCloudSync(""); + } return errCode; } @@ -1032,6 +1047,54 @@ bool RdbStoreImpl::IsMemoryRdb() const return isMemoryRdb; } +void RdbStoreImpl::DoCloudSync(const std::string &table) +{ + LOG_INFO("RdbStoreImpl DoCloudSync start: %{public}s", table.c_str()); +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) + if (pool_ == nullptr) { + return; + } + { + std::shared_lock lock(rwMutex_); + if (cloudTables_.empty() || (!table.empty() && cloudTables_.find(table) == cloudTables_.end())) { + return; + } + } + { + std::lock_guard lock(mutex_); + if (syncTables_ == nullptr) { + syncTables_ = std::make_shared>(); + } + auto empty = syncTables_->empty(); + if (table.empty()) { + syncTables_->insert(cloudTables_.begin(), cloudTables_.end()); + } else { + syncTables_->insert(table); + } + if (!empty) { + LOG_INFO("RdbStoreImpl DoCloudSync empty"); + return; + } + } + auto interval = + std::chrono::duration_cast(std::chrono::milliseconds(INTERVAL)); + pool_->Schedule(interval, [this]() { + std::shared_ptr> ptr; + { + std::lock_guard lock(mutex_); + ptr = syncTables_; + syncTables_ = nullptr; + } + if (ptr == nullptr) { + return; + } + LOG_INFO("RdbStoreImpl DoCloudSync start: %{public}s", ptr->begin()->c_str()); + SyncOption syncOption = { DistributedRdb::TIME_FIRST, false }; + Sync(syncOption, { ptr->begin(), ptr->end() }, nullptr); + }); +#endif +} + //std::string RdbStoreImpl::GetName() //{ // return name; @@ -1135,7 +1198,8 @@ std::shared_ptr RdbStoreImpl::QueryByStep(const std::string &sql, std } #if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) -int RdbStoreImpl::SetDistributedTables(const std::vector &tables, int32_t type) +int RdbStoreImpl::SetDistributedTables(const std::vector &tables, int32_t type, + const DistributedRdb::DistributedConfig &distributedConfig) { DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__)); if (tables.empty()) { @@ -1151,6 +1215,13 @@ int RdbStoreImpl::SetDistributedTables(const std::vector &tables, i LOG_ERROR("Fail to set distributed tables, error=%{public}d", errorCode); return errorCode; } + + LOG_INFO("RdbStoreProxy::SetDistributedTables tablename:%{public}s, type:%{public}d, config:%{public}d", + tables.begin()->c_str(), type, distributedConfig.autoSync); + if (type == DistributedRdb::DISTRIBUTED_CLOUD && distributedConfig.autoSync) { + std::unique_lock lock(rwMutex_); + cloudTables_.insert(tables.begin(), tables.end()); + } return E_OK; } @@ -1192,7 +1263,7 @@ int RdbStoreImpl::Sync(const SyncOption &option, const AbsRdbPredicates &predica for (auto &[key, value] : details) { briefs.insert_or_assign(key, value.code); } - if(callback!=nullptr){ + if (callback != nullptr) { callback(briefs); } }); diff --git a/relational_store/interfaces/inner_api/js/@ohos.data.relationalStore.d.ts b/relational_store/interfaces/inner_api/js/@ohos.data.relationalStore.d.ts index 9741d368d6d9cf20b4e366ae1aa4bc418005ea8b..20ca9b933701ead66745a6cb961897b6d86d4224 100644 --- a/relational_store/interfaces/inner_api/js/@ohos.data.relationalStore.d.ts +++ b/relational_store/interfaces/inner_api/js/@ohos.data.relationalStore.d.ts @@ -176,7 +176,7 @@ declare namespace relationalStore { schedule: Progress; code: number; // to see the ProcessCode details: { - [table: string]:TableDetail + [table: string]:TableDetail }; } diff --git a/relational_store/interfaces/inner_api/rdb/include/rdb_store.h b/relational_store/interfaces/inner_api/rdb/include/rdb_store.h index 513b1016d0bc917b9829dd4401dcc2f9b3de3e79..139b6270d91c844e3acdb2fd74f78427d870bc7b 100644 --- a/relational_store/interfaces/inner_api/rdb/include/rdb_store.h +++ b/relational_store/interfaces/inner_api/rdb/include/rdb_store.h @@ -386,7 +386,8 @@ public: * @param tables Indicates the tables name you want to set. */ virtual int SetDistributedTables(const std::vector &tables, - int32_t type = DistributedRdb::DistributedTableType::DISTRIBUTED_DEVICE) = 0; + int32_t type = DistributedRdb::DistributedTableType::DISTRIBUTED_DEVICE, + const DistributedRdb::DistributedConfig &distributedConfig = { false }) = 0; /** * @brief Obtain distributed table name of specified remote device according to local table name. diff --git a/relational_store/interfaces/inner_api/rdb/include/rdb_types.h b/relational_store/interfaces/inner_api/rdb/include/rdb_types.h index 373bf3dfa9ab93f38b866c88a84c97a79da26615..188e88dc59dc76a198a7ec95725d40cfa5324bac 100644 --- a/relational_store/interfaces/inner_api/rdb/include/rdb_types.h +++ b/relational_store/interfaces/inner_api/rdb/include/rdb_types.h @@ -68,6 +68,10 @@ enum DistributedTableType { DISTRIBUTED_CLOUD }; +struct DistributedConfig { + bool autoSync = false; +}; + enum Progress { SYNC_BEGIN, SYNC_IN_PROGRESS, diff --git a/relational_store/test/js/relationalstore/unittest/src/RdbStoreCloud.test.js b/relational_store/test/js/relationalstore/unittest/src/RdbStoreCloud.test.js new file mode 100644 index 0000000000000000000000000000000000000000..c21bc4a34ce3d624cdd5cb35dcc366a1ae859aab --- /dev/null +++ b/relational_store/test/js/relationalstore/unittest/src/RdbStoreCloud.test.js @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import data_relationalStore from '@ohos.data.relationalStore'; +import ability_featureAbility from '@ohos.ability.featureAbility' +import {DistributedType} from "../../../../../interfaces/inner_api/js/@ohos.data.relationalStore"; + +const TAG = "[RELATIONAL_STORE_JSKITS_TEST]" +const STORE_NAME = "cloud_rdb.db" +const E_NOT_SUPPORTED = 801; +var rdbStore = undefined; +var context = ability_featureAbility.getContext() + +describe('rdbStoreDistributedCloudTest', function () { + beforeAll(async function (done) { + console.info(TAG + 'beforeAll') + const config = { + "name": STORE_NAME, + securityLevel: data_relationalStore.SecurityLevel.S1, + } + try { + rdbStore = await data_relationalStore.getRdbStore(context, config); + console.log(TAG + "create rdb store success") + let sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT," + + "name TEXT NOT NULL," + + "age INTEGER)" + try { + await rdbStore.executeSql(sqlStatement, null) + console.log(TAG + "create table employee success") + } catch (err) { + console.log(TAG + "create table employee failed") + expect(null).assertFail() + } + + sqlStatement = "CREATE TABLE IF NOT EXISTS product (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT," + + "name TEXT NOT NULL," + + "price REAL," + + "vendor INTEGER," + + "describe TEXT)" + try { + await rdbStore.executeSql(sqlStatement, null) + console.log(TAG + "create table product success") + done() + } catch (err) { + console.log(TAG + "create table product failed") + expect(null).assertFail() + } + } catch (err) { + console.log(TAG + "create rdb store failed" + `, error code is ${err.code}, message is ${err.message}`) + expect(null).assertFail() + } + done() + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + }) + + afterEach(async function () { + console.info(TAG + 'afterEach') + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + rdbStore = null + await data_relationalStore.deleteRdbStore(context, STORE_NAME); + }) + + console.log(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.name set distributed table cloud none table + * @tc.number SUB_DDM_AppDataFWK_JSRDB_CLOUD_0001 + * @tc.desc rdb set distributed table cloud using none table as argment + */ + it('testRdbStoreCloud0001', 0, async function (done) { + console.log(TAG + "************* testRdbStoreCloud0001 start *************"); + try { + let config = { + autoSync:false + } + await rdbStore.setDistributedTables([],rdbStore.DistributedType.DISTRIBUTED_CLOUD,config) + console.log(TAG + "set none to be distributed table cloud success"); + expect(false).assertTrue(); + } catch (err) { + console.log(TAG + `set none to be distributed table cloud failed, err code is ${err.code}, message is ${err.message}.`); + expect(E_NOT_SUPPORTED).assertEqual(err.code); + } + done() + console.log(TAG + "************* testRdbStoreCloud0001 end *************"); + }) + + /** + * @tc.name set distributed table cloud using one table name + * @tc.number SUB_DDM_AppDataFWK_JSRDB_CLOUD_0002 + * @tc.desc set distributed table cloud using one table name + */ + it('testRdbStoreCloud0002', 0, async function (done) { + console.log(TAG + "************* testRdbStoreCloud0002 start *************"); + try { + let config = { + autoSync:true + } + await rdbStore.setDistributedTables(['employee'],rdbStore.DistributedType.DISTRIBUTED_CLOUD,config) + console.log(TAG + "set employee to be distributed table cloud success"); + expect(true).assertTrue(); + } catch (err) { + console.log(TAG + `set employee to be distributed table cloud failed, err code is ${err.code}, message is ${err.message}.`); + expect(false).assertTrue(); + } + done() + console.log(TAG + "************* testRdbStoreCloud0002 end *************"); + }) + + /** + * @tc.name set distributed table cloud using two table name + * @tc.number SUB_DDM_AppDataFWK_JSRDB_CLOUD_0003 + * @tc.desc set distributed table cloud using two table name + */ + it('testRdbStoreCloud0003', 0, async function (done) { + console.log(TAG + "************* testRdbStoreCloud0003 start *************"); + try { + let config = { + autoSync:false + } + await rdbStore.setDistributedTables(['employee', 'product'], rdbStore.DistributedType.DISTRIBUTED_CLOUD, + config) + console.log(TAG + "set employee and product to be distributed cloud table success"); + expect(true).assertTrue(); + } catch (err) { + console.log(TAG + `set employee and product to be distributed table failed, err code is ${err.code}, message is ${err.message}.`); + expect(false).assertTrue(); + } + done() + console.log(TAG + "************* testRdbStoreCloud0003 end *************"); + }) + + console.log(TAG + "*************Unit Test End*************"); +}) diff --git a/relational_store/test/native/rdb/fuzztest/rdbimpl_fuzzer/rdbimpl_fuzzer.cpp b/relational_store/test/native/rdb/fuzztest/rdbimpl_fuzzer/rdbimpl_fuzzer.cpp index ac381ef363bb9a3a0566fad14ab0a92158b03a0f..1a133444a54b726238bec10876b1fb8ded2d76d0 100644 --- a/relational_store/test/native/rdb/fuzztest/rdbimpl_fuzzer/rdbimpl_fuzzer.cpp +++ b/relational_store/test/native/rdb/fuzztest/rdbimpl_fuzzer/rdbimpl_fuzzer.cpp @@ -25,7 +25,7 @@ void RdbStoreImplFuzz(const uint8_t *data, size_t size) std::string rawString(reinterpret_cast(data), size); std::vector tables; tables.push_back(rawString); - rdbStoreImpl.SetDistributedTables(tables, size % 2); + rdbStoreImpl.SetDistributedTables(tables, size & 0x1, { size & 0x1 }); } } diff --git a/relational_store/test/native/rdb/unittest/rdb_store_subscribe_test.cpp b/relational_store/test/native/rdb/unittest/rdb_store_subscribe_test.cpp index 964eeb0eed429be78abcc51c9b957ed81188526e..c22fa1ae9ffd9881dff31b6920bf291126e2b1c9 100644 --- a/relational_store/test/native/rdb/unittest/rdb_store_subscribe_test.cpp +++ b/relational_store/test/native/rdb/unittest/rdb_store_subscribe_test.cpp @@ -1,17 +1,18 @@ /* -* Copyright (c) 2023 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include #include