未验证 提交 5ce1b41c 编写于 作者: O openharmony_ci 提交者: Gitee

!7055 【distributeddatamgr】【monthly】SingleKvStoreKVPromiseJsTest.js 用例优化

Merge pull request !7055 from wuxiaodan/monthly_20221018
......@@ -773,21 +773,16 @@ describe('SingleKvStoreCallbackTest', function () {
* @tc.name Test Js Api SingleKvStore.Delete() testcase 001
*/
it('SUB_DDM_DKV_SINGLEKVSTORE_DELETE_CALLBACK_2700', 0, async function (done) {
console.log('SingleKvStoreDeletePredicatesCallbackTest001');
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETE_CALLBACK_2700');
try {
let predicates = new dataShare.DataSharePredicates();
await kvStore.delete(predicates, function (err,data) {
if (err == undefined) {
console.log('SingleKvStoreDeletePredicatesCallbackTest001 delete success');
expect(null).assertFail();
} else {
console.error('SingleKvStoreDeletePredicatesCallbackTest001 delete fail' + err`, error code is ${err.code}, message is ${err.message}`);
expect(err != undefined).assertTrue();
}
await kvStore.delete(KEY_TEST_STRING_ELEMENT, function (err,data) {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETE_CALLBACK_2700 delete err: ' + err);
expect(err == undefined).assertTrue();
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETE_CALLBACK_2700 expect fin');
done();
});
}catch(e) {
console.error('SingleKvStoreDeletePredicatesCallbackTest001 e' + `, error code is ${e.code}, message is ${e.message}`);
console.error('SUB_DDM_DKV_SINGLEKVSTORE_DELETE_CALLBACK_2700 e' + `, error code is ${e.code}, message is ${e.message}`);
expect(e.code == 401).assertTrue();
done();
}
......@@ -802,13 +797,10 @@ describe('SingleKvStoreCallbackTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_DELETE_CALLBACK_2800', 0, async function (done) {
console.log('SingleKvStoreDeletePredicatesCallbackTest002');
try {
let predicates = new dataShare.DataSharePredicates();
let arr = ["name"];
predicates.inKeys(arr);
await kvStore.put("name", "Bob", async function (err, data) {
console.log('SingleKvStoreDeletePredicatesCallbackTest002 put success');
expect(err == undefined).assertTrue();
await kvStore.delete(predicates, function (err,data) {
await kvStore.delete("name", function (err,data) {
console.log('SingleKvStoreDeletePredicatesCallbackTest002 delete success');
expect(err == undefined).assertTrue();
done();
......@@ -828,23 +820,20 @@ describe('SingleKvStoreCallbackTest', function () {
* @tc.name Test Js Api SingleKvStore.Delete() testcase 003
*/
it('SUB_DDM_DKV_SINGLEKVSTORE_DELETE_CALLBACK_2900', 0, async function (done) {
console.log('SingleKvStoreDeletePredicatesCallbackTest003');
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETE_CALLBACK_2900');
try {
let predicates = new dataShare.DataSharePredicates();
let arr = [null];
predicates.inKeys(arr);
await kvStore.put("name", "Bob", async function (err, data) {
console.log('SingleKvStoreDeletePredicatesCallbackTest003 put success');
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETE_CALLBACK_2900 put success');
expect(err == undefined).assertTrue();
await kvStore.delete(predicates, function (err,data) {
console.log('SingleKvStoreDeletePredicatesCallbackTest003 delete success: '+err);
expect(err == undefined).assertTrue();
done();
});
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETE_CALLBACK_2900 expect finash');
})
await kvStore.delete(arr, function (err,data) {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETE_CALLBACK_2900 delete success: '+err);
});
} catch(e) {
console.error('SingleKvStoreDeletePredicatesCallbackTest003 e' + `, error code is ${e.code}, message is ${e.message}`);
expect(null).assertFail();
console.error('SUB_DDM_DKV_SINGLEKVSTORE_DELETE_CALLBACK_2900 e' + `, error code is ${e.code}, message is ${e.message}`);
expect(e.code == 401).assertTrue();
done();
}
})
......@@ -2228,8 +2217,8 @@ describe('SingleKvStoreCallbackTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULT_CALLBACK_7800', 0, async function (done) {
console.log('SingleKvStoreGetResultSetPredicatesCallbackTest001');
try {
let predicates = new dataShare.DataSharePredicates();
await kvStore.getResultSet(predicates).then((result) => {
let query = new factory.Query();
await kvStore.getResultSet(query).then((result) => {
console.log('SingleKvStoreGetResultSetPredicatesCallbackTest001 getResultSet success');
}).catch((err) => {
console.error('SingleKvStoreGetResultSetPredicatesCallbackTest001 getResultSet fail ' + err`, error code is ${err.code}, message is ${err.message}`);
......
......@@ -771,17 +771,16 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0100', 0, async function (done) {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0100');
try {
let predicates = new dataShare.DataSharePredicates();
await kvStore.delete(predicates).then((data) => {
await kvStore.delete("KEY_TEST_STRING_ELEMENTS").then((data) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0100 delete success');
expect(null).assertFail();
expect(data == undefined).assertTrue();
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0100 delete fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(err != undefined).assertTrue();
console.error('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0100 delete fail err ' + err);
expect(null).assertFail();
});
}catch(e) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0100 e' + `, error code is ${e.code}, message is ${e.message}`);
expect(e.code == 401).assertTrue();
expect(null).assertFail();
}
done();
})
......@@ -795,13 +794,10 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0200', 0, async function (done) {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0200');
try {
let predicates = new dataShare.DataSharePredicates();
let arr = ["name"];
predicates.inKeys(arr);
await kvStore.put("name", "Bob").then(async (data) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0200 put success');
expect(data == undefined).assertTrue();
await kvStore.delete(predicates).then((data) => {
await kvStore.delete("name").then((data) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0200 delete success');
expect(data == undefined).assertTrue();
}).catch((err) => {
......@@ -828,22 +824,23 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0300', 0, async function (done) {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0300');
try {
let predicates = new dataShare.DataSharePredicates();
let arr = [null];
predicates.inKeys(arr);
await kvStore.put("name", "Bob").then(async (data) => {
await kvStore.put("number", "123").then(async (data) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0300 put success');
expect(data == undefined).assertTrue();
await kvStore.delete("number").then((data) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0300 delete success');
expect(data == undefined).assertTrue();
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0300 delete fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail();
});
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0300 put fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail();
});
await kvStore.delete(predicates, function (err,data) {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0300 delete success');
expect(err != undefined).assertTrue();
done();
});
}catch(e) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0300 e' + `, error code is ${e.code}, message is ${e.message}`);
} catch (e) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_DELETEPREDICATES_PROMISE_0300 put e ' + `, error code is ${e.code}, message is ${e.message}`);
expect(null).assertFail();
}
done();
......@@ -858,7 +855,7 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_ONCHANGE_PROMISE_0100', 0, async function (done) {
try {
kvStore.on('dataChange', 0, function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_ONCHANGE_PROMISE_0100 ' + JSON.stringify(data));
console.info('SUB_DDM_DKV_SINGLEKVSTORE_ONCHANGE_PROMISE_0100 dataChange'+ JSON.stringify(data));
expect(data != null).assertTrue();
});
await kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => {
......@@ -884,7 +881,7 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_ONCHANGE_PROMISE_0200', 0, async function (done) {
try {
kvStore.on('dataChange', 1, function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_ONCHANGE_PROMISE_0200 on ' + JSON.stringify(data));
console.info('SUB_DDM_DKV_SINGLEKVSTORE_ONCHANGE_PROMISE_0200 dataChange' + JSON.stringify(data));
expect(data != null).assertTrue();
});
await kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => {
......@@ -910,7 +907,7 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_ONCHANGE_PROMISE_0300', 0, async function (done) {
try {
kvStore.on('dataChange', 2, function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_ONCHANGE_PROMISE_0300 ' + JSON.stringify(data));
console.info('SUB_DDM_DKV_SINGLEKVSTORE_ONCHANGE_PROMISE_0300 dataChange' + JSON.stringify(data));
expect(data != null).assertTrue();
});
await kvStore.put(KEY_TEST_FLOAT_ELEMENT, VALUE_TEST_FLOAT_ELEMENT).then((data) => {
......@@ -952,6 +949,7 @@ describe('SingleKvStorePromiseTest', function () {
kvStore.sync(syncDeviceIds, mode, 10);
} catch (e) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_ONSYNCCOMPLETE_PROMISE_0100 sync no peer device :e:' + `, error code is ${e.code}, message is ${e.message}`);
expect(null).assertFail();
}
}catch(e) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_ONSYNCCOMPLETE_PROMISE_0100 e ' + `, error code is ${e.code}, message is ${e.message}`);
......@@ -985,6 +983,7 @@ describe('SingleKvStorePromiseTest', function () {
kvStore.sync(syncDeviceIds, mode, 10);
} catch (e) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_ONSYNCCOMPLETE_PROMISE_0200 sync no peer device :e:' + `, error code is ${e.code}, message is ${e.message}`);
expect(null).assertFail();
}
}catch(e) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_ONSYNCCOMPLETE_PROMISE_0200 e ' + `, error code is ${e.code}, message is ${e.message}`);
......@@ -1018,6 +1017,7 @@ describe('SingleKvStorePromiseTest', function () {
kvStore.sync(syncDeviceIds, mode, 10);
} catch (e) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_ONSYNCCOMPLETE_PROMISE_0300 sync no peer device :e:' + `, error code is ${e.code}, message is ${e.message}`);
expect(null).assertFail();
}
}catch(e) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_ONSYNCCOMPLETE_PROMISE_0300 e ' + `, error code is ${e.code}, message is ${e.message}`);
......@@ -1036,7 +1036,7 @@ describe('SingleKvStorePromiseTest', function () {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0100');
try {
var func = function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0100 ' + JSON.stringify(data));
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0100 dataChange' + JSON.stringify(data));
};
kvStore.on('dataChange', 0, func);
kvStore.off('dataChange', func);
......@@ -1058,10 +1058,10 @@ describe('SingleKvStorePromiseTest', function () {
let ret = false;
try {
var func = function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0200 ' + JSON.stringify(data));
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0200 dataChange' + JSON.stringify(data));
};
var func1 = function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0200 ' + JSON.stringify(data));
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0200 dataChange1' + JSON.stringify(data));
};
kvStore.on('dataChange', 0, func);
kvStore.on('dataChange', 0, func1);
......@@ -1083,10 +1083,10 @@ describe('SingleKvStorePromiseTest', function () {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0300');
try {
var func = function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0300 0' + data)
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0300 dataChange' + data)
};
var func1 = function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0300 0' + data)
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0300 dataChange1' + data)
};
kvStore.on('dataChange', 0, func);
kvStore.on('dataChange', 0, func1);
......@@ -1109,7 +1109,7 @@ describe('SingleKvStorePromiseTest', function () {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0400');
try {
var func = function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0400 ' + JSON.stringify(data));
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFCHANGE_PROMISE_0400 dataChange' + JSON.stringify(data));
};
kvStore.on('dataChange', 0, func);
kvStore.off('dataChange');
......@@ -1130,7 +1130,7 @@ describe('SingleKvStorePromiseTest', function () {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0100');
try {
var func = function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0100 0' + data)
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0100 syncComplete' + data)
};
kvStore.on('syncComplete', func);
kvStore.off('syncComplete', func);
......@@ -1151,10 +1151,10 @@ describe('SingleKvStorePromiseTest', function () {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0200');
try {
var func = function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0200 0' + data)
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0200 syncComplete' + data)
};
var func1 = function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0200 0' + data)
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0200 syncComplete1' + data)
};
kvStore.on('syncComplete', func);
kvStore.on('syncComplete', func1);
......@@ -1176,10 +1176,10 @@ describe('SingleKvStorePromiseTest', function () {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0300');
try {
var func = function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0300 0' + data)
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0300 syncComplete' + data)
};
var func1 = function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0300 0' + data)
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0300 syncComplete1' + data)
};
kvStore.on('syncComplete', func);
kvStore.on('syncComplete', func1);
......@@ -1202,7 +1202,7 @@ describe('SingleKvStorePromiseTest', function () {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0400');
try {
var func = function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0400 0' + data)
console.info('SUB_DDM_DKV_SINGLEKVSTORE_OFFSYNCCOMPLETE_PROMISE_0400 syncComplete' + data)
};
kvStore.on('syncComplete', func);
kvStore.off('syncComplete');
......@@ -1228,7 +1228,7 @@ describe('SingleKvStorePromiseTest', function () {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_SETSYNCRANGE_PROMISE_0100 setSyncRange success');
expect(err == undefined).assertTrue();
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_DELETESTRING_PROMISE_0300 delete fail ' + `, error code is ${err.code}, message is ${err.message}`);
console.error('SUB_DDM_DKV_SINGLEKVSTORE_SETSYNCRANGE_PROMISE_0100 fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail();
});
}catch(e) {
......@@ -1253,7 +1253,7 @@ describe('SingleKvStorePromiseTest', function () {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_SETSYNCRANGE_PROMISE_0200 setSyncRange success');
expect(err == undefined).assertTrue();
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_SETSYNCRANGE_PROMISE_0200 delete fail ' + `, error code is ${err.code}, message is ${err.message}`);
console.error('SUB_DDM_DKV_SINGLEKVSTORE_SETSYNCRANGE_PROMISE_0200 fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail();
});
}catch(e) {
......@@ -1278,7 +1278,7 @@ describe('SingleKvStorePromiseTest', function () {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_SETSYNCRANGE_PROMISE_0300 setSyncRange success');
expect(err == undefined).assertTrue();
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_SETSYNCRANGE_PROMISE_0300 delete fail ' + `, error code is ${err.code}, message is ${err.message}`);
console.error('SUB_DDM_DKV_SINGLEKVSTORE_SETSYNCRANGE_PROMISE_0300 fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail();
});
}catch(e) {
......@@ -1553,24 +1553,29 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0100', 0, async function (done) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0100');
try {
let values = [];
let arr1 = new Uint8Array([4,5,6,7]);
let arr2 = new Uint8Array([4,5,6,7,8]);
let vb1 = {key : "name_1", value : arr1};
let vb2 = {key : "name_2", value : arr2};
values.push(vb1);
values.push(vb2);
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0100 values: ' + JSON.stringify(values));
await kvStore.putBatch(values).then(async (err) => {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'batch_test_number_key';
var entry = {
key : key + i,
value : {
type : factory.ValueType.DOUBLE,
value : 2.00
}
}
entries.push(entry);
}
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0100 entries: ' + JSON.stringify(entries));
await kvStore.putBatch(entries).then(async (err) => {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0100 putBatch success');
expect(err == undefined).assertTrue();
var query = new factory.Query();
query.prefixKey("name_");
query.prefixKey("batch_test_");
await kvStore.getEntries(query).then((entrys) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0100 getEntries success');
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0100 entrys.length: ' + entrys.length);
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0100 entrys[0]: ' + JSON.stringify(entrys[1]));
expect(entrys.length == 2).assertTrue();
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0100 entrys[0]: ' + JSON.stringify(entrys[0]));
expect(entrys.length == 10).assertTrue();
done();
});
});
......@@ -1590,22 +1595,29 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0200', 0, async function (done) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0200');
try {
let values = [];
let vb1 = {key : "name_1", value : "arr1"};
let vb2 = {key : "name_2", value : "arr2"};
values.push(vb1);
values.push(vb2);
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0200 values: ' + JSON.stringify(values));
await kvStore.putBatch(values).then(async (err) => {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'key_test_int';
var entry = {
key: key + i,
value: {
type: factory.ValueType.INTEGER,
value: '123'
}
}
entries.push(entry);
}
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0200 entries: ' + JSON.stringify(entries));
await kvStore.putBatch(entries).then(async (err) => {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0100 putBatch success');
expect(err == undefined).assertTrue();
var query = new factory.Query();
query.prefixKey("name_");
query.prefixKey("key_test_");
await kvStore.getEntries(query).then((entrys) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0200 getEntries success');
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0200 entrys.length: ' + entrys.length);
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0200 entrys[0]: ' + JSON.stringify(entrys[1]));
expect(entrys.length == 2).assertTrue();
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0200 entrys[0]: ' + JSON.stringify(entrys[0]));
expect(entrys.length == 10).assertTrue();
done();
}).catch((err) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0200 delete fail ' + err);
......@@ -1631,24 +1643,29 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0300', 0, async function (done) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0300');
try {
let values = [];
let vb1 = {key : "name_1", value : 123};
let vb2 = {key : "name_2", value : 321.0};
let vb3 = {key : "name_3", value : 321.00};
values.push(vb1);
values.push(vb2);
values.push(vb3);
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0300 values: ' + JSON.stringify(values));
await kvStore.putBatch(values).then(async (err) => {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'key_test_boolean';
var entry = {
key: key + i,
value: {
type: factory.ValueType.BOOLEAN,
value: 'true'
}
}
entries.push(entry);
}
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0300 entries: ' + JSON.stringify(entries));
await kvStore.putBatch(entries).then(async (err) => {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0300 putBatch success');
expect(err == undefined).assertTrue();
var query = new factory.Query();
query.prefixKey("name_");
query.prefixKey("key_test_");
await kvStore.getEntries(query).then((entrys) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0300 getEntries success');
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0300 entrys.length: ' + entrys.length);
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0300 entrys[0]: ' + JSON.stringify(entrys[2]));
expect(entrys.length == 3).assertTrue();
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0300 entrys[0]: ' + JSON.stringify(entrys[0]));
expect(entrys.length == 10).assertTrue();
done();
});
});
......@@ -1668,22 +1685,29 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0400', 0, async function (done) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0400');
try {
let values = [];
let vb1 = {key : "name_1", value : true};
let vb2 = {key : "name_2", value : false};
values.push(vb1);
values.push(vb2);
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0400 values: ' + JSON.stringify(values));
await kvStore.putBatch(values).then(async (err) => {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'key_test_float';
var entry = {
key: key + i,
value: {
type: factory.ValueType.FLOAT,
value: '321.12'
}
}
entries.push(entry);
}
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0400 entries: ' + JSON.stringify(entries));
await kvStore.putBatch(entries).then(async (err) => {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0400 putBatch success');
expect(err == undefined).assertTrue();
var query = new factory.Query();
query.prefixKey("name_");
query.prefixKey("key_test_");
await kvStore.getEntries(query).then((entrys) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0400 getEntries success');
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0400 entrys.length: ' + entrys.length);
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0400 entrys[0]: ' + JSON.stringify(entrys[1]));
expect(entrys.length == 2).assertTrue();
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0400 entrys[0]: ' + JSON.stringify(entrys[0]));
expect(entrys.length == 10).assertTrue();
done();
});
});
......@@ -1703,23 +1727,32 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0500', 0, async function (done) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0500');
try {
let values = [];
let vb1 = {key : "name_1", value : null};
let vb2 = {key : "name_2", value : null};
values.push(vb1);
values.push(vb2);
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0500 values: ' + JSON.stringify(values));
await kvStore.putBatch(values).then(async (err) => {
let entries = [];
for (var i = 0; i < 10; i++) {
var key = 'key_test_string';
var entry = {
key: key + i,
value: {
type: factory.ValueType.STRING,
value: 'value-string-001'
}
}
entries.push(entry);
}
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0500 entries: ' + JSON.stringify(entries));
await kvStore.putBatch(entries).then(async (err) => {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0500 putBatch success');
expect(err == undefined).assertTrue();
var query = new factory.Query();
query.prefixKey("name_");
query.prefixKey("key_test_");
await kvStore.getEntries(query).then((entrys) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0500 getEntries success');
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0500 entrys.length: ' + entrys.length);
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0500 entrys[0]: ' + JSON.stringify(entrys[1]));
expect(entrys.length == 2).assertTrue();
expect(entrys[0].value == null).assertTrue();
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0500 entrys[1]: ' + JSON.stringify(entrys[1]));
expect(entrys.length == 10).assertTrue();
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0500 entrys[0]: ' + JSON.stringify(entrys[0]));
console.log('SUB_DDM_DKV_SINGLEKVSTORE_PUTBATCHVALUE_PROMISE_0500 entrys[0]: ' + JSON.stringify(entrys[0].value));
expect(entrys[0].value.value == 'value-string-001').assertTrue();
done();
});
});
......@@ -1787,6 +1820,7 @@ describe('SingleKvStorePromiseTest', function () {
let keys = ['batch_test_string_key1', 'batch_test_string_key2'];
await kvStore.deleteBatch(keys).then((err) => {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_DELETEBATCHVALUE_PROMISE_0200 deleteBatch success');
expect(err == undefined).assertTrue();
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_DELETEBATCHVALUE_PROMISE_0200 deleteBatch fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail();
......@@ -1826,6 +1860,7 @@ describe('SingleKvStorePromiseTest', function () {
let keys = ['batch_test_string_key1', 'batch_test_string_keya'];
await kvStore.deleteBatch(keys).then((err) => {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_DELETEBATCHVALUE_PROMISE_0300 deleteBatch success');
expect(err == undefined).assertTrue();
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_DELETEBATCHVALUE_PROMISE_0300 deleteBatch fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail();
......@@ -1852,7 +1887,7 @@ describe('SingleKvStorePromiseTest', function () {
try {
var count = 0;
kvStore.on('dataChange', factory.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_STARTTRANSACTION_PROMISE_0100 ' + JSON.stringify(data));
console.info('SUB_DDM_DKV_SINGLEKVSTORE_STARTTRANSACTION_PROMISE_0100 dataChange ' + JSON.stringify(data));
count++;
});
await kvStore.startTransaction().then(async (err) => {
......@@ -1906,7 +1941,7 @@ describe('SingleKvStorePromiseTest', function () {
try {
var count = 0;
kvStore.on('dataChange', 0, function (data) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_STARTTRANSACTION_PROMISE_0200 ' + JSON.stringify(data));
console.info('SUB_DDM_DKV_SINGLEKVSTORE_STARTTRANSACTION_PROMISE_0200 dataChange ' + JSON.stringify(data));
count++;
});
await kvStore.startTransaction().then(async (err) => {
......@@ -2615,15 +2650,28 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0400', 0, async function (done) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0400');
try {
kvStore.getResultSet('test_key_string', 123).then((result) => {
let resultSet;
await kvStore.getResultSet('test_key_string', 123).then((result) => {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0400 getResultSet success');
kvStore.closeResultSet(result);
})
resultSet = result;
expect(resultSet.getCount() == 0).assertTrue();
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0400 getResultSet fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail();
});
await kvStore.closeResultSet(resultSet).then((err) => {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0400 closeResultSet success');
expect(err == undefined).assertTrue();
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0400 closeResultSet fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail();
});
}catch(e) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0400 e ' + `, error code is ${e.code}, message is ${e.message}`);
expect(null).assertFail();
}
done();
})
/**
......@@ -2762,9 +2810,9 @@ describe('SingleKvStorePromiseTest', function () {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0700 putBatch fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail();
});
let predicates = new dataShare.DataSharePredicates();
predicates.prefixKey("name_");
await kvStore.getResultSet(predicates).then((result) => {
let query = new factory.Query();
query.prefixKey("name_");
await kvStore.getResultSet(query).then((result) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0700 getResultSet success');
resultSet = result;
expect(resultSet.getCount() == 10).assertTrue();
......@@ -2795,13 +2843,24 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0800', 0, async function (done) {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0800');
try {
let predicates = new dataShare.DataSharePredicates();
await kvStore.getResultSet(predicates, async function (err, result) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0800 GetResultSet success: '+`, error code is ${err.code}, message is ${err.message}`);
kvStore.closeResultSet(result);
let resultSet;
let query = new factory.Query();
await kvStore.getResultSet(query).then((result) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0800 getResultSet success');
resultSet = result;
expect(resultSet.getCount() == 0).assertTrue();
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0800 getResultSet fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail();
});
await kvStore.closeResultSet(resultSet).then((err) => {
console.log('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0800 closeResultSet success');
expect(err == undefined).assertTrue();
done();
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0800 closeResultSet fail ' + `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail();
});
} catch(e) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_GETRESULTSET_PROMISE_0800 e' + `, error code is ${e.code}, message is ${e.message}`);
expect(null).assertFail();
......@@ -2873,7 +2932,6 @@ describe('SingleKvStorePromiseTest', function () {
it('SUB_DDM_DKV_SINGLEKVSTORE_CLOSERESULTSET_PROMISE_0300', 0, async function (done) {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CLOSERESULTSET_PROMISE_0300');
try {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CLOSERESULTSET_PROMISE_0300 success');
let resultSet = null;
await kvStore.closeResultSet().then(() => {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CLOSERESULTSET_PROMISE_0300 closeResultSet success');
......@@ -2895,16 +2953,21 @@ describe('SingleKvStorePromiseTest', function () {
* @tc.name Test Js Api SingleKvStoreCloseResultSet testcase 004
*/
it('SUB_DDM_DKV_SINGLEKVSTORE_CLOSERESULTSET_PROMISE_0400', 0, async function (done) {
let errorInfo = undefined;
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CLOSERESULTSET_PROMISE_0400');
try {
kvStore.closeResultSet("")
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CLOSERESULTSET_PROMISE_0400 success');
}catch(err) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_CLOSERESULTSET_PROMISE_0400 e ' + `, error code is ${err.code}, message is ${err.message}`);
errorInfo = err
let resultSet = null;
await kvStore.closeResultSet("").then(() => {
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CLOSERESULTSET_PROMISE_0400 closeResultSet success');
expect(null).assertFail();
}).catch((err) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_CLOSERESULTSET_PROMISE_0400 closeResultSet fail ' + `, error code is ${err.code}, message is ${err.message}`);
});
}catch(e) {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_CLOSERESULTSET_PROMISE_0400 e ' + `, error code is ${e.code}, message is ${e.message}`);
expect(e.code == 401).assertTrue();
}
expect(errorInfo.code).assertEqual("401");
done();
})
/**
......@@ -2968,9 +3031,11 @@ describe('SingleKvStorePromiseTest', function () {
});
await getInsertEntries.then(function(insertEntries){
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CHANGENOTIFICATION_PROMISE_0100 getInsertEntries' + JSON.stringify(insertEntries));
expect(insertEntries).assertNotNull();
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CHANGENOTIFICATION_PROMISE_0100 getInsertEntries key ' + insertEntries[0].key);
expect(insertEntries[0].key == "getInsertEntries").assertTrue();
}).catch((error) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_CHANGENOTIFICATION_PROMISE_0100 can NOT getInsertEntries, fail:' + `, error code is ${error.code}, message is ${error.message}`);
expect(null).assertFail();
});
done();
})
......@@ -2995,9 +3060,11 @@ describe('SingleKvStorePromiseTest', function () {
});
await getUpdateEntries.then(function(updateEntries){
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CHANGENOTIFICATION_PROMISE_0200 getUpdateEntries' + JSON.stringify(updateEntries));
expect(updateEntries).assertNotNull();
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CHANGENOTIFICATION_PROMISE_0200 getUpdateEntries key ' + updateEntries[0].key);
expect(updateEntries[0].key == "getUpdateEntries").assertTrue();
}).catch((error) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_CHANGENOTIFICATION_PROMISE_0200 can NOT getUpdateEntries, fail:' + `, error code is ${error.code}, message is ${error.message}`);
expect(null).assertFail();
});
done();
})
......@@ -3021,10 +3088,12 @@ describe('SingleKvStorePromiseTest', function () {
});
});
await getdeleteEntries.then(function(deleteEntries){
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CHANGENOTIFICATION_PROMISE_0300 deleteEntries' + JSON.stringify(getdeleteEntries));
expect(deleteEntries != null).assertNotNull();
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CHANGENOTIFICATION_PROMISE_0300 deleteEntries' + JSON.stringify(deleteEntries));
console.info('SUB_DDM_DKV_SINGLEKVSTORE_CHANGENOTIFICATION_PROMISE_0200 getUpdateEntries key ' + deleteEntries[0].key);
expect(deleteEntries[0].key == "deleteEntries").assertTrue();
}).catch((error) => {
console.error('SUB_DDM_DKV_SINGLEKVSTORE_CHANGENOTIFICATION_PROMISE_0300 can NOT getdeleteEntries, fail:' + `, error code is ${error.code}, message is ${error.message}`);
expect(null).assertFail();
});
done();
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册