Skip to content

Commit f6c8f6c

Browse files
committed
More test cases to increase the test coverage
1 parent 343d0ff commit f6c8f6c

File tree

13 files changed

+1271
-24
lines changed

13 files changed

+1271
-24
lines changed

test/aq1.js

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe('217. aq1.js', function() {
129129
Object.assign(
130130
queue2.deqOptions,
131131
{
132-
visibility: oracledb.AQ_VISIBILITY_IMMEDIATE, // Change the visibility so no explicit commit is required
132+
visibility: oracledb.AQ_VISIBILITY_IMMEDIATE, // Change the visibility so that no explicit commit is required
133133
wait: 25 // seconds it will wait if there are no messages
134134
}
135135
);
@@ -204,4 +204,151 @@ describe('217. aq1.js', function() {
204204
assert.deepStrictEqual(messages, []);
205205
}); // 217.6
206206

207+
it('217.7 get delay property', async () => {
208+
/* Enqueue */
209+
const queue1 = await conn.getQueue(rawQueueName);
210+
211+
// Send a message immediately without requiring a commit
212+
queue1.enqOptions.visibility = oracledb.AQ_VISIBILITY_IMMEDIATE;
213+
214+
const messageString = 'This is my other message';
215+
const message = {
216+
payload: messageString, // the message itself
217+
delay: 5 // Delay the message by 5 seconds
218+
};
219+
const myMsg = await queue1.enqOne(message);
220+
221+
/* Dequeue */
222+
const queue2 = await conn.getQueue(rawQueueName);
223+
Object.assign(
224+
queue2.deqOptions,
225+
{
226+
visibility: oracledb.AQ_VISIBILITY_IMMEDIATE, // Change the visibility so that no explicit commit is required
227+
}
228+
);
229+
queue2.deqOptions.delay = myMsg.delay;
230+
const msg = await queue2.deqOne();
231+
if (msg) {
232+
assert.strictEqual(msg.payload.toString(), messageString);
233+
}
234+
}); // 217.7
235+
236+
it('217.8 get deliveryMode property', async () => {
237+
/* Enqueue */
238+
const queue1 = await conn.getQueue(rawQueueName);
239+
240+
// Send a message immediately without requiring a commit
241+
queue1.enqOptions.visibility = oracledb.AQ_VISIBILITY_IMMEDIATE;
242+
queue1.enqOptions.deliveryMode = 1; // Delivery mode when enqueuing messages
243+
244+
const messageString = 'This is my other message';
245+
const message = {
246+
payload: messageString // the message itself
247+
};
248+
const myMsg = await queue1.enqOne(message);
249+
250+
// Get the deliveryMode attribute in enqOptions
251+
assert.strictEqual(queue1.enqOptions.deliveryMode, 1);
252+
253+
/* Dequeue */
254+
const queue2 = await conn.getQueue(rawQueueName);
255+
Object.assign(
256+
queue2.deqOptions,
257+
{
258+
visibility: oracledb.AQ_VISIBILITY_IMMEDIATE, // Change the visibility so that no explicit commit is required
259+
}
260+
);
261+
queue2.deqOptions.deliveryMode = myMsg.deliveryMode;
262+
const msg = await queue2.deqOne();
263+
if (msg) {
264+
assert.strictEqual(msg.payload.toString(), messageString);
265+
}
266+
}); // 217.8
267+
268+
it('217.9 get exceptionQueue property', async () => {
269+
/* Enqueue */
270+
const queue1 = await conn.getQueue(rawQueueName);
271+
272+
// Send a message immediately without requiring a commit
273+
queue1.enqOptions.visibility = oracledb.AQ_VISIBILITY_IMMEDIATE;
274+
275+
const messageString = 'This is my other message';
276+
const message = {
277+
payload: messageString, // the message itself
278+
exceptionQueue: "QueueName" // Name of the exception queue defined when the message was enqueued
279+
};
280+
const myMsg = await queue1.enqOne(message);
281+
282+
/* Dequeue */
283+
const queue2 = await conn.getQueue(rawQueueName);
284+
Object.assign(
285+
queue2.deqOptions,
286+
{
287+
visibility: oracledb.AQ_VISIBILITY_IMMEDIATE, // Change the visibility so that no explicit commit is required
288+
}
289+
);
290+
queue2.deqOptions.exceptionQueue = myMsg.exceptionQueue;
291+
const msg = await queue2.deqOne();
292+
if (msg) {
293+
assert.strictEqual(msg.payload.toString(), messageString);
294+
}
295+
}); // 217.9
296+
297+
it('217.10 set and get visibility attribute', async () => {
298+
/* Enqueue */
299+
const queue1 = await conn.getQueue(rawQueueName);
300+
301+
// Send a message immediately without requiring a commit
302+
queue1.enqOptions.visibility = oracledb.AQ_VISIBILITY_IMMEDIATE;
303+
304+
const messageString = 'This is my other message';
305+
const message = {
306+
payload: messageString, // the message itself
307+
};
308+
await queue1.enqOne(message);
309+
assert.strictEqual(queue1.enqOptions.visibility, oracledb.AQ_VISIBILITY_IMMEDIATE);
310+
311+
/* Dequeue */
312+
const queue2 = await conn.getQueue(rawQueueName);
313+
Object.assign(
314+
queue2.deqOptions,
315+
{
316+
visibility: oracledb.AQ_VISIBILITY_IMMEDIATE, // Change the visibility so that no explicit commit is required
317+
}
318+
);
319+
const msg = await queue2.deqOne();
320+
assert.strictEqual(queue2.deqOptions.visibility, oracledb.AQ_VISIBILITY_IMMEDIATE);
321+
assert.strictEqual(msg.payload.toString(), messageString);
322+
}); // 217.10
323+
324+
it('217.11 get numAttempts attribute', async () => {
325+
/* Enqueue */
326+
const queue1 = await conn.getQueue(rawQueueName);
327+
328+
// Send a message immediately without requiring a commit
329+
queue1.enqOptions.visibility = oracledb.AQ_VISIBILITY_IMMEDIATE;
330+
331+
const messageString = 'This is my other message';
332+
const message = {
333+
payload: messageString, // the message itself
334+
};
335+
await queue1.enqOne(message);
336+
337+
/* Dequeue */
338+
const queue2 = await conn.getQueue(rawQueueName);
339+
340+
/*1st dequeue*/
341+
let msg = await queue2.deqOne();
342+
if (msg) {
343+
assert.strictEqual(msg.payload.toString(), messageString);
344+
}
345+
assert.strictEqual(msg.numAttempts, 0); // should be 0
346+
347+
/*rollback*/
348+
await conn.rollback();
349+
350+
/*2nd dequeue attempt*/
351+
msg = await queue2.deqOne();
352+
assert.strictEqual(msg.numAttempts, 1); // should be 1
353+
}); // 217.11
207354
});

test/aq10.js

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/* Copyright (c) 2024, Oracle and/or its affiliates. */
2+
3+
/******************************************************************************
4+
*
5+
* This software is dual-licensed to you under the Universal Permissive License
6+
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
7+
* 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
8+
* either license.
9+
*
10+
* If you elect to accept the software under the Apache License, Version 2.0,
11+
* the following applies:
12+
*
13+
* Licensed under the Apache License, Version 2.0 (the "License");
14+
* you may not use this file except in compliance with the License.
15+
* You may obtain a copy of the License at
16+
*
17+
* https://www.apache.org/licenses/LICENSE-2.0
18+
*
19+
* Unless required by applicable law or agreed to in writing, software
20+
* distributed under the License is distributed on an "AS IS" BASIS,
21+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
* See the License for the specific language governing permissions and
23+
* limitations under the License.
24+
*
25+
* NAME
26+
* 302. aq10.js
27+
*
28+
* DESCRIPTION
29+
* Test Oracle Advanced Queueing (AQ) condition attribute.
30+
* condition: A String that defines the condition that must be satisfied
31+
* in order for a message to be dequeued.
32+
*****************************************************************************/
33+
'use strict';
34+
35+
const oracledb = require('oracledb');
36+
const dbConfig = require('./dbconfig.js');
37+
const testsUtil = require('./testsUtil.js');
38+
const assert = require('assert');
39+
40+
describe('302. aq10.js', function() {
41+
let isRunnable = true;
42+
let conn;
43+
const AQ_USER = 'NODB_SCHEMA_AQTEST10';
44+
const AQ_USER_PWD = testsUtil.generateRandomPassword();
45+
46+
const objQueueName = "NODB_ADDR_QUEUE";
47+
const objType = "NODB_ADDR_TYP";
48+
const objTable = "NODB_TAB_ADDR";
49+
50+
before(async function() {
51+
const prerequisites = await testsUtil.checkPrerequisites(2100000000, 2100000000);
52+
if (!dbConfig.test.DBA_PRIVILEGE || oracledb.thin || !prerequisites) {
53+
isRunnable = false;
54+
}
55+
56+
if (!isRunnable) this.skip();
57+
58+
await testsUtil.createAQtestUser(AQ_USER, AQ_USER_PWD);
59+
const credential = {
60+
user: AQ_USER,
61+
password: AQ_USER_PWD,
62+
connectString: dbConfig.connectString
63+
};
64+
conn = await oracledb.getConnection(credential);
65+
66+
// Create the Type
67+
let plsql = `
68+
CREATE OR REPLACE TYPE ${objType} AS OBJECT (
69+
NAME VARCHAR2(10),
70+
ADDRESS VARCHAR2(50)
71+
);
72+
`;
73+
await conn.execute(plsql);
74+
75+
// Create and start a queue
76+
plsql = `
77+
BEGIN
78+
DBMS_AQADM.CREATE_QUEUE_TABLE(
79+
QUEUE_TABLE => '${AQ_USER}.${objTable}',
80+
QUEUE_PAYLOAD_TYPE => '${objType}'
81+
);
82+
DBMS_AQADM.CREATE_QUEUE(
83+
QUEUE_NAME => '${AQ_USER}.${objQueueName}',
84+
QUEUE_TABLE => '${AQ_USER}.${objTable}'
85+
);
86+
DBMS_AQADM.START_QUEUE(
87+
QUEUE_NAME => '${AQ_USER}.${objQueueName}'
88+
);
89+
END;
90+
`;
91+
await conn.execute(plsql);
92+
});
93+
94+
after (async function() {
95+
if (!isRunnable) return;
96+
97+
await conn.execute(`
98+
BEGIN
99+
DBMS_AQADM.STOP_QUEUE('${AQ_USER}.${objQueueName}');
100+
END; `);
101+
await conn.execute(`
102+
BEGIN
103+
DBMS_AQADM.DROP_QUEUE_TABLE(
104+
QUEUE_TABLE => '${AQ_USER}.${objTable}',
105+
FORCE => TRUE);
106+
END; `);
107+
108+
await conn.execute(`DROP TYPE ${objType}`);
109+
await conn.close();
110+
await testsUtil.dropAQtestUser(AQ_USER);
111+
});
112+
113+
const addrData1 = {
114+
NAME: "John",
115+
ADDRESS: "100 Oracle Parkway Redwood City, CA US 94065"
116+
};
117+
118+
const addrData2 = {
119+
NAME: "Jenny",
120+
ADDRESS: "200 Oracle Parkway Redwood City, CA US 94065"
121+
};
122+
123+
const addrData3 = {
124+
NAME: "Laura",
125+
ADDRESS: "300 Oracle Parkway Redwood City, CA US 94065"
126+
};
127+
128+
it('302.1 condition attribute in dequeue', async () => {
129+
// Enqueue
130+
const queue = await conn.getQueue(
131+
objQueueName,
132+
{ payloadType: objType }
133+
);
134+
const message1 = new queue.payloadTypeClass(addrData1);
135+
await queue.enqOne(message1);
136+
await conn.commit();
137+
138+
const message2 = new queue.payloadTypeClass(addrData2);
139+
await queue.enqOne(message2);
140+
await conn.commit();
141+
142+
const message3 = new queue.payloadTypeClass(addrData3);
143+
await queue.enqOne(message3);
144+
await conn.commit();
145+
146+
// Dequeue
147+
const queue2 = await conn.getQueue(
148+
objQueueName,
149+
{ payloadType: objType }
150+
);
151+
152+
queue2.deqOptions.condition = `tab.user_data.NAME = '${addrData2.NAME}'`;
153+
const msgDeq = await queue2.deqOne();
154+
assert.strictEqual(msgDeq.payload.NAME, addrData2.NAME);
155+
assert.strictEqual(msgDeq.payload.ADDRESS, addrData2.ADDRESS);
156+
}); // 302.1
157+
158+
it('302.2 Negative - wrong identifier in condition attribute', async () => {
159+
// Dequeue
160+
const queue2 = await conn.getQueue(
161+
objQueueName,
162+
{ payloadType: objType }
163+
);
164+
165+
queue2.deqOptions.condition = `someString.NAME = '${addrData2.NAME}'`;
166+
await assert.rejects(
167+
async () => await queue2.deqOne(),
168+
/ORA-00904:/ //ORA-00904: "SOMESTRING"."NAME": invalid identifier
169+
);
170+
assert.strictEqual(queue2.deqOptions.condition, `someString.NAME = '${addrData2.NAME}'`);
171+
}); // 302.2
172+
});

0 commit comments

Comments
 (0)