29
29
const assert = require ( 'assert' ) ;
30
30
const oracledb = require ( 'oracledb' ) ;
31
31
const dbconfig = require ( './dbconfig.js' ) ;
32
+ const testsUtil = require ( './testsUtil.js' ) ;
32
33
33
34
describe ( "256. executeQueue.js" , function ( ) {
34
35
let connection ;
35
36
let errorOnConcurrentExecuteBak = oracledb . errorOnConcurrentExecute ;
36
37
38
+ const content = [ ] ;
39
+ content [ 0 ] = { name : "Venkat" , address : { city : "Bengaluru" } } ;
40
+ content [ 1 ] = { name : "May" , address : { city : "London" } } ;
41
+ const loopCount = 2 ;
42
+
37
43
before ( async function ( ) {
38
44
connection = await oracledb . getConnection ( dbconfig ) ;
39
45
} ) ; //before()
@@ -48,7 +54,7 @@ describe("256. executeQueue.js", function() {
48
54
oracledb . errorOnConcurrentExecute = errorOnConcurrentExecuteBak ;
49
55
} ) ; //afterEach()
50
56
51
- describe ( "256.1 oracledb.errorOnConcurrentExecute " , function ( ) {
57
+ describe ( "256.1 Connection.execute() " , function ( ) {
52
58
53
59
// causes a break to be issued; this must be done *after* an execute has
54
60
// already taken place; otherwise, the break() is ignored; a sleep of 200
@@ -67,41 +73,39 @@ describe("256. executeQueue.js", function() {
67
73
await connection . execute ( sql ) ;
68
74
}
69
75
70
- async function query ( connection ) {
76
+ async function doQuery ( connection ) {
71
77
const result = await connection . execute ( `select * from dual` ) ;
72
78
return ( result . rows [ 0 ] [ 0 ] ) ;
73
79
}
74
80
75
- it ( '256.1.1 property set to false' , async function ( ) {
81
+ it ( '256.1.1 errorOnConcurrentExecute set to false' , async function ( ) {
76
82
oracledb . errorOnConcurrentExecute = false ;
77
83
const promises = [ ] ;
78
- const loopCount = 2 ;
79
84
for ( let i = 0 ; i < loopCount ; i ++ ) {
80
- promises [ i ] = query ( connection ) ;
85
+ promises [ i ] = doQuery ( connection ) ;
81
86
}
82
87
let values = await Promise . allSettled ( promises ) ;
83
88
for ( let i = 0 ; i < loopCount ; i ++ ) {
84
89
assert . strictEqual ( values [ i ] . status , 'fulfilled' ) ;
85
90
assert . strictEqual ( values [ i ] . value , 'X' ) ;
86
91
}
87
- } ) ; // 256.1.1
92
+ } ) ;
88
93
89
- it ( '256.1.2 property set to true' , async function ( ) {
94
+ it ( '256.1.2 errorOnConcurrentExecute set to true' , async function ( ) {
90
95
oracledb . errorOnConcurrentExecute = true ;
91
96
const promises = [ ] ;
92
- const loopCount = 2 ;
93
97
for ( let i = 0 ; i < loopCount ; i ++ ) {
94
- promises [ i ] = query ( connection ) ;
98
+ promises [ i ] = doQuery ( connection ) ;
95
99
}
96
100
const values = await Promise . allSettled ( promises ) ;
97
101
assert . strictEqual ( values [ 1 ] . status , 'rejected' ) ;
98
102
assert . match ( values [ 1 ] . reason . message , / N J S - 0 8 1 : / ) ;
99
- } ) ; // 256.1.2
103
+ } ) ;
100
104
101
105
it ( '256.1.3 break() not constrained by queue' , async function ( ) {
102
106
103
- // This test uses dbms_session.sleep which needs 18c
104
- if ( connection . oracleServerVersion < 1800000000 ) {
107
+ // Skip for older versions since this test might hang unless DISABLE_OOB=ON is in sqlnet.ora
108
+ if ( connection . oracleServerVersion <= 1900000000 || oracledb . oracleClientVersion <= 1900000000 ) {
105
109
this . skip ( ) ;
106
110
return ;
107
111
}
@@ -111,8 +115,315 @@ describe("256. executeQueue.js", function() {
111
115
const values = await Promise . allSettled ( promises ) ;
112
116
assert . strictEqual ( values [ 0 ] . status , 'rejected' ) ;
113
117
assert . match ( values [ 0 ] . reason . message , / O R A - 0 1 0 1 3 : / ) ;
114
- } ) ; // 256.1.2
118
+ } ) ;
119
+ } ) ;
120
+
121
+ describe ( "256.2 SodaDatabase.createCollection()" , function ( ) {
122
+ before ( async function ( ) {
123
+ const runnable = await testsUtil . isSodaRunnable ( ) ;
124
+ if ( ! runnable ) {
125
+ this . skip ( ) ;
126
+ }
127
+ } ) ;
128
+ async function doCreateCollection ( sd , collName ) {
129
+ return await sd . createCollection ( collName ) ;
130
+ }
131
+
132
+ it ( '256.2.1 errorOnConcurrentExecute set to false' , async function ( ) {
133
+ oracledb . errorOnConcurrentExecute = false ;
134
+ const promises = [ ] ;
135
+ const sd = connection . getSodaDatabase ( ) ;
136
+ let collName = "soda_collection" ;
137
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
138
+ promises [ i ] = doCreateCollection ( sd , collName + i ) ;
139
+ }
140
+ let values = await Promise . allSettled ( promises ) ;
141
+ collName = "soda_collection" ;
142
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
143
+ assert . strictEqual ( values [ i ] . status , 'fulfilled' ) ;
144
+ assert . strictEqual ( values [ i ] . value . name , collName + i ) ;
145
+ ( values [ i ] . value ) . drop ( ) ;
146
+ }
147
+ } ) ;
148
+
149
+ it ( '256.2.2 errorOnConcurrentExecute set to true' , async function ( ) {
150
+ oracledb . errorOnConcurrentExecute = true ;
151
+ const promises = [ ] ;
152
+ const sd = connection . getSodaDatabase ( ) ;
153
+ let collName = "soda_collection" ;
154
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
155
+ collName = collName + i ;
156
+ promises [ i ] = doCreateCollection ( sd , collName ) ;
157
+ }
158
+ const values = await Promise . allSettled ( promises ) ;
159
+ assert . strictEqual ( values [ 1 ] . status , 'rejected' ) ;
160
+ assert . match ( values [ 1 ] . reason . message , / N J S - 0 8 1 : / ) ;
161
+ } ) ;
162
+ } ) ;
163
+
164
+ describe ( "256.3 SodaCollection.insertOne()" , function ( ) {
165
+ before ( async function ( ) {
166
+ const runnable = await testsUtil . isSodaRunnable ( ) ;
167
+ if ( ! runnable ) {
168
+ this . skip ( ) ;
169
+ }
170
+ } ) ;
171
+ async function doInsertCollection ( collection , content ) {
172
+ return await collection . insertOne ( content ) ;
173
+ }
174
+
175
+ it ( '256.3.1 errorOnConcurrentExecute set to false' , async function ( ) {
176
+ oracledb . errorOnConcurrentExecute = false ;
177
+ const promises = [ ] ;
178
+ const sd = connection . getSodaDatabase ( ) ;
179
+ const collection = await sd . createCollection ( "soda_collection_256_3_1" ) ;
180
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
181
+ promises [ i ] = doInsertCollection ( collection , content [ i ] ) ;
182
+ }
183
+ await Promise . allSettled ( promises ) ;
184
+ const res1 = await collection . find ( ) . count ( ) ;
185
+ assert . strictEqual ( res1 . count , 2 ) ;
186
+ await connection . commit ( ) ;
187
+ await collection . drop ( ) ;
188
+ } ) ;
189
+
190
+ it ( '256.3.2 errorOnConcurrentExecute set to true' , async function ( ) {
191
+ oracledb . errorOnConcurrentExecute = true ;
192
+ const promises = [ ] ;
193
+ const sd = connection . getSodaDatabase ( ) ;
194
+ const collection = await sd . createCollection ( "soda_collection_256_3_2" ) ;
195
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
196
+ promises [ i ] = doInsertCollection ( collection , content [ i ] ) ;
197
+ }
198
+ const values = await Promise . allSettled ( promises ) ;
199
+ assert . strictEqual ( values [ 1 ] . status , 'rejected' ) ;
200
+ assert . match ( values [ 1 ] . reason . message , / N J S - 0 8 1 : / ) ;
201
+ } ) ;
202
+ } ) ;
115
203
116
- } ) ; // 256.1
204
+ describe ( "256.4 SodaOperation.count()" , function ( ) {
205
+ before ( async function ( ) {
206
+ const runnable = await testsUtil . isSodaRunnable ( ) ;
207
+ if ( ! runnable ) {
208
+ this . skip ( ) ;
209
+ }
210
+ } ) ;
211
+ async function doCount ( collection ) {
212
+ return await collection . find ( ) . count ( ) ;
213
+ }
117
214
118
- } ) ; // 256
215
+ it ( '256.4.1 errorOnConcurrentExecute set to false' , async function ( ) {
216
+ oracledb . errorOnConcurrentExecute = false ;
217
+ const promises = [ ] ;
218
+ const sd = connection . getSodaDatabase ( ) ;
219
+ const collection = await sd . createCollection ( "soda_collection_256_4_1" ) ;
220
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
221
+ await collection . insertOne ( content [ i ] ) ;
222
+ }
223
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
224
+ promises [ i ] = doCount ( collection ) ;
225
+ }
226
+ let values = await Promise . allSettled ( promises ) ;
227
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
228
+ assert . strictEqual ( values [ i ] . status , 'fulfilled' ) ;
229
+ assert . strictEqual ( values [ i ] . value . count , 2 ) ;
230
+ }
231
+ await connection . commit ( ) ;
232
+ await collection . drop ( ) ;
233
+ } ) ;
234
+
235
+ it ( '256.4.2 errorOnConcurrentExecute set to true' , async function ( ) {
236
+ oracledb . errorOnConcurrentExecute = true ;
237
+ const promises = [ ] ;
238
+ const sd = connection . getSodaDatabase ( ) ;
239
+ const collection = await sd . createCollection ( "soda_collection_256_4_2" ) ;
240
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
241
+ await collection . insertOne ( content [ i ] ) ;
242
+ }
243
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
244
+ promises [ i ] = doCount ( collection ) ;
245
+ }
246
+ const values = await Promise . allSettled ( promises ) ;
247
+ assert . strictEqual ( values [ 1 ] . status , 'rejected' ) ;
248
+ assert . match ( values [ 1 ] . reason . message , / N J S - 0 8 1 : / ) ;
249
+ } ) ;
250
+ } ) ;
251
+
252
+ describe ( "256.5 SodaDocCursor.getNext()" , function ( ) {
253
+ before ( async function ( ) {
254
+ const runnable = await testsUtil . isSodaRunnable ( ) ;
255
+ if ( ! runnable ) {
256
+ this . skip ( ) ;
257
+ }
258
+ } ) ;
259
+ async function doGetNext ( docCursor ) {
260
+ return await docCursor . getNext ( ) ;
261
+ }
262
+
263
+ it ( '256.5.1 errorOnConcurrentExecute set to false' , async function ( ) {
264
+ oracledb . errorOnConcurrentExecute = false ;
265
+ const promises = [ ] ;
266
+ const sd = connection . getSodaDatabase ( ) ;
267
+ const collection = await sd . createCollection ( "soda_collection_256_5_1" ) ;
268
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
269
+ await collection . insertOne ( content [ i ] ) ;
270
+ }
271
+ const docCursor = await collection . find ( ) . getCursor ( ) ;
272
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
273
+ promises [ i ] = doGetNext ( docCursor ) ;
274
+ }
275
+ let values = await Promise . allSettled ( promises ) ;
276
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
277
+ assert . strictEqual ( values [ i ] . status , 'fulfilled' ) ;
278
+ assert . equal ( values [ i ] . value . getContent ( ) . toString ( ) , content [ i ] ) ;
279
+ }
280
+ await connection . commit ( ) ;
281
+ await collection . drop ( ) ;
282
+ } ) ;
283
+
284
+ it ( '256.5.2 errorOnConcurrentExecute set to true' , async function ( ) {
285
+ oracledb . errorOnConcurrentExecute = true ;
286
+ const promises = [ ] ;
287
+ const sd = connection . getSodaDatabase ( ) ;
288
+ const collection = await sd . createCollection ( "soda_collection_256_5_2" ) ;
289
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
290
+ await collection . insertOne ( content [ i ] ) ;
291
+ }
292
+ const docCursor = await collection . find ( ) . getCursor ( ) ;
293
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
294
+ promises [ i ] = doGetNext ( docCursor ) ;
295
+ }
296
+ const values = await Promise . allSettled ( promises ) ;
297
+ assert . strictEqual ( values [ 1 ] . status , 'rejected' ) ;
298
+ assert . match ( values [ 1 ] . reason . message , / N J S - 0 8 1 : / ) ;
299
+ } ) ;
300
+ } ) ;
301
+
302
+ describe ( "256.6 Execute queue length" , function ( ) {
303
+ async function doQuery ( connection ) {
304
+ const ql = connection . _requestQueue . length ; // This one is an internal variable
305
+ await connection . execute ( `select * from dual` ) ;
306
+ return ( ql ) ;
307
+ }
308
+
309
+ it ( '256.6.1 errorOnConcurrentExecute set to false' , async function ( ) {
310
+ oracledb . errorOnConcurrentExecute = false ;
311
+ const promises = [ ] ;
312
+ for ( let i = 0 ; i < 4 ; i ++ ) {
313
+ promises [ i ] = doQuery ( connection ) ;
314
+ }
315
+ let values = await Promise . allSettled ( promises ) ;
316
+ assert . strictEqual ( values [ 0 ] . status , 'fulfilled' ) ;
317
+ assert . strictEqual ( values [ 0 ] . value , 0 ) ; // It will execute first, 0 in the queue
318
+ assert . strictEqual ( values [ 1 ] . status , 'fulfilled' ) ;
319
+ assert . strictEqual ( values [ 1 ] . value , 0 ) ; // When the 2nd starts, there should be 1 executing, and 0 in the queue
320
+ assert . strictEqual ( values [ 2 ] . status , 'fulfilled' ) ;
321
+ assert . strictEqual ( values [ 2 ] . value , 1 ) ; // When the 3rd starts, there should be 1 executing, and 1 in the queue
322
+ assert . strictEqual ( values [ 3 ] . status , 'fulfilled' ) ;
323
+ assert . strictEqual ( values [ 3 ] . value , 2 ) ; // When the 4th starts, there should be 1 executing, and 2 in the queue
324
+ const queueTotal = values . reduce ( ( prev , cur ) => prev + cur . value , 0 ) ;
325
+ assert . strictEqual ( queueTotal , 3 ) ;
326
+ } ) ;
327
+
328
+ it ( '256.6.2 errorOnConcurrentExecute set to true' , async function ( ) {
329
+ oracledb . errorOnConcurrentExecute = true ;
330
+ const promises = [ ] ;
331
+
332
+ for ( let i = 0 ; i < 3 ; i ++ ) {
333
+ promises [ i ] = doQuery ( connection ) ;
334
+ }
335
+ const values = await Promise . allSettled ( promises ) ;
336
+ assert . strictEqual ( values [ 1 ] . status , 'rejected' ) ;
337
+ assert . match ( values [ 1 ] . reason . message , / N J S - 0 8 1 : / ) ;
338
+ } ) ;
339
+ } ) ;
340
+
341
+ describe ( "256.7 Lob.getData()" , function ( ) {
342
+ const tab = 'nodb_tab_myclob' ;
343
+ let conn ;
344
+ before ( async function ( ) {
345
+ try {
346
+ conn = await oracledb . getConnection ( dbconfig ) ;
347
+ const sql =
348
+ `create table ${ tab } (
349
+ id number(9) not null,
350
+ value clob not null
351
+ )` ;
352
+ const plsql = testsUtil . sqlCreateTable ( tab , sql ) ;
353
+ await conn . execute ( plsql ) ;
354
+ } catch ( err ) {
355
+ assert . fail ( err ) ;
356
+ }
357
+ } ) ;
358
+
359
+ after ( async function ( ) {
360
+ try {
361
+ let sql = `drop table ${ tab } purge` ;
362
+ await conn . execute ( sql ) ;
363
+ await conn . close ( ) ;
364
+ } catch ( err ) {
365
+ assert . fail ( err ) ;
366
+ }
367
+ } ) ;
368
+
369
+ beforeEach ( async function ( ) {
370
+ try {
371
+ await conn . execute ( `Delete from ` + tab ) ;
372
+ } catch ( error ) {
373
+ assert . fail ( error ) ;
374
+ }
375
+ } ) ;
376
+
377
+ async function doGetData ( lob ) {
378
+ return await lob . getData ( ) ;
379
+ }
380
+
381
+ it ( '256.7.1 errorOnConcurrentExecute set to false' , async function ( ) {
382
+ oracledb . errorOnConcurrentExecute = false ;
383
+ const promises = [ ] ;
384
+ const clob = [ ] ;
385
+ const content = 'A short string value' ;
386
+ let sql = `insert into ${ tab } values (1, '${ content } ')` ;
387
+ await conn . execute ( sql ) ;
388
+
389
+ sql = `select * from ${ tab } where id = 1` ;
390
+ const result1 = await conn . execute ( sql ) ;
391
+ const result2 = await conn . execute ( sql ) ;
392
+ clob [ 0 ] = result1 . rows [ 0 ] [ 1 ] ;
393
+ clob [ 1 ] = result2 . rows [ 0 ] [ 1 ] ;
394
+
395
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
396
+ promises [ i ] = doGetData ( clob [ i ] ) ;
397
+ }
398
+ let values = await Promise . allSettled ( promises ) ;
399
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
400
+ assert . strictEqual ( values [ i ] . status , 'fulfilled' ) ;
401
+ assert . equal ( values [ 0 ] . value , content ) ;
402
+ }
403
+ } ) ;
404
+
405
+ it ( '256.7.2 errorOnConcurrentExecute set to true' , async function ( ) {
406
+ oracledb . errorOnConcurrentExecute = true ;
407
+ const promises = [ ] ;
408
+ const clob = [ ] ;
409
+ const content = 'A short string value' ;
410
+ let sql = `insert into ${ tab } values (1, '${ content } ')` ;
411
+ await conn . execute ( sql ) ;
412
+
413
+ sql = `select * from ${ tab } where id = 1` ;
414
+ const result1 = await conn . execute ( sql ) ;
415
+ const result2 = await conn . execute ( sql ) ;
416
+ clob [ 0 ] = result1 . rows [ 0 ] [ 1 ] ;
417
+ clob [ 1 ] = result2 . rows [ 0 ] [ 1 ] ;
418
+
419
+ for ( let i = 0 ; i < loopCount ; i ++ ) {
420
+ promises [ i ] = doGetData ( clob [ i ] ) ;
421
+ }
422
+ const values = await Promise . allSettled ( promises ) ;
423
+ assert . strictEqual ( values [ 0 ] . status , 'fulfilled' ) ;
424
+ assert . equal ( values [ 0 ] . value , content ) ;
425
+ assert . strictEqual ( values [ 1 ] . status , 'rejected' ) ;
426
+ assert . match ( values [ 1 ] . reason . message , / N J S - 0 8 1 : / ) ;
427
+ } ) ;
428
+ } ) ;
429
+ } ) ;
0 commit comments