From 3033600b858ec12c3cfc6694a9397759dc51f5ac Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 31 Jan 2023 17:05:27 +0800 Subject: [PATCH 1/3] update Signed-off-by: htt1997 --- .../.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md | 9 + data_object/bundle.json | 5 +- .../src/communicator/dev_manager.cpp | 1 + .../communicator/softbus_adapter_standard.cpp | 1 + .../test/unittest/object_store_test.cpp | 398 - .../jskitsimpl/include/adaptor/js_watcher.h | 10 +- .../src/adaptor/js_distributedobjectstore.cpp | 15 +- .../src/adaptor/js_object_wrapper.cpp | 4 + .../jskitsimpl/src/adaptor/js_watcher.cpp | 8 + .../jskitsimpl/src/common/napi_queue.cpp | 8 +- data_object/interfaces/innerkits/BUILD.gn | 4 +- .../interfaces/innerkits/distributed_object.h | 109 + .../innerkits/distributed_objectstore.h | 75 + .../interfaces/innerkits/objectstore_errors.h | 87 + data_object/interfaces/jskits/BUILD.gn | 6 +- .../.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md | 9 + data_share/datashare.gni | 8 + .../common/include/datashare_abs_result_set.h | 3 + .../common/include/ishared_result_set_proxy.h | 1 + .../native/common/include/shared_block.h | 13 +- .../common/src/datashare_abs_result_set.cpp | 22 +- .../common/src/datashare_result_set.cpp | 42 +- .../common/src/ishared_result_set_proxy.cpp | 16 + .../native/common/src/shared_block.cpp | 16 +- .../consumer/include/datashare_connection.h | 1 + .../consumer/src/datashare_connection.cpp | 15 +- .../native/consumer/src/datashare_helper.cpp | 5 + .../native/consumer/src/datashare_proxy.cpp | 2 - .../proxy/include/data_share_manager_impl.h | 3 - .../proxy/src/data_share_service_proxy.cpp | 12 +- data_share/interfaces/inner_api/BUILD.gn | 6 + .../interfaces/inner_api/common/BUILD.gn | 6 + .../consumer/include/datashare_result_set.h | 3 + .../src/mediadatashare_unit_test.cpp | 75 +- datamgr_service/BUILD.gn | 6 - .../src/account_delegate_normal_impl.cpp | 2 +- .../distributeddataservice/app/BUILD.gn | 4 - .../distributeddataservice/service/BUILD.gn | 2 +- .../service/rdb/rdb_notifier_proxy.cpp | 70 + .../service/rdb/rdb_notifier_proxy.h | 40 + .../service/rdb/rdb_service_impl.cpp | 1 + .../service/rdb/rdb_service_impl.h | 6 +- .../service/rdb/rdb_service_stub.h | 5 +- .../service/rdb/rdb_syncer.h | 2 +- .../fuzztest/devicekvstore_fuzzer/BUILD.gn | 73 - .../distributedkvdatamanager_fuzzer/BUILD.gn | 73 - .../kvstorescheduler_fuzzer.cpp | 71 - .../fuzztest/singlekvstore_fuzzer/BUILD.gn | 73 - .../fuzztest/typesutil_fuzzer/project.xml | 25 - kv_store/BUILD.gn | 20 +- kv_store/bundle.json | 4 +- kv_store/frameworks/CMakeLists.txt | 3 - .../frameworks/common}/dds_trace.h | 0 .../include/ikvstore_client_death_observer.h | 4 +- .../include/ikvstore_data_service.h | 4 +- .../include/ikvstore_observer.h | 2 +- .../include/ikvstore_sync_callback.h | 3 +- .../src/kvstore_client_death_observer.h | 2 +- .../distributeddatafwk/test/BUILD.gn | 93 +- .../kvdb/include/kv_types_util.h | 32 +- .../innerkitsimpl/kvdb/test/BUILD.gn | 82 +- .../kvdb/test/auto_sync_timer_test.cpp | 139 +- .../kvdb/test/single_store_impl_test.cpp | 3 +- .../object/include/iobject_callback.h | 18 +- .../object/include/iobject_service.h | 2 +- .../object/include/object_service_proxy.h | 4 +- .../distributeddata/src/js_kv_manager.cpp | 8 + .../distributedkvstore/src/js_kv_manager.cpp | 5 + .../distributedkvstore/src/napi_queue.cpp | 8 +- kv_store/frameworks/libs/CMakeLists.txt | 3 +- .../relational_store_sqlite_ext.cpp | 2 +- .../libs/distributeddb/test/BUILD.gn | 5 + .../test/fuzztest/common/fuzzer_data.cpp | 8 +- .../test/fuzztest/common/fuzzer_data.h | 5 +- .../distributeddb/test/moduletest/BUILD.gn | 708 + .../include/auto_launch_callback.h | 53 + .../distributeddb/include/delegate_callback.h | 49 + .../include/delegate_kv_mgr_callback.h | 43 + .../include/distributed_rdb_tools.h | 104 + .../include/distributed_test_sysinfo.h | 113 + .../include/distributed_test_tools.h | 436 + .../include/distributeddb_constant.h | 133 + .../include/distributeddb_data_generator.h | 567 + .../include/distributeddb_log_print.h | 33 + .../include/distributeddb_nb_test_tools.h | 356 + .../include/distributeddb_schema_test_tools.h | 311 + .../include/kv_store_observer_impl.h | 86 + .../include/kv_store_snapshot_callback.h | 42 + .../src/auto_launch_callback.cpp | 72 + .../distributeddb/src/delegate_callback.cpp | 36 + .../src/delegate_kv_mgr_callback.cpp | 31 + .../src/distributed_rdb_tools.cpp | 247 + .../src/distributed_test_sysinfo.cpp | 302 + .../src/distributed_test_tools.cpp | 1993 + .../src/distributeddb_constant.cpp | 35 + .../src/distributeddb_data_generator.cpp | 637 + .../src/distributeddb_nb_test_tools.cpp | 739 + .../src/distributeddb_schema_test_tools.cpp | 354 + .../src/kv_store_observer_impl.cpp | 221 + .../src/kv_store_snapshot_callback.cpp | 36 + .../distributed_crud_transaction_tools.h | 64 + .../distributeddb_nb_cursor_testcase.h | 55 + .../include/process_communicator_test_stub.h | 96 + .../distributed_crud_transaction_tools.cpp | 274 + .../src/distributed_rdb_exception_test.cpp | 352 + .../src/distributeddb_kv_backup_test.cpp | 1226 + .../src/distributeddb_kv_batch_crud_test.cpp | 1085 + ...distributeddb_kv_concurrency_crud_test.cpp | 323 + .../src/distributeddb_kv_create_test.cpp | 1979 + .../src/distributeddb_kv_crud_test.cpp | 720 + .../distributeddb_kv_observer_snap_test.cpp | 1587 + .../src/distributeddb_kv_observer_test.cpp | 1683 + .../src/distributeddb_kv_realdel_test.cpp | 374 + ...distributeddb_kv_transaction_perf_test.cpp | 339 + .../src/distributeddb_kv_transaction_test.cpp | 1997 + .../src/distributeddb_nb_autolaunch_test.cpp | 775 + .../src/distributeddb_nb_backup_test.cpp | 1517 + .../src/distributeddb_nb_batch_crud_test.cpp | 2472 + .../src/distributeddb_nb_create_test.cpp | 1969 + .../src/distributeddb_nb_crud_power_test.cpp | 157 + .../src/distributeddb_nb_crud_test.cpp | 1877 + .../src/distributeddb_nb_cursor_test.cpp | 790 + .../src/distributeddb_nb_cursor_testcase.cpp | 2027 + .../src/distributeddb_nb_db_damage_test.cpp | 251 + ...teddb_nb_enable_sync_by_closed_db_test.cpp | 762 + ...distributeddb_nb_local_batch_crud_test.cpp | 1035 + .../src/distributeddb_nb_observer_test.cpp | 2222 + ...buteddb_nb_predicate_query_expand_test.cpp | 1188 + .../distributeddb_nb_predicate_query_test.cpp | 1956 + .../src/distributeddb_nb_schema_test.cpp | 2396 + .../distributeddb_nb_schema_upgrade_test.cpp | 1383 + ...stributeddb_interfaces_index_unit_test.cpp | 4 +- ...ributeddb_storage_data_connection_test.cpp | 11 +- ...qlite_single_ver_natural_executor_test.cpp | 88 +- ..._sqlite_single_ver_storage_engine_test.cpp | 160 + .../innerkits/distributeddata/BUILD.gn | 14 +- .../include/change_notification.h | 2 +- .../distributeddata/include/data_query.h | 110 +- .../jskits/distributeddata/BUILD.gn | 17 +- .../jskits/distributedkvstore/BUILD.gn | 17 +- .../distributed_test.cpp | 26 +- .../distributed_test_agent.cpp | 28 +- .../test/fuzztest/blob_fuzzer/BUILD.gn | 22 +- .../test/fuzztest/blob_fuzzer/blob_fuzzer.cpp | 3 +- .../test/fuzztest/blob_fuzzer/blob_fuzzer.h | 0 .../test/fuzztest/blob_fuzzer/corpus/init | 0 .../test/fuzztest/blob_fuzzer/project.xml | 0 .../fuzztest/devicekvstore_fuzzer/BUILD.gn | 51 + .../fuzztest/devicekvstore_fuzzer/corpus/init | 0 .../devicekvstore_fuzzer.cpp | 0 .../devicekvstore_fuzzer.h | 0 .../fuzztest/devicekvstore_fuzzer/project.xml | 0 .../distributedkvdatamanager_fuzzer/BUILD.gn | 56 + .../corpus/init | 0 .../distributedkvdatamanager_fuzzer.cpp | 0 .../distributedkvdatamanager_fuzzer.h | 0 .../project.xml | 0 .../fuzztest/singlekvstore_fuzzer}/BUILD.gn | 23 +- .../singlekvstore_fuzzer}/corpus/init | 0 .../fuzztest/singlekvstore_fuzzer/project.xml | 0 .../singlekvstore_fuzzer.cpp | 0 .../singlekvstore_fuzzer.h | 0 .../fuzztest/taskscheduler_fuzzer/BUILD.gn | 8 +- .../taskscheduler_fuzzer}/corpus/init | 0 .../taskscheduler_fuzzer}/project.xml | 0 .../taskscheduler_fuzzer.cpp | 0 .../taskscheduler_fuzzer.h | 0 .../test/fuzztest/typesutil_fuzzer/BUILD.gn | 26 +- .../fuzztest/typesutil_fuzzer}/corpus/init | 0 .../fuzztest/typesutil_fuzzer}/project.xml | 0 .../typesutil_fuzzer/typesutil_fuzzer.cpp | 45 - .../typesutil_fuzzer/typesutil_fuzzer.h | 0 .../{ => distributedKVStore}/BUILD.gn | 2 +- .../{ => distributedKVStore}/config.json | 0 .../test/unittest/distributeddata/BUILD.gn | 30 + .../test/unittest/distributeddata/config.json | 75 + kv_store/test/unittest/openharmony_sx.p7b | Bin 3509 -> 0 bytes mock/CMakeLists.txt | 4 +- .../huks/libhukssdk/include/hks_api.h | 70 +- .../huks/libhukssdk/include/hks_mem.h | 61 + .../huks/libhukssdk/include/hks_param.h | 48 +- .../huks/libhukssdk/include/hks_type.h | 922 +- mock/sqlite/include/sqlite3.h | 3054 +- mock/sqlite/include/sqlite3ext.h | 647 +- mock/sqlite/include/sqlite3sym.h | 40 +- mock/sqlite/src/shell.c | 30689 ++++++----- mock/sqlite/src/sqlite3.c | 44828 +++++++++------- mock/src/mock_huks.cpp | 24 + .../.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md | 9 + .../frameworks/js/common/include/js_utils.h | 2 + .../frameworks/js/common/src/js_utils.cpp | 10 + .../js/napi/src/napi_preferences_helper.cpp | 3 + .../js/napi/src/napi_storage_helper.cpp | 5 +- .../.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md | 9 + relational_store/bundle.json | 2 + .../js/napi/common/include/js_utils.h | 3 +- .../js/napi/common/src/js_ability.cpp | 12 +- .../js/napi/common/src/js_utils.cpp | 2 +- .../frameworks/js/napi/dataability/BUILD.gn | 2 +- .../include/napi_async_proxy.h | 9 + .../include/napi_data_ability_predicates.h | 2 - .../src/napi_data_ability_predicates.cpp | 13 +- .../frameworks/js/napi/rdb/BUILD.gn | 59 +- .../js/napi/rdb/include/napi_async_call.h | 102 +- .../js/napi/rdb/include/napi_rdb_error.h | 4 +- .../js/napi/rdb/include/napi_rdb_predicates.h | 8 +- .../js/napi/rdb/include/napi_rdb_store.h | 8 +- .../js/napi/rdb/include/napi_rdb_trace.h | 13 +- .../js/napi/rdb/include/napi_result_set.h | 11 +- .../rdb/mock/include/napi_rdb_predicates.h | 8 +- .../js/napi/rdb/mock/include/napi_rdb_store.h | 8 +- .../napi/rdb/mock/include/napi_result_set.h | 9 +- .../js/napi/rdb/src/napi_async_call.cpp | 149 +- .../js/napi/rdb/src/napi_rdb_predicates.cpp | 77 +- .../js/napi/rdb/src/napi_rdb_store.cpp | 222 +- .../js/napi/rdb/src/napi_rdb_store_helper.cpp | 49 +- .../js/napi/rdb/src/napi_result_set.cpp | 31 +- .../js/napi/rdb/src/napi_uv_queue.cpp | 6 + .../relationalstore/include/napi_async_call.h | 99 +- .../relationalstore/include/napi_rdb_error.h | 19 + .../include/napi_rdb_predicates.h | 2 - .../relationalstore/include/napi_rdb_store.h | 3 - .../mock/include/napi_rdb_predicates.h | 2 - .../mock/include/napi_rdb_store.h | 3 - .../relationalstore/src/napi_async_call.cpp | 149 +- .../src/napi_rdb_const_properties.cpp | 12 +- .../src/napi_rdb_predicates.cpp | 12 +- .../relationalstore/src/napi_rdb_store.cpp | 241 +- .../src/napi_rdb_store_helper.cpp | 37 +- .../relationalstore/src/napi_uv_queue.cpp | 6 + .../native/appdatafwk/src/shared_block.cpp | 1 - .../native}/rdb/include/irdb_service.h | 19 +- .../native}/rdb/include/rdb_manager.h | 4 +- .../native/rdb/include}/rdb_manager_impl.h | 22 +- .../native/rdb/include/rdb_notifier_stub.h | 56 +- .../native/rdb/include/rdb_security_manager.h | 13 +- .../native/rdb/include}/rdb_service_proxy.h | 6 +- .../native/rdb/include/rdb_store_impl.h | 3 - .../frameworks/native/rdb/include/rdb_trace.h | 11 +- .../native}/rdb/include/rdb_types_util.h | 0 .../native/rdb/include/sqlite_sql_builder.h | 2 +- .../native/rdb/mock/include/rdb_store_impl.h | 3 - .../rdb/mock/include/sqlite_sql_builder.h | 2 +- .../native/rdb/src/abs_predicates.cpp | 76 +- .../native/rdb/src/abs_result_set.cpp | 7 + .../native/rdb/src/abs_shared_result_set.cpp | 22 +- .../frameworks/native/rdb/src/rdb_helper.cpp | 162 +- .../native}/rdb/src/rdb_manager.cpp | 0 .../native}/rdb/src/rdb_manager_impl.cpp | 89 +- .../native/rdb/src/rdb_notifier_stub.cpp | 75 +- .../native/rdb/src/rdb_security_manager.cpp | 112 +- .../native}/rdb/src/rdb_service_proxy.cpp | 6 +- .../native/rdb/src/rdb_store_impl.cpp | 20 +- .../native}/rdb/src/rdb_types_util.cpp | 0 .../native/rdb/src/sqlite_connection.cpp | 2 +- .../native/rdb/src/sqlite_connection_pool.cpp | 2 - .../native/rdb/src/sqlite_sql_builder.cpp | 34 +- .../native/rdb/src/sqlite_statement.cpp | 46 +- .../native/rdb/src/step_result_set.cpp | 1 - .../src/rdb_result_set_bridge.cpp | 1 - .../rdb_data_share_adapter/src/rdb_utils.cpp | 1 + .../interfaces/inner_api/rdb/BUILD.gn | 13 +- .../inner_api/rdb/include/abs_result_set.h | 2 + .../inner_api/rdb/include/rdb_common.h | 22 +- .../inner_api/rdb/include/rdb_helper.h | 12 +- .../inner_api/rdb/include/rdb_notifier.h | 33 + .../inner_api}/rdb/include/rdb_service.h | 7 +- .../inner_api/rdb/include/rdb_store.h | 12 +- .../inner_api/rdb/include/rdb_store_config.h | 5 - .../inner_api}/rdb/include/rdb_types.h | 10 +- .../inner_api/rdb/mock/include/rdb_common.h | 20 +- .../inner_api/rdb/mock/include/rdb_helper.h | 16 +- .../inner_api/rdb/mock/include/rdb_store.h | 12 +- .../rdb/mock/include/rdb_store_config.h | 5 - .../RdbstoreChangeEncryptKeyJsunit.test.js | 177 - .../src/V9_RdbstoreCallBackJsunit.test.js | 249 - .../src/V9_RdbstorePromiseJsunit.test.js | 204 - .../src/RdbstoreRdbstoreJsunit.test.js | 131 +- relational_store/test/native/rdb/BUILD.gn | 3 +- .../rdb_store_impl_test/BUILD.gn | 2 + .../rdb/unittest/rdb_get_status_test.cpp | 124 - .../rdb/unittest/rdb_get_store_test.cpp | 471 + .../native/rdb/unittest/rdb_helper_test.cpp | 41 + .../native/rdb/unittest/rdb_insert_test.cpp | 1 + .../rdb/unittest/rdb_open_callback_test.cpp | 1 + .../rdb_sqlite_shared_result_set_test.cpp | 37 + .../native/rdb/unittest/rdb_update_test.cpp | 1 + .../native/rdb/unittest/rdb_upgrade_test.cpp | 1 + .../unittest/rdb_data_share_adapter_test.cpp | 43 + test/include/CMakeLists.txt | 1 - 290 files changed, 92203 insertions(+), 37466 deletions(-) create mode 100644 data_object/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md delete mode 100644 data_object/frameworks/innerkitsimpl/test/unittest/object_store_test.cpp create mode 100644 data_share/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md create mode 100644 datamgr_service/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp create mode 100644 datamgr_service/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h delete mode 100644 datamgr_service/test/fuzztest/devicekvstore_fuzzer/BUILD.gn delete mode 100644 datamgr_service/test/fuzztest/distributedkvdatamanager_fuzzer/BUILD.gn delete mode 100644 datamgr_service/test/fuzztest/kvstorescheduler_fuzzer/kvstorescheduler_fuzzer.cpp delete mode 100644 datamgr_service/test/fuzztest/singlekvstore_fuzzer/BUILD.gn delete mode 100644 datamgr_service/test/fuzztest/typesutil_fuzzer/project.xml rename {datamgr_service/services/distributeddataservice/adapter/include/dfx => kv_store/frameworks/common}/dds_trace.h (100%) create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/BUILD.gn create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/auto_launch_callback.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_callback.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_kv_mgr_callback.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_rdb_tools.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_sysinfo.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_tools.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_constant.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_data_generator.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_log_print.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_nb_test_tools.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_schema_test_tools.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/kv_store_observer_impl.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/kv_store_snapshot_callback.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/auto_launch_callback.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/delegate_callback.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/delegate_kv_mgr_callback.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/distributed_rdb_tools.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/distributed_test_sysinfo.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/distributed_test_tools.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/distributeddb_constant.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/distributeddb_data_generator.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/distributeddb_nb_test_tools.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/distributeddb_schema_test_tools.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/kv_store_observer_impl.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/kv_store_snapshot_callback.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/include/distributed_crud_transaction_tools.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/include/distributeddb_nb_cursor_testcase.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/include/process_communicator_test_stub.h create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributed_crud_transaction_tools.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributed_rdb_exception_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_kv_backup_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_kv_batch_crud_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_kv_concurrency_crud_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_kv_create_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_kv_crud_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_kv_observer_snap_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_kv_observer_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_kv_realdel_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_kv_transaction_perf_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_kv_transaction_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_autolaunch_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_backup_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_batch_crud_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_create_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_crud_power_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_crud_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_cursor_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_cursor_testcase.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_db_damage_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_enable_sync_by_closed_db_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_local_batch_crud_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_observer_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_predicate_query_expand_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_predicate_query_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_schema_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_schema_upgrade_test.cpp create mode 100644 kv_store/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_storage_sqlite_single_ver_storage_engine_test.cpp rename {datamgr_service => kv_store}/test/fuzztest/blob_fuzzer/BUILD.gn (62%) rename {datamgr_service => kv_store}/test/fuzztest/blob_fuzzer/blob_fuzzer.cpp (97%) rename {datamgr_service => kv_store}/test/fuzztest/blob_fuzzer/blob_fuzzer.h (100%) rename {datamgr_service => kv_store}/test/fuzztest/blob_fuzzer/corpus/init (100%) rename {datamgr_service => kv_store}/test/fuzztest/blob_fuzzer/project.xml (100%) create mode 100644 kv_store/test/fuzztest/devicekvstore_fuzzer/BUILD.gn rename {datamgr_service => kv_store}/test/fuzztest/devicekvstore_fuzzer/corpus/init (100%) rename {datamgr_service => kv_store}/test/fuzztest/devicekvstore_fuzzer/devicekvstore_fuzzer.cpp (100%) rename {datamgr_service => kv_store}/test/fuzztest/devicekvstore_fuzzer/devicekvstore_fuzzer.h (100%) rename {datamgr_service => kv_store}/test/fuzztest/devicekvstore_fuzzer/project.xml (100%) create mode 100644 kv_store/test/fuzztest/distributedkvdatamanager_fuzzer/BUILD.gn rename {datamgr_service => kv_store}/test/fuzztest/distributedkvdatamanager_fuzzer/corpus/init (100%) rename {datamgr_service => kv_store}/test/fuzztest/distributedkvdatamanager_fuzzer/distributedkvdatamanager_fuzzer.cpp (100%) rename {datamgr_service => kv_store}/test/fuzztest/distributedkvdatamanager_fuzzer/distributedkvdatamanager_fuzzer.h (100%) rename {datamgr_service => kv_store}/test/fuzztest/distributedkvdatamanager_fuzzer/project.xml (100%) rename {datamgr_service/test/fuzztest/kvstorescheduler_fuzzer => kv_store/test/fuzztest/singlekvstore_fuzzer}/BUILD.gn (64%) rename {datamgr_service/test/fuzztest/kvstorescheduler_fuzzer => kv_store/test/fuzztest/singlekvstore_fuzzer}/corpus/init (100%) rename {datamgr_service => kv_store}/test/fuzztest/singlekvstore_fuzzer/project.xml (100%) rename {datamgr_service => kv_store}/test/fuzztest/singlekvstore_fuzzer/singlekvstore_fuzzer.cpp (100%) rename {datamgr_service => kv_store}/test/fuzztest/singlekvstore_fuzzer/singlekvstore_fuzzer.h (100%) rename {datamgr_service => kv_store}/test/fuzztest/taskscheduler_fuzzer/BUILD.gn (83%) rename {datamgr_service/test/fuzztest/singlekvstore_fuzzer => kv_store/test/fuzztest/taskscheduler_fuzzer}/corpus/init (100%) rename {datamgr_service/test/fuzztest/kvstorescheduler_fuzzer => kv_store/test/fuzztest/taskscheduler_fuzzer}/project.xml (100%) rename {datamgr_service => kv_store}/test/fuzztest/taskscheduler_fuzzer/taskscheduler_fuzzer.cpp (100%) rename {datamgr_service => kv_store}/test/fuzztest/taskscheduler_fuzzer/taskscheduler_fuzzer.h (100%) rename {datamgr_service => kv_store}/test/fuzztest/typesutil_fuzzer/BUILD.gn (61%) rename {datamgr_service/test/fuzztest/taskscheduler_fuzzer => kv_store/test/fuzztest/typesutil_fuzzer}/corpus/init (100%) rename {datamgr_service/test/fuzztest/taskscheduler_fuzzer => kv_store/test/fuzztest/typesutil_fuzzer}/project.xml (100%) rename {datamgr_service => kv_store}/test/fuzztest/typesutil_fuzzer/typesutil_fuzzer.cpp (74%) rename {datamgr_service => kv_store}/test/fuzztest/typesutil_fuzzer/typesutil_fuzzer.h (100%) rename kv_store/test/unittest/{ => distributedKVStore}/BUILD.gn (94%) rename kv_store/test/unittest/{ => distributedKVStore}/config.json (100%) create mode 100644 kv_store/test/unittest/distributeddata/BUILD.gn create mode 100644 kv_store/test/unittest/distributeddata/config.json delete mode 100644 kv_store/test/unittest/openharmony_sx.p7b create mode 100644 mock/innerkits/huks/libhukssdk/include/hks_mem.h create mode 100644 preferences/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md create mode 100644 relational_store/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md rename relational_store/frameworks/js/napi/{common => dataability}/include/napi_async_proxy.h (97%) rename {kv_store/frameworks/innerkitsimpl => relational_store/frameworks/native}/rdb/include/irdb_service.h (63%) rename {kv_store/frameworks/innerkitsimpl => relational_store/frameworks/native}/rdb/include/rdb_manager.h (92%) rename {kv_store/frameworks/innerkitsimpl/rdb/src => relational_store/frameworks/native/rdb/include}/rdb_manager_impl.h (74%) rename kv_store/frameworks/innerkitsimpl/rdb/include/rdb_notifier.h => relational_store/frameworks/native/rdb/include/rdb_notifier_stub.h (55%) rename {kv_store/frameworks/innerkitsimpl/rdb/src => relational_store/frameworks/native/rdb/include}/rdb_service_proxy.h (96%) rename {kv_store/frameworks/innerkitsimpl => relational_store/frameworks/native}/rdb/include/rdb_types_util.h (100%) rename {kv_store/frameworks/innerkitsimpl => relational_store/frameworks/native}/rdb/src/rdb_manager.cpp (100%) rename {kv_store/frameworks/innerkitsimpl => relational_store/frameworks/native}/rdb/src/rdb_manager_impl.cpp (61%) rename kv_store/frameworks/innerkitsimpl/rdb/src/rdb_notifier.cpp => relational_store/frameworks/native/rdb/src/rdb_notifier_stub.cpp (57%) rename {kv_store/frameworks/innerkitsimpl => relational_store/frameworks/native}/rdb/src/rdb_service_proxy.cpp (98%) rename {kv_store/frameworks/innerkitsimpl => relational_store/frameworks/native}/rdb/src/rdb_types_util.cpp (100%) rename datamgr_service/test/fuzztest/kvstorescheduler_fuzzer/kvstorescheduler_fuzzer.h => relational_store/interfaces/inner_api/rdb/include/rdb_common.h (60%) create mode 100644 relational_store/interfaces/inner_api/rdb/include/rdb_notifier.h rename {kv_store/frameworks/innerkitsimpl => relational_store/interfaces/inner_api}/rdb/include/rdb_service.h (94%) rename {kv_store/frameworks/innerkitsimpl => relational_store/interfaces/inner_api}/rdb/include/rdb_types.h (93%) rename datamgr_service/test/fuzztest/typesutil_fuzzer/corpus/init => relational_store/interfaces/inner_api/rdb/mock/include/rdb_common.h (60%) delete mode 100644 relational_store/test/js/rdb/unittest/src/RdbstoreChangeEncryptKeyJsunit.test.js delete mode 100644 relational_store/test/js/rdb/unittest/src/V9_RdbstoreCallBackJsunit.test.js delete mode 100644 relational_store/test/js/rdb/unittest/src/V9_RdbstorePromiseJsunit.test.js delete mode 100644 relational_store/test/native/rdb/unittest/rdb_get_status_test.cpp create mode 100644 relational_store/test/native/rdb/unittest/rdb_get_store_test.cpp diff --git a/data_object/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/data_object/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md new file mode 100644 index 00000000..6d08f016 --- /dev/null +++ b/data_object/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md @@ -0,0 +1,9 @@ +* **IssueNo**: +* **Description**: +* **Sig**: SIG_DataManagement +* **Feature or Bugfix**: +* **Binary Source**:No/Yes +* **TDD**:Pass/Fail/NA +* **XTS**:Pass/Fail/NA +* **Pretest**:Pass/Fail/NA + \ No newline at end of file diff --git a/data_object/bundle.json b/data_object/bundle.json index a8ae0c95..99f5c541 100644 --- a/data_object/bundle.json +++ b/data_object/bundle.json @@ -54,11 +54,12 @@ "samgr", "ipc", "hiviewdfx_hilog_native", - "libuv", "utils_base", "access_token" ], - "third_party": [] + "third_party": [ + "libuv" + ] }, "build": { "sub_component": [ diff --git a/data_object/frameworks/innerkitsimpl/src/communicator/dev_manager.cpp b/data_object/frameworks/innerkitsimpl/src/communicator/dev_manager.cpp index c14f0088..ff03a7cf 100644 --- a/data_object/frameworks/innerkitsimpl/src/communicator/dev_manager.cpp +++ b/data_object/frameworks/innerkitsimpl/src/communicator/dev_manager.cpp @@ -120,6 +120,7 @@ void DevManager::RegisterDevCallback() } LOG_INFO("register device callback failed, try again."); std::thread th = std::thread([this]() { + pthread_setname_np(pthread_self(), "Data_Object_InitDevManager"); constexpr int RETRY_TIMES = 300; int i = 0; int32_t status = DM_ERROR; diff --git a/data_object/frameworks/innerkitsimpl/src/communicator/softbus_adapter_standard.cpp b/data_object/frameworks/innerkitsimpl/src/communicator/softbus_adapter_standard.cpp index d22ccce3..d72b0f83 100644 --- a/data_object/frameworks/innerkitsimpl/src/communicator/softbus_adapter_standard.cpp +++ b/data_object/frameworks/innerkitsimpl/src/communicator/softbus_adapter_standard.cpp @@ -118,6 +118,7 @@ Status SoftBusAdapter::StopWatchDeviceChange( void SoftBusAdapter::NotifyAll(const DeviceInfo &deviceInfo, const DeviceChangeType &type) { std::thread th = std::thread([this, deviceInfo, type]() { + pthread_setname_np(pthread_self(), "Data_Object_NotifyAll"); std::vector listeners; { std::lock_guard lock(deviceChangeMutex_); diff --git a/data_object/frameworks/innerkitsimpl/test/unittest/object_store_test.cpp b/data_object/frameworks/innerkitsimpl/test/unittest/object_store_test.cpp deleted file mode 100644 index c9368112..00000000 --- a/data_object/frameworks/innerkitsimpl/test/unittest/object_store_test.cpp +++ /dev/null @@ -1,398 +0,0 @@ -/* - * Copyright (c) 2022 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 -#include - -#include "distributed_object.h" -#include "distributed_objectstore.h" -#include "objectstore_errors.h" -#include "store_observer.h" -#include "auto_launch_export.h" -#include "kv_store_delegate_manager.h" -#include "flat_object_store.h" -#include "distributed_objectstore_impl.h" - -using namespace testing::ext; -using namespace OHOS::ObjectStore; - -constexpr static double SALARY = 100.5; - -static void TestSetSessionId(std::string bundleName, std::string sessionId) -{ - DistributedObjectStore *objectStore = DistributedObjectStore::GetInstance(bundleName); - EXPECT_NE(nullptr, objectStore); - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_NE(nullptr, object); - - uint32_t ret = objectStore->DeleteObject(sessionId); - EXPECT_EQ(SUCCESS, ret); -} - -static void TestSaveAndRevokeSave(std::string bundleName, std::string sessionId) -{ - DistributedObjectStore *objectStore = DistributedObjectStore::GetInstance(bundleName); - EXPECT_NE(nullptr, objectStore); - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_NE(nullptr, object); - - uint32_t ret = object->PutString("name", "zhangsan"); - EXPECT_EQ(SUCCESS, ret); - ret = object->PutDouble("salary", SALARY); - EXPECT_EQ(SUCCESS, ret); - ret = object->PutBoolean("isTrue", true); - EXPECT_EQ(SUCCESS, ret); - - ret = object->Save("local"); - EXPECT_EQ(SUCCESS, ret); - ret = object->RevokeSave(); - EXPECT_EQ(SUCCESS, ret); - - ret = objectStore->DeleteObject(sessionId); - EXPECT_EQ(SUCCESS, ret); -} - -class NativeObjectStoreTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void NativeObjectStoreTest::SetUpTestCase(void) -{ - // input testsuit setup step,setup invoked before all testcases -} - -void NativeObjectStoreTest::TearDownTestCase(void) -{ - // input testsuit teardown step,teardown invoked after all testcases -} - -void NativeObjectStoreTest::SetUp(void) -{ - // input testcase setup step,setup invoked before each testcases -} - -void NativeObjectStoreTest::TearDown(void) -{ - // input testcase teardown step,teardown invoked after each testcases -} - -/** - * @tc.name: DistributedObjectStore_Create_Destroy_001 - * @tc.desc: test Create DistributedObject and Destroy DistrbutedObject - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObjectStore_Create_Destroy_001, TestSize.Level1) -{ - std::string bundleName = "default"; - std::string sessionId = "123456"; - DistributedObjectStore *objectStore = DistributedObjectStore::GetInstance(bundleName); - EXPECT_NE(nullptr, objectStore); - - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_NE(nullptr, object); - - uint32_t ret = objectStore->DeleteObject(sessionId); - EXPECT_EQ(SUCCESS, ret); -} - -/** - * @tc.name: DistributedObjectStore_Create_Destroy_002 - * @tc.desc: test Create DistributedObject and Destroy DistrbutedObject - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObjectStore_Create_Destroy_002, TestSize.Level1) -{ - std::string sessionId = "123456"; - - auto objectStore = new DistributedObjectStoreImpl(nullptr); - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_EQ(nullptr, object); -} - -/** - * @tc.name: DistributedObjectStore_Create_Destroy_003 - * @tc.desc: test Create DistributedObject and Destroy DistrbutedObject - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObjectStore_Create_Destroy_003, TestSize.Level1) -{ - std::string bundleName = "default"; - std::string sessionId = "123456"; - DistributedObjectStore *objectStore = DistributedObjectStore::GetInstance(bundleName); - EXPECT_NE(nullptr, objectStore); - - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_NE(nullptr, object); - - DistributedObject *object2 = objectStore->CreateObject(sessionId); - EXPECT_EQ(nullptr, object2); - - uint32_t ret = objectStore->DeleteObject(sessionId); - EXPECT_EQ(SUCCESS, ret); -} - -/** - * @tc.name: DistributedObjectStore_Get_001 - * @tc.desc: test DistributedObjectStore Get. - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObjectStore_Get_001, TestSize.Level1) -{ - std::string bundleName = "default"; - std::string sessionId = "123456"; - DistributedObjectStore *objectStore = DistributedObjectStore::GetInstance(bundleName); - EXPECT_NE(nullptr, objectStore); - - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_NE(nullptr, object); - - DistributedObject *object2 = nullptr; - uint32_t ret = objectStore->Get(sessionId, &object2); - EXPECT_EQ(SUCCESS, ret); - EXPECT_EQ(object, object2); - - ret = objectStore->DeleteObject(sessionId); - EXPECT_EQ(SUCCESS, ret); -} - -/** - * @tc.name: DistributedObjectStore_Watch_UnWatch_001 - * @tc.desc: test DistributedObjectStore Watch and UnWatch. - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObjectStore_Watch_UnWatch_001, TestSize.Level1) -{ - std::string bundleName = "default"; - std::string sessionId = "123456"; - DistributedObjectStore *objectStore = DistributedObjectStore::GetInstance(bundleName); - EXPECT_NE(nullptr, objectStore); - - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_NE(nullptr, object); - - auto watcherPtr = std::shared_ptr(); - uint32_t ret = objectStore->Watch(object, watcherPtr); - EXPECT_EQ(SUCCESS, ret); - - ret = objectStore->UnWatch(object); - EXPECT_EQ(SUCCESS, ret); - - ret = objectStore->DeleteObject(sessionId); - EXPECT_EQ(SUCCESS, ret); -} - -/** - * @tc.name: DistributedObjectStore_SetStatusNotifier_001 - * @tc.desc: test DistributedObjectStore SetStatusNotifier. - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObjectStore_SetStatusNotifier_001, TestSize.Level1) -{ - std::string bundleName = "default"; - std::string sessionId = "123456"; - DistributedObjectStore *objectStore = DistributedObjectStore::GetInstance(bundleName); - EXPECT_NE(nullptr, objectStore); - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_NE(nullptr, object); - - auto notifierPtr = std::shared_ptr(); - uint32_t ret = objectStore->SetStatusNotifier(notifierPtr); - EXPECT_EQ(ret, 0); - - ret = objectStore->DeleteObject(sessionId); - EXPECT_EQ(ret, 0); -} - -/** - * @tc.name: DistributedObject_Double_001 - * @tc.desc: test DistributedObjectStore PutDouble. - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObject_Double_001, TestSize.Level1) -{ - std::string bundleName = "default"; - std::string sessionId = "123456"; - DistributedObjectStore *objectStore = DistributedObjectStore::GetInstance(bundleName); - EXPECT_NE(nullptr, objectStore); - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_NE(nullptr, object); - - uint32_t ret = object->PutDouble("salary", SALARY); - EXPECT_EQ(ret, 0); - - double value = 0.0; - object->GetDouble("salary", value); - EXPECT_EQ(ret, 0); - EXPECT_EQ(value, SALARY); - - ret = objectStore->DeleteObject(sessionId); - EXPECT_EQ(ret, 0); -} - -/** - * @tc.name: DistributedObject_Boolean_001 - * @tc.desc: test DistributedObjectStore PutBoolean. - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObject_Boolean_001, TestSize.Level1) -{ - std::string bundleName = "default"; - std::string sessionId = "123456"; - DistributedObjectStore *objectStore = DistributedObjectStore::GetInstance(bundleName); - EXPECT_NE(nullptr, objectStore); - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_NE(nullptr, object); - - uint32_t ret = object->PutBoolean("isTrue", true); - EXPECT_EQ(SUCCESS, ret); - - bool value = false; - ret = object->GetBoolean("isTrue", value); - EXPECT_EQ(SUCCESS, ret); - EXPECT_EQ(true, value); - - ret = objectStore->DeleteObject(sessionId); - EXPECT_EQ(SUCCESS, ret); -} - -/** - * @tc.name: DistributedObject_String_001 - * @tc.desc: test DistributedObjectStore String. - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObject_String_001, TestSize.Level1) -{ - std::string bundleName = "default"; - std::string sessionId = "123456"; - DistributedObjectStore *objectStore = DistributedObjectStore::GetInstance(bundleName); - EXPECT_NE(nullptr, objectStore); - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_NE(nullptr, object); - - uint32_t ret = object->PutString("name", "zhangsan"); - EXPECT_EQ(SUCCESS, ret); - - std::string value = ""; - ret = object->GetString("name", value); - EXPECT_EQ(SUCCESS, ret); - EXPECT_EQ(value, "zhangsan"); - - ret = objectStore->DeleteObject(sessionId); - EXPECT_EQ(SUCCESS, ret); -} - -/** - * @tc.name: DistributedObject_GetSessionId_001 - * @tc.desc: test DistributedObjectStore GetSessionId. - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObject_GetSessionId_001, TestSize.Level1) -{ - std::string bundleName = "default"; - std::string sessionId = "123456"; - DistributedObjectStore *objectStore = DistributedObjectStore::GetInstance(bundleName); - EXPECT_NE(nullptr, objectStore); - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_NE(nullptr, object); - std::string getSessionId = object->GetSessionId(); - EXPECT_EQ(sessionId, getSessionId); - uint32_t ret = objectStore->DeleteObject(sessionId); - EXPECT_EQ(SUCCESS, ret); -} - -/** - * @tc.name: DistributedObject_TestSetSessionId_001 - * @tc.desc: test DistributedObjectStore TestSetSessionId. - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObject_TestSetSessionId_001, TestSize.Level1) -{ - std::thread t1(TestSetSessionId, "default1", "session1"); - std::thread t2(TestSetSessionId, "default2", "session2"); - std::thread t3(TestSetSessionId, "default3", "session3"); - t1.join(); - t2.join(); - t3.join(); -} - -/** - * @tc.name: DistributedObject_GetType_001 - * @tc.desc: test DistributedObject GetType. - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObject_GetType_001, TestSize.Level1) -{ - std::string bundleName = "default"; - std::string sessionId = "123456"; - DistributedObjectStore *objectStore = DistributedObjectStore::GetInstance(bundleName); - EXPECT_NE(nullptr, objectStore); - DistributedObject *object = objectStore->CreateObject(sessionId); - EXPECT_NE(nullptr, object); - - uint32_t ret = object->PutString("name", "zhangsan"); - EXPECT_EQ(SUCCESS, ret); - Type type; - ret = object->GetType("name", type); - EXPECT_EQ(SUCCESS, ret); - EXPECT_EQ(TYPE_STRING, type); - - ret = object->PutDouble("salary", SALARY); - EXPECT_EQ(SUCCESS, ret); - ret = object->GetType("salary", type); - EXPECT_EQ(SUCCESS, ret); - EXPECT_EQ(TYPE_DOUBLE, type); - - ret = object->PutBoolean("isTrue", true); - EXPECT_EQ(SUCCESS, ret); - ret = object->GetType("isTrue", type); - EXPECT_EQ(SUCCESS, ret); - EXPECT_EQ(TYPE_BOOLEAN, type); - - ret = objectStore->DeleteObject(sessionId); - EXPECT_EQ(SUCCESS, ret); -} - -/** - * @tc.name: DistributedObject_Save_RevokeSave_001 - * @tc.desc: test DistributedObjectStore Save. - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObject_Save_RevokeSave_001, TestSize.Level1) -{ - std::string bundleName = "default"; - std::string sessionId = "123456"; - TestSaveAndRevokeSave(bundleName, sessionId); -} - -/** - * @tc.name: DistributedObject_Save_RevokeSave_002 - * @tc.desc: test DistributedObjectStore Save. - * @tc.type: FUNC - */ -HWTEST_F(NativeObjectStoreTest, DistributedObject_Save_RevokeSave_002, TestSize.Level1) -{ - std::thread t1(TestSaveAndRevokeSave, "default1", "session1"); - std::thread t2(TestSaveAndRevokeSave, "default2", "session2"); - std::thread t3(TestSaveAndRevokeSave, "default3", "session3"); - t1.join(); - t2.join(); - t3.join(); -} \ No newline at end of file diff --git a/data_object/frameworks/jskitsimpl/include/adaptor/js_watcher.h b/data_object/frameworks/jskitsimpl/include/adaptor/js_watcher.h index 877c3180..54ee6a11 100644 --- a/data_object/frameworks/jskitsimpl/include/adaptor/js_watcher.h +++ b/data_object/frameworks/jskitsimpl/include/adaptor/js_watcher.h @@ -38,6 +38,11 @@ public: virtual ~EventListener() { } + + bool IsEmpty() + { + return handlers_ == nullptr; + } virtual bool Add(napi_env env, napi_value handler); @@ -58,7 +63,6 @@ public: bool Del(napi_env env, napi_value handler) override; void Clear(napi_env env) override; - private: bool isWatched_ = false; DistributedObjectStore *objectStore_; @@ -74,7 +78,6 @@ public: bool Del(napi_env env, napi_value handler) override; void Clear(napi_env env) override; - private: JSWatcher *watcher_; std::string sessionId_; @@ -93,7 +96,8 @@ public: void Emit(const char *type, const std::string &sessionId, const std::vector &changeData); void Emit(const char *type, const std::string &sessionId, const std::string &networkId, const std::string &status); - + + bool IsEmpty(); private: struct ChangeArgs { ChangeArgs(const napi_ref callback, const std::string &sessionId, const std::vector &changeData); diff --git a/data_object/frameworks/jskitsimpl/src/adaptor/js_distributedobjectstore.cpp b/data_object/frameworks/jskitsimpl/src/adaptor/js_distributedobjectstore.cpp index 368a6a5c..297bb50c 100644 --- a/data_object/frameworks/jskitsimpl/src/adaptor/js_distributedobjectstore.cpp +++ b/data_object/frameworks/jskitsimpl/src/adaptor/js_distributedobjectstore.cpp @@ -118,21 +118,28 @@ napi_value JSDistributedObjectStore::NewDistributedObject( return; } auto objectWrapper = static_cast(data); + + JSDistributedObjectStore::DelCallback(env, g_changeCallBacks, objectWrapper->GetObjectId()); + JSDistributedObjectStore::DelCallback(env, g_statusCallBacks, objectWrapper->GetObjectId()); + if (objectWrapper->GetObject() == nullptr) { delete objectWrapper; return; } - - g_changeCallBacks.Erase(objectWrapper->GetObjectId()); - g_statusCallBacks.Erase(objectWrapper->GetObjectId()); LOG_INFO("start delete object"); DistributedObjectStore::GetInstance(JSDistributedObjectStore::GetBundleName(env)) ->DeleteObject(objectWrapper->GetObject()->GetSessionId()); delete objectWrapper; }, nullptr, nullptr); + + if (status != napi_ok) { + LOG_WARN("error! napi_wrap failed."); + delete objectWrapper; + return nullptr; + } + RestoreWatchers(env, objectWrapper, objectId); - objectStore->NotifyCachedStatus(object->GetSessionId()); CHECK_EQUAL_WITH_RETURN_NULL(status, napi_ok); return result; diff --git a/data_object/frameworks/jskitsimpl/src/adaptor/js_object_wrapper.cpp b/data_object/frameworks/jskitsimpl/src/adaptor/js_object_wrapper.cpp index 17814002..5c211f69 100644 --- a/data_object/frameworks/jskitsimpl/src/adaptor/js_object_wrapper.cpp +++ b/data_object/frameworks/jskitsimpl/src/adaptor/js_object_wrapper.cpp @@ -56,6 +56,10 @@ void JSObjectWrapper::DeleteWatch(napi_env env, const char *type, napi_value han if (watcher_ != nullptr) { watcher_->Off(type, handler); LOG_INFO("JSObjectWrapper::DeleteWatch %{public}s", type); + if (watcher_->IsEmpty()) { + LOG_DEBUG("delete JSWatcher"); + watcher_ = nullptr; + } } else { LOG_ERROR("JSObjectWrapper::DeleteWatch watcher_ is null"); } diff --git a/data_object/frameworks/jskitsimpl/src/adaptor/js_watcher.cpp b/data_object/frameworks/jskitsimpl/src/adaptor/js_watcher.cpp index 7c1d4fec..40f96472 100644 --- a/data_object/frameworks/jskitsimpl/src/adaptor/js_watcher.cpp +++ b/data_object/frameworks/jskitsimpl/src/adaptor/js_watcher.cpp @@ -177,6 +177,14 @@ void JSWatcher::Emit( return; } +bool JSWatcher::IsEmpty() +{ + if (changeEventListener_->IsEmpty() && statusEventListener_->IsEmpty()) { + return true; + } + return false; +} + EventHandler *EventListener::Find(napi_env env, napi_value handler) { EventHandler *result = nullptr; diff --git a/data_object/frameworks/jskitsimpl/src/common/napi_queue.cpp b/data_object/frameworks/jskitsimpl/src/common/napi_queue.cpp index 4b58bab0..124fc32c 100644 --- a/data_object/frameworks/jskitsimpl/src/common/napi_queue.cpp +++ b/data_object/frameworks/jskitsimpl/src/common/napi_queue.cpp @@ -75,8 +75,6 @@ napi_value NapiQueue::AsyncWork(napi_env env, std::shared_ptr ctxt, NapiAsyncExecute execute, NapiAsyncComplete complete) { LOG_DEBUG("name=%{public}s", name.c_str()); - ctxt->execute = std::move(execute); - ctxt->complete = std::move(complete); napi_value promise = nullptr; if (ctxt->callbackRef == nullptr) { @@ -111,8 +109,10 @@ napi_value NapiQueue::AsyncWork(napi_env env, std::shared_ptr ctxt, GenerateOutput(ctxt); }, reinterpret_cast(ctxt.get()), &ctxt->work); - napi_queue_async_work(ctxt->env, ctxt->work); + ctxt->execute = std::move(execute); + ctxt->complete = std::move(complete); ctxt->hold = ctxt; // save crossing-thread ctxt. + napi_queue_async_work(ctxt->env, ctxt->work); return promise; } @@ -159,6 +159,8 @@ void NapiQueue::GenerateOutput(ContextBase *ctxt) LOG_DEBUG("call callback function"); napi_call_function(ctxt->env, nullptr, callback, RESULT_ALL, result, &callbackResult); } + ctxt->execute = nullptr; + ctxt->complete = nullptr; ctxt->hold.reset(); // release ctxt. } } // namespace OHOS::DistributedData diff --git a/data_object/interfaces/innerkits/BUILD.gn b/data_object/interfaces/innerkits/BUILD.gn index 15b4b053..c1ced95e 100644 --- a/data_object/interfaces/innerkits/BUILD.gn +++ b/data_object/interfaces/innerkits/BUILD.gn @@ -59,12 +59,12 @@ ohos_shared_library("distributeddataobject_impl") { deps = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", - "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk", "//third_party/bounds_checking_function:libsec_shared", "//third_party/libuv:uv", ] external_deps = [ "c_utils:utils", + "device_manager:devicemanagersdk", "dsoftbus:softbus_client", "hitrace_native:hitrace_meter", "hitrace_native:libhitracechain", @@ -74,6 +74,6 @@ ohos_shared_library("distributeddataobject_impl") { "samgr:samgr_proxy", ] public_configs = [ ":objectstore_public_config" ] - relative_install_dir = "module/data" + innerapi_tags = [ "platformsdk" ] subsystem_name = "distributeddatamgr" } diff --git a/data_object/interfaces/innerkits/distributed_object.h b/data_object/interfaces/innerkits/distributed_object.h index e2ffb7ff..3270dec6 100644 --- a/data_object/interfaces/innerkits/distributed_object.h +++ b/data_object/interfaces/innerkits/distributed_object.h @@ -30,17 +30,126 @@ enum Type : uint8_t { class DistributedObject { public: virtual ~DistributedObject(){}; + + /** + * @brief Put or update the data whose value type is double into the database, which means that the data of + * objects in the same sessionId is put or updated. + * + * @param key Indicates the key of key-value data to put or update. + * @param value Indicates the value of key-value data to put or update. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t PutDouble(const std::string &key, double value) = 0; + + /** + * @brief Put or update the data whose value type is bool into the database, which means that the data of + * objects in the same sessionId is put or updated. + * + * @param key Indicates the key of key-value data to put or update. + * @param value Indicates the value of key-value data to put or update. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t PutBoolean(const std::string &key, bool value) = 0; + + /** + * @brief Put or update the data whose value type is string into the database, which means that the data of + * objects in the same sessionId is put or updated. + * + * @param key Indicates the key of key-value data to put or update. + * @param value Indicates the value of key-value data to put or update. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t PutString(const std::string &key, const std::string &value) = 0; + + /** + * @brief Put or update the data whose value type is bytes stream into the database, which means that the data of + * objects in the same sessionId is put or updated. + * + * @param key Indicates the key of key-value data to put or update. + * @param value Indicates the value of key-value data to put or update. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t PutComplex(const std::string &key, const std::vector &value) = 0; + + /** + * @brief Get the data whose value type is double from the database according to the key, + * which means that the data of objects in the same sessionId is get. + * + * @param key Indicates the key of key-value data to put or update. + * @param value Indicates the value of key-value data to put or update. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t GetDouble(const std::string &key, double &value) = 0; + + /** + * @brief Get the data whose value type is bool from the database according to the key, + * which means that the data of objects in the same sessionId is get. + * + * @param key Indicates the key of key-value data to get. + * @param value Indicates the value of key-value data to get. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t GetBoolean(const std::string &key, bool &value) = 0; + + /** + * @brief Get the data whose value type is string from the database according to the key, + * which means that the data of objects in the same sessionId is get. + * + * @param key Indicates the key of key-value data to put or update. + * @param value Indicates the value of key-value data to put or update. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t GetString(const std::string &key, std::string &value) = 0; + + /** + * @brief Get the data whose value type is complex from the database according to the key, + * which means that the data of objects in the same sessionId is get. + * + * @param key Indicates the key of key-value data to put or update. + * @param value Indicates the value of key-value data to put or update. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t GetComplex(const std::string &key, std::vector &value) = 0; + + /** + * @brief Get the value type of key-value data by the key + * + * @param key Indicates the key of key-value data. + * @param value Indicates the value of key-value data. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t GetType(const std::string &key, Type &type) = 0; + + /** + * @brief Save the data to local device. + * + * @param deviceId Indicates the device Id. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t Save(const std::string &deviceId) = 0; + + /** + * @brief Revoke save data. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t RevokeSave() = 0; + + /** + * @brief Get the sessionId of the object. + * + * @return Returns sessionId of the object. + */ virtual std::string &GetSessionId() = 0; }; diff --git a/data_object/interfaces/innerkits/distributed_objectstore.h b/data_object/interfaces/innerkits/distributed_objectstore.h index 2de9313b..dab7f78c 100644 --- a/data_object/interfaces/innerkits/distributed_objectstore.h +++ b/data_object/interfaces/innerkits/distributed_objectstore.h @@ -31,14 +31,89 @@ public: class DistributedObjectStore { public: virtual ~DistributedObjectStore(){}; + + /** + * @brief Get the instance to handle the object, such as create the object. + * + * @param bundleName Indicates the bundleName. + * + * @return Returns the pointer to the DistributedObjectStore class. + */ static DistributedObjectStore *GetInstance(const std::string &bundleName = ""); + + /** + * @brief Create a object according to the sessionId. + * + * @param sessionId Indicates the sessionId. + * + * @return Returns the pointer to the DistributedObject class. + */ virtual DistributedObject *CreateObject(const std::string &sessionId) = 0; + + /** + * @brief Create a object according to the sessionId. + * + * @param sessionId Indicates the sessionId. + * @param status Indicates whether the distributed object is created successfully, + * 0 means success, other means fail. + * + * @return Returns the pointer to the DistributedObject class. + */ virtual DistributedObject *CreateObject(const std::string &sessionId, uint32_t &status) = 0; + + /** + * @brief Get the double pointer to the object. + * + * @param sessionId Indicates the sessionId. + * @param object Indicates the double pointer to the object. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t Get(const std::string &sessionId, DistributedObject **object) = 0; + + /** + * @brief Delete the object according to the sessionId. + * + * @param sessionId Indicates the sessionId. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t DeleteObject(const std::string &sessionId) = 0; + + /** + * @brief Set listening for data changes. + * + * @param object Indicates the pointer to the DistributedObject class. + * @param objectWatcher Indicates callback function for data changes. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t Watch(DistributedObject *object, std::shared_ptr objectWatcher) = 0; + + /** + * @brief Undo listening for data changes. + * + * @param object Indicates the pointer to the DistributedObject class. + * + * @return Returns the pointer to the DistributedObject class. + */ virtual uint32_t UnWatch(DistributedObject *object) = 0; + + /** + * @brief Set listening for device online and offline . + * + * @param notifier Indicates callback function for device online ond offline. + * + * @return Returns 0 for success, others for failure. + */ virtual uint32_t SetStatusNotifier(std::shared_ptr notifier) = 0; + + /** + * @brief Notify the status of the local device from the cached callback function according to the sessionId. + * + * @param sessionId Indicates the sessionId. + * + */ virtual void NotifyCachedStatus(const std::string &sessionId) = 0; }; } // namespace OHOS::ObjectStore diff --git a/data_object/interfaces/innerkits/objectstore_errors.h b/data_object/interfaces/innerkits/objectstore_errors.h index 6e2557f3..7e347f6b 100644 --- a/data_object/interfaces/innerkits/objectstore_errors.h +++ b/data_object/interfaces/innerkits/objectstore_errors.h @@ -21,27 +21,114 @@ namespace OHOS::ObjectStore { constexpr uint32_t BASE_ERR_OFFSET = 1650; /* module defined errors */ +/** + * @brief Executed successfully. + */ constexpr uint32_t SUCCESS = 0; + +/** + * @brief Database setup failure. + */ constexpr uint32_t ERR_DB_SET_PROCESS = BASE_ERR_OFFSET + 1; + +/** + * @brief Already exit. + */ constexpr uint32_t ERR_EXIST = BASE_ERR_OFFSET + 2; + +/** + * @brief Illegal data length. + */ constexpr uint32_t ERR_DATA_LEN = BASE_ERR_OFFSET + 3; + +/** + * @brief Memory allocation failure. + */ constexpr uint32_t ERR_NOMEM = BASE_ERR_OFFSET + 4; + +/** + * @brief Database is not initialized. + */ constexpr uint32_t ERR_DB_NOT_INIT = BASE_ERR_OFFSET + 5; + +/** + * @brief Kvstore error. + */ constexpr uint32_t ERR_DB_GETKV_FAIL = BASE_ERR_OFFSET + 6; + +/** + * @brief Database not exist. + */ constexpr uint32_t ERR_DB_NOT_EXIST = BASE_ERR_OFFSET + 7; + +/** + * @brief Get database data failure. + */ constexpr uint32_t ERR_DB_GET_FAIL = BASE_ERR_OFFSET + 8; + +/** + * @brief Get database entry failure. + */ constexpr uint32_t ERR_DB_ENTRY_FAIL = BASE_ERR_OFFSET + 9; + +/** + * @brief Close database failure. + */ constexpr uint32_t ERR_CLOSE_STORAGE = BASE_ERR_OFFSET + 10; + +/** + * @brief The object is null. + */ constexpr uint32_t ERR_NULL_OBJECT = BASE_ERR_OFFSET + 11; + +/** + * @brief registration failed. + */ constexpr uint32_t ERR_REGISTER = BASE_ERR_OFFSET + 12; + +/** + * @brief The object store is null. + */ constexpr uint32_t ERR_NULL_OBJECTSTORE = BASE_ERR_OFFSET + 13; + +/** + * @brief Get the object failure. + */ constexpr uint32_t ERR_GET_OBJECT = BASE_ERR_OFFSET + 14; + +/** + * @brief Unregistered. + */ constexpr uint32_t ERR_NO_OBSERVER = BASE_ERR_OFFSET + 15; + +/** + * @brief Deregistration failure. + */ constexpr uint32_t ERR_UNRIGSTER = BASE_ERR_OFFSET + 16; + +/** + * @brief Only one device. + */ constexpr uint32_t ERR_SINGLE_DEVICE = BASE_ERR_OFFSET + 17; + +/** + * @brief The pointer is null. + */ constexpr uint32_t ERR_NULL_PTR = BASE_ERR_OFFSET + 18; + +/** + * @brief Processing failure. + */ constexpr uint32_t ERR_PROCESSING = BASE_ERR_OFFSET + 19; + +/** + * @brief ResultSet processing failure. + */ constexpr uint32_t ERR_RESULTSET = BASE_ERR_OFFSET + 20; + +/** + * @brief Input parameters error. + */ constexpr uint32_t ERR_INVALID_ARGS = BASE_ERR_OFFSET + 21; } // namespace OHOS::ObjectStore diff --git a/data_object/interfaces/jskits/BUILD.gn b/data_object/interfaces/jskits/BUILD.gn index 55676b89..5a3ea00d 100644 --- a/data_object/interfaces/jskits/BUILD.gn +++ b/data_object/interfaces/jskits/BUILD.gn @@ -66,10 +66,7 @@ config("objectstore_config") { config("objectstore_public_config") { visibility = [ ":*" ] - include_dirs = [ - ".", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", - ] + include_dirs = [ "." ] } base_output_path = @@ -113,7 +110,6 @@ ohos_shared_library("distributeddataobject") { deps = [ ":distributed_data_object_abc", ":distributed_data_object_js", - "//foundation/ability/ability_runtime/frameworks/native/ability/native:abilitykit_native", "//foundation/distributeddatamgr/data_object/interfaces/innerkits:distributeddataobject_impl", "//third_party/libuv:uv", ] diff --git a/data_share/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/data_share/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md new file mode 100644 index 00000000..6d08f016 --- /dev/null +++ b/data_share/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md @@ -0,0 +1,9 @@ +* **IssueNo**: +* **Description**: +* **Sig**: SIG_DataManagement +* **Feature or Bugfix**: +* **Binary Source**:No/Yes +* **TDD**:Pass/Fail/NA +* **XTS**:Pass/Fail/NA +* **Pretest**:Pass/Fail/NA + \ No newline at end of file diff --git a/data_share/datashare.gni b/data_share/datashare.gni index ee65df1a..a4271628 100644 --- a/data_share/datashare.gni +++ b/data_share/datashare.gni @@ -38,3 +38,11 @@ datashare_native_consumer_path = "${datashare_base_path}/frameworks/native/consumer" datashare_native_proxy_path = "${datashare_base_path}/frameworks/native/proxy" + +declare_args() { + suspend_manager_enable = true + if (defined(global_parts_info) && + !defined(global_parts_info.resourceschedule_efficiency_manager)) { + suspend_manager_enable = false + } +} diff --git a/data_share/frameworks/native/common/include/datashare_abs_result_set.h b/data_share/frameworks/native/common/include/datashare_abs_result_set.h index f89b5473..755f294a 100644 --- a/data_share/frameworks/native/common/include/datashare_abs_result_set.h +++ b/data_share/frameworks/native/common/include/datashare_abs_result_set.h @@ -16,6 +16,7 @@ #ifndef DATASHARE_ABS_RESULT_SET_H #define DATASHARE_ABS_RESULT_SET_H +#include #include #include "basic/result_set.h" @@ -56,8 +57,10 @@ protected: static const int INIT_POS = -1; // Current row position int rowPos_; + int count_; // Indicates whether the result set is closed bool isClosed_; + std::map indexCache_; }; } // namespace DataShare } // namespace OHOS diff --git a/data_share/frameworks/native/common/include/ishared_result_set_proxy.h b/data_share/frameworks/native/common/include/ishared_result_set_proxy.h index 52e4dd09..a979fd21 100644 --- a/data_share/frameworks/native/common/include/ishared_result_set_proxy.h +++ b/data_share/frameworks/native/common/include/ishared_result_set_proxy.h @@ -32,6 +32,7 @@ public: bool OnGo(int startRowIndex, int targetRowIndex, int *cachedIndex = nullptr) override; int Close() override; private: + void ReportEventToSuspendManager(const std::string &uriString) const; std::mutex mutex_; static BrokerDelegator delegator_; std::vector columnNames_; diff --git a/data_share/frameworks/native/common/include/shared_block.h b/data_share/frameworks/native/common/include/shared_block.h index 9a79b156..1230171c 100644 --- a/data_share/frameworks/native/common/include/shared_block.h +++ b/data_share/frameworks/native/common/include/shared_block.h @@ -293,7 +293,7 @@ private: */ uint32_t Alloc(size_t size, bool aligned = false); - uint32_t *GetRowOffset(uint32_t row); + inline uint32_t *GetRowOffset(uint32_t row); uint32_t *AllocRowOffset(); @@ -304,7 +304,16 @@ private: uint32_t OffsetFromPtr(void *ptr); - void *OffsetToPtr(uint32_t offset, uint32_t bufferSize = 0); + inline void *OffsetToPtr(uint32_t offset, uint32_t bufferSize = 0) + { + if (offset >= mSize) { + return nullptr; + } + if (offset + bufferSize > mSize) { + return nullptr; + } + return static_cast(mData) + offset; + } /** * Convert utf8 string to utf16. diff --git a/data_share/frameworks/native/common/src/datashare_abs_result_set.cpp b/data_share/frameworks/native/common/src/datashare_abs_result_set.cpp index 71f531f0..d006905e 100644 --- a/data_share/frameworks/native/common/src/datashare_abs_result_set.cpp +++ b/data_share/frameworks/native/common/src/datashare_abs_result_set.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace DataShare { -DataShareAbsResultSet::DataShareAbsResultSet() : rowPos_(INIT_POS), isClosed_(false) +DataShareAbsResultSet::DataShareAbsResultSet() : rowPos_(INIT_POS), count_(-1), isClosed_(false) {} DataShareAbsResultSet::~DataShareAbsResultSet() {} @@ -176,18 +176,25 @@ int DataShareAbsResultSet::IsEnded(bool &result) int DataShareAbsResultSet::GetColumnCount(int &count) { - std::vector columnNames; - int ret = GetAllColumnNames(columnNames); - if (ret != E_OK) { - LOG_ERROR("return GetAllColumnNames ret is wrong!"); - return ret; + if (count_ == -1) { + std::vector columnNames; + int ret = GetAllColumnNames(columnNames); + if (ret != E_OK) { + LOG_ERROR("return GetAllColumnNames ret is wrong!"); + return ret; + } + count_ = static_cast(columnNames.size()); } - count = static_cast(columnNames.size()); + count = count_; return E_OK; } int DataShareAbsResultSet::GetColumnIndex(const std::string &columnName, int &columnIndex) { + if (indexCache_.find(columnName) != indexCache_.end()) { + columnIndex = indexCache_[columnName]; + return E_OK; + } auto periodIndex = columnName.rfind('.'); std::string columnNameLower = columnName; if (periodIndex != std::string::npos) { @@ -206,6 +213,7 @@ int DataShareAbsResultSet::GetColumnIndex(const std::string &columnName, int &co std::string lowerName = name; transform(name.begin(), name.end(), lowerName.begin(), ::tolower); if (lowerName == columnNameLower) { + indexCache_[columnName] = columnIndex; return E_OK; } columnIndex++; diff --git a/data_share/frameworks/native/common/src/datashare_result_set.cpp b/data_share/frameworks/native/common/src/datashare_result_set.cpp index 10d00eb5..4b69a5bf 100644 --- a/data_share/frameworks/native/common/src/datashare_result_set.cpp +++ b/data_share/frameworks/native/common/src/datashare_result_set.cpp @@ -53,7 +53,7 @@ DataShareResultSet::DataShareResultSet(std::shared_ptr &bridge) DataShareResultSet::~DataShareResultSet() { - ClosedBlock(); + Close(); } int DataShareResultSet::GetAllColumnNames(std::vector &columnNames) @@ -163,7 +163,6 @@ int DataShareResultSet::GoToRow(int position) int DataShareResultSet::GetBlob(int columnIndex, std::vector &value) { - DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__)); int errorCode = CheckState(columnIndex); if (errorCode != E_OK) { return errorCode; @@ -202,9 +201,9 @@ int DataShareResultSet::GetBlob(int columnIndex, std::vector &value) int DataShareResultSet::GetString(int columnIndex, std::string &value) { - int errorCode = CheckState(columnIndex); - if (errorCode != E_OK) { - return errorCode; + if (sharedBlock_ == nullptr) { + LOG_ERROR("sharedBlock is null!"); + return E_ERROR; } AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_ - startRowPos_, columnIndex); if (!cellUnit) { @@ -214,13 +213,10 @@ int DataShareResultSet::GetString(int columnIndex, std::string &value) int type = cellUnit->type; if (type == AppDataFwk::SharedBlock::CELL_UNIT_TYPE_STRING) { size_t sizeIncludingNull; - const char *tempValue = sharedBlock_->GetCellUnitValueString(cellUnit, &sizeIncludingNull); - if ((sizeIncludingNull <= 1) || (tempValue == nullptr)) { - value = ""; - return E_ERROR; - } - value = tempValue; + value = std::string(sharedBlock_->GetCellUnitValueString(cellUnit, &sizeIncludingNull)); return E_OK; + } else if (type == AppDataFwk::SharedBlock::CELL_UNIT_TYPE_NULL) { + return E_ERROR; } else if (type == AppDataFwk::SharedBlock::CELL_UNIT_TYPE_INTEGER) { int64_t tempValue = cellUnit->cell.longValue; value = std::to_string(tempValue); @@ -232,8 +228,6 @@ int DataShareResultSet::GetString(int columnIndex, std::string &value) value = os.str(); } return E_OK; - } else if (type == AppDataFwk::SharedBlock::CELL_UNIT_TYPE_NULL) { - return E_ERROR; } else if (type == AppDataFwk::SharedBlock::CELL_UNIT_TYPE_BLOB) { return E_ERROR; } else { @@ -244,6 +238,10 @@ int DataShareResultSet::GetString(int columnIndex, std::string &value) int DataShareResultSet::GetInt(int columnIndex, int &value) { + if (sharedBlock_ == nullptr) { + LOG_ERROR("sharedBlock is null!"); + return E_ERROR; + } AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_ - startRowPos_, columnIndex); if (!cellUnit) { LOG_ERROR("cellUnit is null!"); @@ -255,9 +253,9 @@ int DataShareResultSet::GetInt(int columnIndex, int &value) int DataShareResultSet::GetLong(int columnIndex, int64_t &value) { - int errorCode = CheckState(columnIndex); - if (errorCode != E_OK) { - return errorCode; + if (sharedBlock_ == nullptr) { + LOG_ERROR("sharedBlock is null!"); + return E_ERROR; } AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_ - startRowPos_, columnIndex); if (!cellUnit) { @@ -350,6 +348,7 @@ int DataShareResultSet::Close() DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__)); DataShareAbsResultSet::Close(); ClosedBlock(); + bridge_ = nullptr; return E_OK; } @@ -402,9 +401,7 @@ int DataShareResultSet::CheckState(int columnIndex) if (columnIndex >= cnt || columnIndex < 0) { return E_INVALID_COLUMN_INDEX; } - int rowCnt = 0; - GetRowCount(rowCnt); - if (rowPos_ < 0 || rowPos_ >= rowCnt) { + if (rowPos_ == INITIAL_POS) { return E_INVALID_STATEMENT; } return E_OK; @@ -430,5 +427,12 @@ bool DataShareResultSet::Unmarshalling(MessageParcel &parcel) } return true; } + +void DataShareResultSet::SetUri(const std::string &uri) +{ + if (!uri.empty()) { + uri_ = uri; + } +} } // namespace DataShare } // namespace OHOS \ No newline at end of file diff --git a/data_share/frameworks/native/common/src/ishared_result_set_proxy.cpp b/data_share/frameworks/native/common/src/ishared_result_set_proxy.cpp index 058c68db..f2a4299a 100644 --- a/data_share/frameworks/native/common/src/ishared_result_set_proxy.cpp +++ b/data_share/frameworks/native/common/src/ishared_result_set_proxy.cpp @@ -19,6 +19,9 @@ #include "datashare_errno.h" #include "datashare_log.h" #include "iremote_proxy.h" +#ifdef EFFICIENCY_MANAGER_ENABLE +#include "suspend_manager_client.h" +#endif namespace OHOS::DataShare { std::function(MessageParcel &parcel)> ISharedResultSet::consumerCreator_ = @@ -52,6 +55,7 @@ int ISharedResultSetProxy::GetAllColumnNames(std::vector &columnNam request.WriteInterfaceToken(GetDescriptor()); MessageParcel reply; MessageOption msgOption; + ReportEventToSuspendManager(uri_); int errCode = Remote()->SendRequest(FUNC_GET_ALL_COLUMN_NAMES, request, reply, msgOption); if (errCode != 0) { LOG_ERROR("IPC Error %{public}x", errCode); @@ -80,6 +84,7 @@ int ISharedResultSetProxy::GetRowCount(int &count) request.WriteInterfaceToken(GetDescriptor()); MessageParcel reply; MessageOption msgOption; + ReportEventToSuspendManager(uri_); int errCode = Remote()->SendRequest(FUNC_GET_ROW_COUNT, request, reply, msgOption); if (errCode != 0) { LOG_ERROR("IPC Error %{public}x", errCode); @@ -104,6 +109,7 @@ bool ISharedResultSetProxy::OnGo(int oldRowIndex, int newRowIndex, int *cachedIn request.WriteInt32(newRowIndex); MessageParcel reply; MessageOption msgOption; + ReportEventToSuspendManager(uri_); int errCode = Remote()->SendRequest(FUNC_ON_GO, request, reply, msgOption); if (errCode != 0) { LOG_ERROR("IPC Error %{public}x", errCode); @@ -126,6 +132,7 @@ int ISharedResultSetProxy::Close() request.WriteInterfaceToken(GetDescriptor()); MessageParcel reply; MessageOption msgOption; + ReportEventToSuspendManager(uri_); int errCode = Remote()->SendRequest(FUNC_CLOSE, request, reply, msgOption); if (errCode != 0) { LOG_ERROR("IPC Error %{public}x", errCode); @@ -133,4 +140,13 @@ int ISharedResultSetProxy::Close() } return reply.ReadInt32(); } + +void ISharedResultSetProxy::ReportEventToSuspendManager(const std::string &uriString) const +{ +#ifdef EFFICIENCY_MANAGER_ENABLE + OHOS::SuspendManager::AppInfo appInfo(-1, -1, uriString, "", "THAW_BY_DATASHARE_EXTENSION_CALLED"); + appInfo.SetIsExtension(true); + OHOS::SuspendManager::SuspendManagerClient::GetInstance().ThawOneAppByAppInfo(appInfo); +#endif +} } // namespace OHOS::DataShare \ No newline at end of file diff --git a/data_share/frameworks/native/common/src/shared_block.cpp b/data_share/frameworks/native/common/src/shared_block.cpp index b5e16c12..0028401e 100644 --- a/data_share/frameworks/native/common/src/shared_block.cpp +++ b/data_share/frameworks/native/common/src/shared_block.cpp @@ -64,7 +64,6 @@ bool SharedBlock::Init() int SharedBlock::CreateSharedBlock(const std::string &name, size_t size, sptr ashmem, SharedBlock *&outSharedBlock) { - LOG_DEBUG("CreateSharedBlock into."); outSharedBlock = new SharedBlock(name, ashmem, size, false); if (outSharedBlock == nullptr) { LOG_ERROR("CreateSharedBlock: new SharedBlock error."); @@ -257,7 +256,7 @@ uint32_t SharedBlock::Alloc(size_t size, bool aligned) return offset; } -uint32_t *SharedBlock::GetRowOffset(uint32_t row) +inline uint32_t *SharedBlock::GetRowOffset(uint32_t row) { uint32_t rowPos = row; @@ -453,19 +452,6 @@ size_t SharedBlock::SetRawData(const void *rawData, size_t size) return SHARED_BLOCK_OK; } -void *SharedBlock::OffsetToPtr(uint32_t offset, uint32_t bufferSize) -{ - if (offset >= mSize) { - LOG_ERROR("Offset %{public}" PRIu32 " out of bounds, max value %{public}zu", offset, mSize); - return nullptr; - } - if (offset + bufferSize > mSize) { - LOG_ERROR("End offset %{public}" PRIu32 " out of bounds, max value %{public}zu", offset + bufferSize, mSize); - return nullptr; - } - return static_cast(mData) + offset; -} - uint32_t SharedBlock::OffsetFromPtr(void *ptr) { return static_cast(ptr) - static_cast(mData); diff --git a/data_share/frameworks/native/consumer/include/datashare_connection.h b/data_share/frameworks/native/consumer/include/datashare_connection.h index 02dd7581..bc9f4e1b 100644 --- a/data_share/frameworks/native/consumer/include/datashare_connection.h +++ b/data_share/frameworks/native/consumer/include/datashare_connection.h @@ -80,6 +80,7 @@ private: void DisconnectDataShareExtAbility(); void SetDataShareProxy(sptr proxy); bool IsExtAbilityConnected(); + void ReportEventToSuspendManager(const std::string &uriString) const; std::mutex mutex_; std::shared_ptr dataShareProxy_; diff --git a/data_share/frameworks/native/consumer/src/datashare_connection.cpp b/data_share/frameworks/native/consumer/src/datashare_connection.cpp index 1fd7eb3f..17e80b48 100644 --- a/data_share/frameworks/native/consumer/src/datashare_connection.cpp +++ b/data_share/frameworks/native/consumer/src/datashare_connection.cpp @@ -18,6 +18,9 @@ #include "ability_manager_client.h" #include "datashare_proxy.h" #include "datashare_log.h" +#ifdef EFFICIENCY_MANAGER_ENABLE +#include "suspend_manager_client.h" +#endif namespace OHOS { namespace DataShare { @@ -41,7 +44,7 @@ void DataShareConnection::OnAbilityConnectDone( return; } std::unique_lock lock(condition_.mutex); - SetDataShareProxy(iface_cast(remoteObject)); + SetDataShareProxy(new (std::nothrow) DataShareProxy(remoteObject)); condition_.condition.notify_all(); } @@ -72,6 +75,7 @@ void DataShareConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName */ bool DataShareConnection::ConnectDataShareExtAbility(const Uri &uri, const sptr token) { + ReportEventToSuspendManager(uri.ToString()); if (dataShareProxy_ != nullptr) { return true; } @@ -157,5 +161,14 @@ bool DataShareConnection::IsConnected() { return dataShareProxy_ != nullptr; } + +void DataShareConnection::ReportEventToSuspendManager(const std::string &uriString) const +{ +#ifdef EFFICIENCY_MANAGER_ENABLE + OHOS::SuspendManager::AppInfo appInfo(-1, -1, uriString, "", "THAW_BY_DATASHARE_EXTENSION_CALLED"); + appInfo.SetIsExtension(true); + OHOS::SuspendManager::SuspendManagerClient::GetInstance().ThawOneAppByAppInfo(appInfo); +#endif +} } // namespace DataShare } // namespace OHOS \ No newline at end of file diff --git a/data_share/frameworks/native/consumer/src/datashare_helper.cpp b/data_share/frameworks/native/consumer/src/datashare_helper.cpp index 39cae15a..c4ad97b5 100644 --- a/data_share/frameworks/native/consumer/src/datashare_helper.cpp +++ b/data_share/frameworks/native/consumer/src/datashare_helper.cpp @@ -340,6 +340,11 @@ std::shared_ptr DataShareHelper::Query( if (proxy != nullptr) { resultset = proxy->Query(uri, predicates, columns); } + + if (resultset) { + resultset->SetUri(uri_.ToString()); + } + return resultset; } diff --git a/data_share/frameworks/native/consumer/src/datashare_proxy.cpp b/data_share/frameworks/native/consumer/src/datashare_proxy.cpp index 93625c25..8f9ddcc4 100644 --- a/data_share/frameworks/native/consumer/src/datashare_proxy.cpp +++ b/data_share/frameworks/native/consumer/src/datashare_proxy.cpp @@ -249,7 +249,6 @@ int DataShareProxy::Delete(const Uri &uri, const DataSharePredicates &predicates std::shared_ptr DataShareProxy::Query(const Uri &uri, const DataSharePredicates &predicates, std::vector &columns) { - LOG_INFO("begin."); MessageParcel data; if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) { LOG_ERROR("WriteInterfaceToken failed"); @@ -278,7 +277,6 @@ std::shared_ptr DataShareProxy::Query(const Uri &uri, LOG_ERROR("Query fail to SendRequest. err: %{public}d", err); return nullptr; } - LOG_INFO("end successfully."); return ISharedResultSet::ReadFromParcel(reply); } diff --git a/data_share/frameworks/native/proxy/include/data_share_manager_impl.h b/data_share/frameworks/native/proxy/include/data_share_manager_impl.h index aeca5e66..9ab3b44c 100644 --- a/data_share/frameworks/native/proxy/include/data_share_manager_impl.h +++ b/data_share/frameworks/native/proxy/include/data_share_manager_impl.h @@ -77,9 +77,6 @@ public: explicit DataShareKvServiceProxy(const sptr &impl); ~DataShareKvServiceProxy() = default; sptr GetFeatureInterface(const std::string &name) override; - -private: - static inline BrokerDelegator delegator_; }; } // namespace OHOS::DataShare #endif diff --git a/data_share/frameworks/native/proxy/src/data_share_service_proxy.cpp b/data_share/frameworks/native/proxy/src/data_share_service_proxy.cpp index a1062a34..8c0efb12 100644 --- a/data_share/frameworks/native/proxy/src/data_share_service_proxy.cpp +++ b/data_share/frameworks/native/proxy/src/data_share_service_proxy.cpp @@ -27,9 +27,9 @@ DataShareServiceProxy::DataShareServiceProxy(const sptr &object) LOG_INFO("Construct complete."); } -int DataShareServiceProxy::Insert(const Uri &uri, const DataShareValuesBucket &value) +int32_t DataShareServiceProxy::Insert(const Uri &uri, const DataShareValuesBucket &value) { - std::string uriStr = uri.ToString(); + const std::string &uriStr = uri.ToString(); MessageParcel data; if (!data.WriteInterfaceToken(IDataShareService::GetDescriptor())) { LOG_ERROR("Write descriptor failed!"); @@ -53,7 +53,7 @@ int DataShareServiceProxy::Insert(const Uri &uri, const DataShareValuesBucket &v int32_t DataShareServiceProxy::Update(const Uri &uri, const DataSharePredicates &predicate, const DataShareValuesBucket &valuesBucket) { - std::string uriStr = uri.ToString(); + const std::string &uriStr = uri.ToString(); MessageParcel data; if (!data.WriteInterfaceToken(IDataShareService::GetDescriptor())) { LOG_ERROR("Write descriptor failed!"); @@ -74,9 +74,9 @@ int32_t DataShareServiceProxy::Update(const Uri &uri, return reply.ReadInt32(); } - int DataShareServiceProxy::Delete(const Uri &uri, const DataSharePredicates &predicate) +int32_t DataShareServiceProxy::Delete(const Uri &uri, const DataSharePredicates &predicate) { - std::string uriStr = uri.ToString(); + const std::string &uriStr = uri.ToString(); MessageParcel data; if (!data.WriteInterfaceToken(IDataShareService::GetDescriptor())) { LOG_ERROR("Write descriptor failed!"); @@ -100,7 +100,7 @@ int32_t DataShareServiceProxy::Update(const Uri &uri, std::shared_ptr DataShareServiceProxy::Query( const Uri &uri, const DataSharePredicates &predicates, std::vector &columns) { - std::string uriStr = uri.ToString(); + const std::string &uriStr = uri.ToString(); MessageParcel data; if (!data.WriteInterfaceToken(IDataShareService::GetDescriptor())) { LOG_ERROR("WriteInterfaceToken failed!"); diff --git a/data_share/interfaces/inner_api/BUILD.gn b/data_share/interfaces/inner_api/BUILD.gn index dc7426ce..deaeb1d6 100644 --- a/data_share/interfaces/inner_api/BUILD.gn +++ b/data_share/interfaces/inner_api/BUILD.gn @@ -51,6 +51,7 @@ config("ability_public_config") { ohos_shared_library("datashare_consumer") { include_dirs = [] + defines = [] sources = [ "${datashare_native_consumer_path}/src/connection_factory.cpp", @@ -81,6 +82,11 @@ ohos_shared_library("datashare_consumer") { "samgr:samgr_proxy", ] + if (suspend_manager_enable) { + external_deps += [ "efficiency_manager:suspend_manager_client" ] + defines += [ "EFFICIENCY_MANAGER_ENABLE" ] + } + public_deps = [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", "//foundation/arkui/napi:ace_napi", diff --git a/data_share/interfaces/inner_api/common/BUILD.gn b/data_share/interfaces/inner_api/common/BUILD.gn index 2ea8ce82..95bd8587 100644 --- a/data_share/interfaces/inner_api/common/BUILD.gn +++ b/data_share/interfaces/inner_api/common/BUILD.gn @@ -24,6 +24,7 @@ config("ability_config") { } ohos_shared_library("datashare_common") { + defines = [] include_dirs = [ "${datashare_common_napi_path}/include", "${datashare_common_native_path}/include", @@ -64,6 +65,11 @@ ohos_shared_library("datashare_common") { "relational_store:native_appdatafwk", ] + if (suspend_manager_enable) { + external_deps += [ "efficiency_manager:suspend_manager_client" ] + defines += [ "EFFICIENCY_MANAGER_ENABLE" ] + } + subsystem_name = "distributeddatamgr" part_name = "data_share" } diff --git a/data_share/interfaces/inner_api/consumer/include/datashare_result_set.h b/data_share/interfaces/inner_api/consumer/include/datashare_result_set.h index bdc3765d..f3fe488d 100644 --- a/data_share/interfaces/inner_api/consumer/include/datashare_result_set.h +++ b/data_share/interfaces/inner_api/consumer/include/datashare_result_set.h @@ -52,6 +52,7 @@ public: virtual void SetBlock(AppDataFwk::SharedBlock *block); int Close() override; bool HasBlock() const; + void SetUri(const std::string &uri); protected: int CheckState(int columnIndex); @@ -63,6 +64,8 @@ protected: bool Unmarshalling(MessageParcel &parcel); bool Marshalling(MessageParcel &parcel); + std::string uri_ = ""; + private: static int blockId_; // The actual position of the first row of data in the shareblock diff --git a/data_share/test/native/unittest/mediadatashare_test/src/mediadatashare_unit_test.cpp b/data_share/test/native/unittest/mediadatashare_test/src/mediadatashare_unit_test.cpp index e3577846..b18ba63b 100644 --- a/data_share/test/native/unittest/mediadatashare_test/src/mediadatashare_unit_test.cpp +++ b/data_share/test/native/unittest/mediadatashare_test/src/mediadatashare_unit_test.cpp @@ -540,15 +540,15 @@ HWTEST_F(MediaDataShareUnitTest, MediaDataShare_Predicates_Test_019, TestSize.Le LOG_INFO("MediaDataShare_Predicates_Test_019, End"); } -// HWTEST_F(MediaDataShareUnitTest, MediaDataShare_Predicates_Test_020, TestSize.Level0) -// { -// LOG_INFO("MediaDataShare_Predicates_Test_020::Start"); -// DataShare::DataSharePredicates predicates; -// predicates.SetSettingMode(DataShare::SettingMode::PREDICATES_METHOD); -// DataShare::SettingMode setting = predicates.GetSettingMode(); -// EXPECT_EQ(setting, DataShare::SettingMode::PREDICATES_METHOD); -// LOG_INFO("MediaDataShare_Predicates_Test_020, End"); -// } +HWTEST_F(MediaDataShareUnitTest, MediaDataShare_Predicates_Test_020, TestSize.Level0) +{ + LOG_INFO("MediaDataShare_Predicates_Test_020::Start"); + DataShare::DataSharePredicates predicates; + predicates.SetSettingMode(DataShare::SettingMode::PREDICATES_METHOD); + int16_t setting = predicates.GetSettingMode(); + EXPECT_EQ(setting, DataShare::SettingMode::PREDICATES_METHOD); + LOG_INFO("MediaDataShare_Predicates_Test_020, End"); +} HWTEST_F(MediaDataShareUnitTest, MediaDataShare_Predicates_Test_021, TestSize.Level0) { @@ -886,17 +886,17 @@ HWTEST_F(MediaDataShareUnitTest, MediaDataShare_ResultSet_Test_003, TestSize.Lev Uri uri(MEDIALIBRARY_DATA_URI); auto resultSet = helper->Query(uri, predicates, columns); AppDataFwk::SharedBlock *block = nullptr; - if (resultSet != nullptr) { - bool hasBlock = resultSet->HasBlock(); - EXPECT_EQ(hasBlock, true); - block = resultSet->GetBlock(); - EXPECT_NE(block, nullptr); - - resultSet->SetBlock(block); - EXPECT_EQ(block, resultSet->GetBlock()); - resultSet->FillBlock(0, block); - EXPECT_EQ(block, resultSet->GetBlock()); - } + ASSERT_TRUE(resultSet != nullptr); + + bool hasBlock = resultSet->HasBlock(); + EXPECT_EQ(hasBlock, true); + block = resultSet->GetBlock(); + EXPECT_NE(block, nullptr); + + resultSet->SetBlock(block); + EXPECT_EQ(block, resultSet->GetBlock()); + resultSet->FillBlock(0, block); + EXPECT_EQ(block, resultSet->GetBlock()); LOG_INFO("MediaDataShare_ResultSet_Test_003, End"); } @@ -948,6 +948,41 @@ HWTEST_F(MediaDataShareUnitTest, MediaDataShare_ResultSet_Test_005, TestSize.Lev LOG_INFO("MediaDataShare_ResultSet_Test_005, End"); } +HWTEST_F(MediaDataShareUnitTest, MediaDataShare_ResultSet_Test_006, TestSize.Level0) +{ + LOG_INFO("MediaDataShare_ResultSet_Test_006::Start"); + std::shared_ptr helper = g_mediaDataShareHelper; + ASSERT_TRUE(helper != nullptr); + Uri uri(MEDIALIBRARY_DATA_URI); + DataShare::DataShareValuesBucket valuesBucket; + int value = 1112; + valuesBucket.Put(MEDIA_DATA_DB_PARENT_ID, value); + int retVal = helper->Insert(uri, valuesBucket); + EXPECT_EQ((retVal > 0), true); + + DataShare::DataSharePredicates predicates; + predicates.EqualTo(MEDIA_DATA_DB_PARENT_ID, value); + vector columns; + auto resultSet = helper->Query(uri, predicates, columns); + int columnIndex = 0; + int result = 0; + ASSERT_TRUE(resultSet != nullptr); + resultSet->GoToFirstRow(); + resultSet->GetColumnIndex(MEDIA_DATA_DB_PARENT_ID, columnIndex); + DataShare::DataType dt; + resultSet->GetDataType(0, dt); + EXPECT_EQ(dt, DataShare::DataType::TYPE_INTEGER); + resultSet->GetInt(columnIndex, result); + EXPECT_EQ(result, value); + + DataShare::DataSharePredicates deletePredicates; + std::string selections = MEDIA_DATA_DB_PARENT_ID + " = 1112"; + deletePredicates.SetWhereClause(selections); + retVal = helper->Delete(uri, deletePredicates); + EXPECT_EQ((retVal >= 0), true); + LOG_INFO("MediaDataShare_ResultSet_Test_006, End"); +} + HWTEST_F(MediaDataShareUnitTest, Creator_ContextNull_Test_001, TestSize.Level0) { LOG_INFO("Creator_ContextNull_Test_001::Start"); diff --git a/datamgr_service/BUILD.gn b/datamgr_service/BUILD.gn index e0313ca8..2a6d0268 100644 --- a/datamgr_service/BUILD.gn +++ b/datamgr_service/BUILD.gn @@ -30,13 +30,7 @@ group("fuzztest") { deps = [] deps += [ "test/fuzztest/autolaunch_fuzzer:fuzztest", - "test/fuzztest/blob_fuzzer:fuzztest", - "test/fuzztest/devicekvstore_fuzzer:fuzztest", - "test/fuzztest/distributedkvdatamanager_fuzzer:fuzztest", "test/fuzztest/kvstoredisksize_fuzzer:fuzztest", - "test/fuzztest/singlekvstore_fuzzer:fuzztest", - "test/fuzztest/taskscheduler_fuzzer:fuzztest", - "test/fuzztest/typesutil_fuzzer:fuzztest", ] } ############################################################################### diff --git a/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp b/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp index 553f9582..ddca36ad 100644 --- a/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp +++ b/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp @@ -32,7 +32,7 @@ using namespace OHOS::EventFwk; using namespace OHOS::AAFwk; using namespace OHOS::DistributedData; using namespace Security::AccessToken; -// AccountDelegate::BaseInstance AccountDelegate::getInstance_ = AccountDelegateNormalImpl::GetBaseInstance; +//AccountDelegate::BaseInstance AccountDelegate::getInstance_ = AccountDelegateNormalImpl::GetBaseInstance; AccountDelegate *AccountDelegateNormalImpl::GetBaseInstance() { static AccountDelegateNormalImpl accountDelegate; diff --git a/datamgr_service/services/distributeddataservice/app/BUILD.gn b/datamgr_service/services/distributeddataservice/app/BUILD.gn index d4f0e710..3e962580 100644 --- a/datamgr_service/services/distributeddataservice/app/BUILD.gn +++ b/datamgr_service/services/distributeddataservice/app/BUILD.gn @@ -48,10 +48,6 @@ config("module_private_config") { "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/matrix/include", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/app/src/session_manager", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework/include", - "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/kvdb/include", - "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/rdb/include", - "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/object/include", - "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/rdb/src", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/backup/include", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/kvdb", "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/mod_securitylabel", diff --git a/datamgr_service/services/distributeddataservice/service/BUILD.gn b/datamgr_service/services/distributeddataservice/service/BUILD.gn index b1b15a8a..3b1d66dc 100644 --- a/datamgr_service/services/distributeddataservice/service/BUILD.gn +++ b/datamgr_service/services/distributeddataservice/service/BUILD.gn @@ -41,7 +41,6 @@ config("module_public_config") { "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include", "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/kvdb/include", "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/object/include", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include/", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include/relational", @@ -93,6 +92,7 @@ ohos_shared_library("distributeddatasvc") { "object/object_service_impl.cpp", "object/object_service_stub.cpp", "permission/src/permit_delegate.cpp", + "rdb/rdb_notifier_proxy.cpp", "rdb/rdb_result_set_impl.cpp", "rdb/rdb_result_set_stub.cpp", "rdb/rdb_service_impl.cpp", diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp new file mode 100644 index 00000000..8818a092 --- /dev/null +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2022 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. + */ +#define LOG_TAG "RdbNotifierProxy" +#include "rdb_notifier_proxy.h" +#include "itypes_util.h" +#include "log_print.h" +namespace OHOS::DistributedRdb { +RdbNotifierProxy::RdbNotifierProxy(const sptr &object) : IRemoteProxy(object) +{ + ZLOGI("construct"); +} + +RdbNotifierProxy::~RdbNotifierProxy() noexcept +{ + ZLOGI("destroy"); +} + +int32_t RdbNotifierProxy::OnComplete(uint32_t seqNum, const SyncResult &result) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + ZLOGE("write descriptor failed"); + return RDB_ERROR; + } + if (!ITypesUtil::Marshal(data, seqNum, result)) { + return RDB_ERROR; + } + + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (Remote()->SendRequest(RDB_NOTIFIER_CMD_SYNC_COMPLETE, data, reply, option) != 0) { + ZLOGE("send request failed"); + return RDB_ERROR; + } + return RDB_OK; +} + +int RdbNotifierProxy::OnChange(const std::string &storeName, const std::vector &devices) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + ZLOGE("write descriptor failed"); + return RDB_ERROR; + } + if (!ITypesUtil::Marshal(data, storeName, devices)) { + ZLOGE("write store name or devices failed"); + return RDB_ERROR; + } + + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (Remote()->SendRequest(RDB_NOTIFIER_CMD_DATA_CHANGE, data, reply, option) != 0) { + ZLOGE("send request failed"); + return RDB_ERROR; + } + return RDB_OK; +} +} // namespace OHOS::DistributedRdb diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h b/datamgr_service/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h new file mode 100644 index 00000000..375cc745 --- /dev/null +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_KV_STORE_FRAMEWORKS_INNERKITSIMPL_RDB_RDB_NOTIFIER_PROXY_H +#define OHOS_DISTRIBUTED_DATA_KV_STORE_FRAMEWORKS_INNERKITSIMPL_RDB_RDB_NOTIFIER_PROXY_H +#include +#include +#include "rdb_notifier.h" +namespace OHOS::DistributedRdb { +class RdbNotifierProxyBroker : public IRdbNotifier, public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedRdb.IRdbNotifier"); +}; + +class RdbNotifierProxy : public IRemoteProxy { +public: + explicit RdbNotifierProxy(const sptr& object); + virtual ~RdbNotifierProxy() noexcept; + + int32_t OnComplete(uint32_t seqNum, const SyncResult& result) override; + + int32_t OnChange(const std::string& storeName, const std::vector& devices) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace OHOS::DistributedRdb +#endif // OHOS_DISTRIBUTED_DATA_KV_STORE_FRAMEWORKS_INNERKITSIMPL_RDB_RDB_NOTIFIER_PROXY_H 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 8efce4fc..85bc6d7c 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -24,6 +24,7 @@ #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" #include "permission/permission_validator.h" +#include "rdb_notifier_proxy.h" #include "types_export.h" #include "utils/anonymous.h" using OHOS::DistributedKv::AccountDelegate; diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h index fab58d9f..35f93b7c 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -21,14 +21,14 @@ #include #include #include -#include "metadata/store_meta_data.h" +#include "concurrent_map.h" #include "metadata/secret_key_meta_data.h" +#include "metadata/store_meta_data.h" +#include "rdb_notifier_proxy.h" #include "rdb_syncer.h" -#include "concurrent_map.h" #include "store_observer.h" #include "timer.h" #include "visibility.h" - namespace OHOS::DistributedRdb { class API_EXPORT RdbServiceImpl : public RdbServiceStub { public: diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.h b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.h index 3f812325..901a7d6e 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.h +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.h @@ -16,14 +16,15 @@ #ifndef DISTRIBUTED_RDB_SERVICE_STUB_H #define DISTRIBUTED_RDB_SERVICE_STUB_H -#include -#include "irdb_service.h" +#include "iremote_stub.h" +#include "rdb_service.h" #include "rdb_notifier.h" #include "feature/feature_system.h" namespace OHOS::DistributedRdb { class RdbServiceStub : public RdbService, public DistributedData::FeatureSystem::Feature { public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedRdb.IRdbService"); int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) override; int32_t Sync(const RdbSyncerParam& param, const SyncOption& option, diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.h b/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.h index 53268ef8..e049a864 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.h +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_syncer.h @@ -20,12 +20,12 @@ #include #include "metadata/store_meta_data.h" -#include "rdb_notifier.h" #include "rdb_store_observer_impl.h" #include "rdb_types.h" #include "relational_store_delegate.h" #include "relational_store_manager.h" #include "metadata/secret_key_meta_data.h" +#include "iremote_object.h" namespace OHOS::DistributedRdb { class RdbSyncer { public: diff --git a/datamgr_service/test/fuzztest/devicekvstore_fuzzer/BUILD.gn b/datamgr_service/test/fuzztest/devicekvstore_fuzzer/BUILD.gn deleted file mode 100644 index 577a1e34..00000000 --- a/datamgr_service/test/fuzztest/devicekvstore_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2022 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") - -##############################fuzztest########################################## -ohos_fuzztest("DeviceKvStoreFuzzTest") { - module_out_path = "datamgr_service/distributeddatafwk" - - include_dirs = [ - "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src", - "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include", - "//foundation/distributeddatamgr/kv_store/frameworks/common", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include", - "//commonlibrary/c_utils/base/include", - ] - - fuzz_config_file = "//foundation/distributeddatamgr/datamgr_service/test/fuzztest/devicekvstore_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "devicekvstore_fuzzer.cpp" ] - - defines = [ - "SQLITE_ENABLE_SNAPSHOT", - "_LARGEFILE64_SOURCE", - "_FILE_OFFSET_BITS=64", - "SQLITE_HAS_CODEC", - "SQLITE_ENABLE_JSON1", - "USING_HILOG_LOGGER", - "USE_SQLITE_SYMBOLS", - "USING_DB_JSON_EXTRACT_AUTOMATICALLY", - "LOW_LEVEL_MEM_DEV", - "JSONCPP_USE_BUILDER", - "OMIT_FLATBUFFER", - "RELATIONAL_STORE", - "SQLITE_DISTRIBUTE_RELATIONAL", - ] - - deps = [ - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", - ] - - external_deps = [ "c_utils:utils" ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [] - deps += [ - # deps file - ":DeviceKvStoreFuzzTest", - ] -} -############################################################################### diff --git a/datamgr_service/test/fuzztest/distributedkvdatamanager_fuzzer/BUILD.gn b/datamgr_service/test/fuzztest/distributedkvdatamanager_fuzzer/BUILD.gn deleted file mode 100644 index 2ff80cab..00000000 --- a/datamgr_service/test/fuzztest/distributedkvdatamanager_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2022 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") - -##############################fuzztest########################################## -ohos_fuzztest("DistributedKvDataManagerFuzzTest") { - module_out_path = "datamgr_service/distributeddatafwk" - - include_dirs = [ - "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src", - "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include", - "//foundation/distributeddatamgr/kv_store/frameworks/common", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include", - "//commonlibrary/c_utils/base/include", - ] - - fuzz_config_file = "//foundation/distributeddatamgr/datamgr_service/test/fuzztest/distributedkvdatamanager_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "distributedkvdatamanager_fuzzer.cpp" ] - - defines = [ - "SQLITE_ENABLE_SNAPSHOT", - "_LARGEFILE64_SOURCE", - "_FILE_OFFSET_BITS=64", - "SQLITE_HAS_CODEC", - "SQLITE_ENABLE_JSON1", - "USING_HILOG_LOGGER", - "USE_SQLITE_SYMBOLS", - "USING_DB_JSON_EXTRACT_AUTOMATICALLY", - "LOW_LEVEL_MEM_DEV", - "JSONCPP_USE_BUILDER", - "OMIT_FLATBUFFER", - "RELATIONAL_STORE", - "SQLITE_DISTRIBUTE_RELATIONAL", - ] - - deps = [ - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", - ] - - external_deps = [ "c_utils:utils" ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [] - deps += [ - # deps file - ":DistributedKvDataManagerFuzzTest", - ] -} -############################################################################### diff --git a/datamgr_service/test/fuzztest/kvstorescheduler_fuzzer/kvstorescheduler_fuzzer.cpp b/datamgr_service/test/fuzztest/kvstorescheduler_fuzzer/kvstorescheduler_fuzzer.cpp deleted file mode 100644 index 0ffccabc..00000000 --- a/datamgr_service/test/fuzztest/kvstorescheduler_fuzzer/kvstorescheduler_fuzzer.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2022 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 "kvstorescheduler_fuzzer.h" - -#include -#include - -#include "kv_scheduler.h" - -using namespace OHOS::DistributedKv; -namespace OHOS { -static constexpr int MAX_DELAY_TIME = 5; -static constexpr int MAX_INTERVAL_TIME = 3; -void AtFuzz(size_t time) -{ - KvScheduler kvScheduler; - std::chrono::system_clock::time_point tp = std::chrono::system_clock::now() + - std::chrono::duration(time % MAX_DELAY_TIME); - auto task = kvScheduler.At(tp, []() { }); - std::this_thread::sleep_for(std::chrono::seconds(MAX_INTERVAL_TIME)); - kvScheduler.Remove(task); -} - -void EveryFUZZ(size_t time) -{ - KvScheduler kvScheduler; - std::chrono::duration delay(time % MAX_DELAY_TIME); - std::chrono::duration interval(time % MAX_INTERVAL_TIME); - kvScheduler.Every(delay, interval, []() { }); - std::this_thread::sleep_for(std::chrono::seconds(MAX_INTERVAL_TIME)); - kvScheduler.Every(0, delay, interval, []() { }); - kvScheduler.Every(1, delay, interval, []() { }); - std::this_thread::sleep_for(std::chrono::seconds(MAX_INTERVAL_TIME)); - kvScheduler.Every(interval, []() { }); - kvScheduler.Clean(); -} - -void ResetFuzz(size_t time) -{ - KvScheduler kvScheduler; - std::chrono::duration interval(time % MAX_INTERVAL_TIME); - std::chrono::system_clock::time_point tp1 = std::chrono::system_clock::now() + - std::chrono::duration(MAX_DELAY_TIME / 2); - auto schedulerTask = kvScheduler.At(tp1, []() {}); - std::chrono::system_clock::time_point tp2 = std::chrono::system_clock::now() + - std::chrono::duration(time % MAX_DELAY_TIME); - kvScheduler.Reset(schedulerTask, tp2, interval); -} -} // namespace OHOS -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - /* Run your code on data */ - OHOS::AtFuzz(size); - OHOS::EveryFUZZ(size); - OHOS::ResetFuzz(size); - return 0; -} diff --git a/datamgr_service/test/fuzztest/singlekvstore_fuzzer/BUILD.gn b/datamgr_service/test/fuzztest/singlekvstore_fuzzer/BUILD.gn deleted file mode 100644 index 76b4c5da..00000000 --- a/datamgr_service/test/fuzztest/singlekvstore_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2022 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SingleKvStoreFuzzTest") { - module_out_path = "datamgr_service/distributeddatafwk" - - include_dirs = [ - "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src", - "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include", - "//foundation/distributeddatamgr/kv_store/frameworks/common", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include", - "//commonlibrary/c_utils/base/include", - ] - - fuzz_config_file = "//foundation/distributeddatamgr/datamgr_service/test/fuzztest/singlekvstore_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "singlekvstore_fuzzer.cpp" ] - - defines = [ - "SQLITE_ENABLE_SNAPSHOT", - "_LARGEFILE64_SOURCE", - "_FILE_OFFSET_BITS=64", - "SQLITE_HAS_CODEC", - "SQLITE_ENABLE_JSON1", - "USING_HILOG_LOGGER", - "USE_SQLITE_SYMBOLS", - "USING_DB_JSON_EXTRACT_AUTOMATICALLY", - "LOW_LEVEL_MEM_DEV", - "JSONCPP_USE_BUILDER", - "OMIT_FLATBUFFER", - "RELATIONAL_STORE", - "SQLITE_DISTRIBUTE_RELATIONAL", - ] - - deps = [ - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", - ] - - external_deps = [ "c_utils:utils" ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [] - deps += [ - # deps file - ":SingleKvStoreFuzzTest", - ] -} -############################################################################### diff --git a/datamgr_service/test/fuzztest/typesutil_fuzzer/project.xml b/datamgr_service/test/fuzztest/typesutil_fuzzer/project.xml deleted file mode 100644 index be92381e..00000000 --- a/datamgr_service/test/fuzztest/typesutil_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 30 - - 4096 - - diff --git a/kv_store/BUILD.gn b/kv_store/BUILD.gn index ffdc42dd..613ec6ea 100644 --- a/kv_store/BUILD.gn +++ b/kv_store/BUILD.gn @@ -25,6 +25,7 @@ group("build_native_test") { deps = [ "frameworks/innerkitsimpl/distributeddatafwk/test:unittest", "frameworks/libs/distributeddb/test:unittest", + "frameworks/libs/distributeddb/test/moduletest:moduletest", ] } @@ -34,6 +35,23 @@ group("unittest") { deps = [] deps += [ "frameworks/innerkitsimpl/kvdb/test:unittest", - "test/unittest:unittest", + "test/unittest/distributedKVStore:unittest", + "test/unittest/distributeddata:unittest", ] } + +############################################################################### + +group("fuzztest") { + testonly = true + deps = [] + deps += [ + "test/fuzztest/blob_fuzzer:fuzztest", + "test/fuzztest/devicekvstore_fuzzer:fuzztest", + "test/fuzztest/distributedkvdatamanager_fuzzer:fuzztest", + "test/fuzztest/singlekvstore_fuzzer:fuzztest", + "test/fuzztest/taskscheduler_fuzzer:fuzztest", + "test/fuzztest/typesutil_fuzzer:fuzztest", + ] +} +############################################################################### diff --git a/kv_store/bundle.json b/kv_store/bundle.json index 64e33319..80acb146 100644 --- a/kv_store/bundle.json +++ b/kv_store/bundle.json @@ -119,7 +119,9 @@ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/test:distributeddatamgr_fuzztest", "//foundation/distributeddatamgr/kv_store:distributedtest", "//foundation/distributeddatamgr/kv_store:build_native_test", - "//foundation/distributeddatamgr/kv_store/test/unittest:unittest", + "//foundation/distributeddatamgr/kv_store:fuzztest", + "//foundation/distributeddatamgr/kv_store/test/unittest/distributeddata:unittest", + "//foundation/distributeddatamgr/kv_store/test/unittest/distributedKVStore:unittest", "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/kvdb/test:unittest" ] } diff --git a/kv_store/frameworks/CMakeLists.txt b/kv_store/frameworks/CMakeLists.txt index 004e2d70..c58a251a 100644 --- a/kv_store/frameworks/CMakeLists.txt +++ b/kv_store/frameworks/CMakeLists.txt @@ -11,17 +11,14 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") set(MOCK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../mock) add_definitions(-DNAPI_EXPERIMENTAL) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/distributeddatafwk/src kvdbSrc) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/rdb/src kvdbSrc) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/kvdb/src kvdbSrc) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/object/src kvdbSrc) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/jskitsimpl/distributedkvstore/src kvdbSrc) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/jskitsimpl/distributedkvstore/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/distributeddatafwk/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/distributeddatafwk/src) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/rdb/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/kvdb/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/object/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/rdb/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../interfaces/innerkits/distributeddata/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../interfaces/innerkits) diff --git a/datamgr_service/services/distributeddataservice/adapter/include/dfx/dds_trace.h b/kv_store/frameworks/common/dds_trace.h similarity index 100% rename from datamgr_service/services/distributeddataservice/adapter/include/dfx/dds_trace.h rename to kv_store/frameworks/common/dds_trace.h diff --git a/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_client_death_observer.h b/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_client_death_observer.h index 2d391111..ca6cbbc7 100644 --- a/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_client_death_observer.h +++ b/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_client_death_observer.h @@ -19,6 +19,7 @@ #include "iremote_broker.h" #include "iremote_proxy.h" #include "iremote_stub.h" +#include "visibility.h" namespace OHOS { namespace DistributedKv { @@ -28,10 +29,9 @@ public: }; class KvStoreClientDeathObserverStub : public IRemoteStub { -public: }; -class KvStoreClientDeathObserverProxy : public IRemoteProxy { +class API_EXPORT KvStoreClientDeathObserverProxy : public IRemoteProxy { public: explicit KvStoreClientDeathObserverProxy(const sptr &impl); ~KvStoreClientDeathObserverProxy() = default; diff --git a/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_data_service.h b/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_data_service.h index e6f280d6..b67e248d 100644 --- a/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_data_service.h +++ b/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_data_service.h @@ -54,7 +54,7 @@ protected: class KvStoreDataServiceStub : public IRemoteStub { public: - int OnRemoteRequest(uint32_t code, MessageParcel &data, + int API_EXPORT OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; private: @@ -78,7 +78,7 @@ private: }; }; -class KvStoreDataServiceProxy : public IRemoteProxy { +class API_EXPORT KvStoreDataServiceProxy : public IRemoteProxy { public: explicit KvStoreDataServiceProxy(const sptr &impl); ~KvStoreDataServiceProxy() = default; diff --git a/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_observer.h b/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_observer.h index 2dd19b74..4f18454a 100644 --- a/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_observer.h +++ b/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_observer.h @@ -39,7 +39,7 @@ public: MessageParcel &reply, MessageOption &option) override; }; -class KvStoreObserverProxy : public IRemoteProxy { +class API_EXPORT KvStoreObserverProxy : public IRemoteProxy { public: explicit KvStoreObserverProxy(const sptr &impl); ~KvStoreObserverProxy() = default; diff --git a/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_sync_callback.h b/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_sync_callback.h index 83265028..94742c1e 100644 --- a/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_sync_callback.h +++ b/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include/ikvstore_sync_callback.h @@ -21,6 +21,7 @@ #include "iremote_proxy.h" #include "iremote_stub.h" #include "types.h" +#include "visibility.h" namespace OHOS { namespace DistributedKv { @@ -36,7 +37,7 @@ public: MessageParcel &reply, MessageOption &option) override; }; -class KvStoreSyncCallbackProxy : public IRemoteProxy { +class API_EXPORT KvStoreSyncCallbackProxy : public IRemoteProxy { public: explicit KvStoreSyncCallbackProxy(const sptr &impl); ~KvStoreSyncCallbackProxy() = default; diff --git a/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src/kvstore_client_death_observer.h b/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src/kvstore_client_death_observer.h index 88f1db22..b027cfea 100644 --- a/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src/kvstore_client_death_observer.h +++ b/kv_store/frameworks/innerkitsimpl/distributeddatafwk/src/kvstore_client_death_observer.h @@ -20,7 +20,7 @@ namespace OHOS { namespace DistributedKv { -class KvStoreClientDeathObserver : public KvStoreClientDeathObserverStub { +class API_EXPORT KvStoreClientDeathObserver : public KvStoreClientDeathObserverStub { public: KvStoreClientDeathObserver(); diff --git a/kv_store/frameworks/innerkitsimpl/distributeddatafwk/test/BUILD.gn b/kv_store/frameworks/innerkitsimpl/distributeddatafwk/test/BUILD.gn index 58252a44..42c1aace 100644 --- a/kv_store/frameworks/innerkitsimpl/distributeddatafwk/test/BUILD.gn +++ b/kv_store/frameworks/innerkitsimpl/distributeddatafwk/test/BUILD.gn @@ -20,17 +20,86 @@ config("module_private_config") { include_dirs = [ "../include/", + "../src/", "../../kvdb/include/", - "../../../../interfaces/innerkits/distributeddata/", + "../../kvdb/src/", + "../../../common/", + "../../../../interfaces/innerkits/distributeddata/include/", # for ipc_core interfaces. "//commonlibrary/c_utils/base/include", "//foundation/distributeddatamgr/data_share/interfaces/inner_api/common/include", "//foundation/distributeddatamgr/data_share/interfaces/inner_api/provider/include", "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include", + "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/mod_securitylabel", + "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp/include", + "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include", ] } +############################################################################### +ohos_source_set("distributeddatafwk_src_file") { + testonly = true + + old_sources = [ + "../src/blob.cpp", + "../src/change_notification.cpp", + "../src/data_query.cpp", + "../src/device_status_change_listener_client.cpp", + "../src/distributed_kv_data_manager.cpp", + "../src/ikvstore_client_death_observer.cpp", + "../src/ikvstore_data_service.cpp", + "../src/ikvstore_observer.cpp", + "../src/ikvstore_sync_callback.cpp", + "../src/kv_utils.cpp", + "../src/kvstore_client_death_observer.cpp", + "../src/kvstore_datashare_bridge.cpp", + "../src/kvstore_observer_client.cpp", + "../src/kvstore_service_death_notifier.cpp", + "../src/kvstore_sync_callback_client.cpp", + "../src/sync_observer.cpp", + ] + + kvdb_sources = [ + "../../kvdb/src/auto_sync_timer.cpp", + "../../kvdb/src/backup_manager.cpp", + "../../kvdb/src/convertor.cpp", + "../../kvdb/src/dev_manager.cpp", + "../../kvdb/src/device_convertor.cpp", + "../../kvdb/src/kv_types_util.cpp", + "../../kvdb/src/kvdb_service_client.cpp", + "../../kvdb/src/observer_bridge.cpp", + "../../kvdb/src/security_manager.cpp", + "../../kvdb/src/single_store_impl.cpp", + "../../kvdb/src/store_factory.cpp", + "../../kvdb/src/store_manager.cpp", + "../../kvdb/src/store_result_set.cpp", + "../../kvdb/src/store_util.cpp", + "../../kvdb/src/system_api.cpp", + "../../kvdb/src/task_executor.cpp", + ] + + sources = old_sources + kvdb_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk", + ] + external_deps = [ + "c_utils:utils", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "hitrace_native:libhitracechain", + "hiviewdfx_hilog_native:libhilog", + "huks:libhukssdk", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + part_name = "kv_store" +} + ohos_unittest("DistributedKvDataManagerTest") { module_out_path = module_output_path @@ -46,8 +115,8 @@ ohos_unittest("DistributedKvDataManagerTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -67,8 +136,8 @@ ohos_unittest("DistributedKvDataManagerEncryptTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -88,8 +157,8 @@ ohos_unittest("LocalSubscribeStoreTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -109,8 +178,8 @@ ohos_unittest("LocalSubscribeDeviceStoreTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -130,8 +199,8 @@ ohos_unittest("SingleKvStoreClientQueryTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -151,8 +220,8 @@ ohos_unittest("SingleKvStoreClientTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -172,8 +241,8 @@ ohos_unittest("DeviceKvStoreTest") { ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] } @@ -186,8 +255,8 @@ ohos_unittest("BlobTest") { configs = [ ":module_private_config" ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] @@ -205,8 +274,8 @@ ohos_unittest("TypesUtilTest") { configs = [ ":module_private_config" ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] @@ -224,8 +293,8 @@ ohos_unittest("KvUtilTest") { configs = [ ":module_private_config" ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] @@ -243,8 +312,8 @@ ohos_unittest("KvstoreDatashareBridgeTest") { configs = [ ":module_private_config" ] deps = [ + ":distributeddatafwk_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] diff --git a/kv_store/frameworks/innerkitsimpl/kvdb/include/kv_types_util.h b/kv_store/frameworks/innerkitsimpl/kvdb/include/kv_types_util.h index dbe7cf8d..b81432e4 100644 --- a/kv_store/frameworks/innerkitsimpl/kvdb/include/kv_types_util.h +++ b/kv_store/frameworks/innerkitsimpl/kvdb/include/kv_types_util.h @@ -31,44 +31,44 @@ using Options = DistributedKv::Options; using Options = DistributedKv::Options; using SyncPolicy = DistributedKv::SyncPolicy; template<> -bool Marshalling(const Blob &input, MessageParcel &data); +API_EXPORT bool Marshalling(const Blob &input, MessageParcel &data); template<> -bool Unmarshalling(Blob &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(Blob &output, MessageParcel &data); template<> -bool Marshalling(const AppId &input, MessageParcel &data); +API_EXPORT bool Marshalling(const AppId &input, MessageParcel &data); template<> -bool Unmarshalling(AppId &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(AppId &output, MessageParcel &data); template<> -bool Marshalling(const StoreId &input, MessageParcel &data); +API_EXPORT bool Marshalling(const StoreId &input, MessageParcel &data); template<> -bool Unmarshalling(StoreId &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(StoreId &output, MessageParcel &data); template<> -bool Marshalling(const Entry &input, MessageParcel &data); +API_EXPORT bool Marshalling(const Entry &input, MessageParcel &data); template<> -bool Unmarshalling(Entry &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(Entry &output, MessageParcel &data); template<> -bool Marshalling(const DeviceInfo &input, MessageParcel &data); +API_EXPORT bool Marshalling(const DeviceInfo &input, MessageParcel &data); template<> -bool Unmarshalling(DeviceInfo &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(DeviceInfo &output, MessageParcel &data); template<> -bool Marshalling(const ChangeNotification ¬ification, MessageParcel &parcel); +API_EXPORT bool Marshalling(const ChangeNotification ¬ification, MessageParcel &parcel); template<> -bool Unmarshalling(ChangeNotification &output, MessageParcel &parcel); +API_EXPORT bool Unmarshalling(ChangeNotification &output, MessageParcel &parcel); template<> -bool Marshalling(const Options &input, MessageParcel &data); +API_EXPORT bool Marshalling(const Options &input, MessageParcel &data); template<> -bool Unmarshalling(Options &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(Options &output, MessageParcel &data); template<> -bool Marshalling(const SyncPolicy &input, MessageParcel &data); +API_EXPORT bool Marshalling(const SyncPolicy &input, MessageParcel &data); template<> -bool Unmarshalling(SyncPolicy &output, MessageParcel &data); +API_EXPORT bool Unmarshalling(SyncPolicy &output, MessageParcel &data); int64_t GetTotalSize(const std::vector &entries); int64_t GetTotalSize(const std::vector &entries); diff --git a/kv_store/frameworks/innerkitsimpl/kvdb/test/BUILD.gn b/kv_store/frameworks/innerkitsimpl/kvdb/test/BUILD.gn index 1fcd673c..e94bd9a1 100644 --- a/kv_store/frameworks/innerkitsimpl/kvdb/test/BUILD.gn +++ b/kv_store/frameworks/innerkitsimpl/kvdb/test/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import("//build/test.gni") +import("//foundation/distributeddatamgr/data_share/datashare.gni") module_output_path = "kv_store/distributeddatafwk" @@ -20,6 +21,9 @@ config("module_private_config") { include_dirs = [ "//commonlibrary/c_utils/base/include", + "${datashare_innerapi_path}/common/include", + "${datashare_innerapi_path}/provider/include", + "//foundation/distributeddatamgr/kv_store/frameworks/common", "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/kvdb/include", "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/kvdb/src", "//foundation/distributeddatamgr/kv_store/frameworks/innerkitsimpl/distributeddatafwk/include", @@ -28,11 +32,77 @@ config("module_private_config") { "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/app_distributeddata/include", "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/app/include", + "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/mod_securitylabel", + "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp/include", + "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include", "//test/testfwk/developer_test/aw/distributed", ] lib_dirs = [ "//foundation/appexecfwk/libs" ] } +############################################################################### +ohos_source_set("kvdb_src_file") { + testonly = true + + old_sources = [ + "../../distributeddatafwk/src/blob.cpp", + "../../distributeddatafwk/src/change_notification.cpp", + "../../distributeddatafwk/src/data_query.cpp", + "../../distributeddatafwk/src/device_status_change_listener_client.cpp", + "../../distributeddatafwk/src/distributed_kv_data_manager.cpp", + "../../distributeddatafwk/src/ikvstore_client_death_observer.cpp", + "../../distributeddatafwk/src/ikvstore_data_service.cpp", + "../../distributeddatafwk/src/ikvstore_observer.cpp", + "../../distributeddatafwk/src/ikvstore_sync_callback.cpp", + "../../distributeddatafwk/src/kv_utils.cpp", + "../../distributeddatafwk/src/kvstore_client_death_observer.cpp", + "../../distributeddatafwk/src/kvstore_datashare_bridge.cpp", + "../../distributeddatafwk/src/kvstore_observer_client.cpp", + "../../distributeddatafwk/src/kvstore_service_death_notifier.cpp", + "../../distributeddatafwk/src/kvstore_sync_callback_client.cpp", + "../../distributeddatafwk/src/sync_observer.cpp", + ] + + kvdb_sources = [ + "../src/auto_sync_timer.cpp", + "../src/backup_manager.cpp", + "../src/convertor.cpp", + "../src/dev_manager.cpp", + "../src/device_convertor.cpp", + "../src/kv_types_util.cpp", + "../src/kvdb_service_client.cpp", + "../src/observer_bridge.cpp", + "../src/security_manager.cpp", + "../src/single_store_impl.cpp", + "../src/store_factory.cpp", + "../src/store_manager.cpp", + "../src/store_result_set.cpp", + "../src/store_util.cpp", + "../src/system_api.cpp", + "../src/task_executor.cpp", + ] + + sources = old_sources + kvdb_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk", + ] + external_deps = [ + "c_utils:utils", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "hitrace_native:libhitracechain", + "hiviewdfx_hilog_native:libhilog", + "huks:libhukssdk", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + part_name = "kv_store" +} + ohos_unittest("SingleStoreImplTest") { module_out_path = module_output_path @@ -49,9 +119,9 @@ ohos_unittest("SingleStoreImplTest") { ] deps = [ + ":kvdb_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/:distributeddb", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } @@ -71,9 +141,9 @@ ohos_unittest("StoreUtilTest") { ] deps = [ + ":kvdb_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/:distributeddb", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } @@ -93,9 +163,9 @@ ohos_unittest("BackupManagerTest") { ] deps = [ + ":kvdb_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/:distributeddb", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } @@ -116,9 +186,9 @@ ohos_unittest("AutoSyncTimerTest") { ] deps = [ + ":kvdb_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/:distributeddb", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } @@ -139,9 +209,9 @@ ohos_unittest("DevManagerTest") { ] deps = [ + ":kvdb_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/:distributeddb", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } @@ -162,9 +232,9 @@ ohos_unittest("SingleStoreImplGetTopTest") { ] deps = [ + ":kvdb_src_file", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/:distributeddb", - "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/:distributeddata_inner", "//third_party/googletest:gtest", ] } diff --git a/kv_store/frameworks/innerkitsimpl/kvdb/test/auto_sync_timer_test.cpp b/kv_store/frameworks/innerkitsimpl/kvdb/test/auto_sync_timer_test.cpp index 75468660..1e8d53bb 100644 --- a/kv_store/frameworks/innerkitsimpl/kvdb/test/auto_sync_timer_test.cpp +++ b/kv_store/frameworks/innerkitsimpl/kvdb/test/auto_sync_timer_test.cpp @@ -129,7 +129,7 @@ void AutoSyncTimerTest::TearDown(void) /** * @tc.name: SingleWrite -* @tc.desc: get the store id of the kv store +* @tc.desc: single write * @tc.type: FUNC * @tc.require: I4XVQQ * @tc.author: Yang Qing @@ -151,13 +151,13 @@ HWTEST_F(AutoSyncTimerTest, SingleWrite, TestSize.Level0) } /** -* @tc.name: MultiWrite -* @tc.desc: get the store id of the kv store +* @tc.name: MultiWriteBelowDelayTime +* @tc.desc: write every 40 milliseconds * @tc.type: FUNC * @tc.require: I4XVQQ * @tc.author: Yang Qing */ -HWTEST_F(AutoSyncTimerTest, MultiWrite, TestSize.Level1) +HWTEST_F(AutoSyncTimerTest, MultiWriteBelowDelayTime, TestSize.Level1) { auto *instance = KVDBServiceMock::GetInstance(); ASSERT_NE(instance, nullptr); @@ -169,7 +169,7 @@ HWTEST_F(AutoSyncTimerTest, MultiWrite, TestSize.Level1) std::thread thread([&finished] { while (!finished.load()) { AutoSyncTimer::GetInstance().DoAutoSync("ut_test", { { "ut_test_store" } }); - usleep(40); + std::this_thread::sleep_for(std::chrono::milliseconds(40)); } }); EXPECT_EQ(static_cast(instance->GetCallCount(1)), 1); @@ -182,6 +182,68 @@ HWTEST_F(AutoSyncTimerTest, MultiWrite, TestSize.Level1) ASSERT_EQ(it->second.count("ut_test_store"), 1); } +/** +* @tc.name: MultiWriteOverDelayTime +* @tc.desc: write every 150 milliseconds +* @tc.type: FUNC +* @tc.require: I4XVQQ +* @tc.author: Yang Qing + */ +HWTEST_F(AutoSyncTimerTest, MultiWriteOverDelayTime, TestSize.Level1) +{ + auto *instance = KVDBServiceMock::GetInstance(); + ASSERT_NE(instance, nullptr); + instance->ResetToZero(); + instance->startTime = time_point_cast(system_clock::now()).time_since_epoch().count(); + instance->endTime = 0; + instance->values_.clear(); + std::atomic_bool finished = false; + std::thread thread([&finished] { + while (!finished.load()) { + AutoSyncTimer::GetInstance().DoAutoSync("ut_test", { { "ut_test_store" } }); + std::this_thread::sleep_for(std::chrono::milliseconds(150)); + } + }); + EXPECT_EQ(static_cast(instance->GetCallCount(1)), 1); + ASSERT_LT(instance->endTime - instance->startTime, 100); + finished.store(true); + thread.join(); + auto it = instance->values_.find("ut_test"); + ASSERT_NE(it, instance->values_.end()); + ASSERT_EQ(it->second.count("ut_test_store"), 1); +} + +/** +* @tc.name: MultiWriteOverForceTime +* @tc.desc: write every 400 milliseconds +* @tc.type: FUNC +* @tc.require: I4XVQQ +* @tc.author: Yang Qing + */ +HWTEST_F(AutoSyncTimerTest, MultiWriteOverForceTime, TestSize.Level1) +{ + auto *instance = KVDBServiceMock::GetInstance(); + ASSERT_NE(instance, nullptr); + instance->ResetToZero(); + instance->startTime = time_point_cast(system_clock::now()).time_since_epoch().count(); + instance->endTime = 0; + instance->values_.clear(); + std::atomic_bool finished = false; + std::thread thread([&finished] { + while (!finished.load()) { + AutoSyncTimer::GetInstance().DoAutoSync("ut_test", { { "ut_test_store" } }); + std::this_thread::sleep_for(std::chrono::milliseconds(400)); + } + }); + EXPECT_EQ(static_cast(instance->GetCallCount(1)), 1); + ASSERT_LT(instance->endTime - instance->startTime, 100); + finished.store(true); + thread.join(); + auto it = instance->values_.find("ut_test"); + ASSERT_NE(it, instance->values_.end()); + ASSERT_EQ(it->second.count("ut_test_store"), 1); +} + /** * @tc.name: SingleWriteOvertenKVStores * @tc.desc: single write over ten kv stores @@ -281,4 +343,69 @@ HWTEST_F(AutoSyncTimerTest, MultiWriteOvertenKVStores, TestSize.Level1) ASSERT_EQ(it->second.count("ut_test_store9"), 1); ASSERT_EQ(it->second.count("ut_test_store10"), 1); } -} \ No newline at end of file + +/** +* @tc.name: DoubleWrite +* @tc.desc: double wirte +* @tc.type: FUNC +* @tc.require: I4XVQQ +* @tc.author: YangQing + */ +HWTEST_F(AutoSyncTimerTest, DoubleWrite, TestSize.Level1) +{ + auto *instance = KVDBServiceMock::GetInstance(); + ASSERT_NE(instance, nullptr); + instance->ResetToZero(); + instance->startTime = time_point_cast(system_clock::now()).time_since_epoch().count(); + instance->endTime = 0; + instance->values_.clear(); + AutoSyncTimer::GetInstance().DoAutoSync("ut_test", { + { "ut_test_store0" }, + { "ut_test_store1" }, + { "ut_test_store2" }, + { "ut_test_store3" }, + { "ut_test_store4" }, + { "ut_test_store5" }, + { "ut_test_store6" }, + { "ut_test_store7" }, + { "ut_test_store8" }, + { "ut_test_store9" }, + { "ut_test_store10" }, + }); + AutoSyncTimer::GetInstance().DoAutoSync("ut_test", { + { "ut_test_store-0" }, + { "ut_test_store-1" }, + { "ut_test_store-2" }, + { "ut_test_store-3" }, + { "ut_test_store-4" }, + { "ut_test_store-5" }, + { "ut_test_store-6" }, + { "ut_test_store-7" }, + { "ut_test_store-8" }, + }); + EXPECT_EQ(static_cast(instance->GetCallCount(1)), 1); + ASSERT_LT(instance->endTime - instance->startTime, 100); + EXPECT_EQ(static_cast(instance->GetCallCount(20)), 20); + auto it = instance->values_.find("ut_test"); + ASSERT_EQ(it->second.count("ut_test_store0"), 1); + ASSERT_EQ(it->second.count("ut_test_store1"), 1); + ASSERT_EQ(it->second.count("ut_test_store2"), 1); + ASSERT_EQ(it->second.count("ut_test_store3"), 1); + ASSERT_EQ(it->second.count("ut_test_store4"), 1); + ASSERT_EQ(it->second.count("ut_test_store5"), 1); + ASSERT_EQ(it->second.count("ut_test_store6"), 1); + ASSERT_EQ(it->second.count("ut_test_store7"), 1); + ASSERT_EQ(it->second.count("ut_test_store8"), 1); + ASSERT_EQ(it->second.count("ut_test_store9"), 1); + ASSERT_EQ(it->second.count("ut_test_store10"), 1); + ASSERT_EQ(it->second.count("ut_test_store-0"), 1); + ASSERT_EQ(it->second.count("ut_test_store-1"), 1); + ASSERT_EQ(it->second.count("ut_test_store-2"), 1); + ASSERT_EQ(it->second.count("ut_test_store-3"), 1); + ASSERT_EQ(it->second.count("ut_test_store-4"), 1); + ASSERT_EQ(it->second.count("ut_test_store-5"), 1); + ASSERT_EQ(it->second.count("ut_test_store-6"), 1); + ASSERT_EQ(it->second.count("ut_test_store-7"), 1); + ASSERT_EQ(it->second.count("ut_test_store-8"), 1); +} +} // namespace OHOS::Test \ No newline at end of file diff --git a/kv_store/frameworks/innerkitsimpl/kvdb/test/single_store_impl_test.cpp b/kv_store/frameworks/innerkitsimpl/kvdb/test/single_store_impl_test.cpp index 68023fef..b669a2a2 100644 --- a/kv_store/frameworks/innerkitsimpl/kvdb/test/single_store_impl_test.cpp +++ b/kv_store/frameworks/innerkitsimpl/kvdb/test/single_store_impl_test.cpp @@ -1260,8 +1260,7 @@ HWTEST_F(SingleStoreImplTest, GetKVStoreWithAreaEL2, TestSize.Level0) options.kvStoreType = SINGLE_VERSION; options.securityLevel = S2; options.area = EL2; - options.baseDir = "/data/service/el2/100/" - ""; + options.baseDir = "/data/service/el2/100/SingleStoreImplTest"; Status status; kvStore = StoreManager::GetInstance().GetKVStore(appId, storeId, options, status); ASSERT_NE(kvStore, nullptr); diff --git a/kv_store/frameworks/innerkitsimpl/object/include/iobject_callback.h b/kv_store/frameworks/innerkitsimpl/object/include/iobject_callback.h index 1fbb341d..f37636ad 100644 --- a/kv_store/frameworks/innerkitsimpl/object/include/iobject_callback.h +++ b/kv_store/frameworks/innerkitsimpl/object/include/iobject_callback.h @@ -31,12 +31,12 @@ public: virtual void Completed(const std::map &results) = 0; }; -class ObjectSaveCallbackStub : public IRemoteStub { +class API_EXPORT ObjectSaveCallbackStub : public IRemoteStub { public: int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; -class ObjectSaveCallbackProxy : public IRemoteProxy { +class API_EXPORT ObjectSaveCallbackProxy : public IRemoteProxy { public: explicit ObjectSaveCallbackProxy(const sptr &impl); ~ObjectSaveCallbackProxy() = default; @@ -52,12 +52,12 @@ public: virtual void Completed(int32_t status) = 0; }; -class ObjectRevokeSaveCallbackStub : public IRemoteStub { +class API_EXPORT ObjectRevokeSaveCallbackStub : public IRemoteStub { public: int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; -class ObjectRevokeSaveCallbackProxy : public IRemoteProxy { +class API_EXPORT ObjectRevokeSaveCallbackProxy : public IRemoteProxy { public: explicit ObjectRevokeSaveCallbackProxy(const sptr &impl); ~ObjectRevokeSaveCallbackProxy() = default; @@ -73,12 +73,12 @@ public: virtual void Completed(const std::map> &results) = 0; }; -class ObjectRetrieveCallbackStub : public IRemoteStub { +class API_EXPORT ObjectRetrieveCallbackStub : public IRemoteStub { public: int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; -class ObjectRetrieveCallbackProxy : public IRemoteProxy { +class API_EXPORT ObjectRetrieveCallbackProxy : public IRemoteProxy { public: explicit ObjectRetrieveCallbackProxy(const sptr &impl); ~ObjectRetrieveCallbackProxy() = default; @@ -94,12 +94,12 @@ public: virtual void Completed(const std::map> &results) = 0; }; -class ObjectChangeCallbackStub : public IRemoteStub { +class API_EXPORT ObjectChangeCallbackStub : public IRemoteStub { public: int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; -class ObjectChangeCallbackProxy : public IRemoteProxy { +class API_EXPORT ObjectChangeCallbackProxy : public IRemoteProxy { public: explicit ObjectChangeCallbackProxy(const sptr &impl); ~ObjectChangeCallbackProxy() = default; @@ -108,7 +108,7 @@ public: private: static inline BrokerDelegator delegator_; }; -} // namespace DistributedKv +} // namespace DistributedObject } // namespace OHOS #endif // I_KVSTORE_SYNC_CALLBACK_H diff --git a/kv_store/frameworks/innerkitsimpl/object/include/iobject_service.h b/kv_store/frameworks/innerkitsimpl/object/include/iobject_service.h index cbeb3e75..3f024d8a 100644 --- a/kv_store/frameworks/innerkitsimpl/object/include/iobject_service.h +++ b/kv_store/frameworks/innerkitsimpl/object/include/iobject_service.h @@ -24,5 +24,5 @@ namespace OHOS::DistributedObject { class IObjectService : public ObjectService, public IRemoteBroker { }; -} // namespace OHOS::DistributedRdb +} // namespace OHOS::DistributedObject #endif diff --git a/kv_store/frameworks/innerkitsimpl/object/include/object_service_proxy.h b/kv_store/frameworks/innerkitsimpl/object/include/object_service_proxy.h index 1357fa1b..7af20003 100644 --- a/kv_store/frameworks/innerkitsimpl/object/include/object_service_proxy.h +++ b/kv_store/frameworks/innerkitsimpl/object/include/object_service_proxy.h @@ -22,7 +22,7 @@ #include "iobject_service.h" namespace OHOS::DistributedObject { -class ObjectServiceProxy : public IRemoteProxy { +class API_EXPORT ObjectServiceProxy : public IRemoteProxy { public: explicit ObjectServiceProxy(const sptr &impl); ~ObjectServiceProxy() = default; @@ -40,5 +40,5 @@ public: private: static inline BrokerDelegator delegator_; }; -} // namespace OHOS::DistributedRdb +} // namespace OHOS::DistributedObject #endif diff --git a/kv_store/frameworks/jskitsimpl/distributeddata/src/js_kv_manager.cpp b/kv_store/frameworks/jskitsimpl/distributeddata/src/js_kv_manager.cpp index ba1124b5..7933a326 100644 --- a/kv_store/frameworks/jskitsimpl/distributeddata/src/js_kv_manager.cpp +++ b/kv_store/frameworks/jskitsimpl/distributeddata/src/js_kv_manager.cpp @@ -20,6 +20,7 @@ #include "js_util.h" #include "log_print.h" #include "napi_queue.h" +#include using namespace OHOS::DistributedKv; @@ -142,7 +143,14 @@ napi_value JsKVManager::GetKVStore(napi_env env, napi_callback_info info) ZLOGD("GetSingleKvStore status:%{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; CHECK_STATUS_RETURN_VOID(ctxt, "GetSingleKvStore() failed!"); + ZLOGI("thread sleep start"); + std::this_thread::sleep_for(std::chrono::seconds(3)); + ZLOGI("thread sleep end, ctxt->kvStore->SetNative(kvStore) start"); + uint32_t result; + napi_reference_ref(ctxt->env,ctxt->ref,&result); + ZLOGI("ctxt->ref:%{public}d",result); ctxt->kvStore->SetNative(kvStore); + ZLOGI("ctxt->kvStore->SetNative(kvStore) end"); ctxt->kvStore->SetSchemaInfo(!ctxt->options.schema.empty()); ctxt->kvStore->SetContextParam(kvm->param_); ctxt->kvStore->SetUvQueue(kvm->uvQueue_); diff --git a/kv_store/frameworks/jskitsimpl/distributedkvstore/src/js_kv_manager.cpp b/kv_store/frameworks/jskitsimpl/distributedkvstore/src/js_kv_manager.cpp index 225b6adb..cb786e29 100644 --- a/kv_store/frameworks/jskitsimpl/distributedkvstore/src/js_kv_manager.cpp +++ b/kv_store/frameworks/jskitsimpl/distributedkvstore/src/js_kv_manager.cpp @@ -21,6 +21,7 @@ #include "log_print.h" #include "napi_queue.h" #include "js_error_utils.h" +#include using namespace OHOS::DistributedKv; @@ -150,7 +151,11 @@ napi_value JsKVManager::GetKVStore(napi_env env, napi_callback_info info) ctxt->status = (GenerateNapiError(status, ctxt->jsCode, ctxt->error) == Status::SUCCESS) ? napi_ok : napi_generic_failure; + ZLOGI("thread sleep start"); + std::this_thread::sleep_for(std::chrono::seconds(10)); + ZLOGI("thread sleep end, ctxt->kvStore->SetKvStorePtr(kvStore) start"); ctxt->kvStore->SetKvStorePtr(kvStore); + ZLOGI("ctxt->kvStore->SetKvStorePtr(kvStore) end"); ctxt->kvStore->SetSchemaInfo(!ctxt->options.schema.empty()); ctxt->kvStore->SetContextParam(kvm->param_); ctxt->kvStore->SetUvQueue(kvm->uvQueue_); diff --git a/kv_store/frameworks/jskitsimpl/distributedkvstore/src/napi_queue.cpp b/kv_store/frameworks/jskitsimpl/distributedkvstore/src/napi_queue.cpp index d6059434..45c9c97c 100644 --- a/kv_store/frameworks/jskitsimpl/distributedkvstore/src/napi_queue.cpp +++ b/kv_store/frameworks/jskitsimpl/distributedkvstore/src/napi_queue.cpp @@ -72,8 +72,6 @@ napi_value NapiQueue::AsyncWork(napi_env env, std::shared_ptr ctxt, NapiAsyncExecute execute, NapiAsyncComplete complete) { ZLOGD("name=%{public}s", name.c_str()); - ctxt->execute = std::move(execute); - ctxt->complete = std::move(complete); napi_value promise = nullptr; if (ctxt->callbackRef == nullptr) { @@ -108,8 +106,10 @@ napi_value NapiQueue::AsyncWork(napi_env env, std::shared_ptr ctxt, GenerateOutput(ctxt); }, reinterpret_cast(ctxt.get()), &ctxt->work); - napi_queue_async_work(ctxt->env, ctxt->work); + ctxt->execute = std::move(execute); + ctxt->complete = std::move(complete); ctxt->hold = ctxt; // save crossing-thread ctxt. + napi_queue_async_work(ctxt->env, ctxt->work); return promise; } @@ -151,6 +151,8 @@ void NapiQueue::GenerateOutput(ContextBase* ctxt) ZLOGD("call callback function"); napi_call_function(ctxt->env, nullptr, callback, RESULT_ALL, result, &callbackResult); } + ctxt->execute = nullptr; + ctxt->complete = nullptr; ctxt->hold.reset(); // release ctxt. } } // namespace OHOS::DistributedKVStore diff --git a/kv_store/frameworks/libs/CMakeLists.txt b/kv_store/frameworks/libs/CMakeLists.txt index dc72c78b..f6e7f302 100644 --- a/kv_store/frameworks/libs/CMakeLists.txt +++ b/kv_store/frameworks/libs/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.10.2) project(distributeddb) - set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -fno-rtti -fvisibility=default -D_GNU_SOURCE") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -fPIC -fpic -ffunction-sections -D_GLIBC_MOCK") @@ -9,7 +8,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=0") set(MOCK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../mock) add_definitions(-DUSE_HARMONY_SQLITE -DUSING_HILOG_LOGGER -DOMIT_FLATBUFFER -DEVLOOP_TIMER_ONLY) #-DOMIT_JSON add_definitions(-DUSING_DB_JSON_EXTRACT_AUTOMATICALLY -DSQLITE_ENABLE_JSON1 -DRELATIONAL_STORE -DOMIT_ZLIB) -add_definitions(-DWINDOWS_PLATFORM -DSQLITE_HAS_CODEC -DJSONCPP_USE_BUILDER -DEKEYREVOKED=128) +add_definitions(-DWINDOWS_PLATFORM -DSQLITE_HAS_CODEC -DJSONCPP_USE_BUILDER -DEKEYREVOKED=128 -DSQLITE_ENABLE_DROPTABLE_CALLBACK) add_definitions(-Dfseeko64=fseeko) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/common/src distributeddbSrc) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/common/src/evloop/src distributeddbSrc) diff --git a/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_sqlite_ext.cpp b/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_sqlite_ext.cpp index 29637fd9..65ab912f 100644 --- a/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_sqlite_ext.cpp +++ b/kv_store/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_sqlite_ext.cpp @@ -413,7 +413,7 @@ void PostHandle(sqlite3 *db) RegisterCalcHash(db); RegisterGetSysTime(db); RegisterGetLastTime(db); - // (void)sqlite3_set_droptable_handle(db, &ClearTheLogAfterDropTable); + (void)sqlite3_set_droptable_handle(db, &ClearTheLogAfterDropTable); (void)sqlite3_busy_timeout(db, BUSY_TIMEOUT); std::string recursiveTrigger = "PRAGMA recursive_triggers = ON;"; (void)ExecuteRawSQL(db, recursiveTrigger); diff --git a/kv_store/frameworks/libs/distributeddb/test/BUILD.gn b/kv_store/frameworks/libs/distributeddb/test/BUILD.gn index c3db3c40..c1659816 100644 --- a/kv_store/frameworks/libs/distributeddb/test/BUILD.gn +++ b/kv_store/frameworks/libs/distributeddb/test/BUILD.gn @@ -538,6 +538,10 @@ distributeddb_unittest( sources = [ "unittest/common/storage/distributeddb_storage_sqlite_single_ver_natural_executor_test.cpp" ] } +distributeddb_unittest("DistributedDBStorageSQLiteSingleVerStorageEngineTest") { + sources = [ "unittest/common/storage/distributeddb_storage_sqlite_single_ver_storage_engine_test.cpp" ] +} + distributeddb_unittest("DistributedDBStorageMemorySingleVerNaturalStoreTest") { sources = [ "unittest/common/storage/distributeddb_storage_memory_single_ver_naturall_store_test.cpp", @@ -832,6 +836,7 @@ group("unittest") { ":DistributedDBStorageResultAndJsonOptimizeTest", ":DistributedDBStorageSQLiteSingleVerNaturalExecutorTest", ":DistributedDBStorageSQLiteSingleVerNaturalStoreTest", + ":DistributedDBStorageSQLiteSingleVerStorageEngineTest", ":DistributedDBStorageSingleVerUpgradeTest", ":DistributedDBStorageTransactionDataTest", ":DistributedDBStorageTransactionRecordTest", diff --git a/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.cpp b/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.cpp index f21b4ae6..f06718b4 100644 --- a/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.cpp +++ b/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.cpp @@ -55,8 +55,12 @@ uint64_t FuzzerData::GetUInt64() return *r; } -std::vector FuzzerData::GetSequence(size_t size) +std::vector FuzzerData::GetSequence(size_t size, uint32_t mod) { + if (mod == 0) { + return {}; + } + size = size % mod; if (curr_ + size > data_ + size_) { return {}; } @@ -71,7 +75,7 @@ std::string FuzzerData::GetString(size_t len) return ""; } - std::string res = std::string(curr_, curr_ + len - 1); + std::string res = std::string(curr_, curr_ + len); curr_ += len; return res; } diff --git a/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.h b/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.h index 447ec8cc..135cabef 100644 --- a/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.h +++ b/kv_store/frameworks/libs/distributeddb/test/fuzztest/common/fuzzer_data.h @@ -22,6 +22,7 @@ #include namespace DistributedDBTest { + class FuzzerData final { public: FuzzerData(const uint8_t *data, size_t size); @@ -30,11 +31,13 @@ public: int GetInt(); uint32_t GetUInt32(); uint64_t GetUInt64(); - std::vector GetSequence(size_t size); + std::vector GetSequence(size_t size, uint32_t mod = MOD); std::string GetString(size_t len); std::vector GetStringVector(size_t size); std::vector GetU16StringVector(size_t size); private: + static const uint32_t MOD = 1024; // MOD length + const uint8_t *data_; const size_t size_; const uint8_t *curr_; diff --git a/kv_store/frameworks/libs/distributeddb/test/moduletest/BUILD.gn b/kv_store/frameworks/libs/distributeddb/test/moduletest/BUILD.gn new file mode 100644 index 00000000..0095263f --- /dev/null +++ b/kv_store/frameworks/libs/distributeddb/test/moduletest/BUILD.gn @@ -0,0 +1,708 @@ +# 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("//build/test.gni") + +module_output_path = "kv_store/distributeddb" + +mul_sources = [ + "common/distributeddb/src/auto_launch_callback.cpp", + "common/distributeddb/src/delegate_callback.cpp", + "common/distributeddb/src/delegate_kv_mgr_callback.cpp", + "common/distributeddb/src/distributed_test_tools.cpp", + "common/distributeddb/src/kv_store_observer_impl.cpp", + "common/distributeddb/src/kv_store_snapshot_callback.cpp", +] + +############################################################################### +config("module_private_config") { + visibility = [ ":*" ] + + include_dirs = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/multiver", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/storage/src/sqlite", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/interfaces/src", + + # "../adapter/include/communicator", + "//developtools/liblog", + "common/distributeddb/include", + "include", + "//commonlibrary/c_utils/base/include", + "//third_party/sqlite/include", + "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata/include", + "//third_party/openssl/include/", + ] + + defines = [ + "_LARGEFILE64_SOURCE", + "_FILE_OFFSET_BITS=64", + "SQLITE_HAS_CODEC", + "USE_SQLITE_SYMBOLS", + "USING_HILOG_LOGGER", + "TESTCASES_USING_GTEST_EXT", + "OMIT_JSON", + "LOW_LEVEL_MEM_DEV", + "RELEASE_MODE_V2", + "RELEASE_MODE_V3", + ] + ldflags = [ "-Wl,--exclude-libs,ALL" ] +} + +##############################moduletest########################################## +ohos_moduletest("DistributeddbKvTransactionTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributed_crud_transaction_tools.cpp", + "src/distributeddb_kv_transaction_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbKvTransactionPerfTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributed_crud_transaction_tools.cpp", + "src/distributeddb_kv_transaction_perf_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbKvConcurrencyCrudTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_concurrency_crud_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbKvBatchCrudTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_batch_crud_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbKvCreateTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_create_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbKvCrudTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_crud_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbKvObserverTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_observer_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbKvObserverSnapTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributed_test_sysinfo.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_observer_snap_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbKvBackupTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_backup_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbKvRealdelTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "src/distributeddb_kv_realdel_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbCreateTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_create_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbNbCrudTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_crud_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} +ohos_moduletest("DistributeddbNbObserverTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_observer_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbCursorTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_cursor_test.cpp", + "src/distributeddb_nb_cursor_testcase.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbBackupTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_backup_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbBatchCrudTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_batch_crud_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbLocalBatchCrudTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_local_batch_crud_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbSchemaDbTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_schema_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbPredicateQueryTest") { + module_out_path = module_output_path + + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "src/distributeddb_nb_predicate_query_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbPredicateQueryExpandTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "common/distributeddb/src/distributeddb_schema_test_tools.cpp", + "src/distributeddb_nb_predicate_query_expand_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbAutolaunchTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "common/distributeddb/src/distributeddb_schema_test_tools.cpp", + "src/distributeddb_nb_autolaunch_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributedbNbDbDamageTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "common/distributeddb/src/distributeddb_schema_test_tools.cpp", + "src/distributeddb_nb_db_damage_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbCrudPowerTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "common/distributeddb/src/distributeddb_schema_test_tools.cpp", + "src/distributeddb_nb_crud_power_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbSchemaTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "common/distributeddb/src/distributeddb_schema_test_tools.cpp", + "src/distributeddb_nb_schema_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +ohos_moduletest("DistributeddbNbSchemaUpgradeTest") { + module_out_path = module_output_path + sources = [ + "common/distributeddb/src/distributeddb_constant.cpp", + "common/distributeddb/src/distributeddb_data_generator.cpp", + "common/distributeddb/src/distributeddb_nb_test_tools.cpp", + "common/distributeddb/src/distributeddb_schema_test_tools.cpp", + "src/distributeddb_nb_schema_upgrade_test.cpp", + ] + sources += mul_sources + configs = [ ":module_private_config" ] + + deps = [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb:distributeddb", + "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_shared", + "//third_party/sqlite:sqlite", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + part_name = "datamgr_service" +} + +############################################################################### +group("moduletest") { + testonly = true + deps = [ + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + "//third_party/sqlite:sqlite", + ] + + deps += [ + ":DistributedbNbDbDamageTest", + ":DistributeddbKvBackupTest", + ":DistributeddbKvBatchCrudTest", + ":DistributeddbKvConcurrencyCrudTest", + ":DistributeddbKvCreateTest", + ":DistributeddbKvCrudTest", + ":DistributeddbKvObserverSnapTest", + ":DistributeddbKvObserverTest", + ":DistributeddbKvRealdelTest", + ":DistributeddbKvTransactionPerfTest", + ":DistributeddbKvTransactionTest", + ":DistributeddbNbAutolaunchTest", + ":DistributeddbNbBackupTest", + ":DistributeddbNbBatchCrudTest", + ":DistributeddbNbCreateTest", + ":DistributeddbNbCrudPowerTest", + ":DistributeddbNbCrudTest", + ":DistributeddbNbCursorTest", + ":DistributeddbNbLocalBatchCrudTest", + ":DistributeddbNbObserverTest", + ":DistributeddbNbPredicateQueryExpandTest", + ":DistributeddbNbPredicateQueryTest", + ":DistributeddbNbSchemaTest", + ":DistributeddbNbSchemaUpgradeTest", + ] +} diff --git a/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/auto_launch_callback.h b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/auto_launch_callback.h new file mode 100644 index 00000000..17e1f409 --- /dev/null +++ b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/auto_launch_callback.h @@ -0,0 +1,53 @@ +/* + * 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. + */ +#ifndef AUTO_LAUNCH_CALLBACK_H +#define AUTO_LAUNCH_CALLBACK_H + +#include +#include "auto_launch_export.h" +#include "types_export.h" + +#ifdef RELEASE_MODE_V2 +class AutoLaunchCallback { +public: + AutoLaunchCallback() {} + ~AutoLaunchCallback() {} + + // Delete the copy and assign constructors + AutoLaunchCallback(const AutoLaunchCallback &callback) = delete; + AutoLaunchCallback &operator=(const AutoLaunchCallback &callback) = delete; + AutoLaunchCallback(AutoLaunchCallback &&callback) = delete; + AutoLaunchCallback &operator=(AutoLaunchCallback &&callback) = delete; + + void AutoLaunchNotifier(const std::string &userId, const std::string &appId, const std::string &storeId, + DistributedDB::AutoLaunchStatus status); + int GetStatus(); + void Clear(); +#ifdef RELEASE_MODE_V3 + bool AutoLaunchRequestNotifier(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m); + void AddHashIdentity(const std::string &hashIdentity); + void ClearHashIdentities(); + void SetAutoLaunchParam(DistributedDB::AutoLaunchParam &autoLaunchParam); +#endif + +private: + int realStatus_ = 0; + std::vector hashIdentities_; +#ifdef RELEASE_MODE_V3 + DistributedDB::AutoLaunchParam autoLaunchParam_; +#endif +}; +#endif // end of RELEASE_MODE_V2 +#endif // AUTO_LAUNCH_CALLBACK_H \ No newline at end of file diff --git a/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_callback.h b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_callback.h new file mode 100644 index 00000000..a6a045fc --- /dev/null +++ b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_callback.h @@ -0,0 +1,49 @@ +/* + * 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. + */ +#ifndef DELEGATE_CALLBACK_H +#define DELEGATE_CALLBACK_H +#include "kv_store_snapshot_delegate.h" +#include "types_export.h" + +// DelegateCallback conclude the Callback implements of function< void(DBStatus, KvStoreSnapshotDelegate*)> +class DelegateCallback { +public: + DelegateCallback() {} + ~DelegateCallback() {} + + // Delete the copy and assign constructors + DelegateCallback(const DelegateCallback &callback) = delete; + DelegateCallback& operator=(const DelegateCallback &callback) = delete; + DelegateCallback(DelegateCallback &&callback) = delete; + DelegateCallback& operator=(DelegateCallback &&callback) = delete; + + void Callback(DistributedDB::DBStatus status, DistributedDB::KvStoreSnapshotDelegate *kvStoreSnapshotDelegate); + void CallbackKv(DistributedDB::DBStatus status, const DistributedDB::Value &value); + + DistributedDB::DBStatus GetStatus(); + const DistributedDB::Value &GetValue(); + + const DistributedDB::KvStoreSnapshotDelegate *GetKvStoreSnapshot() + { + return kvStoreSnapshotDelegate_; + } + +private: + DistributedDB::DBStatus status_ = DistributedDB::DBStatus::INVALID_ARGS; + DistributedDB::Value value_ = {}; + DistributedDB::KvStoreSnapshotDelegate *kvStoreSnapshotDelegate_ = nullptr; +}; + +#endif // DELEGATE_CALLBACK_H \ No newline at end of file diff --git a/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_kv_mgr_callback.h b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_kv_mgr_callback.h new file mode 100644 index 00000000..35b08709 --- /dev/null +++ b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/delegate_kv_mgr_callback.h @@ -0,0 +1,43 @@ +/* + * 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. + */ +#ifndef DELEGATE_KV_MGR_CALLBACK_H +#define DELEGATE_KV_MGR_CALLBACK_H + +#include "kv_store_delegate.h" + +// DelegateKvMgrCallback conclude the Callback implements of function< void(DBStatus, KvStoreDelegate*)> +class DelegateKvMgrCallback { +public: + DelegateKvMgrCallback() {} + ~DelegateKvMgrCallback() {} + + // Delete the copy and assign constructors + DelegateKvMgrCallback(const DelegateKvMgrCallback &callback) = delete; + DelegateKvMgrCallback& operator=(const DelegateKvMgrCallback &callback) = delete; + DelegateKvMgrCallback(DelegateKvMgrCallback &&callback) = delete; + DelegateKvMgrCallback& operator=(DelegateKvMgrCallback &&callback) = delete; + + void Callback(DistributedDB::DBStatus status, DistributedDB::KvStoreDelegate *kvStoreDelegate); + + DistributedDB::DBStatus GetStatus(); + + const DistributedDB::KvStoreDelegate *GetKvStore(); + +private: + DistributedDB::DBStatus status_ = DistributedDB::DBStatus::INVALID_ARGS; + DistributedDB::KvStoreDelegate *kvStoreDelegate_ = nullptr; +}; + +#endif // DELEGATE_KV_MGR_CALLBACK_H \ No newline at end of file diff --git a/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_rdb_tools.h b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_rdb_tools.h new file mode 100644 index 00000000..d5ccbb88 --- /dev/null +++ b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_rdb_tools.h @@ -0,0 +1,104 @@ +/* + * 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. + */ +#ifndef DISTRIBUTED_RDB_MODULE_TEST_TOOLS_H +#define DISTRIBUTED_RDB_MODULE_TEST_TOOLS_H +#include +#include + +#include "relational_store_delegate.h" +#include "relational_store_manager.h" +#include "distributed_test_sysinfo.h" +#include "distributeddb_data_generator.h" +#include "log_print.h" +#ifdef TESTCASES_USING_GTEST +#define HWTEST_F(test_case_name, test_name, level) TEST_F(test_case_name, test_name) +#endif + +struct RdbParameters { + std::string path; + std::string storeId; + std::string appId; + std::string userId; + RdbParameters(str::string pathStr, std::string storeIdStr, std::string appIdStr, std::string userIdStr) + : pathStr(pathStr), storeId(storeIdStr), appId(appIdStr), userId(userIdStr) + { + } +}; + +const static std::string TAG = "DistributedRdbTools"; + +const static std::string NORMAL_PATH = "/data/test/"; +const static std::string NON_EXISTENT_PATH = "/data/test/nonExistent_rdb/"; +const static std::string UNREADABLE_PATH = "/data/test/unreadable_rdb/"; +const static std::string UNWRITABLE_PATH = "/data/test/unwritable_rdb/"; + +const static std::string NULL_STOREID = {}; +const static std::string ILLEGAL_STOREID = "rdb_$%#@~%"; +const static std::string MODE_STOREID = "rdb_mode"; +const static std::string FULL_STOREID = "rdb_full"; +const static std::string SUPER_STOREID = "rdb_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + +const static std::string NON_EXISTENT_TABLE = "non_table"; +const static std::string KEYWORD_START_TABLE = "naturalbase_rdb_a"; + +const static std::string NORMAL_TABLE = "NORMAL_RDB"; +const static std::string CONSTRAINT_TABLE = "CONSTRAINT_RDB"; + +const static RdbParameters g_rdbParameter1(NORMAL_PATH, DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter2(NORMAL_PATH, DistributedDBDataGenerator::STORE_ID, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter3(NORMAL_PATH, ILLEGAL_STOREID, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter4(NORMAL_PATH, MODE_STOREID, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter5(NORMAL_PATH, SUPER_STOREID, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter6(NON_EXISTENT_PATH, DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter7(UNREADABLE_PATH, DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter8(UNWRITABLE_PATH, DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +const static RdbParameters g_rdbParameter9(NORMAL_PATH, FULL_STOREID, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); + +class DistributedRdbTools final { +public: + DistributedRdbTools() {} + ~DistributedRdbTools() {} + // Relational Database OpenStore And CreateDistributeTable + static DistributedDB::DBStatus GetOpenStoreStatus(const RelatetionalStoreManager *&manager, + RelatetionalStoreDelegate *&delegate, const RdbParameters ¶m); + static DistributedDB::DBStatus GetCreateDistributedTableStatus(const RelatetionalStoreDelegate *&delegate, + const std::string &tableName); + static bool CloseStore(const DistributedDB::RelatetionalStoreDelegate *&delegate); + + static bool InitSqlite3Store(sqlite3 *&db, const RdbParameters ¶m); + static bool InitTableDataAndTrigger(const sqlite3 *&db) ; + static bool AlterTableAttributes(const sqlite3 *&db); + static bool Sqlite3ExecOpration(const sqlite3 *&db, cont char *&sql_name); + static void CloseSqlite3Store(sqlite3 *&db); +} +#endif // DISTRIBUTED_RDB_MODULE_TEST_TOOLS_H \ No newline at end of file diff --git a/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_sysinfo.h b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_sysinfo.h new file mode 100644 index 00000000..417e9979 --- /dev/null +++ b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_sysinfo.h @@ -0,0 +1,113 @@ +/* + * 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. + */ +#ifndef DISTRIBUTED_TEST_SYSINFO_H +#define DISTRIBUTED_TEST_SYSINFO_H + +#include +#include "distributeddb_log_print.h" +#if defined(RUNNING_ON_LINUX) +#include +#elif defined RUNNING_ON_WIN +#endif + +const uint64_t SYSTEM_INFO_BUFFER_SIZE = 20; +const uint64_t PROC_BUFFER_LENGTH = 4096; +const uint64_t DEFAULT_INTEVAL = 250000; +const uint64_t DEFAULT_COUNT = 5; + +#if defined(RUNNING_ON_LINUX) +const std::string SYS_MEM_FILE = "/proc/meminfo"; +const std::string SYS_CPU_FILE = "/proc/stat"; +const std::string POWER_FOLLOW_FILE = "/sys/class/power_supply/Battery/current_now"; +const std::string VOLTAGE_FILE = "/sys/class/power_supply/Battery/voltage_now"; +const std::string FILE_READ_PERMISSION = "r"; + +// struct of mem occupy +struct MemOccupy { + char memTotalName_[SYSTEM_INFO_BUFFER_SIZE]; + uint64_t memTotal_; + char memFreeName_[SYSTEM_INFO_BUFFER_SIZE]; + uint64_t memFree_; + char buffersName_[SYSTEM_INFO_BUFFER_SIZE]; + uint64_t buffers_; + char cachedName_[SYSTEM_INFO_BUFFER_SIZE]; + uint64_t cached_; + char swapCachedName_[SYSTEM_INFO_BUFFER_SIZE]; + uint64_t swapCached_; +}; + +// struct of cpu occupy +struct CpuOccupy { + char name_[SYSTEM_INFO_BUFFER_SIZE]; + uint64_t user_; + uint64_t nice_; + uint64_t system_; + uint64_t idle_; + uint64_t iowait_; + uint64_t irq_; + uint64_t softirq_; +}; +#elif defined RUNNING_ON_WIN +#endif + +enum SeqNo { + FIRST = 1, + SECOND +}; + +// this class get system info, such as system or cpu storage and power at the moment +class DistributedTestSysInfo final { +public: + + DistributedTestSysInfo(); + ~DistributedTestSysInfo() {} + + // Delete the copy and assign constructors + DistributedTestSysInfo(const DistributedTestSysInfo &distributeTestSysInfo) = delete; + DistributedTestSysInfo& operator=(const DistributedTestSysInfo &distributeTestSysInfo) = delete; + DistributedTestSysInfo(DistributedTestSysInfo &&distributeTestSysInfo) = delete; + DistributedTestSysInfo& operator=(DistributedTestSysInfo &&distributeTestSysInfo) = delete; + + // read memory information from system file + void GetSysMemOccpy(SeqNo seqNo); + // read cpu information from system file sleep microSeconds between first and second read. + void GetSysCpuUsage(SeqNo seqNo, uint64_t microSeconds); + // read value from specific file + float ReadSysValFromFile(const std::string &filePath); + // read value from specific file and take the average within totalCount + float GetSysMeanCurrentVal(const std::string &filePath, int totalCount, uint64_t microSeconds); + // read power from specific file + void GetSysCurrentPower(SeqNo seqNo, int totalCount, uint64_t microSeconds); + + uint64_t GetFirstMemFree() const; + uint64_t GetSecondMemFree() const; + float GetFirstCpuUsage() const; + float GetSecondCpuUsage() const; + float GetFirstPower() const; + float GetSecondPower() const; + + void SaveSecondToFirst(); + +private: +#if defined(RUNNING_ON_LINUX) + MemOccupy memStatFirst_, memStatSecond_; + CpuOccupy cpuStatFirst_, cpuStatSecond_; +#elif defined RUNNING_ON_WIN +#endif + float cpuStatFirstUsage_, cpuStatSecondUsage_; + float powerStatFirst_, powerStatSecond_; + float val_; +}; +#endif // DISTRIBUTED_TEST_SYSINFO_H \ No newline at end of file diff --git a/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_tools.h b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_tools.h new file mode 100644 index 00000000..6e1e512d --- /dev/null +++ b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributed_test_tools.h @@ -0,0 +1,436 @@ +/* + * 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. + */ +#ifndef DISTRIBUTED_DB_MODULE_TEST_TOOLS_H +#define DISTRIBUTED_DB_MODULE_TEST_TOOLS_H +#include +#include + +#include "kv_store_delegate.h" +#include "kv_store_delegate_manager.h" +#include "kv_store_observer_impl.h" +#include "distributed_test_sysinfo.h" +#include "distributeddb_data_generator.h" +#include "log_print.h" +#ifdef RUN_MST_ON_TRUNCK // only need it in WAGNER env if run MST +#define HWTEST_F(test_case_name, test_name, level) TEST_F(test_case_name, test_name) +#endif +#define ULL(x) (static_cast(x)) +const int MAX_DIR_LENGTH = 4096; // the max length of directory +const int BUF_LEN = 8192; +const static std::string TAG = "DistributedTestTools"; // for log +const int AUTHORITY = 0755; +const int E_OK = 0; +const int E_ERROR = -1; +const std::string DIRECTOR = "/data/test/getstub/"; // default work dir. +static std::condition_variable g_conditionKvVar; + +struct KvDBParameters { + std::string storeId; + std::string appId; + std::string userId; + KvDBParameters(std::string storeIdStr, std::string appIdStr, std::string userIdStr) + : storeId(storeIdStr), appId(appIdStr), userId(userIdStr) + { + } +}; + +struct KvOption { + bool createIfNecessary = true; + bool localOnly = false; + bool isEncryptedDb = false; // whether need encrypt + DistributedDB::CipherType cipher = DistributedDB::CipherType::DEFAULT; // cipher type + std::vector passwd; // cipher password + KvOption(bool createIfNecessary1, bool isLocalOnly, + bool isEncryptedDb1, DistributedDB::CipherType cipher1, std::vector passwd1) + : createIfNecessary(createIfNecessary1), + localOnly(isLocalOnly), + isEncryptedDb(isEncryptedDb1), + cipher(cipher1), passwd(passwd1) + { + } + KvOption() + {} +}; + +struct EncrypteAttribute { + bool isEncryptedDb = false; + std::vector passwd; +}; + +const static KvDBParameters g_kvdbParameter1(DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); +const static KvDBParameters g_kvdbParameter2(DistributedDBDataGenerator::STORE_ID_2, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_2); +const static KvDBParameters g_kvdbParameter3(DistributedDBDataGenerator::STORE_ID_3, + DistributedDBDataGenerator::APP_ID_3, DistributedDBDataGenerator::USER_ID_3); +const static KvDBParameters g_kvdbParameter4(DistributedDBDataGenerator::STORE_ID_4, + DistributedDBDataGenerator::APP_ID_4, DistributedDBDataGenerator::USER_ID_4); +const static KvDBParameters g_kvdbParameter5(DistributedDBDataGenerator::STORE_ID_5, + DistributedDBDataGenerator::APP_ID_5, DistributedDBDataGenerator::USER_ID_5); +const static KvDBParameters g_kvdbParameter6(DistributedDBDataGenerator::STORE_ID_6, + DistributedDBDataGenerator::APP_ID_6, DistributedDBDataGenerator::USER_ID_6); +const static KvDBParameters g_kvdbParameter1_1_2(DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_2); +const static KvDBParameters g_kvdbParameter1_2_1(DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_1); +const static KvDBParameters g_kvdbParameter1_2_2(DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_2); +const static KvDBParameters g_kvdbParameter2_1_1(DistributedDBDataGenerator::STORE_ID_2, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); +const static KvDBParameters g_kvdbParameter2_1_2(DistributedDBDataGenerator::STORE_ID_2, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_2); +const static KvDBParameters KVDB_PARAMETER_PERFORM(DistributedDBDataGenerator::STORE_ID_PERFORM, + DistributedDBDataGenerator::APP_ID_PERFORM, DistributedDBDataGenerator::USER_ID_PERFORM); +const static KvOption g_createKvDiskUnencrypted(true, false, false, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::NULL_PASSWD_VECTOR); +const static KvOption g_createKvDiskEncrypted(true, false, true, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::PASSWD_VECTOR_1); +const static KvOption g_createLocalDiskUnencrypted(true, true, false, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::NULL_PASSWD_VECTOR); +const static KvOption g_createLocalDiskEncrypted(true, true, true, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::PASSWD_VECTOR_1); +static KvOption g_kvOption = g_createKvDiskEncrypted; +bool CompareVector(const std::vector& first, const std::vector& second); +bool CompareEntriesVector(std::vector& retVec, + std::vector& expectVec); +void PutUniqueKey(std::vector& entryVec, + const DistributedDB::Key &putKey, const DistributedDB::Value &putValue); +int Uint8VecToString(std::vector& vec, std::string& str); +int GetIntValue(DistributedDB::Value &value); +int RemoveDir(const std::string &directory); +int SetDir(const std::string &directory, const int authRight = AUTHORITY); +void CopyFile(const std::string &srcFile, const std::string &destFile); +void CopyDir(const std::string &srcDir, const std::string &destDir, const int authRight = AUTHORITY); +void CheckFileNumber(const std::string &filePath, int &fileCount); +DistributedDB::Value GetValueWithInt(int val); +std::vector GenRanKeyVal(int putGetTimes, int keyLength, int valueLength, char val); +std::vector GetKeysFromEntries(std::vector entries, bool random); +bool GetRandBool(); +bool PutEntries(DistributedDB::KvStoreNbDelegate *&delegate, std::vector &entries); + +using SysTime = std::chrono::time_point; +using SysDurTime = std::chrono::duration; + +struct PerformanceData { + int putGetTimes; + int keyLength; + int valueLength; + bool putBatch; + bool getBatch; + bool useClear; + bool getSysInfo; + bool isLocal; + double openDuration; + double putDuration; + double readPutDuration; + double updateDuration; + double readUpdateDuration; + double deleteDuration; + double closeDuration; + PerformanceData(int putGetTimes, int keyLength, int valueLength, + bool putBatch, bool getBatch, bool useClear, bool getSysInfo, bool isLocal) + : putGetTimes(putGetTimes), keyLength(keyLength), valueLength(valueLength), + putBatch(putBatch), getBatch(getBatch), useClear(useClear), + getSysInfo(getSysInfo), isLocal(isLocal), + openDuration(0.0), putDuration(0.0), readPutDuration(0.0), updateDuration(0.0), + readUpdateDuration(0.0), deleteDuration(0.0), closeDuration(0.0) + { + } +}; + +struct Duration { + double putDuration = 0.0; + double readDuration = 0.0; + double updateDuration = 0.0; + double deleteDuration = 0.0; + Duration() = default; + void Clear() + { + putDuration = readDuration = updateDuration = deleteDuration = 0.0; + } +}; + +struct BackupDuration { + double exportDuration = 0.0; + double importDuration = 0.0; + BackupDuration() = default; + BackupDuration(double exportDur, double importDur) + { + exportDuration = exportDur; + importDuration = importDur; + } + BackupDuration operator+(const BackupDuration &backupDur) const + { + return BackupDuration(exportDuration + backupDur.exportDuration, importDuration + backupDur.importDuration); + } + void Clear() + { + exportDuration = importDuration = 0; + } +}; + +enum KvDbType { + ENCRYED = 0, + UNENCRYED = 1 +}; + +enum OperRecordNum { + SINGLE = 1, + SMALL_BATCH = 100, + BATCH = 128, +}; + +enum class OperType { + PUT, + PUT_LOCAL, + UPDATE, + UPDATE_LOCAL, + DELETE, + DELETE_LOCAL +}; + +struct KvPerfData { + KvDbType kvDbType; + int testCnt; + OperRecordNum operRecordNum; + int keyLength; + int valueLength; + bool isPresetRecords; + int presetRecordsCnt; + std::vector allCrudDur; + KvPerfData(KvDbType kvDbType, int testCnt, OperRecordNum operRecordNum, int keyLength, int valueLength, + bool isPresetRecords, int presetRecordsCnt) + : kvDbType(kvDbType), testCnt(testCnt), operRecordNum(operRecordNum), + keyLength(keyLength), valueLength(valueLength), + isPresetRecords(isPresetRecords), presetRecordsCnt(presetRecordsCnt) + { + } +}; + +struct RekeyTypesDur { + double nullPasswdToPasswd1 = 0.0; + double passwd1ToPasswd1 = 0.0; + double passwd1ToPasswd2 = 0.0; + double passwd2ToNullPasswd = 0.0; + RekeyTypesDur() = default; + RekeyTypesDur(double nullPasswdToPasswd1, double passwd1ToPasswd1, + double passwd1ToPasswd2, double passwd2ToNullPasswd) + : nullPasswdToPasswd1(nullPasswdToPasswd1), passwd1ToPasswd1(passwd1ToPasswd1), + passwd1ToPasswd2(passwd1ToPasswd2), passwd2ToNullPasswd(passwd2ToNullPasswd) + { + } + RekeyTypesDur operator+(const RekeyTypesDur &rekeyTypesDur) const + { + return RekeyTypesDur(nullPasswdToPasswd1 + rekeyTypesDur.nullPasswdToPasswd1, + passwd1ToPasswd1 + rekeyTypesDur.passwd1ToPasswd1, + passwd1ToPasswd2 + rekeyTypesDur.passwd1ToPasswd2, + passwd2ToNullPasswd + rekeyTypesDur.passwd2ToNullPasswd); + } +}; + +struct KvRekeyPerfData { + int testCnt; + int presetRecordsCnt; + int keyLength; + int valueLength; + std::vector allRekeyDur; + KvRekeyPerfData(int testCnt, int presetRecordsCnt, int keyLength, int valueLength) + : testCnt(testCnt), presetRecordsCnt(presetRecordsCnt), keyLength(keyLength), valueLength(valueLength) + { + } +}; + +struct KvBackupPerfData { + KvDbType kvDbType; + int testCnt; + int presetRecordsCnt; + int keyLength; + int valueLength; + std::vector allBackupDur; + KvBackupPerfData(KvDbType kvDbType, int testCnt, int presetRecordsCnt, int keyLength, int valueLength) + : kvDbType(kvDbType), testCnt(testCnt), presetRecordsCnt(presetRecordsCnt), + keyLength(keyLength), valueLength(valueLength) + { + } +}; + +struct PerImageGallery { + uint64_t putDuration = 0; + uint64_t readDuration = 0; + void Clear() + { + putDuration = 0; + readDuration = 0; + } +}; +struct NbGalleryPerfData { + int testCnt; + unsigned int keyLength; + unsigned int valueLength; + bool isLocal; + bool isPresetRecords; + int presetRecordsCnt; + std::vector allCrudDur; + NbGalleryPerfData(int testCnt, int keyLength, int valueLength, + bool isLocal, bool isPresetRecords, int presetRecordsCnt) + : testCnt(testCnt), keyLength(keyLength), valueLength(valueLength), + isLocal(isLocal), isPresetRecords(isPresetRecords), presetRecordsCnt(presetRecordsCnt) + { + } +}; +struct NbLocalPerfData { + int testCnt; + unsigned int keyLength; + unsigned int valueLength; + bool isLocal; + bool isPresetRecords; + int presetRecordsCnt; + std::vector allCrudDur; + NbLocalPerfData(int testCnt, int keyLength, int valueLength, + bool isLocal, bool isPresetRecords, int presetRecordsCnt) + : testCnt(testCnt), keyLength(keyLength), valueLength(valueLength), + isLocal(isLocal), isPresetRecords(isPresetRecords), presetRecordsCnt(presetRecordsCnt) + { + } +}; + +struct QueryDur { + double getEntriesDuration = 0.0; + double getResultSetDuration = 0.0; + QueryDur() = default; + void Clear() + { + getEntriesDuration = getResultSetDuration = 0; + } +}; +struct NbSchemaCRUDPerfData { + int testCnt; + OperRecordNum operRecordNum; + unsigned int keyLength; + unsigned int valueLength; + bool isLocal; + bool isPresetRecords; + unsigned int presetRecordsCnt; + bool isQueryNeeded; + bool isIndexSchema; + std::vector allCrudDur; + std::vector allQueryDur; + NbSchemaCRUDPerfData(int testCnt, OperRecordNum operRecordNum, int keyLength, int valueLength, + bool isLocal, bool isPresetRecords, int presetRecordsCnt, int isQueryNeeded, int isIndexSchema) + : testCnt(testCnt), operRecordNum(operRecordNum), keyLength(keyLength), valueLength(valueLength), + isLocal(isLocal), isPresetRecords(isPresetRecords), presetRecordsCnt(presetRecordsCnt), + isQueryNeeded(isQueryNeeded), isIndexSchema(isIndexSchema) + { + } +}; + +// default kvStoreDelegateManager's config. +const DistributedDB::KvStoreConfig KV_CONFIG = { + .dataDir = DIRECTOR +}; + +class DistributedTestTools final { +public: + DistributedTestTools() {} + ~DistributedTestTools() {} + + // Delete the copy and assign constructors + DistributedTestTools(const DistributedTestTools &distributeDBTools) = delete; + DistributedTestTools& operator=(const DistributedTestTools &distributeDBTools) = delete; + DistributedTestTools(DistributedTestTools &&distributeDBTools) = delete; + DistributedTestTools& operator=(DistributedTestTools &&distributeDBTools) = delete; + + // this static method is to compare if the two Value has the same data. + static bool IsValueEquals(const DistributedDB::Value &v1, const DistributedDB::Value &v2); + static DistributedDB::KvStoreDelegate::Option TransferKvOptionType(const KvOption &optionParam); + static DistributedDB::KvStoreDelegate* GetDelegateSuccess(DistributedDB::KvStoreDelegateManager *&outManager, + const KvDBParameters ¶m, const KvOption &optionParam); + static DistributedDB::KvStoreDelegate* GetDelegateStatus(DistributedDB::KvStoreDelegateManager *&outManager, + DistributedDB::DBStatus &status, const KvDBParameters ¶m, const KvOption &optionParam); + + static DistributedDB::DBStatus GetDelegateNotGood( + DistributedDB::KvStoreDelegateManager *&outManager, DistributedDB::KvStoreDelegate *&outDelegate, + const std::string &storeId, const std::string &appId, const std::string &userId, const KvOption &optionParam); + + static DistributedDB::DBStatus Put(DistributedDB::KvStoreDelegate &kvStoreDelegate, + const DistributedDB::Key &key, const DistributedDB::Value &value); + + static DistributedDB::DBStatus PutBatch(DistributedDB::KvStoreDelegate &kvStoreDelegate, + const std::vector &entries); + + static DistributedDB::DBStatus Delete(DistributedDB::KvStoreDelegate &kvStoreDelegate, + const DistributedDB::Key &key); + + static DistributedDB::DBStatus DeleteBatch(DistributedDB::KvStoreDelegate &kvStoreDelegate, + const std::vector &keys); + + static DistributedDB::DBStatus Clear(DistributedDB::KvStoreDelegate &kvStoreDelegate); + + static DistributedDB::KvStoreSnapshotDelegate *GetKvStoreSnapshot(DistributedDB::KvStoreDelegate &kvStoreDelegate); + static DistributedDB::Value Get(DistributedDB::KvStoreDelegate &kvStoreDelegate, const DistributedDB::Key &key); + static DistributedDB::Value Get(DistributedDB::KvStoreSnapshotDelegate &kvStoreSnapshotDelegate, + const DistributedDB::Key &key); + + static std::vector GetEntries( + DistributedDB::KvStoreSnapshotDelegate &kvStoreSnapshotDelegate, const DistributedDB::Key &key); + static std::vector GetEntries(DistributedDB::KvStoreDelegate &kvStoreDelegate, + const DistributedDB::Key &keyPrefix); + + static DistributedDB::KvStoreSnapshotDelegate *RegisterSnapObserver(DistributedDB::KvStoreDelegate *delegate, + DistributedDB::KvStoreObserver *observer); + static DistributedDB::DBStatus RegisterObserver(DistributedDB::KvStoreDelegate *delegate, + DistributedDB::KvStoreObserver *observer); + static DistributedDB::DBStatus UnRegisterObserver(DistributedDB::KvStoreDelegate *delegate, + DistributedDB::KvStoreObserver *observer); + static bool CalculateOpenPerformance(PerformanceData &performanceData); + static bool CalculateInsertPerformance(PerformanceData &performanceData); + static bool CalculateGetPutPerformance(PerformanceData &performanceData); + static bool CalculateUpdatePerformance(PerformanceData &performanceData); + static bool CalculateGetUpdatePerformance(PerformanceData &performanceData); + static bool CalculateUseClearPerformance(PerformanceData &performanceData); + static bool CalculateTransactionPerformance(PerformanceData &performanceData); + static bool CloseAndRelease(DistributedDB::KvStoreDelegateManager *&manager, + DistributedDB::KvStoreDelegate *&delegate); + static bool CloseAndRelease(DistributedDB::KvStoreDelegateManager *&manager, + DistributedDB::KvStoreNbDelegate *&delegate); + static bool VerifyDbRecordCnt(DistributedDB::KvStoreNbDelegate *&delegate, unsigned int recordCnt, + bool isLocal = false); + static bool VerifyRecordsInDb(DistributedDB::KvStoreNbDelegate *&delegate, + std::vector &entriesExpected, + const std::vector &keyPrefix = DistributedDBDataGenerator::KEY_EMPTY, bool isLocal = false); + static bool GetRecordCntByKey(const std::string &dbName, + const std::string &strSql, std::vector &sqlParam, KvOption &option, int &count); + static bool QuerySpecifiedData(const std::string &dbName, const std::string &strSql, + EncrypteAttribute &attribute, int &count); + static bool RepeatCheckAsyncResult(const std::function &inPred, int repeatLimit, + uint32_t repeatInterval); + static bool CompareKey(const DistributedDB::Entry &entry1, const DistributedDB::Entry &entry2); + static void CopyFile(const std::string &srcFile, const std::string &destFile); +}; + +std::string TransferStringToHashHexString(const std::string &origStr); + +int RemoveDatabaseDirectory(const std::string &directory); + +bool VerifyObserverResult(const KvStoreObserverImpl &pObserver, + int changedTimes, ListType type, const std::list &lst, + uint32_t timeout = DistributedDBDataGenerator::DistributedDBConstant::THIRTY_MINUTES); +bool VerifyObserverResult(const KvStoreObserverImpl &pObserver, + int changedTimes, ListType type, const std::vector &vec, + uint32_t timeout = DistributedDBDataGenerator::DistributedDBConstant::THIRTY_MINUTES); +bool VerifyObserverForSchema(const KvStoreObserverImpl &pObserver, + int changedTimes, ListType type, const std::vector &expectEntry, + uint32_t timeout = DistributedDBDataGenerator::DistributedDBConstant::THIRTY_MINUTES); +#endif // DISTRIBUTED_DB_MODULE_TEST_TOOLS_H diff --git a/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_constant.h b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_constant.h new file mode 100644 index 00000000..4f50a04d --- /dev/null +++ b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_constant.h @@ -0,0 +1,133 @@ +/* + * 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. + */ + +#ifndef DISTRIBUTEDDB_CONSTANT_DEFINE_H +#define DISTRIBUTEDDB_CONSTANT_DEFINE_H + +#include +#include "store_types.h" + +namespace DistributedDBDataGenerator { +const int TEST_ID_1 = 1; +const int TEST_ID_2 = 2; +const int TEST_ID_3 = 3; +const int TEST_ID_4 = 4; +const int TEST_ID_5 = 5; +const int TEST_ID_6 = 6; +const int TEST_ID_7 = 7; +const int TEST_ID_8 = 8; +const int TEST_ID_9 = 9; +const int TEST_ID_10 = 10; +const int TEST_ID_11 = 11; +const int TEST_ID_12 = 12; +const int TEST_ID_13 = 13; +const int TEST_ID_14 = 14; +const int TEST_ID_15 = 15; +const int TEST_ID_16 = 16; +const int TEST_ID_17 = 17; +const int TEST_ID_18 = 18; +const int TEST_ID_19 = 19; +const int TEST_ID_20 = 20; +const int TEST_ID_21 = 21; +const int TEST_ID_22 = 22; +const int TEST_ID_23 = 23; +const int TEST_ID_24 = 24; +const int TEST_ID_25 = 25; +const int TEST_ID_26 = 26; +const int TEST_ID_27 = 27; +const int TEST_ID_28 = 28; +const int TEST_ID_29 = 29; +const int TEST_ID_30 = 30; +const int TEST_ID_31 = 31; +const int TEST_ID_32 = 32; +const int TEST_ID_33 = 33; +const int TEST_ID_34 = 34; +const int TEST_ID_35 = 35; +const int TEST_ID_36 = 36; +const int TEST_ID_37 = 37; +const int TEST_ID_38 = 38; +const int TEST_ID_39 = 39; +const int TEST_ID_40 = 40; +const int TEST_ID_41 = 41; +const int TEST_ID_42 = 42; +const int TEST_ID_43 = 43; +const int TEST_ID_44 = 44; +const int TEST_ID_45 = 45; +const int TEST_ID_46 = 46; +const int TEST_ID_47 = 47; +const int TEST_ID_48 = 48; +const int TEST_ID_49 = 49; +const int TEST_ID_50 = 50; +const int TEST_ID_51 = 51; +const int TEST_ID_52 = 52; + +class DistributedDBConstant { +public: + static const std::string NB_DIRECTOR; // default work dir. + static const std::string NB_DATABASE_NAME; + static const std::string NORMAL_COMMON_SCHEMA; + static const std::string COMPATIBLE_FOR_NORMAL_COMMON_SCHEMA; + static const std::string UNCOMPATIBLE_FOR_NORMAL_COMMON_SCHEMA; + // default kvStoreDelegateManager's config. + static const DistributedDB::KvStoreConfig CONFIG; + static const std::string DB_FILE_DOCUMENT; + static constexpr int UNLOCK_ACCESS = 0; + static constexpr int LOCKED_ACCESS = 1; + static constexpr uint32_t THIRTY_MINUTES = 1800; + static constexpr uint32_t WAIT_UNTIL_CALLBACK_COME = 0; + +// ************************ SYNC PACKET ************************************ + static constexpr int ZERO_PACKET = 0; + static constexpr int ONE_PACKET = 1; + static constexpr int TWO_PACKETS = 2; + static constexpr int THREE_PACKETS = 3; + static constexpr int FOUR_PACKETS = 4; + static constexpr int EIGHT_PACKETS = 8; + static constexpr int FIRST_PACKET = 1; + static constexpr int THIRD_PACKET = 3; + static constexpr int FIFTH_PACKET = 5; + static constexpr int EIGHTH_PACKET = 8; + static constexpr uint32_t THROW_PACKET_CNT_LEN = 168; // the length of data packet is greater than 168 + // the length of registering subscriber packet is greater than 111 + static constexpr uint32_t REGISTER_SUBSCRIBER_PACKET_LEN = 111; + +// ************************ MILLISECOND ************************************ + static const unsigned int THREE_S_TO_MS = 3000; + static const unsigned int FIVE_S_TO_MS = 5000; + static const unsigned int EIGHT_S_TO_MS = 8000; + static const unsigned int NINE_S_TO_MS = 9000; + static const unsigned int TEN_S_TO_MS = 10000; + static const unsigned int SIXTY_S_TO_MS = 60000; + +// ************************ compression ratio ************************** + static const unsigned int COMPRESSION_RATIO_ZERO = 0; + static const unsigned int COMPRESSION_RATIO_TEN = 10; + static const unsigned int COMPRESSION_RATIO_TWENTY = 20; + static const unsigned int COMPRESSION_RATIO_THIRTY = 30; + static const unsigned int COMPRESSION_RATIO_FORTY = 40; + static const unsigned int COMPRESSION_RATIO_FIFTY = 50; + static const unsigned int COMPRESSION_RATIO_SIXTY = 60; + static const unsigned int COMPRESSION_RATIO_SEVENTY = 70; + static const unsigned int COMPRESSION_RATIO_EIGHTY = 80; + static const unsigned int COMPRESSION_RATIO_NINETY = 90; + static const unsigned int COMPRESSION_RATIO_ONE_HUNDRED = 100; + static const unsigned int COMPRESSION_RATIO_ONE_HUNDRED_AND_ONE = 101; + +// ************************ record number ************************** + static const unsigned int THIRTY_THOUSAND_RECORDS = 30000; +}; +} // namespace DistributedDBDataGenerator + +#endif // DISTRIBUTEDDB_CONSTANT_DEFINE_H diff --git a/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_data_generator.h b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_data_generator.h new file mode 100644 index 00000000..4603d80b --- /dev/null +++ b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_data_generator.h @@ -0,0 +1,567 @@ +/* + * 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. + */ +#ifndef DISTRIBUTED_DB_MODULE_TEST_TYPES_H +#define DISTRIBUTED_DB_MODULE_TEST_TYPES_H + +#include +#include +#include +#include "kv_store_delegate.h" +#include "kv_store_delegate_manager.h" +#include "distributed_test_sysinfo.h" +#include "distributeddb_log_print.h" +#include "distributeddb_constant.h" + +struct EntrySize { + unsigned int keySize = 0; + unsigned int valSize = 0; + void Set(unsigned int keySizeInput, unsigned int valSizeInput) + { + this->keySize = keySizeInput; + this->valSize = valSizeInput; + } +}; + +enum DBType { + UNENCRYPTED_DISK_DB = 0, + ENCRYPTED_DISK_DB, + MEMORY_DB +}; + +struct TimeSamp { + std::vector startTime; + std::vector endTime; + TimeSamp() + { + } +}; + +struct ImagePerSamp { + std::vector firstStep; + std::vector secondStep; + ImagePerSamp() + { + } +}; + +struct PerTimeLength { + std::vector entriesDuration; + std::vector cursorDuration; + std::vector moveNextDuration; + std::vector entryDurationForward; + std::vector movePreviousDuration; + std::vector entryDurationBackup; +}; + +struct Schema { + std::vector version; + std::vector mode; + std::vector define; + std::vector index; +}; +struct LongDefine { + int recordNum; + int recordSize; + char prefix; +}; + +struct NumberSize { + EntrySize entrySize; + int recordsNumber; + bool isRoundBack = false; + NumberSize() : recordsNumber(0) + { + } +}; + +enum class RandType { + ALPHA_NUM, + ALPHA_NUM_UNDERLINE, + SPECIAL, +}; + +// ************************ number class ********************************** +const unsigned int OBSERVER_NUM = 8; +const int BUFFER_COUNT = 5; +const unsigned int NB_OBSERVER_NUM = 4; +const unsigned int NB_OPERATION_NUM = 100; +const unsigned int NB_PREDATA_NUM = 50; +const unsigned int RECORDS_SMALL_CNT = 2; +const unsigned int NO_RECORD = 0; +const unsigned int THREE_RECORDS = 3; +const unsigned int THREE_PERF_DATA = 3; +const unsigned int BATCH_RECORDS = 128; +const static int ONE_RECORD = 1; +const static int TWO_RECORDS = 2; +const static int FOUR_RECORDS = 4; +const static int FIVE_RECORDS = 5; +const static int SIX_RECORDS = 6; +const static int EIGHT_RECORDS = 8; +const static int NINE_RECORDS = 9; +const static int TEN_RECORDS = 10; +const static int SIXTEEN_RECORDS = 16; +const static int TWENTY_RECORDS = 20; +const static int THIRTY_RECORDS = 30; +const static int THIRTYTWO_RECORDS = 32; +const static int FORTY_RECORDS = 40; +const static int FIFTY_RECORDS = 50; +const static int SIXTY_RECORDS = 60; +const static int EIGHTY_RECORDS = 80; +const static int ONE_HUNDRED_RECORDS = 100; +const static int TWO_HUNDREDS_RECORDS = 200; +const static int FIVE_HUNDREDS_RECORDS = 500; +const static int SIX_HUNDREDS_RECORDS = 600; +const static int ONE_THOUSAND_RECORDS = 1000; +const static int TWO_THOUSANDS_RECORDS = 2000; +const static int TWO_FIVE_ZERO_ZERO_RECORDS = 2500; +const static int TWO_FIVE_SIX_ZERO_RECORDS = 2560; +const static int FIVE_THOUSANDS_RECORDS = 5000; +const static int TEN_THOUSAND_RECORDS = 10000; +const static int FIFTEEN_THOUSAND_RECORDS = 15000; +const static int TWENTY_THOUSAND_RECORDS = 20000; +const static int THIRTY_THOUSAND_RECORDS = 30000; +const static int FIFTY_THOUSAND_RECORDS = 50000; +const static int HUNDRED_THOUSAND_RECORDS = 100000; +const static int FOUR_HUNDRED_THOUSAND_RECORDS = 400000; +const static int FIVE_HUNDRED_THOUSAND_RECORDS = 500000; +const static int TWO_FIVE_SIX_RECORDS = 256; +const static int FIRST_RECORD = 1; +const static int SECOND_RECORD = 2; +const static int DATAS_ACCOUNT = 300; +const static int DATA_LEN = 13; +const static int NINE_CNT = 9; +const static int TEN_CNT = 10; +const static unsigned int TWO_DEVICES = 2; +const static unsigned int FOUR_DEVICES = 4; +const static int THIRD_FUNC = 3; +const static int FOURTH_FUNC = 4; +const static int FIFTH_FUNC = 5; +const static int THREE_DBS = 3; +const static int EIGHT_DBS = 8; +const static int TEN_DBS = 10; +const static int ELEVEN_DBS = 11; +const static int TWELVE_DBS = 12; +const static int FIRST_DB = 1; +const static int FIFTH_DB = 5; +const static int TENTH_DB = 10; +const static int ELEVENTH_DB = 11; +const static int TWELFTH_DB = 12; + +// ************************ loop times class ************************** +const unsigned int MOD_NUM = 2; +const unsigned int BIG_MOD_NUM = 3; + +const unsigned int ID_CNT_START = 0; +const unsigned int ID_MIN_CNT = 2; +const unsigned int ID_MEDIUM_CNT = 3; +const unsigned int ID_MAX_CNT = 16; +const unsigned int STORE_CNT = 4; +const unsigned int DIR_CNT_START = 0; +const unsigned int DIR_MAX_CNT = 14; +const static int MANYTINES = 3; +const static int ONE_TIME = 1; +const static int TWO_TIMES = 2; +const static int FIVE_TIMES = 5; +const static int TEN_TIMES = 10; +const static int FIFTY_TIMES = 50; +const static int HUNDRED_TIMES = 100; + +// ************************ time class ************************** +const unsigned int UNIQUE_SECOND = 1; +const unsigned int TWO_SECONDS = 2; +const unsigned int THREE_SECONDS = 3; +const unsigned int FOUR_SECONDS = 4; +const unsigned int FIVE_SECONDS = 5; +const unsigned int SIX_SECONDS = 6; +const unsigned int TEN_SECONDS = 10; +const unsigned int FIFTEEN_SECONDS = 15; +const unsigned int TWENTY_SECONDS = 20; +const unsigned int THIRTY_SECONDS = 30; +const unsigned int FORTY_SECONDS = 40; +const unsigned int SIXTY_SECONDS = 60; +const unsigned int ONE_HUNDRED_SECONDS = 100; +const unsigned int TWO_HUNDREDS_SECONDS = 200; +const unsigned int THREE_HUNDREDS_SECONDS = 300; +const unsigned int FOUR_HUNDREDS_SECONDS = 400; +const unsigned int FIVE_HUNDREDS_SECONDS = 500; +const unsigned int SIX_HUNDREDS_SECONDS = 600; +const unsigned int SEVEN_HUNDREDS_SECONDS = 700; +const unsigned int EIGHT_HUNDREDS_SECONDS = 800; +const unsigned int TEN_HUNDREDS_SECONDS = 1000; +const unsigned int ONE_FIVE_ZERO_ZERO_SECONDS = 1500; +const unsigned int SIXTEEN_HUNDREDS_SECONDS = 1600; +const unsigned int EIGHTEEN_HUNDREDS_SECONDS = 1800; +const unsigned int TWENTY_HUNDREDS_SECONDS = 2000; +const unsigned int THREE_THOUSANDS_SECONDS = 3000; +const unsigned int THREE_SIX_ZERO_ZERO_SECONDS = 3600; +const unsigned int EIGHT_THOUSANDS_SECONDS = 8000; +const unsigned int TEN_THOUSANDS_SECONDS = 10000; +const unsigned int WAIT_FOR_LONG_TIME = 15000; +const unsigned int WAIT_FOR_FIFTY_MS = 50000; +const unsigned int WAIT_FOR_LAST_SYNC = 500000; +const unsigned int WAIT_FOR_TWO_HUNDREDS_MS = 200000; +const int FIFTY_MILI_SECONDS = 50; +const int HUNDRED_MILLI_SECONDS = 100; +const static int MILLSECONDS_PER_SECOND = 1000; + +// ************************ length of key class ************************** +const static int KEY_SIX_BYTE = 6; +const static int KEY_EIGHT_BYTE = 8; +const static int KEY_THIRTYTWO_BYTE = 32; +const static int KEY_SIXTYFOUR_BYTE = 64; +const static int KEY_TWO_FIVE_SIX_BYTE = 256; +const static int KEY_ONE_K_BYTE = 1024; +const static int KEY_ONE_HUNDRED_BYTE = 100; + +// ************************ length of value class ************************** +const unsigned int SMALL_VALUE_SIZE = 2; +const unsigned int ONE_K_LONG_STRING = 1024; // 1K +const unsigned int TWO_K_LONG_STRING = 2048; // 2K +const unsigned int TWO_POINT_FOUR_LONG = 2400; // 2.4K +const unsigned int THREE_K_LONG_STRING = 3072; // 3K +const unsigned int FOUR_K_LONG_STRING = 4096; // 4K +const unsigned int ONE_M_LONG_STRING = 1048576; // 1M +const unsigned int TWO_M_LONG_STRING = 2097152; // 2M +const unsigned int FOUR_M_LONG_STRING = 4194304; // 4M +const unsigned int TEN_M_LONG_STRING = 10485760; // 10M +const static int VALUE_SIX_BYTE = 6; +const static int VALUE_ONE_HUNDRED_BYTE = 100; +const static int VALUE_FIVE_HUNDRED_BYTE = 500; +const static int VALUE_ONE_K_BYTE = 1024; +const static int VALUE_HUNDRED_K_BYTE = 102400; +const static int VALUE_TWENTY_K_BYTE = 20480; +const static int VALUE_TWO_POINT_FOUR_K_BYTE = 2458; +const static int PASSWD_BYTE = 129; + +// ************************ bool class ************************************* +const bool IS_LOCAL_ONLY = true; +const bool IS_NOT_LOCAL_ONLY = false; +const bool IS_NEED_CREATE = true; +const bool IS_NOT_NEED_CREATE = false; + +// ************************ range verify class ***************************** +const static int CHANGED_ZERO_TIME = 0; +const static int CHANGED_ONE_TIME = 1; +const static int CHANGED_TWO_TIMES = 2; +const static int CHANGED_THREE_TIMES = 3; +const static int CHANGED_ONE_HUNDRED_TIMES = 100; +const static int CHANGED_TWO_HUNDRED_TIMES = 200; +const static int CHANGED_TWO_FIVE_SIX_TIMES = 256; +const static int CHANGED_ONE_THOUSAND_TIMES = 1000; +const static int CHANGED_TEN_THOUSAND_TIMES = 10000; +const unsigned int RECORDS_NUM_START = 1; +const unsigned int RECORDS_NUM_END = 128; +const unsigned int DEFAULT_START = 1; +const unsigned int DEFAULT_ANOTHER_START = 11; +const unsigned int OBSERVER_CNT_START = 0; +const unsigned int OBSERVER_CNT_END = 8; +const unsigned int NB_OBSERVER_CNT_START = 0; +const unsigned int NB_OBSERVER_CNT_END = 4; +const unsigned int NB_OPERATION_CNT_START = 0; +const unsigned int NB_OPERATION_CNT_END = 5; + +const int LOCAL_OPER_CNT = 2; +const int NATIVE_OPER_CNT = 6; +const static int OPER_CNT_START = 0; +const static int OPER_CNT_END = 10; +const static int MODE_RAND_MIN = 0; +const static int MODE_RAND_MAX = 2; + +// ************************ USED FOR THREAD ******************************** +const unsigned int SINGLE_THREAD_NUM = 2; +const unsigned int CHAR_SPAN_MIN = 0; +const unsigned int CHAR_SPAN_MAX = 255; + +// ************************ USED FOR INDEX ********************************* +const int INDEX_ZEROTH = 0; +const int INDEX_FIRST = 1; +const int INDEX_SECOND = 2; +const int INDEX_THIRD = 3; +const int INDEX_FORTH = 4; +const int INDEX_FIFTH = 5; +const int INDEX_SIXTH = 6; +const int INDEX_SEVENTH = 7; +const int INDEX_EIGHTTH = 8; +const int INDEX_NINTH = 9; +const int INDEX_TENTH = 10; +const int INDEX_NINE_NINE_NINTH = 999; +const int INDEX_FIVE_THOUSANDS = 5000; +const int INDEX_TEN_THOUSANDS = 10000; +const int INDEX_FIFTEEN_THOUSANDS = 15000; + +// ************************ OTHER CLASS ************************************ +const int TABLE_MAX = 60; + +const static int ENCRYPT_COUNT = 100; + +const static int EVEN_NUMBER = 2; + +const int VALUE_FIVE_HUNDRED = 500; +const int VALUE_SUM = VALUE_FIVE_HUNDRED + VALUE_FIVE_HUNDRED; +const int VALUE_CHANGE1_FIRST = 400; +const int VALUE_CHANGE1_SECOND = VALUE_SUM - VALUE_CHANGE1_FIRST; +const int VALUE_CHANGE2_FIRST = 700; +const int VALUE_CHANGE2_SECOND = VALUE_SUM - VALUE_CHANGE2_FIRST; + +const static std::string MULTIDB = "/multi_ver/value_storage.db"; +const static std::string KVMULTIDB = "/multi_ver/multi_ver_data.db"; +const static std::string SYNC_MULTI_VER_QUERY_SQL = "select count(*) from version_data;"; +const static std::string DATABASE_INFOR_FILE = "/single_ver/main/gen_natural_store.db"; +const static std::string SYNC_VALUE_SLICE_QUERY_SQL = "select count(*) from data;"; +const static std::string QUERY_SQL = "select count(*) from version_data where key = ?;"; +const static std::string MULTI_KEY_QUERY_SQL = "select count(*) from version_data where key = ? or key = ?;"; + +typedef std::chrono::time_point microClock_type; + +// place some const values for testcases in namespace. +namespace DistributedDBDataGenerator { +const std::string STORE_ID = ""; +const std::string STORE_ID_1 = "STORE_ID_1"; +const std::string STORE_ID_2 = "STORE_ID_2"; +const std::string STORE_ID_3 = "STORE_ID_3"; +const std::string STORE_ID_4 = "STORE_ID_4"; +const std::string STORE_ID_5 = "STORE_ID_5"; +const std::string STORE_ID_6 = "STORE_ID_6"; +const std::string STORE_ID_7 = "STORE_ID_7"; +const std::string STORE_ID_8 = "STORE_ID_8"; +const std::string STORE_ID_9 = "STORE_ID_9"; +const std::string STORE_ID_10 = "STORE_ID_10"; +const std::string JSON_SCHEMA_STORE_ID_11 = "JSON_SCHEMA_STORE_ID_11"; +const std::string STORE_ID_PERFORM = "STORE_ID_PERFORM"; +const static std::string STORE_ID_SYNC_1 = "SYNC1"; +const static std::string STORE_ID_SYNC_2 = "SYNC2"; +const static std::string STORE_ID_SYNC_3 = "SYNC3"; +const static std::string STORE_ID_SYNC_4 = "SYNC4"; +const static std::string STORE_ID_SYNC_5 = "SYNC5"; +const static std::string STORE_ID_SYNC_6 = "SYNC6"; +const static std::string STORE_ID_SYNC_7 = "SYNC7"; +const static std::string STORE_ID_SYNC_8 = "SYNC8"; +const static std::string STORE_ID_SYNC_9 = "SYNC9"; +const static std::string STORE_ID_SYNC_10 = "SYNC10"; + +const std::string APP_ID = "APP_ID"; +const std::string APP_ID_1 = "APP_ID_1"; +const std::string APP_ID_2 = "APP_ID_2"; +const std::string APP_ID_3 = "APP_ID_3"; +const std::string APP_ID_4 = "APP_ID_4"; +const std::string APP_ID_5 = "APP_ID_5"; +const std::string APP_ID_6 = "APP_ID_6"; +const std::string APP_ID_PERFORM = "APP_ID_PERFORM"; +const std::string APP_ID_NB_1 = "APP_ID_NB_1"; +const std::string APP_ID_NB_2 = "APP_ID_NB_2"; +const std::string APP_ID_LOCAL_1 = "APP_ID_LOCAL_1"; + +const std::string USER_ID = "USER_ID"; +const std::string USER_ID_1 = "USER_ID_1"; +const std::string USER_ID_2 = "USER_ID_2"; +const std::string USER_ID_3 = "USER_ID_3"; +const std::string USER_ID_4 = "USER_ID_4"; +const std::string USER_ID_5 = "USER_ID_5"; +const std::string USER_ID_6 = "USER_ID_6"; +const std::string USER_ID_PERFORM = "USER_ID_PERFORM"; + +const std::vector K1_HASH_KEY = { 0xA2, 0xAB, 0x19, 0x59, 0xC1, 0xC3, 0xBF, 0xA2, 0x95, 0xB0, 0xFC, 0x90, + 0x19, 0x93, 0x78, 0x27, 0x2D, 0xB7, 0x6B, 0x45}; +const std::vector K2_HASH_KEY = { 0xBF, 0xEB, 0x73, 0x4D, 0x2E, 0xB5, 0xD0, 0x91, 0x51, 0x45, 0xC1, 0x86, + 0x12, 0x48, 0x75, 0x7D, 0x4F, 0xD3, 0x2B, 0xC2 }; +const std::vector K3_HASH_KEY = { 0xB5, 0x32, 0xA5, 0x44, 0x0D, 0xD8, 0x42, 0x2D, 0x9D, 0x5F, 0x8D, 0x99, + 0x9B, 0x31, 0x06, 0x87, 0xD4, 0xA2, 0xFE, 0xD9 }; +const std::vector K4_HASH_KEY = { 0x5E, 0xF8, 0x76, 0x6D, 0xE9, 0x35, 0x32, 0x44, 0x24, 0xB5, 0x63, 0xAA, + 0x3E, 0xB0, 0xC7, 0x46, 0x6B, 0x29, 0x3C, 0x94 }; +const std::vector NULL_HASH_KEY = {}; +const DistributedDB::Key KEY_1 = { 'k', '1' }; +const DistributedDB::Key KEY_2 = { 'k', '2' }; +const DistributedDB::Key KEY_3 = { 'k', '3' }; +const DistributedDB::Key KEY_4 = { 'k', '4' }; +const DistributedDB::Key KEY_5 = { 'k', '5' }; +const DistributedDB::Key KEY_6 = { 'k', '6' }; +const DistributedDB::Key KEY_7 = { 'k', '7' }; +const DistributedDB::Key KEY_8 = { 'k', '8' }; +const DistributedDB::Key KEY_9 = { 'k', '9' }; +const DistributedDB::Key KEY_10 = { 'k', '1', '0' }; +const DistributedDB::Key KEY_6_BYTE = { 'k', 'k', 'k', 'k', 'k', '1' }; +const DistributedDB::Key KEY_A_1 = { 'a', 'b', 'c' }; +const DistributedDB::Key KEY_A_2 = { 'a', 'b', 'c', 'd', 'a', 's', 'd' }; +const DistributedDB::Key KEY_A_3 = { 'a', 'b', 'c', 'd', 's' }; +const DistributedDB::Key KEY_BIG_1 = { 'b', 'i', 'g', '1' }; + +const std::vector NULL_K1 = {}; +const DistributedDB::Key KEY_EMPTY = { }; +const DistributedDB::Key KEY_K = { 'k' }; +const DistributedDB::Key KEY_A = { 'a' }; +const DistributedDB::Key KEY_E = { 'k', 'e' }; +const DistributedDB::Key OK_KEY_1 = { 'o', 'k' }; + +const DistributedDB::Value VALUE_1 = { 'v', '1' }; +const DistributedDB::Value VALUE_2 = { 'v', '2' }; +const DistributedDB::Value VALUE_3 = { 'v', '3' }; +const DistributedDB::Value VALUE_4 = { 'v', '4' }; +const DistributedDB::Value VALUE_5 = { 'v', '5' }; +const DistributedDB::Value VALUE_6 = { 'v', '6' }; +const DistributedDB::Value VALUE_7 = { 'v', '7' }; +const DistributedDB::Value VALUE_8 = { 'v', '8' }; +const DistributedDB::Value VALUE_9 = { 'v', '9' }; +const DistributedDB::Value VALUE_10 = { 'v', '1', '0' }; +const DistributedDB::Value VALUE_A_1 = { 'a', '1' }; +const DistributedDB::Value VALUE_A_2 = { 'a', '2' }; +const DistributedDB::Value VALUE_A_3 = { 'a', '3' }; +const DistributedDB::Value VALUE_EMPTY = { }; +const DistributedDB::Value OK_VALUE_1 = { 'o', 'k' }; + +const std::vector IMAGE_KEY_PRE = {'a', 'l', 'b', 'u', 'm', '_'}; +const std::vector IMAGE_FILE_KEY_PRE = {'f', 'i', 'l', 'e', '_'}; +const std::string IMAGE_VALUE_PRE = {"\"_id\":23,\"local_media_id\":0," \ + "\"_data\":\"/storage/emulated/0/Pictures/.Gallery2/recycle/GF6DA7BR\"," \ + "\"_size\":427460,\"date_added\":1518606965,\"date_modified\":1519460678," \ + "\"mime_type\":\"image/jpeg\",\"title\":\"MagazinePic-05-2.3.001-bigpicture_05_4\"," \ + "\"description\":\"\",\"_display_name\":\"MagazinePic-05-2.3.001-bigpicture_05_4.jpg\"," \ + "\"orientation\":0,\"latitude\":0,\"longitude\":0,\"datetaken\":1514792938000," \ + "\"bucket_id\":771419238,\"bucket_display_name\":\"MagazineUnlock\",\"duration\":0," \ + "\"resolution\":\"1440x2560\",\"media_type\":1,\"storage_id\":65537,\"width\":1440," \ + "\"height\":2560,\"is_hdr\":0,\"is_hw_privacy\":0,\"hw_voice_offset\":0,\"is_hw_favorite\":0," \ + "\"hw_image_refocus\":0,\"is_hw_burst\":0,\"hw_rectify_offset\":0,\"contenturi\":\"\"," \ + "\"hash\":\"e46cf1bb4773421fbded2e2583fe7130\",\"special_file_list\":0,\"special_file_type\":0," \ + "\"special_file_offset\":0,\"relative_bucket_id\":1793967153,\"albumId\":\"default-album-3\",\"fileType\":1," \ + "\"fileId\":0,\"videoThumbId\":0,\"thumbId\":0,\"lcdThumbId\":0,\"thumbType\":3,\"localThumbPath\":\"\"," \ + "\"localBigThumbPath\":\"\",\"expand\":\"\",\"showDateToken\":1514792938000,\"visit_time\":0," \ + "\"last_update_time\":1519461225861,\"source\":\"\",\"geo_code\":0,\"location_key\":104473884060," \ + "\"story_id\":0,\"story_cluster_state\":\"todo\",\"search_data_status\":0,\"category_id\":-2," \ + "\"portrait_id\":0,\"portrait_cluster_state\":\"todo\",\"dirty\":0,\"recycleFlag\":2," \ + "\"recycledTime\":1519550100614,\"sourcePath\":\"/storage/emulated/0/MagazineUnlock/MagazinePic\"," \ + "\"sourceFileName\":\"MagazinePic-05-2.3.001-bigpict\",\"garbage\":0,\"uniqueId\":0,\"localKey\":\"\"," \ + "\"picture_score\":99,\"cam_perception\":\"\",\"cam_exif_flag\":1,\"sync_status\":0," \ + "\"album_name\":\".MagazineUnlock\",\"ocr_status\":0"}; + +const DistributedDB::Key KEY_SEARCH_0 = KEY_A; +const DistributedDB::Key KEY_SEARCH = { 'a', 'b' }; +const DistributedDB::Key KEY_SEARCH_2 = { 'a', 'b', 'c', 'd', 'e' }; +const std::vector K_SEARCH_3 = { 'b', 'i', 'g'}; +const DistributedDB::Key KEY_SEARCH_3 = { 'b', 'i', 'g'}; +const DistributedDB::Key KEY_SEARCH_4 = { 'k' }; +const std::vector K_SEARCH_5 = { 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k' }; +const DistributedDB::Key KEY_SEARCH_6 = { 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', 'k', '6' }; +const DistributedDB::Key PERFORMANCEKEY = { 'p', 'e', 'r' }; +const DistributedDB::Key KEY_CONS_1 = { 'c', 'o', 'n', 's', '1' }; +const DistributedDB::Key KEY_CONS_2 = { 'c', 'o', 'n', 's', '2' }; +const DistributedDB::Key KEY_BATCH_CONS_1 = { 'r', 'e', 's', 'u', 'l', 't', '1' }; +const DistributedDB::Key KEY_BATCH_CONS_2 = { 'r', 'e', 's', 'u', 'l', 't', '2' }; +const DistributedDB::Key KEY_BATCH_CONS_3 = { 'r', 'e', 's', 'u', 'l', 't', '3' }; +const std::vector KEYS_1 = { KEY_1, KEY_2 }; +const DistributedDB::Entry ENTRY_1 = { .key = KEY_1, .value = VALUE_1 }; +const DistributedDB::Entry ENTRY_2 = { .key = KEY_2, .value = VALUE_2 }; +const DistributedDB::Entry ENTRY_3 = { .key = KEY_3, .value = VALUE_3 }; +const DistributedDB::Entry ENTRY_4 = { .key = KEY_4, .value = VALUE_4 }; +const DistributedDB::Entry ENTRY_5 = { .key = KEY_5, .value = VALUE_5 }; +const DistributedDB::Entry ENTRY_6 = { .key = KEY_6, .value = VALUE_6 }; +const DistributedDB::Entry ENTRY_7 = { .key = KEY_7, .value = VALUE_7 }; +const DistributedDB::Entry ENTRY_8 = { .key = KEY_8, .value = VALUE_8 }; +const DistributedDB::Entry ENTRY_9 = { .key = KEY_9, .value = VALUE_9 }; +const DistributedDB::Entry ENTRY_10 = { .key = KEY_10, .value = VALUE_10 }; +const DistributedDB::Entry ENTRY_1_2 = { .key = KEY_1, .value = VALUE_2 }; +const DistributedDB::Entry ENTRY_2_3 = { .key = KEY_2, .value = VALUE_3 }; +const DistributedDB::Entry ENTRY_3_1 = { .key = KEY_3, .value = VALUE_1 }; +const DistributedDB::Entry ENTRY_4_5 = { .key = KEY_4, .value = VALUE_5 }; +const DistributedDB::Entry ENTRY_5_6 = { .key = KEY_5, .value = VALUE_6 }; +const DistributedDB::Entry ENTRY_2_1 = { .key = KEY_2, .value = VALUE_1 }; +const DistributedDB::Entry ENTRY_1_3 = { .key = KEY_1, .value = VALUE_3 }; +const DistributedDB::Entry ENTRY_2_4 = { .key = KEY_2, .value = VALUE_4 }; +const DistributedDB::Entry ENTRY_1_4 = { .key = KEY_1, .value = VALUE_4 }; +const DistributedDB::Entry ENTRY_3_4 = { .key = KEY_3, .value = VALUE_4 }; +const DistributedDB::Entry ENTRY_1_NULL = { .key = KEY_1, .value = VALUE_EMPTY }; +const DistributedDB::Entry ENTRY_2_NULL = { .key = KEY_2, .value = VALUE_EMPTY }; +const DistributedDB::Entry ENTRY_3_NULL = { .key = KEY_3, .value = VALUE_EMPTY }; +const DistributedDB::Entry ENTRY_NULL_1 = { .key = KEY_EMPTY, .value = VALUE_2 }; +const DistributedDB::Entry ENTRY_NULL_2 = { .key = KEY_EMPTY, .value = VALUE_3 }; +const DistributedDB::Entry ENTRY_NULL_3 = { .key = KEY_EMPTY, .value = VALUE_1 }; +const DistributedDB::Entry ENTRY_NULL = { .key = KEY_EMPTY, .value = VALUE_EMPTY }; +const DistributedDB::Entry ENTRY_A_1 = { .key = KEY_A_1, .value = VALUE_A_1 }; +const DistributedDB::Entry ENTRY_A_2 = { .key = KEY_A_2, .value = VALUE_A_2 }; +const DistributedDB::Entry ENTRY_A_3 = { .key = KEY_A_3, .value = VALUE_A_3 }; +const DistributedDB::Entry ENTRY_A_1_2 = { .key = KEY_A_1, .value = VALUE_A_2 }; +const DistributedDB::Entry ENTRY_A_2_3 = { .key = KEY_A_2, .value = VALUE_A_3 }; +const DistributedDB::Entry ENTRY_A_3_1 = { .key = KEY_A_3, .value = VALUE_A_1 }; + +const DistributedDB::CipherPassword NULL_PASSWD; +const std::vector NULL_PASSWD_VECTOR = {}; +const std::vector PASSWD_VECTOR_1 = {'P', 'a', 's', 's', 'w', 'o', 'r', 'd', '@', '1', '2', '3'}; +const std::vector PASSWD_VECTOR_2 = {'P', 'a', 's', 's', 'w', 'o', 'r', 'd', '@', 'c', 'o', 'm'}; +const std::vector FILE_PASSWD_VECTOR_1 = {'F', 'i', 'l', 'e', 'p', 'a', 's', 's', 'w', 'd', '1'}; +const std::vector FILE_PASSWD_VECTOR_2 = {'F', 'i', 'l', 'e', 'p', 'a', 's', 's', 'w', 'd', '2'}; + +void GenerateRecord(unsigned int keyNo, DistributedDB::Entry &entry, std::vector keyPrifix = { 'k' }); + +void GenerateCharSet(std::vector &charSet); + +void GenerateAlphaNumUnderlineCharSet(std::vector &charSet); + +void GenerateSpecialCharSet(std::vector &charSet); + +void GenerateFixedLenRandString(unsigned int neededLen, RandType randType, std::string &genString); + +void GenerateRandRecord(DistributedDB::Entry &entry, EntrySize &entrySize, unsigned int keyNo); + +void GenerateRecords(unsigned int recordNum, unsigned int start, + std::vector &allKeys, std::vector &entriesBatch, + std::vector keyPrifix = { 'k' }); +void GenerateMaxBigRecord(unsigned int keyNo, DistributedDB::Entry &entry, + const std::vector &keyPrefix, unsigned int num); +bool GenerateMaxBigRecords(unsigned int recordNum, unsigned int start, + std::vector &allKeys, std::vector &entriesBatch); + +void GenerateTenThousandRecords(unsigned int recordNum, unsigned int start, + std::vector &allKeys, std::vector &entriesBatch); + +void GenerateNormalAsciiRecords(DistributedDB::Entry &entry); + +void GenerateFullAsciiRecords(DistributedDB::Entry &entry); + +void GenerateBiggistKeyRecords(DistributedDB::Entry &entry); + +DistributedDB::Entry GenerateFixedLenKVRecord(unsigned int serialNo, + unsigned int keyLen, uint8_t keyFilledChr, unsigned int valueLen, uint8_t valueFilledChr); + +void GenerateFixedRecords(std::vector &entries, std::vector &allKeys, + int recordNum, unsigned int keySize, unsigned int valSize); + +void GenerateOneRecordForImage(int entryNo, const EntrySize &entrySize, + const std::vector &keyPrefix, const std::vector &val, DistributedDB::Entry &entry); +void GenerateRecordsForImage(std::vector &entries, EntrySize &entrySize, + int num, std::vector keyPrefix = {'k'}, std::vector val = {'v'}); + +void GenerateAppointPrefixAndSizeRecord(int recordNo, const EntrySize &entrySize, + const std::vector &keyPrefix, const std::vector &valPrefix, DistributedDB::Entry &entry); +void GenerateAppointPrefixAndSizeRecords(std::vector &entries, const EntrySize &entrySize, + int num, const std::vector &keyPrefix = {'k'}, const std::vector &valPrefix = {'v'}); +void GenerateAppointPrefixAndSizeRecords(std::vector &entries, int startpoint, + const NumberSize param, const std::vector &keyPrefix = {'k'}, + const std::vector &valPrefix = {'v'}); + +int GetRandInt(const int randMin, const int randMax); + +void GenerateFixedLenRandRecords(std::vector &entries, std::vector &allKeys, + int recordNum, unsigned int keySize, unsigned int valSize); +std::vector GenerateFixedLenRandRecords(std::vector &allKeys, + int recordNum, const EntrySize &entrySize, const std::vector &keyPrefix = {'k'}, + const std::vector &valPrefix = {'v'}); + +const std::string GetDbType(const int type); +void GenerateRandomRecords(std::vector &entries, EntrySize &entrySize, int num); +void GetLongSchemaDefine(LongDefine ¶m, std::string &longDefine); +const std::string SpliceToSchema(const std::string &version, const std::string &mode, + const std::string &define, const std::string &index = "", const std::string &skipSize = ""); +std::vector GetValidSchema(Schema &validSchema, bool hasIndex); +std::map> GetInvalidSchema(Schema &invalidSchema, Schema &validSchema, bool hasIndex); +} // DistributedDBDataGenerator +#endif // DISTRIBUTED_DB_MODULE_TEST_TYPES_H diff --git a/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_log_print.h b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_log_print.h new file mode 100644 index 00000000..7f8a56d2 --- /dev/null +++ b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_log_print.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef DISTRIBUTED_DB_LOG_PRINT_H +#define DISTRIBUTED_DB_LOG_PRINT_H + +#if defined _WIN32 + #ifndef RUNNING_ON_WIN + #define RUNNING_ON_WIN + #endif +#else + #ifndef RUNNING_ON_LINUX + #define RUNNING_ON_LINUX + #endif +#endif + +#include "hilog/log.h" + +static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, 0xD001630, "DistributedDB[TEST]" }; +#define MST_LOG(fmt, ...) \ + OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, "%s: " fmt, __FUNCTION__, ##__VA_ARGS__) +#endif diff --git a/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_nb_test_tools.h b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_nb_test_tools.h new file mode 100644 index 00000000..b75b7086 --- /dev/null +++ b/kv_store/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_nb_test_tools.h @@ -0,0 +1,356 @@ +/* + * 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. + */ +#ifndef DISTRIBUTEDDB_NB_TEST_TOOLS_H +#define DISTRIBUTEDDB_NB_TEST_TOOLS_H + +#include "kv_store_delegate.h" +#include "kv_store_delegate_manager.h" +#include "kv_store_nb_delegate.h" +#include "kv_store_observer.h" +#ifdef RELEASE_MODE_V2 +#include "query.h" +#endif +#include "distributeddb_data_generator.h" +#include "distributed_test_tools.h" + +struct DBParameters { + std::string storeId; + std::string appId; + std::string userId; + DBParameters(std::string storeIdStr, std::string appIdStr, std::string userIdStr) + : storeId(storeIdStr), appId(appIdStr), userId(userIdStr) + { + } +}; + +struct Option { + bool createIfNecessary = true; + bool isMemoryDb = false; // true represents using a memory database + bool isEncryptedDb = false; // whether need encrypt + DistributedDB::CipherType cipher = DistributedDB::CipherType::DEFAULT; // cipher type + std::vector passwd; // cipher password +#ifdef RELEASE_MODE_V2 + std::string schema; + bool createDirByStoreIdOnly = false; +#endif // endif of RELEASE_MODE_V2 +#ifdef RELEASE_MODE_V3 + DistributedDB::SecurityOption secOption; + DistributedDB::KvStoreObserver *observer = nullptr; + DistributedDB::Key key; + unsigned int mode = 0; + int conflictType = 0; + DistributedDB::KvStoreNbConflictNotifier notifier = nullptr; + int conflictResolvePolicy = DistributedDB::LAST_WIN; + bool isNeedIntegrityCheck = false; + bool isNeedRmCorruptedDb = false; + bool isNeedCompressOnSync = false; + uint8_t compressionRate = 100; // default compression rate 100%, that means not compressing +#endif // end of RELEASE_MODE_V3 + Option(bool createIfNecessary, bool isMemoryDb, bool isEncryptedDb, DistributedDB::CipherType cipher, + std::vector passwd) + : createIfNecessary(createIfNecessary), isMemoryDb(isMemoryDb), isEncryptedDb(isEncryptedDb), + cipher(cipher), passwd(passwd) + { + } +#ifdef RELEASE_MODE_V3 + Option(bool createIfNecessary, bool isMemoryDb, bool isEncryptedDb, const DistributedDB::CipherType &cipher, + const std::vector &passwd, const DistributedDB::SecurityOption &secOption, + DistributedDB::KvStoreObserver *observer, const DistributedDB::KvStoreNbConflictNotifier ¬ifier) + : createIfNecessary(createIfNecessary), isMemoryDb(isMemoryDb), isEncryptedDb(isEncryptedDb), + cipher(cipher), passwd(passwd), secOption(secOption), observer(observer), notifier(notifier) + { + } +#endif // endif of RELEASE_MODE_V3 + Option() + {} +}; + +struct ConflictData { + DistributedDB::KvStoreNbConflictType type; + DistributedDB::Key key; + DistributedDB::Value oldValue; + DistributedDB::Value newValue; + bool oldIsDeleted = false; + bool newIsDeleted = false; + bool oldIsNative = false; + bool newIsNative = false; +}; + +enum EntryType { + INSERT_LOCAL = 0, + INSERT_NATIVE = 1, + DELETE_LOCAL = 2, + DELETE_NATIVE = 3, + UPDATE_LOCAL = 4, + UPDATE_NATIVE = 5 +}; + +enum class ReadOrWriteTag { + READ = 0, + WRITE = 1, + DELETE = 2, + REGISTER = 3 +}; + +const static DBParameters g_dbParameter1(DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); +const static DBParameters g_dbParameter2(DistributedDBDataGenerator::STORE_ID_2, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_2); +const static DBParameters g_dbParameter3(DistributedDBDataGenerator::STORE_ID_3, + DistributedDBDataGenerator::APP_ID_3, DistributedDBDataGenerator::USER_ID_3); +const static DBParameters g_dbParameter4(DistributedDBDataGenerator::STORE_ID_4, + DistributedDBDataGenerator::APP_ID_4, DistributedDBDataGenerator::USER_ID_4); +const static DBParameters g_dbParameter5(DistributedDBDataGenerator::STORE_ID_5, + DistributedDBDataGenerator::APP_ID_5, DistributedDBDataGenerator::USER_ID_5); +const static DBParameters g_dbParameter6(DistributedDBDataGenerator::STORE_ID_6, + DistributedDBDataGenerator::APP_ID_6, DistributedDBDataGenerator::USER_ID_6); +const static DBParameters g_dbParameter2_1(DistributedDBDataGenerator::STORE_ID_2, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); +const static DBParameters DB_PARAMETER_0_1(DistributedDBDataGenerator::STORE_ID, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_1); +const static DBParameters g_dbParameter1_2_1(DistributedDBDataGenerator::STORE_ID_1, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_1); +const static DBParameters g_dbParameter2_1_2(DistributedDBDataGenerator::STORE_ID_2, + DistributedDBDataGenerator::APP_ID_1, DistributedDBDataGenerator::USER_ID_2); +const static DBParameters g_dbParameter3_2_1(DistributedDBDataGenerator::STORE_ID_3, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_1); +const static DBParameters g_dbParameter4_2_2(DistributedDBDataGenerator::STORE_ID_4, + DistributedDBDataGenerator::APP_ID_2, DistributedDBDataGenerator::USER_ID_2); +const static Option g_createDiskUnencrypted(true, false, false, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::NULL_PASSWD_VECTOR); +const static Option g_createDiskEncrypted(true, false, true, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::PASSWD_VECTOR_1); +const static Option g_ncreateDiskUnencrypted(false, false, false, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::NULL_PASSWD_VECTOR); +const static Option g_ncreateDiskEncrypted(false, false, true, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::PASSWD_VECTOR_1); +const static Option g_createMemUnencrypted(true, true, false, DistributedDB::CipherType::DEFAULT, + DistributedDBDataGenerator::NULL_PASSWD_VECTOR); +static Option g_option = g_createDiskUnencrypted; +const std::vector