From a4bd62a2176d1438211fc3d006f0debea9e4053e Mon Sep 17 00:00:00 2001 From: wuxiaodan Date: Fri, 23 Feb 2024 10:25:50 +0800 Subject: [PATCH] 223 dcts Signed-off-by: wuxiaodan --- .../test/KvStoreSecurityLevelS1Jsunit.test.js | 199 ++++++++++++++++++ .../main/resources/base/element/string.json | 2 +- testtools/disjsTest/server/testApi.js | 19 ++ 3 files changed, 219 insertions(+), 1 deletion(-) diff --git a/distributeddatamgr/jstest/distributed_kv_store/client/hap/src/main/js/test/KvStoreSecurityLevelS1Jsunit.test.js b/distributeddatamgr/jstest/distributed_kv_store/client/hap/src/main/js/test/KvStoreSecurityLevelS1Jsunit.test.js index 47efb1f..0a3271d 100644 --- a/distributeddatamgr/jstest/distributed_kv_store/client/hap/src/main/js/test/KvStoreSecurityLevelS1Jsunit.test.js +++ b/distributeddatamgr/jstest/distributed_kv_store/client/hap/src/main/js/test/KvStoreSecurityLevelS1Jsunit.test.js @@ -4414,5 +4414,204 @@ export default function kvSyncTestS1() { kvStore.sync(syncDeviceIds, PUSH_PULL); await sleep(600); }) + + + /** + * @tc.number SUB_DISTRIBUTEDDATAMGR_SINGLEKVSTORE_SYNCSCHEMA_0100 + * @tc.name testSyncSchema0100 + * @tc.desc Server kvStore security is S1,client kvStore security is S1, prefixKey("test_"), PULL + * @tc.level: Level 2 + * @tc.type: Functiontion + * @tc.size: MediumTest + */ + it("testSyncSchema0100", 0, async function (done) { + console.info(logTag + "testSyncSchema0100 start"); + + let options = { + createIfMissing: true, + encrypt: false, + backup: false, + autoSync: false, + kvStoreType: factory.KVStoreType.SINGLE_VERSION, + schema: {}, + securityLevel: factory.SecurityLevel.S1, + } + + let name = new factory.FieldNode('name'); + name.type = factory.ValueType.INTEGER; + name.nullable = false; + name.default = 0; + + let schema = new factory.Schema(); + schema.root.appendChild(name); + schema.indexes = ['$.name']; + schema.mode = 1; + + let TEST_SCHEMA_STORE_ID = "SchemaStoreId_0100"; + let TEST_SCHEMA_STORE_ID_PREF = "SchemaStoreId_"; + let schemaIdPref = TEST_SCHEMA_STORE_ID.substring(0, 14); + console.info(logTag + "testSyncSchema0100 schemaIdPref=" + schemaIdPref); + if (schemaIdPref == TEST_SCHEMA_STORE_ID_PREF) { + options.schema = schema; + } + console.info(logTag + "testSyncSchema0100 options.schema=" + options.schema); + + await remoteHelpers.getKvStore(TEST_SCHEMA_STORE_ID, "S1", false); + await sleep(1000); + + await kvManager.getKVStore(TEST_SCHEMA_STORE_ID, options).then((store) => { + kvStore = store; + console.info(logTag + "testSyncSchema0100 getKVStore success. kvStore=" + kvStore); + expect(store != null).assertTrue(); + }).catch((err) => { + console.info(logTag + 'testSyncSchema0100 getKVStore fail. error= ' + error.code + error.message); + expect(null).assertFail(); + }); + + let schemaKey = "test_key_1"; + let schemaValue = '{"name":1}'; + + let result = undefined; + await remoteHelpers.kvPut(schemaKey, schemaValue, "String"); + await sleep(1000); + console.info(logTag + "testSyncSchema0100 Client sync start"); + + const query = new factory.Query(); + query.prefixKey("test_"); + kvStore.sync(syncDeviceIds, query, PULL, 1000); + await sleep(1000); + + await kvStore.get(schemaKey, (err, data) => { + try { + console.info(logTag + "testSyncSchema0100 get data,key is " + schemaKey); + if (err != null) { + console.info(logTag + "testSyncSchema0100 get data error,err: " + err); + } else { + console.info(logTag + "testSyncSchema0100 get data success,result is: " + data); + result = data; + } + console.info(logTag + "testSyncSchema0100 get data finish,result is: " + result); + expect(result).assertEqual(schemaValue); + console.info(logTag + "testSyncSchema0100 end"); + } catch (err) { + console.error('testSyncSchema0100 catch get err:' + `, error code is ${err.code}, message is ${err.message}`); + } + + }) + await sleep(1000); + + await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_SCHEMA_STORE_ID, kvStore, async function () { + console.info(logTag + 'testSyncSchema0100 CLIENT closeKVStore success'); + await kvManager.deleteKVStore(TEST_BUNDLE_NAME, TEST_SCHEMA_STORE_ID, function () { + console.info(logTag + 'testSyncSchema0100 CLIENT deleteKVStore success'); + }); + }); + await remoteHelpers.closeKvStore(TEST_SCHEMA_STORE_ID).then(async (ret) => { + console.info(logTag + "testSyncSchema0100 REMOTE close server kvStore success: " + ret); + }) + await sleep(2000); + kvStore = null; + console.info(logTag + '-----------------testSyncSchema0100 end-----------------'); + done(); + }) + + /** + * @tc.number SUB_DISTRIBUTEDDATAMGR_SINGLEKVSTORE_SYNCSCHEMA_0200 + * @tc.name testSyncSchema0200 + * @tc.desc Server kvStore security is S1,client kvStore security is S1, prefixKey("test_"), PUSH_PULL + * @tc.level: Level 2 + * @tc.type: Functiontion + * @tc.size: MediumTest + */ + it("testSyncSchema0200", 0, async function (done) { + console.info(logTag + "testSyncSchema0200 start"); + + let options = { + createIfMissing: true, + encrypt: false, + backup: false, + autoSync: false, + kvStoreType: factory.KVStoreType.SINGLE_VERSION, + schema: {}, + securityLevel: factory.SecurityLevel.S1, + } + + let name = new factory.FieldNode('name'); + name.type = factory.ValueType.INTEGER; + name.nullable = false; + name.default = 0; + + let schema = new factory.Schema(); + schema.root.appendChild(name); + schema.indexes = ['$.name']; + schema.mode = 1; + + let TEST_SCHEMA_STORE_ID = "SchemaStoreId_0200"; + let TEST_SCHEMA_STORE_ID_PREF = "SchemaStoreId_"; + let schemaIdPref = TEST_SCHEMA_STORE_ID.substring(0, 14); + console.info(logTag + "testSyncSchema0200 schemaIdPref=" + schemaIdPref); + if (schemaIdPref == TEST_SCHEMA_STORE_ID_PREF) { + options.schema = schema; + } + console.info(logTag + "testSyncSchema0200 options.schema=" + options.schema); + + await remoteHelpers.getKvStore(TEST_SCHEMA_STORE_ID, "S1", false); + await sleep(1000); + + await kvManager.getKVStore(TEST_SCHEMA_STORE_ID, options).then((store) => { + kvStore = store; + console.info(logTag + "testSyncSchema0200 getKVStore success. kvStore=" + kvStore); + expect(store != null).assertTrue(); + }).catch((err) => { + console.info(logTag + 'testSyncSchema0200 getKVStore fail. error= ' + error.code + error.message); + expect(null).assertFail(); + }); + + let schemaKey = "test_key_1"; + let schemaValue = '{"name":1}'; + + let result = undefined; + await remoteHelpers.kvPut(schemaKey, schemaValue, "String"); + await sleep(1000); + console.info(logTag + "testSyncSchema0200 Client sync start"); + + const query = new factory.Query(); + query.prefixKey("test_"); + kvStore.sync(syncDeviceIds, query, PUSH_PULL, 1000); + await sleep(1000); + + await kvStore.get(schemaKey, (err, data) => { + try { + console.info(logTag + "testSyncSchema0200 get data,key is " + schemaKey); + if (err != null) { + console.info(logTag + "testSyncSchema0200 get data error,err: " + err); + } else { + console.info(logTag + "testSyncSchema0200 get data success,result is: " + data); + result = data; + } + console.info(logTag + "testSyncSchema0200 get data finish,result is: " + result); + expect(result).assertEqual(schemaValue); + console.info(logTag + "testSyncSchema0200 end"); + } catch (err) { + console.error('testSyncSchema0200 catch get err:' + `, error code is ${err.code}, message is ${err.message}`); + } + }) + await sleep(1000); + + await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_SCHEMA_STORE_ID, kvStore, async function () { + console.info(logTag + 'testSyncSchema0200 CLIENT closeKVStore success'); + await kvManager.deleteKVStore(TEST_BUNDLE_NAME, TEST_SCHEMA_STORE_ID, function () { + console.info(logTag + 'testSyncSchema0200 CLIENT deleteKVStore success'); + }); + }); + await remoteHelpers.closeKvStore(TEST_SCHEMA_STORE_ID).then(async (ret) => { + console.info(logTag + "testSyncSchema0200 REMOTE close server kvStore success: " + ret); + }) + await sleep(2000); + kvStore = null; + console.info(logTag + '-----------------testSyncSchema0200 end-----------------'); + done(); + }) + }) } \ No newline at end of file diff --git a/distributeddatamgr/jstest/distributed_kv_store/server/entry/src/main/resources/base/element/string.json b/distributeddatamgr/jstest/distributed_kv_store/server/entry/src/main/resources/base/element/string.json index 050cbc9..4908056 100644 --- a/distributeddatamgr/jstest/distributed_kv_store/server/entry/src/main/resources/base/element/string.json +++ b/distributeddatamgr/jstest/distributed_kv_store/server/entry/src/main/resources/base/element/string.json @@ -10,7 +10,7 @@ }, { "name": "MainAbility_label", - "value": "StageSupplement" + "value": "kvServer" }, { "name": "MainAbility4_desc", diff --git a/testtools/disjsTest/server/testApi.js b/testtools/disjsTest/server/testApi.js index 6ecda83..0a2d564 100644 --- a/testtools/disjsTest/server/testApi.js +++ b/testtools/disjsTest/server/testApi.js @@ -124,6 +124,25 @@ export default class TestApi{ optionsInfo.securityLevel=disData.SecurityLevel.S1; } + let name = new disData.FieldNode('name'); + name.type = disData.ValueType.INTEGER; + name.nullable = false; + name.default = 0; + + let schema = new disData.Schema(); + schema.root.appendChild(name); + schema.indexes = ['$.name']; + schema.mode = 1; + + + let TEST_SCHEMA_STORE_ID_PREF = "SchemaStoreId_"; + let schemaIdPref = storeId.substring(0, 14); + console.info(logTag + "schemaIdPref=" + schemaIdPref); + if (schemaIdPref == TEST_SCHEMA_STORE_ID_PREF) { + optionsInfo.schema = schema; + } + console.info(logTag + "optionsInfo.schema=" + optionsInfo.schema); + await kvManager.getKVStore(storeId,optionsInfo).then((store) =>{ kvStore = store; console.info(logTag + " getKVStore success, securityLevel is: " + optionsInfo.securityLevel);