• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium';
17import deviceManager from '@ohos.distributedHardware.deviceManager';
18import TestService from '../../../../../../../../../testtools/disjsTest/client/testService.js';
19import RemoteHelper from '../../../../../../../../../testtools/disjsTest/client/remoteHelper.js';
20import factory from '@ohos.data.distributedData';
21import { UiDriver, BY } from '@ohos.UiTest'
22import data_Rdb from '@ohos.data.relationalStore';
23import featureAbility from '@ohos.ability.featureAbility';
24
25var context = featureAbility.getContext();
26const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
27const CREATE_TABLE_NAME = "CREATE TABLE IF NOT EXISTS test"
28const STORE_CONFIG = {
29    name: "RemoteRdb.db",
30    securityLevel: data_Rdb.SecurityLevel.S1
31}
32
33var rdbStore = undefined;
34var resultSet = undefined;
35let dmInstance = null;
36let localDeviceId = undefined;
37let logTag = 'RpcClient:  ';
38let testservice = null;
39let gIRemoteObject = null;
40let remoteHelpers = null;
41let deviceId = null;
42let syncDeviceIds = undefined;
43let deviceList = undefined;
44const TEST_BUNDLE_NAME = 'com.ohos.distributerdbdisjs';
45
46
47function sleep(ms) {
48    return new Promise(resolve => setTimeout(resolve, ms));
49}
50
51async function getPermission() {
52    console.info(`getPermission is start`);
53    let permissions = ['ohos.permission.DISTRIBUTED_DATASYNC'];
54    let context = featureAbility.getContext()
55    context.requestPermissionsFromUser(permissions, 666, (data) => {
56        console.info("request success" + JSON.stringify(data));
57
58    })
59}
60
61async function driveFn() {
62    try {
63        let driver = await UiDriver.create()
64        console.info(` come in driveFn`)
65        console.info(`driver is ${JSON.stringify(driver)}`)
66        sleep(2000);
67        let button = await driver.findComponent(BY.text('允许'));
68        console.info(`button is ${JSON.stringify(button)}`);
69        sleep(5000);
70        await button.click();
71    } catch (err) {
72        console.info('err is ' + err);
73        return;
74    }
75
76}
77
78export default function rdbSyncFirstLevelTest(){
79    describe('rdbSyncFirstLevelTest', function () {
80        beforeAll(async function (done) {
81            console.info(logTag + '-----------------beforeAll begin-----------------');
82            await getPermission();
83            sleep(5000);
84            await driveFn();
85            sleep(100);
86
87            testservice = new TestService();
88            console.info(logTag + "deviceId: " + deviceId);
89            await testservice.toConnectRdbAbility().then(data => {
90                gIRemoteObject = data;
91                console.info(logTag + "toConnectAbility data is" + data);
92                remoteHelpers = new RemoteHelper(testservice,gIRemoteObject);
93            })
94            rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG);
95            console.info(logTag + "create RemoteRdb.db success");
96            await rdbStore.executeSql(CREATE_TABLE_TEST, null);
97            console.info(logTag + "create  remote RemoteRdb.db success");
98            //setDistributedTables
99            let back = rdbStore.setDistributedTables(["test"]);
100            back.then(() => {
101                console.info("SetDistributedTables successfully.");
102            }).catch((err) => {
103                console.info("SetDistributedTables failed, err: " + err.code);
104            })
105            await back;
106
107            await deviceManager.createDeviceManager(TEST_BUNDLE_NAME,async (error, deviceManager) =>{
108                console.info(logTag + "CLIENT Create device manager success");
109                localDeviceId = deviceManager.getLocalDeviceInfoSync().deviceId;
110                console.info(logTag + "local device id is: " + localDeviceId);
111                deviceList = deviceManager.getTrustedDeviceListSync();
112                deviceId = deviceList[0].deviceId;
113                syncDeviceIds = [deviceId];
114                dmInstance = deviceManager;
115                dmInstance.on("deviceStateChange", (data) => {
116                    console.log("deviceStateChange: " + JSON.stringify(data));
117                });
118            })
119
120            function storeObserver(devices) {
121                for (let i = 0; i < devices.length; i++) {
122                    console.log('device=' + devices[i] + ' data changed');
123                }
124            }
125            try {
126                rdbStore.on('dataChange', data_Rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
127            } catch (err) {
128                console.log('Register observer failed');
129            }
130            console.info(logTag + '-----------------beforeAll end-----------------');
131            done();
132        })
133
134        beforeEach(async function(done){
135            console.info(logTag + "-----------------beforeEach 0 -----------------");
136            done();
137        })
138
139        afterEach(async function (done) {
140            console.info(logTag + '-----------------afterEach begin-----------------');
141            try {
142                let deleletPre = new data_Rdb.RdbPredicates("test");
143                await rdbStore.delete(deleletPre);
144                console.info(logTag + "REMOTE afterEach delete rdbStore success");
145            } catch (error) {
146                console.info(logTag + "REMOTE afterEach delete rdbStore error: " + error.message);
147            }
148            console.info(logTag + '-----------------afterEach end-----------------');
149            done();
150        })
151
152        afterAll(async function (done){
153            console.info(logTag + '-----------------afterAll begin-----------------');
154            rdbStore = null;
155            await data_Rdb.deleteRdbStore(context, "RemoteRdb.db").then(() => {
156                console.info(logTag + "delete RemoteRdb success");
157            });
158            await data_Rdb.deleteRdbStore(context, "RemoteS2Rdb.db").then(() => {
159                console.info(logTag + "delete RemoteS2Rdb success");
160            });
161            await sleep(50);
162            console.info(logTag + '-----------------afterAll end-----------------');
163            done();
164        })
165
166        /**
167         * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_0100
168         * @tc.name testRdbSyncTest0010
169         * @tc.desc Server rdbStore Insert first and synchronize
170         */
171         it("testRdbSyncTest0010", 0, async function (done) {
172            console.info(logTag + "testRdbSyncTest0010 start");
173            var u8 = new Uint8Array([1, 2, 3]);
174            {
175                const valueBucket = {
176                    "name": "zhangsan",
177                    "age": 18,
178                    "salary": 100.5,
179                    "blobType": u8
180                }
181                await rdbStore.insert("test", valueBucket);
182                console.info("testRdbSyncTest0010 insert success");
183            }
184
185            let predicates = new data_Rdb.RdbPredicates('test');
186            predicates.equalTo("name", "zhangsan");
187            let resultSet = await rdbStore.query(predicates);
188            try {
189                expect(true).assertEqual(resultSet.goToFirstRow());
190                const id = resultSet.getLong(resultSet.getColumnIndex("id"));
191                const name = resultSet.getString(resultSet.getColumnIndex("name"));
192                console.info(logTag + "testRdbSyncTest0010 id=" + id + ", name=" + name);
193                expect(1).assertEqual(id);
194                expect("zhangsan").assertEqual(name);
195            } catch (e) {
196                console.info("testRdbSyncTest0010 insert error " + e);
197                expect().assertFail();
198            }
199            resultSet = null;
200            predicates.inDevices(syncDeviceIds);
201            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
202            promise.then((result) => {
203                console.log('testRdbSyncTest0010 sync done.');
204                for (let i = 0; i < result.length; i++) {
205                    console.log('testRdbSyncTest0010 device=' + result[i][0] + ' status=' + result[i][1]);
206                    let status = result[i][1];
207                    expect(status == 0).assertTrue();
208                }
209            }).catch((err) => {
210                console.log('testRdbSyncTest0010 sync failed' + err.code);
211                expect().assertFail();
212            })
213            await promise;
214
215            done();
216            console.info(logTag + "************* testRdbStoreInsert0001 end *************");
217        })
218
219         /**
220         * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_0200
221         * @tc.name testRdbSyncTest0020
222         * @tc.desc Server rdbStore Insert twice and synchronize twice
223         */
224        it("testRdbSyncTest0020", 0, async function (done) {
225            console.info(logTag + "testRdbSyncTest0020 start");
226            //push data to remote device
227            var u8 = new Uint8Array([1, 2, 3]);
228            {
229                const valueBucket = {
230                    "name": "xuewang",
231                    "age": 300,
232                    "salary": 20.533,
233                    "blobType": u8
234                }
235                await rdbStore.insert("test", valueBucket);
236                console.info("testRdbSyncTest0020 insert success");
237            }
238
239            let predicates = new data_Rdb.RdbPredicates('test');
240
241            predicates.inDevices(syncDeviceIds);
242            console.info(logTag + "testRdbSyncTest0020 sync before" + syncDeviceIds);
243            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
244            promise.then((result) => {
245                console.log('testRdbSyncTest0020 sync done.');
246                for (let i = 0; i < result.length; i++) {
247                    console.log('testRdbSyncTest0020 device=' + result[i][0] + ' status=' + result[i][1]);
248                    let status = result[i][1];
249                    expect(status == 0).assertTrue();
250                }
251            }).catch((err) => {
252                console.log('testRdbSyncTest0020 sync failed' + err.code);
253                expect().assertFalse();
254            })
255            await promise;
256
257            let  u8Arr = new Uint8Array([1,2,3,4,5]);
258            {
259                const valueBucket1 = {
260                    "name": "xuewang22",
261                    "age": 10,
262                    "salary": 50.366,
263                    "blobType": u8Arr
264                }
265                await rdbStore.insert("test", valueBucket1);
266                console.info("testRdbSyncTest0020 insert success");
267            }
268            //query
269            let resultSet = await rdbStore.query(predicates);
270            try {
271                console.info(logTag + "testRdbSyncTest0020 resultSet.rowCount: "+ resultSet.rowCount);
272                expect(2).assertEqual(resultSet.rowCount);
273            } catch (e) {
274                console.info("testRdbSyncTest0020 query error " + e);
275                expect().assertFail();
276            }
277            resultSet = null;
278            let promiseTwo = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
279            promiseTwo.then((result) => {
280                for (let i = 0; i < result.length; i++) {
281                    console.log('testRdbSyncTest0020 device=' + result[i][0] + ' status=' + result[i][1]);
282                    let status = result[i][1];
283                    expect(status == 0).assertTrue();
284                }
285            }).catch((err) => {
286                console.log('testRdbSyncTest0020 sync failed' + err.code);
287                expect().assertFalse();
288            })
289            await promise;
290
291            done();
292            console.info(logTag + "************* testRdbStoreInsert0010 end *************");
293        })
294
295        /**
296        * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_0300
297        * @tc.name testRdbSyncTest0030
298        * @tc.desc Server rdbStore Insert synchronization and then update synchronization
299        */
300        it("testRdbSyncTest0030", 0, async function (done) {
301            console.info(logTag + "testRdbSyncTest0030 start");
302
303            //push data to remote device
304            var u8 = new Uint8Array([1, 2, 3]);
305            {
306                const valueBucket = {
307                    "name": "xuewang",
308                    "age": 300,
309                    "salary": 20.533,
310                    "blobType": u8
311                }
312                await rdbStore.insert("test", valueBucket);
313                console.info("testRdbSyncTest0030 insert success");
314            }
315
316            let predicates = new data_Rdb.RdbPredicates('test');
317            predicates.inDevices(syncDeviceIds);
318            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates)
319            promise.then((result) => {
320                console.log('testRdbSyncTest0030 sync done.');
321                for (let i = 0; i < result.length; i++) {
322                    console.log('testRdbSyncTest0030 device=' + result[i][0] + ' status=' + result[i][1]);
323                    let status = result[i][1];
324                    expect(status == 0).assertTrue();
325                }
326            }).catch((err) => {
327                console.log('testRdbSyncTest0030 sync failed' + err.code);
328                expect().assertFalse();
329            })
330            await promise;
331
332            let  u8Arr = new Uint8Array([1,2,3,4,5]);
333            {
334                const valueBucket1 = {
335                    "name": "xuewang22",
336                    "age": 10,
337                    "salary": 50.366,
338                    "blobType": u8Arr
339                }
340                let updatePromise = rdbStore.update(valueBucket1, predicates);
341                await updatePromise.then(async (ret) => {
342                    expect(1).assertEqual(ret);
343                    let resultSet = await rdbStore.query(predicates);
344                    expect(true).assertEqual(resultSet.goToFirstRow());
345                    const name = await resultSet.getString(resultSet.getColumnIndex("name"));
346                    expect("xuewang22").assertEqual(name);
347                    resultSet = null;
348                }).catch((err) => {
349                    console.info("testRdbSyncTest0030 update err: "+err.message);
350                    expect(null).assertFail();
351                })
352            }
353            let promiseTwo = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
354            promiseTwo.then((result) => {
355                for (let i = 0; i < result.length; i++) {
356                    console.log('testRdbSyncTest0030 device=' + result[i][0] + ' status=' + result[i][1]);
357                    let status = result[i][1];
358                    expect(status == 0).assertTrue();
359                }
360            }).catch((err) => {
361                console.log('testRdbSyncTest0030 sync failed' + err.code);
362                expect().assertFalse();
363            })
364            await promise;
365
366            done();
367            console.info(logTag + "************* testRdbSyncTest0030 end *************");
368        })
369
370
371        /**
372        * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_0400
373        * @tc.name testRdbSyncTest0040
374        * @tc.desc Server rdbStore Insert synchronization, and then delete synchronization
375        */
376        it("testRdbSyncTest0040", 0, async function (done) {
377            console.info(logTag + "testRdbSyncTest0040 start");
378
379            //push data to remote device
380            var u8 = new Uint8Array([1, 2, 3])
381            {
382                const valueBucket = {
383                    "name": "xuewang",
384                    "age": 300,
385                    "salary": 20.533,
386                    "blobType": u8
387                }
388                await rdbStore.insert("test", valueBucket);
389                console.info("testRdbSyncTest0040 insert success");
390            }
391
392            let predicates = new data_Rdb.RdbPredicates('test');
393            predicates.inDevices(syncDeviceIds);
394            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
395            promise.then((result) => {
396                console.log('testRdbSyncTest0040 sync done.');
397                for (let i = 0; i < result.length; i++) {
398                    console.log('testRdbSyncTest0040 device=' + result[i][0] + ' status=' + result[i][1]);
399                    let status = result[i][1];
400                    expect(status == 0).assertTrue();
401                }
402            }).catch((err) => {
403                console.log('testRdbSyncTest0040 sync failed' + err.code);
404                expect().assertFalse();
405            })
406            await promise;
407            predicates.equalTo("name", "xuewang");
408            await rdbStore.delete(predicates).then((number) => {
409                expect(1).assertEqual(number)
410            }).then(async () => {
411                resultSet = await rdbStore.query(predicates).catch((err) =>{
412                    console.log("testRdbSyncTest0040 query failed err: " + err);
413                    expect().assertFalse();
414                })
415            })
416            let promiseTwo = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
417            promiseTwo.then((result) => {
418                for (let i = 0; i < result.length; i++) {
419                    console.log('testRdbSyncTest0040 device=' + result[i][0] + ' status=' + result[i][1]);
420                    let status = result[i][1];
421                    expect(status == 0).assertTrue();
422                }
423            }).catch((err) => {
424                console.log('testRdbSyncTest0040 sync failed' + err.code);
425                expect().assertFalse();
426            })
427            await promise;
428            done();
429            console.info(logTag + "************* testRdbSyncTest0040 end *************");
430        })
431
432
433
434        /**
435        * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_0500
436        * @tc.name testRdbSyncTest0050
437        * @tc.desc Server rdbStore batchInsert sync
438        */
439        it("testRdbSyncTest0050", 0, async function (done) {
440            console.info(logTag + "testRdbSyncTest0050 start");
441
442            //push data to remote device
443            {
444                var u8 = new Uint8Array([1, 2, 3])
445                const valueBucket1 = {
446                    "name": "zhangsan",
447                    "age": 18,
448                    "salary": 100.5,
449                    "blobType": u8
450                }
451                const valueBucket2 = {
452                    "name": "lisi",
453                    "age": 23,
454                    "salary": 200,
455                    "blobType": u8
456                }
457                const valueBucket3 = {
458                    "name": "wangwu",
459                    "age": 20,
460                    "salary": 100.5,
461                    "blobType": u8
462                }
463                const valueBuckets = [valueBucket1, valueBucket2, valueBucket3];
464                await rdbStore.batchInsert("test", valueBuckets).then((number) => {
465                    console.info(logTag + "testRdbSyncTest0050 batchInsert");
466                    expect(3).assertEqual(number);
467                }).catch((err) =>{
468                    console.info(logTag + "testRdbSyncTest0050 err: " + err.message);
469                    expect().assertFalse();
470                })
471            }
472
473            let predicates = new data_Rdb.RdbPredicates('test');
474            let resultSet = await rdbStore.query(predicates);
475            try {
476                console.info(logTag + "testRdbSyncTest0050 resultSet.rowCount: "+ resultSet.rowCount);
477                expect(3).assertEqual(resultSet.rowCount);
478            } catch (e) {
479                console.info("testRdbSyncTest0050 query error " + e);
480                expect().assertFail();
481            }
482            predicates.inDevices(syncDeviceIds);
483            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
484            promise.then((result) => {
485                console.log('testRdbSyncTest0050 sync done.');
486                for (let i = 0; i < result.length; i++) {
487                    console.log('testRdbSyncTest0050 device=' + result[i][0] + ' status=' + result[i][1]);
488                    let status = result[i][1];
489                    expect(status == 0).assertTrue();
490                }
491            }).catch((err) => {
492                console.log('testRdbSyncTest0050 sync failed' + err.code);
493                expect().assertFalse();
494            })
495            await promise;
496            done();
497            console.info(logTag + "************* testRdbSyncTest0050 end *************");
498        })
499
500
501        /**
502        * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_0600
503        * @tc.name testRdbSyncTest0060
504        * @tc.desc Server rdbStore BatchInsert synchronization and then update synchronization
505        */
506        it("testRdbSyncTest0060", 0, async function (done) {
507            console.info(logTag + "testRdbSyncTest0060 start");
508            //push data to remote device
509            {
510                var u8 = new Uint8Array([1, 2, 3]);
511                const valueBucket1 = {
512                    "name": "lover",
513                    "age": 18,
514                    "salary": 100.5,
515                    "blobType": u8
516                }
517                const valueBucket2 = {
518                    "name": "lucy",
519                    "age": 23,
520                    "salary": 200,
521                    "blobType": u8
522                }
523                const valueBucket3 = {
524                    "name": "jiajiahui",
525                    "age": 88,
526                    "salary": 20.5,
527                    "blobType": u8
528                }
529                const valueBuckets = [valueBucket1, valueBucket2, valueBucket3];
530                await rdbStore.batchInsert("test", valueBuckets).then((number) => {
531                    console.info(logTag + "testRdbSyncTest0060 batchInsert number: "+ number);
532                    expect(3).assertEqual(number);
533                }).catch((err) =>{
534                    console.info(logTag + "testRdbSyncTest0060 err: " + err.message);
535                    expect().assertFalse();
536                })
537            }
538
539            let predicates = new data_Rdb.RdbPredicates('test');
540            predicates.inDevices(syncDeviceIds);
541            await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
542                if (err) {
543                    console.log("testRdbSyncTest0060 query error " + err);
544                    return;
545                }
546                console.log('testRdbSyncTest0060 sync done.');
547                for (let i = 0; i < result.length; i++) {
548                    console.log('testRdbSyncTest0060 device=' + result[i][0] + ' status=' + result[i][1]);
549                }
550            });
551
552            let  u8ArrUpdate = new Uint8Array([1,2,3,4,5]);
553            {
554                const valueBucketUpdate = {
555                    "name": "mingmingUpdate",
556                    "age": 10,
557                    "salary": 50.366,
558                    "blobType": u8ArrUpdate
559                }
560                let predicatesUpdate = new data_Rdb.RdbPredicates('test');
561                predicatesUpdate.equalTo("name", "lucy");
562                let updatePromise = rdbStore.update(valueBucketUpdate, predicatesUpdate);
563                await updatePromise.then(async (ret) => {
564                    expect(1).assertEqual(ret);
565                    console.info("testRdbSyncTest0030 update done: " + ret);
566                }).catch((err) => {
567                    console.info("testRdbSyncTest0030 update err: "+err.message);
568                    expect(null).assertFail();
569                })
570            }
571            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
572
573            promise.then((result) => {
574                console.log('testRdbSyncTest0060 sync done.');
575                for (let i = 0; i < result.length; i++) {
576                    console.log('testRdbSyncTest0060 device=' + result[i][0] + ' status=' + result[i][1]);
577                    let status = result[i][1];
578                    expect(status == 0).assertTrue();
579                }
580            }).catch((err) => {
581                console.log('testRdbSyncTest0060 sync failed' + err.code);
582                expect().assertFalse();
583            })
584            await promise;
585            let resultSet = await rdbStore.query(predicates);
586            expect(true).assertEqual(resultSet.goToRow(1));
587            const name = await resultSet.getString(resultSet.getColumnIndex("name"));
588            expect("mingmingUpdate").assertEqual(name);
589            resultSet = null;
590            done();
591            console.info(logTag + "************* testRdbSyncTest0060 end *************");
592        })
593
594
595
596        /**
597        * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_0700
598        * @tc.name testRdbSyncTest0070
599        * @tc.desc Server rdbStore BatchInsert synchronization, and then delete synchronization
600        */
601         it("testRdbSyncTest0070", 0, async function (done) {
602            console.info(logTag + "testRdbSyncTest0070 start");
603
604            //push data to remote device
605            {
606                var u8 = new Uint8Array([1, 2, 3]);
607                const valueBucket1 = {
608                    "name": "catty",
609                    "age": 18,
610                    "salary": 100.55,
611                    "blobType": u8
612                }
613                const valueBucket2 = {
614                    "name": "lucy",
615                    "age": 23,
616                    "salary": 200,
617                    "blobType": u8
618                }
619                const valueBucket3 = {
620                    "name": "jiajiahui",
621                    "age": 88,
622                    "salary": 20.5,
623                    "blobType": u8
624                }
625                const valueBuckets = [valueBucket1, valueBucket2, valueBucket3];
626                await rdbStore.batchInsert("test", valueBuckets).then((number) => {
627                    console.info(logTag + "testRdbSyncTest0070 batchInsert number: "+ number);
628                    expect(3).assertEqual(number);
629                }).catch((err) =>{
630                    console.info(logTag + "testRdbSyncTest0070 err: " + err.message);
631                    expect().assertFalse();
632                })
633            }
634            let predicates = new data_Rdb.RdbPredicates('test');
635            predicates.inDevices(syncDeviceIds);
636            await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
637                if (err) {
638                    console.log("testRdbSyncTest0070 query error " + err);
639                    expect().assertFail();
640                    return;
641                }
642                for (let i = 0; i < result.length; i++) {
643                    console.log('testRdbSyncTest0070 device=' + result[i][0] + ' status=' + result[i][1]);
644                    let status = result[i][1];
645                    expect(status == 0).assertTrue();
646                }
647            });
648
649            predicates.equalTo("name", "catty");
650            await rdbStore.delete(predicates).then((number) => {
651                expect(1).assertEqual(number);
652            });
653            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
654            let predicatesSelect = new data_Rdb.RdbPredicates('test');
655            promise.then((result) => {
656                console.log('testRdbSyncTest0070 sync done.');
657                for (let i = 0; i < result.length; i++) {
658                    console.log('testRdbSyncTest0070 device=' + result[i][0] + ' status=' + result[i][1]);
659                    let status = result[i][1];
660                    expect(status == 0).assertTrue();
661                }
662            }).catch((err) => {
663                console.log('testRdbSyncTest0070 sync failed' + err.code);
664                expect().assertFalse();
665            });
666            await promise;
667            let resultSet = await rdbStore.query(predicatesSelect);
668            console.log('testRdbSyncTest0070 resultSet=' +resultSet.rowCount);
669            expect(2).assertEqual(resultSet.rowCount);
670            done();
671            console.info(logTag + "************* testRdbSyncTest0070 end *************");
672        })
673
674        /**
675        * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_0800
676        * @tc.name testRdbSyncTest0080
677        * @tc.desc Server rdbStore BatchInsert synchronization, and then delete synchronization,and then update synchronization
678        */
679        it("testRdbSyncTest0080", 0, async function (done) {
680            console.info(logTag + "testRdbSyncTest0080 start");
681
682            //push data to remote device
683            {
684                var u8 = new Uint8Array([1, 2, 3]);
685                const valueBucket1 = {
686                    "name": "liqiang",
687                    "age": 18,
688                    "salary": 100.55,
689                    "blobType": u8
690                }
691                const valueBucket2 = {
692                    "name": "lucy",
693                    "age": 23,
694                    "salary": 200,
695                    "blobType": u8
696                }
697                const valueBucket3 = {
698                    "name": "update0080",
699                    "age": 88,
700                    "salary": 20.5,
701                    "blobType": u8
702                }
703                const valueBuckets = [valueBucket1, valueBucket2, valueBucket3];
704                await rdbStore.batchInsert("test", valueBuckets).then((number) => {
705                    console.info(logTag + "testRdbSyncTest0080 batchInsert number: "+ number);
706                    expect(3).assertEqual(number);
707                }).catch((err) =>{
708                    console.info(logTag + "testRdbSyncTest0080 err: " + err.message);
709                    expect().assertFalse();
710                })
711            }
712            let predicates = new data_Rdb.RdbPredicates('test');
713            predicates.inDevices(syncDeviceIds);
714            await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
715                if (err) {
716                    console.log("testRdbSyncTest0080 query error " + err);
717                    expect().assertFail();
718                    return;
719                }
720                for (let i = 0; i < result.length; i++) {
721                    console.log('testRdbSyncTest0080 device=' + result[i][0] + ' status=' + result[i][1]);
722                    let status = result[i][1];
723                    expect(status == 0).assertTrue();
724                }
725            });
726
727            predicates.equalTo("name", "liqiang");
728            await rdbStore.delete(predicates).then((number) => {
729                console.log("testRdbSyncTest0080 delete number: "+ number);
730                expect(1).assertEqual(number);
731            });
732            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
733            let predicatesSelect = new data_Rdb.RdbPredicates('test');
734            promise.then((result) => {
735                console.log('testRdbSyncTest0080 sync done.');
736                for (let i = 0; i < result.length; i++) {
737                    console.log('testRdbSyncTest0080 device=' + result[i][0] + ' status=' + result[i][1]);
738                    let status = result[i][1];
739                    expect(status == 0).assertTrue();
740                }
741            }).catch((err) => {
742                console.log('testRdbSyncTest0080 sync failed' + err.code);
743                expect().assertFalse();
744            });
745            await promise;
746            let resultSet = await rdbStore.query(predicatesSelect);
747            console.log('testRdbSyncTest0080 resultSet=' +resultSet.rowCount);
748            expect(2).assertEqual(resultSet.rowCount);
749
750            let  u8Arr1 = new Uint8Array([1,2,3,4,5]);
751            {
752                const valueBucketUp = {
753                    "name": "liyaoyao",
754                    "age": 10,
755                    "salary": 654,
756                    "blobType": u8Arr1
757                }
758                let preUpdate = new data_Rdb.RdbPredicates('test');
759                preUpdate.equalTo("name", "update0080");
760                let updatePromise = rdbStore.update(valueBucketUp, preUpdate);
761                await updatePromise.then(async (ret) => {
762                    expect(1).assertEqual(ret);
763                }).catch((err) => {
764                    console.info("testRdbSyncTest0080 update err: "+err.message);
765                    expect(null).assertFail();
766                })
767            }
768            let promiseTwo = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
769            promiseTwo.then((result) => {
770                for (let i = 0; i < result.length; i++) {
771                    console.log('testRdbSyncTest0080 device=' + result[i][0] + ' status=' + result[i][1]);
772                    let status = result[i][1];
773                    expect(status == 0).assertTrue();
774                }
775            }).catch((err) => {
776                console.log('testRdbSyncTest0080 sync failed' + err.code);
777                expect().assertFalse();
778            })
779            await promise;
780
781            done();
782            console.info(logTag + "************* testRdbSyncTest0080 end *************");
783        })
784
785
786        /**
787        * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_0900
788        * @tc.name testRdbSyncTest0090
789        * @tc.desc Server rdbStore BatchInsert synchronization, and then delete synchronization, and then insert synchronization
790        */
791         it("testRdbSyncTest0090", 0, async function (done) {
792            console.info(logTag + "testRdbSyncTest0090 start");
793
794            //push data to remote device
795            {
796                var u8 = new Uint8Array([1, 2, 3]);
797                const valueBucket1 = {
798                    "name": "mimiy",
799                    "age": 18,
800                    "salary": 100.55,
801                    "blobType": u8
802                }
803                const valueBucket2 = {
804                    "name": "lucy",
805                    "age": 23,
806                    "salary": 200,
807                    "blobType": u8
808                }
809                const valueBucket3 = {
810                    "name": "jiajiahui",
811                    "age": 88,
812                    "salary": 20.5,
813                    "blobType": u8
814                }
815                const valueBuckets = [valueBucket1, valueBucket2, valueBucket3];
816                await rdbStore.batchInsert("test", valueBuckets).then((number) => {
817                    console.info(logTag + "testRdbSyncTest0090 batchInsert number: "+ number);
818                    expect(3).assertEqual(number);
819                }).catch((err) =>{
820                    console.info(logTag + "testRdbSyncTest0090 err: " + err.message);
821                    expect().assertFalse();
822                })
823            }
824            let predicates = new data_Rdb.RdbPredicates('test');
825            predicates.inDevices(syncDeviceIds);
826            await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
827                if (err) {
828                    console.log("testRdbSyncTest0090 query error " + err);
829                    expect().assertFail();
830                    return;
831                }
832                for (let i = 0; i < result.length; i++) {
833                    console.log('testRdbSyncTest0090 device=' + result[i][0] + ' status=' + result[i][1]);
834                    let status = result[i][1];
835                    expect(status == 0).assertTrue();
836                }
837            });
838
839            predicates.equalTo("name", "mimiy");
840            await rdbStore.delete(predicates).then((number) => {
841                expect(1).assertEqual(number);
842            });
843            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
844            let predicatesSelect = new data_Rdb.RdbPredicates('test');
845            promise.then((result) => {
846                console.log('testRdbSyncTest0090 sync done.');
847                for (let i = 0; i < result.length; i++) {
848                    console.log('testRdbSyncTest0090 device=' + result[i][0] + ' status=' + result[i][1]);
849                    let status = result[i][1];
850                    expect(status == 0).assertTrue();
851                }
852            }).catch((err) => {
853                console.log('testRdbSyncTest0090 sync failed' + err.code);
854                expect().assertFalse();
855            });
856            await promise;
857            let resultSet = await rdbStore.query(predicatesSelect);
858            console.log('testRdbSyncTest0090 resultSet=' +resultSet.rowCount);
859            expect(2).assertEqual(resultSet.rowCount);
860            resultSet = null;
861            let  u8Arr = new Uint8Array([1,2,3,4,5]);
862            try {
863                const valueBucket1 = {
864                    "name": "xuewang09",
865                    "age": 10,
866                    "salary": 50.466,
867                    "blobType": u8Arr
868                }
869                console.log('testRdbSyncTest0090 last insert before');
870                let insertPromise = rdbStore.insert("test", valueBucket1);
871                await insertPromise.then(async (ret) => {
872                    console.log("testRdbSyncTest0090 insertLast ret: " + ret);
873                }).catch((err) => {
874                    console.info("testRdbSyncTest0090 insert err: "+err.message);
875                    expect(null).assertFail();
876                })
877            } catch (error) {
878                console.info("testRdbSyncTest0090 insert err: "+error.message);
879            }
880            let preLast = new data_Rdb.RdbPredicates('test');
881            let promiseTwo = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, preLast);
882            promiseTwo.then((result) => {
883                for (let i = 0; i < result.length; i++) {
884                    console.log('testRdbSyncTest0090 device=' + result[i][0] + ' status=' + result[i][1]);
885                    let status = result[i][1];
886                    expect(status == 0).assertTrue();
887                }
888            }).catch((err) => {
889                console.log('testRdbSyncTest0090 sync failed' + err.code);
890                expect().assertFalse();
891            })
892            await promiseTwo;
893
894            done();
895            console.info(logTag + "************* testRdbSyncTest0090 end *************");
896        })
897
898
899        /**
900        * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_1000
901        * @tc.name testRdbSyncTest0100
902        * @tc.desc Server rdbStore BatchInsert synchronization callback,
903        */
904        it("testRdbSyncTest0100", 0, async function (done) {
905            console.info(logTag + "testRdbSyncTest0100 start");
906
907            //push data to remote device
908            {
909                var u8 = new Uint8Array([1, 2, 3]);
910                const valueBucket1 = {
911                    "name": "mimiy",
912                    "age": 18,
913                    "salary": 100.55,
914                    "blobType": u8
915                }
916                const valueBucket2 = {
917                    "name": "lucy",
918                    "age": 23,
919                    "salary": 200,
920                    "blobType": u8
921                }
922                const valueBucket3 = {
923                    "name": "jiajiahui",
924                    "age": 88,
925                    "salary": 20.5,
926                    "blobType": u8
927                }
928                const valueBucket4 = {
929                    "name": "subby",
930                    "age": 32,
931                    "salary": 20.5,
932                    "blobType": u8
933                }
934                const valueBucket5 = {
935                    "name": "kang",
936                    "age": 64,
937                    "salary": 34444,
938                    "blobType": u8
939                }
940                const valueBuckets = [valueBucket1, valueBucket2, valueBucket3,valueBucket4,valueBucket5];
941                for(var i = 0; i < 20; i++){
942                    await rdbStore.batchInsert("test", valueBuckets).then((number) => {
943                        console.info(logTag + "testRdbSyncTest0100 batchInsert number: " + number + ", i = " + i);
944                        expect(5).assertEqual(number);
945                    }).catch((err) =>{
946                        console.info(logTag + "testRdbSyncTest0100 err: " + err.message);
947                        expect().assertFalse();
948                    })
949                }
950            }
951            let predicates = new data_Rdb.RdbPredicates('test');
952            predicates.inDevices(syncDeviceIds);
953            await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
954                if (err) {
955                    console.log("testRdbSyncTest0100 query error " + err);
956                    expect().assertFail();
957                    return;
958                }
959                for (let i = 0; i < result.length; i++) {
960                    console.log('testRdbSyncTest0100 device=' + result[i][0] + ' status=' + result[i][1]);
961                    let status = result[i][1];
962                    expect(status == 0).assertTrue();
963                }
964                done();
965            });
966            console.info(logTag + "************* testRdbSyncTest0100 end *************");
967        })
968
969
970        /**
971         * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_1100
972         * @tc.name testRdbSyncTest0110
973         * @tc.desc Server rdbStore Insert first and synchronize salary Number.MIN_VALUE-1
974         */
975         it("testRdbSyncTest0110", 0, async function (done) {
976            console.info(logTag + "testRdbSyncTest0110 start");
977            var u8 = new Uint8Array([1, 2, 3]);
978            {
979                const valueBucket = {
980                    "name": "zhangsan",
981                    "age": 18,
982                    "salary": Number.MIN_VALUE-1,
983                    "blobType": u8
984                }
985                await rdbStore.insert("test", valueBucket);
986                console.info("testRdbSyncTest0010 insert success");
987            }
988
989            let predicates = new data_Rdb.RdbPredicates('test');
990            predicates.equalTo("name", "zhangsan");
991            let resultSet = await rdbStore.query(predicates);
992            try {
993                expect(true).assertEqual(resultSet.goToFirstRow());
994                const id = resultSet.getLong(resultSet.getColumnIndex("id"));
995                const name = resultSet.getString(resultSet.getColumnIndex("name"));
996                console.info(logTag + "testRdbSyncTest0110 id=" + id + ", name=" + name);
997                expect("zhangsan").assertEqual(name);
998            } catch (e) {
999                console.info("testRdbSyncTest0110 insert error " + e);
1000                expect().assertFail();
1001            }
1002            resultSet = null;
1003            let syncPre = new data_Rdb.RdbPredicates('test');
1004            syncPre.inDevices(syncDeviceIds);
1005            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, syncPre);
1006            promise.then((result) => {
1007                console.log('testRdbSyncTest0110 sync done.');
1008                for (let i = 0; i < result.length; i++) {
1009                    console.log('testRdbSyncTest0110 device=' + result[i][0] + ' status=' + result[i][1]);
1010                    let status = result[i][1];
1011                    expect(status == 0).assertTrue();
1012                }
1013            }).catch((err) => {
1014                console.log('testRdbSyncTest0110 sync failed' + err.code);
1015                expect().assertFail();
1016            })
1017            await promise;
1018            done();
1019            console.info(logTag + "************* testRdbSyncTest0110 end *************");
1020        })
1021
1022
1023        /**
1024        * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_1200
1025        * @tc.name testRdbSyncTest0120
1026        * @tc.desc Server rdbStore BatchInsert synchronization, and then update synchronization,and then update synchronization
1027        */
1028         it("testRdbSyncTest0120", 0, async function (done) {
1029            console.info(logTag + "testRdbSyncTest0120 start");
1030
1031            //push data to remote device
1032            {
1033                var u8 = new Uint8Array([1, 2, 3]);
1034                const valueBucket1 = {
1035                    "name": "mimiy",
1036                    "age": 18,
1037                    "salary": 100.55,
1038                    "blobType": u8
1039                }
1040                const valueBucket2 = {
1041                    "name": "lucy",
1042                    "age": 23,
1043                    "salary": 200,
1044                    "blobType": u8
1045                }
1046                const valueBucket3 = {
1047                    "name": "jiajiahui",
1048                    "age": 88,
1049                    "salary": 20.5,
1050                    "blobType": u8
1051                }
1052                const valueBuckets = [valueBucket1, valueBucket2, valueBucket3];
1053                await rdbStore.batchInsert("test", valueBuckets).then((number) => {
1054                    console.info(logTag + "testRdbSyncTest0120 batchInsert number: "+ number);
1055                    expect(3).assertEqual(number);
1056                }).catch((err) =>{
1057                    console.info(logTag + "testRdbSyncTest0120 err: " + err.message);
1058                    expect().assertFalse();
1059                })
1060            }
1061            let predicates = new data_Rdb.RdbPredicates('test');
1062            predicates.inDevices(syncDeviceIds);
1063            await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
1064                if (err) {
1065                    console.log("testRdbSyncTest0120 query error " + err);
1066                    expect().assertFail();
1067                    return;
1068                }
1069                for (let i = 0; i < result.length; i++) {
1070                    console.log('testRdbSyncTest0120 device=' + result[i][0] + ' status=' + result[i][1]);
1071                    let status = result[i][1];
1072                    expect(status == 0).assertTrue();
1073                }
1074            });
1075
1076            let  u8ArrUp = new Uint8Array([1,2,3,4,5]);
1077            {
1078                const valueBucket1 = {
1079                    "name": "xuewang12Up",
1080                    "age": 10,
1081                    "salary": 50.366,
1082                    "blobType": u8ArrUp
1083                }
1084                let preUpdate = new data_Rdb.RdbPredicates('test');
1085                preUpdate.equalTo("name", "mimiy");
1086                let updatePromise = rdbStore.update(valueBucket1, preUpdate);
1087                await updatePromise.then(async (ret) => {
1088                    expect(1).assertEqual(ret);
1089                    let resultSet = await rdbStore.query(predicates);
1090                    expect(true).assertEqual(resultSet.goToFirstRow());
1091                    const name = await resultSet.getString(resultSet.getColumnIndex("name"));
1092                    expect("xuewang12Up").assertEqual(name);
1093                    resultSet = null;
1094                }).catch((err) => {
1095                    console.info("testRdbSyncTest0120 update err: "+err.message);
1096                    expect(null).assertFail();
1097                })
1098            }
1099            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
1100            let predicatesSelect = new data_Rdb.RdbPredicates('test');
1101            promise.then((result) => {
1102                console.log('testRdbSyncTest0120 sync done.');
1103                for (let i = 0; i < result.length; i++) {
1104                    console.log('testRdbSyncTest0120 device=' + result[i][0] + ' status=' + result[i][1]);
1105                    let status = result[i][1];
1106                    expect(status == 0).assertTrue();
1107                }
1108            }).catch((err) => {
1109                console.log('testRdbSyncTest0120 sync failed' + err.code);
1110                expect().assertFalse();
1111            });
1112            await promise;
1113            let resultSet = await rdbStore.query(predicatesSelect);
1114            console.log('testRdbSyncTest0120 resultSet=' +resultSet.rowCount);
1115            expect(3).assertEqual(resultSet.rowCount);
1116
1117            let  u8Arr = new Uint8Array([1,2,3,4,5]);
1118            {
1119                const valueBucket1 = {
1120                    "name": "xuewang12Insert",
1121                    "age": 50,
1122                    "salary": 50.4,
1123                    "blobType": u8Arr
1124                }
1125                let insertPromise = rdbStore.insert("test", valueBucket1);
1126                await insertPromise.then(async (ret) => {
1127                    let resultSet = await rdbStore.query(predicates);
1128                    expect(4).assertEqual(resultSet.rowCount);
1129                    resultSet = null;
1130                }).catch((err) => {
1131                    console.info("testRdbSyncTest0120 insert err: "+err.message);
1132                    expect(null).assertFail();
1133                })
1134            }
1135            let preLast = new data_Rdb.RdbPredicates('test');
1136            let promiseTwo = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, preLast);
1137            promiseTwo.then((result) => {
1138                for (let i = 0; i < result.length; i++) {
1139                    console.log('testRdbSyncTest0120 device=' + result[i][0] + ' status=' + result[i][1]);
1140                    let status = result[i][1];
1141                    expect(status == 0).assertTrue();
1142                }
1143            }).catch((err) => {
1144                console.log('testRdbSyncTest0120 sync failed' + err.code);
1145                expect().assertFalse();
1146            })
1147            await promiseTwo;
1148            done();
1149            console.info(logTag + "************* testRdbSyncTest0120 end *************");
1150        })
1151
1152
1153        /**
1154         * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_1300
1155         * @tc.name testRdbSyncTest0130
1156         * @tc.desc Server rdbStore Insert first and synchronize salary Number.MAX_VALUE+1
1157        */
1158        it("testRdbSyncTest0130", 0, async function (done) {
1159            console.info(logTag + "testRdbSyncTest0130 start");
1160            var u8 = new Uint8Array([1, 2, 3]);
1161            {
1162                const valueBucket = {
1163                    "name": "xiaobin0130",
1164                    "age": 18,
1165                    "salary": Number.MAX_VALUE+1,
1166                    "blobType": u8
1167                }
1168                await rdbStore.insert("test", valueBucket);
1169                console.info("testRdbSyncTest0130 insert success");
1170            }
1171
1172            let predicates = new data_Rdb.RdbPredicates('test');
1173            predicates.equalTo("name", "xiaobin0130");
1174            let resultSet = await rdbStore.query(predicates);
1175            try {
1176                expect(true).assertEqual(resultSet.goToFirstRow());
1177                const id = resultSet.getLong(resultSet.getColumnIndex("id"));
1178                const name = resultSet.getString(resultSet.getColumnIndex("name"));
1179                console.info(logTag + "testRdbSyncTest0130 id=" + id + ", name=" + name);
1180                expect("xiaobin0130").assertEqual(name);
1181            } catch (e) {
1182                console.info("testRdbSyncTest0130 insert error " + e);
1183                expect().assertFail();
1184            }
1185            resultSet = null;
1186            let syncPre = new data_Rdb.RdbPredicates('test');
1187            syncPre.inDevices(syncDeviceIds);
1188            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, syncPre);
1189            promise.then((result) => {
1190                console.log('testRdbSyncTest0130 sync done.');
1191                for (let i = 0; i < result.length; i++) {
1192                    console.log('testRdbSyncTest0130 device=' + result[i][0] + ' status=' + result[i][1]);
1193                    let status = result[i][1];
1194                    expect(status == 0).assertTrue();
1195                }
1196            }).catch((err) => {
1197                console.log('testRdbSyncTest0130 sync failed' + err.code);
1198                expect().assertFail();
1199            })
1200            await promise;
1201            done();
1202            console.info(logTag + "************* testRdbSyncTest0130 end *************");
1203        })
1204
1205
1206        /**
1207         * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_1400
1208         * @tc.name testRdbSyncTest0140
1209         * @tc.desc Server rdbStore Insert first and synchronize,delete all
1210        */
1211         it("testRdbSyncTest0140", 0, async function (done) {
1212            console.info(logTag + "testRdbSyncTest0140 start");
1213            var u8 = new Uint8Array([1, 2, 3]);
1214            {
1215                const valueBucket = {
1216                    "name": "xiaoLi0140",
1217                    "age": 18,
1218                    "salary": 1230,
1219                    "blobType": u8
1220                }
1221                await rdbStore.insert("test", valueBucket);
1222                console.info("testRdbSyncTest0140 insert success");
1223            }
1224
1225            let predicates = new data_Rdb.RdbPredicates('test');
1226            predicates.equalTo("name", "xiaoLi0140");
1227            let resultSet = await rdbStore.query(predicates);
1228            try {
1229                expect(true).assertEqual(resultSet.goToFirstRow());
1230                const id = resultSet.getLong(resultSet.getColumnIndex("id"));
1231                const name = resultSet.getString(resultSet.getColumnIndex("name"));
1232                console.info(logTag + "testRdbSyncTest0140 id=" + id + ", name=" + name);
1233                expect("xiaoLi0140").assertEqual(name);
1234            } catch (e) {
1235                console.info("testRdbSyncTest0140 insert error " + e);
1236                expect().assertFail();
1237            }
1238            resultSet = null;
1239            let syncPre = new data_Rdb.RdbPredicates('test');
1240            syncPre.inDevices(syncDeviceIds);
1241            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, syncPre);
1242            promise.then((result) => {
1243                console.log('testRdbSyncTest0140 sync done.');
1244                for (let i = 0; i < result.length; i++) {
1245                    console.log('testRdbSyncTest0140 device=' + result[i][0] + ' status=' + result[i][1]);
1246                    let status = result[i][1];
1247                    expect(status == 0).assertTrue();
1248                }
1249            }).catch((err) => {
1250                console.log('testRdbSyncTest0140 sync failed' + err.code);
1251                expect().assertFail();
1252            })
1253            await promise;
1254            let deleletPre = new data_Rdb.RdbPredicates("test");
1255            console.log('testRdbSyncTest0140 delete bdefore ' );
1256            await rdbStore.delete(deleletPre);
1257            console.log('testRdbSyncTest0140 delete after ' );
1258            let delPromise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, syncPre);
1259            delPromise.then((result) => {
1260                console.log('testRdbSyncTest0140 sync done.');
1261                for (let i = 0; i < result.length; i++) {
1262                    console.log('testRdbSyncTest0140 device=' + result[i][0] + ' status=' + result[i][1]);
1263                    let status = result[i][1];
1264                    expect(status == 0).assertTrue();
1265                    done();
1266                }
1267            }).catch((err) => {
1268                console.log('testRdbSyncTest0140 sync failed' + err.code);
1269                expect().assertFail();
1270                done();
1271            })
1272            await delPromise;
1273            console.info(logTag + "************* testRdbSyncTest0140 end *************");
1274        })
1275
1276        /**
1277         * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_1600
1278         * @tc.name testRdbSyncTest0160
1279         * @tc.desc Server rdbStore Insert first and synchronize, Sync the null character of the pre-device id
1280        */
1281        it("testRdbSyncTest0160", 0, async function (done) {
1282            console.info(logTag + "testRdbSyncTest0160 start");
1283            var u8 = new Uint8Array([1, 2, 3]);
1284            {
1285                const valueBucket = {
1286                    "name": "zhangsan",
1287                    "age": 18,
1288                    "salary": 100.5,
1289                    "blobType": u8
1290                }
1291                await rdbStore.insert("test", valueBucket);
1292                console.info("testRdbSyncTest0160 insert success");
1293            }
1294
1295            let predicates = new data_Rdb.RdbPredicates('test');
1296            predicates.equalTo("name", "zhangsan");
1297            let resultSet = await rdbStore.query(predicates);
1298            try {
1299                expect(true).assertEqual(resultSet.goToFirstRow());
1300                const id = resultSet.getLong(resultSet.getColumnIndex("id"));
1301                const name = resultSet.getString(resultSet.getColumnIndex("name"));
1302                console.info(logTag + "testRdbSyncTest0160 id=" + id + ", name=" + name);
1303                expect("zhangsan").assertEqual(name);
1304            } catch (e) {
1305                console.info("testRdbSyncTest0160 insert error " + e);
1306                expect().assertFail();
1307            }
1308            resultSet = null;
1309            let syncPre = new data_Rdb.RdbPredicates('emp');
1310            syncPre.inDevices(" ");
1311            let promise = rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, syncPre);
1312            promise.then((result) => {
1313                console.log('testRdbSyncTest0160 sync done.');
1314                for (let i = 0; i < result.length; i++) {
1315                    console.log('testRdbSyncTest0160 device=' + result[i][0] + ' status=' + result[i][1]);
1316                    let status = result[i][1];
1317                    expect(status == 0).assertFail();
1318                    done();
1319                }
1320            }).catch((err) => {
1321                console.log('testRdbSyncTest0160 sync failed' + err.code);
1322                expect(err != null).assertTrue();
1323                done();
1324            })
1325            await promise;
1326            console.info(logTag + "************* testRdbSyncTest0160 end *************");
1327        })
1328
1329
1330
1331        /**
1332         * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_1700
1333         * @tc.name testRdbSyncTest0170
1334         * @tc.desc Server rdbStore Insert first and synchronize, Error in synchronization of pre-tableName
1335         */
1336         it("testRdbSyncTest0170", 0, async function (done) {
1337            console.info(logTag + "testRdbSyncTest0170 start");
1338            var u8 = new Uint8Array([1, 2, 3]);
1339            {
1340                const valueBucket = {
1341                    "name": "zhangsan",
1342                    "age": 18,
1343                    "salary": 100.5,
1344                    "blobType": u8
1345                }
1346                await rdbStore.insert("test", valueBucket);
1347                console.info("testRdbSyncTest0170 insert success");
1348            }
1349
1350            let predicates = new data_Rdb.RdbPredicates('test');
1351            predicates.equalTo("name", "zhangsan");
1352            let resultSet = await rdbStore.query(predicates);
1353            try {
1354                expect(true).assertEqual(resultSet.goToFirstRow());
1355                const id = resultSet.getLong(resultSet.getColumnIndex("id"));
1356                const name = resultSet.getString(resultSet.getColumnIndex("name"));
1357                console.info(logTag + "testRdbSyncTest0170 id=" + id + ", name=" + name);
1358                expect("zhangsan").assertEqual(name);
1359            } catch (e) {
1360                console.info("testRdbSyncTest0170 insert error " + e);
1361                expect().assertFail();
1362            }
1363            resultSet = null;
1364            try {
1365                let syncPre = new data_Rdb.RdbPredicates('emp');
1366                syncPre.inDevices(syncDeviceIds);
1367                let promise = await rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, syncPre);
1368                promise.then((result) => {
1369                    console.log('testRdbSyncTest0170 sync done.');
1370                    for (let i = 0; i < result.length; i++) {
1371                        console.log('testRdbSyncTest0170 device=' + result[i][0] + ' status=' + result[i][1]);
1372                        let status = result[i][1];
1373                        expect(status == 0).assertFail();
1374                        done();
1375                    }
1376                }).catch((err) => {
1377                    console.log('testRdbSyncTest0170 sync failed' + err.code);
1378                    expect().assertFail();
1379                    done();
1380                })
1381            } catch (error) {
1382                console.log('testRdbSyncTest0170 sync failed error.code message: ' + error.code + error.message);
1383                expect(error != null).assertTrue();
1384                done();
1385            }
1386            console.info(logTag + "************* testRdbSyncTest0170 end *************");
1387        })
1388
1389        /**
1390         * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_1800
1391         * @tc.name testRdbSyncTest0180
1392         * @tc.desc Server rdbStore Insert first and synchronize, Pass null in synchronous mode
1393        */
1394        it("testRdbSyncTest0180", 0, async function (done) {
1395            console.info(logTag + "testRdbSyncTest0180 start");
1396            var u8 = new Uint8Array([1, 2, 3]);
1397            {
1398                const valueBucket = {
1399                    "name": "zhangsan",
1400                    "age": 18,
1401                    "salary": 100.5,
1402                    "blobType": u8
1403                }
1404                await rdbStore.insert("test", valueBucket);
1405                console.info("testRdbSyncTest0180 insert success");
1406            }
1407
1408            let predicates = new data_Rdb.RdbPredicates('test');
1409            predicates.equalTo("name", "zhangsan");
1410            let resultSet = await rdbStore.query(predicates);
1411            try {
1412                expect(true).assertEqual(resultSet.goToFirstRow());
1413                const id = resultSet.getLong(resultSet.getColumnIndex("id"));
1414                const name = resultSet.getString(resultSet.getColumnIndex("name"));
1415                console.info(logTag + "testRdbSyncTest0180 id=" + id + ", name=" + name);
1416                expect("zhangsan").assertEqual(name);
1417            } catch (e) {
1418                console.info("testRdbSyncTest0180 insert error " + e);
1419                expect().assertFail();
1420            }
1421            resultSet = null;
1422            try {
1423                predicates.inDevices(syncDeviceIds);
1424                let promise = rdbStore.sync(null, predicates);
1425                promise.then((result) => {
1426                    console.log('testRdbSyncTest0180 sync done.');
1427                    for (let i = 0; i < result.length; i++) {
1428                        console.log('testRdbSyncTest0180 device=' + result[i][0] + ' status=' + result[i][1]);
1429                        let status = result[i][1];
1430                        expect(status == 0).assertFail();
1431                    }
1432                    done();
1433                }).catch((err) => {
1434                    console.log('testRdbSyncTest0180 sync failed' + JSON.stringify(err));
1435                    expect().assertFail();
1436                    done();
1437                })
1438            } catch (error) {
1439                console.log('testRdbSyncTest0180 sync failed error.code message: ' + error.code + error.message);
1440                expect(error.code == 401).assertTrue();
1441                done();
1442            }
1443            // await promise;
1444            console.info(logTag + "************* testRdbSyncTest0180 end *************");
1445        })
1446
1447        /**
1448         * @tc.number SUB_DISTRIBUTEDDATAMGR_SyncRDBTest_1900
1449         * @tc.name testRdbSyncTest0190
1450         * @tc.desc Server get rdbStoreS2 level, Name different
1451        */
1452         it("testRdbSyncTest0190", 0, async function (done) {
1453            console.info(logTag + "testRdbSyncTest0190 start");
1454            var rdbSecondStore = {};
1455            const STORE_CONFIGS2 = {
1456                name: "RemoteS2Rdb.db",
1457                securityLevel: data_Rdb.SecurityLevel.S2
1458            };
1459            const CREATE_TABLE_TEST_S2 = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
1460
1461            rdbSecondStore = await data_Rdb.getRdbStore(context, STORE_CONFIGS2);
1462            console.info("testRdbSyncTest0190 create RemoteS2Rdb.db success");
1463            await rdbSecondStore.executeSql(CREATE_TABLE_TEST_S2, null);
1464            console.info(logTag + "create RemoteS2Rdb.db table success");
1465            //setDistributedTables
1466            let back = rdbSecondStore.setDistributedTables(["test"]);
1467            back.then(() => {
1468                console.info("SetDistributedTables successfully.");
1469            }).catch((err) => {
1470                console.info("SetDistributedTables failed, err: " + err.code);
1471            })
1472            await back;
1473            var u8 = new Uint8Array([1, 2, 3]);
1474            {
1475                const valueBucket = {
1476                    "name": "S2Test",
1477                    "age": 18,
1478                    "salary": 100.5,
1479                    "blobType": u8
1480                }
1481                await rdbSecondStore.insert("test", valueBucket);
1482                console.info("testRdbSyncTest0190 insert success");
1483            }
1484
1485            let predicates = new data_Rdb.RdbPredicates('test');
1486            predicates.equalTo("name", "S2Test");
1487            let resultSet = await rdbSecondStore.query(predicates);
1488            try {
1489                expect(true).assertEqual(resultSet.goToFirstRow());
1490                const id = resultSet.getLong(resultSet.getColumnIndex("id"));
1491                const name = resultSet.getString(resultSet.getColumnIndex("name"));
1492                console.info(logTag + "testRdbSyncTest0190 id=" + id + ", name=" + name);
1493                expect("S2Test").assertEqual(name);
1494            } catch (e) {
1495                console.info("testRdbSyncTest0190 select error " + e);
1496                expect().assertFail();
1497            }
1498            resultSet = null;
1499            try {
1500                predicates.inDevices(syncDeviceIds);
1501                let promise = rdbSecondStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
1502                promise.then((result) => {
1503                    console.log('testRdbSyncTest0190 sync done.');
1504                    for (let i = 0; i < result.length; i++) {
1505                        let status = result[i][1];
1506                        console.log('testRdbSyncTest0190 device=' + result[i][0] + ' status=' + result[i][1]);
1507                        console.log('testRdbSyncTest0190  status=' + status);
1508                        expect(status == 26).assertTrue();
1509                        rdbSecondStore = null;
1510                        done();
1511                    }
1512                }).catch((err) => {
1513                    console.log('testRdbSyncTest0190 sync failed' + err.code);
1514                    expect().assertFail();
1515                    done();
1516                })
1517            } catch (error) {
1518                console.log('testRdbSyncTest0190 sync failed error.code message: ' + error.code + error.message);
1519                expect().assertFail();
1520                done();
1521            }
1522            console.info(logTag + "************* testRdbSyncTest0190 end *************");
1523        })
1524    })
1525}
1526