Skip to content

Commit ac3f4fa

Browse files
committed
Add AQ tests
1 parent 28e46d1 commit ac3f4fa

File tree

6 files changed

+719
-2
lines changed

6 files changed

+719
-2
lines changed

test/aq1.js

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with the Apache
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* NAME
19+
* 217. aq1.js
20+
*
21+
* DESCRIPTION
22+
* Test Oracle Advanced Queueing (AQ).
23+
* The test version of examples/aqraw.js and examples/aqoptions.js.
24+
*
25+
*****************************************************************************/
26+
'use strict';
27+
28+
const oracledb = require('oracledb');
29+
const should = require('should');
30+
const dbconfig = require('./dbconfig.js');
31+
const testsUtil = require('./testsUtil.js');
32+
33+
describe('217. aq1.js', function() {
34+
35+
let isRunnable = true;
36+
let conn;
37+
const AQ_USER = 'NODB_SCHEMA_AQTEST1';
38+
const AQ_USER_PWD = testsUtil.generateRandomPassword();
39+
40+
const rawQueueName = "NODB_RAW_QUEUE";
41+
const RAW_TABLE = 'NODB_RAW_QUEUE_TAB';
42+
43+
before(async function() {
44+
if (!dbconfig.test.DBA_PRIVILEGE) {
45+
isRunnable = false;
46+
}
47+
48+
if (!isRunnable) {
49+
this.skip();
50+
return;
51+
} else {
52+
try {
53+
await testsUtil.createAQtestUser(AQ_USER, AQ_USER_PWD);
54+
55+
let credential = {
56+
user: AQ_USER,
57+
password: AQ_USER_PWD,
58+
connectString: dbconfig.connectString
59+
};
60+
conn = await oracledb.getConnection(credential);
61+
62+
let plsql = `
63+
BEGIN
64+
DBMS_AQADM.CREATE_QUEUE_TABLE(
65+
QUEUE_TABLE => '${AQ_USER}.${RAW_TABLE}',
66+
QUEUE_PAYLOAD_TYPE => 'RAW'
67+
);
68+
DBMS_AQADM.CREATE_QUEUE(
69+
QUEUE_NAME => '${AQ_USER}.${rawQueueName}',
70+
QUEUE_TABLE => '${AQ_USER}.${RAW_TABLE}'
71+
);
72+
DBMS_AQADM.START_QUEUE(
73+
QUEUE_NAME => '${AQ_USER}.${rawQueueName}'
74+
);
75+
END;
76+
`;
77+
await conn.execute(plsql);
78+
79+
} catch (err) {
80+
should.not.exist(err);
81+
}
82+
}
83+
84+
}); // before()
85+
86+
after(async function() {
87+
if (!isRunnable) {
88+
return;
89+
} else {
90+
try {
91+
await conn.close();
92+
await testsUtil.dropAQtestUser(AQ_USER);
93+
} catch (err) {
94+
should.not.exist(err);
95+
}
96+
}
97+
}); // after()
98+
99+
it('217.1 examples/aqraw.js', async () => {
100+
101+
try {
102+
// Enqueue
103+
const queue1 = await conn.getQueue(rawQueueName);
104+
const messageString = 'This is my message';
105+
await queue1.enqOne(messageString);
106+
await conn.commit();
107+
108+
// Dequeue
109+
const queue2 = await conn.getQueue(rawQueueName);
110+
const msg = await queue2.deqOne();
111+
await conn.commit();
112+
113+
should.exist(msg);
114+
should.strictEqual(msg.payload.toString(), messageString);
115+
116+
} catch (err) {
117+
should.not.exist(err);
118+
}
119+
120+
}); // 217.1
121+
122+
it('217.2 examples/aqoptions.js', async () => {
123+
try {
124+
/* Enqueue */
125+
let queue1 = await conn.getQueue(rawQueueName);
126+
127+
// Send a message immediately without requiring a commit
128+
queue1.enqOptions.visibility = oracledb.AQ_VISIBILITY_IMMEDIATE;
129+
130+
const messageString = 'This is my other message';
131+
const message = {
132+
payload: messageString, // the message itself
133+
expiration: 10 // seconds the message will remain in the queue if not dequeued
134+
};
135+
await queue1.enqOne(message);
136+
137+
/* Dequeue */
138+
let queue2 = await conn.getQueue(rawQueueName);
139+
Object.assign(
140+
queue2.deqOptions,
141+
{
142+
visibility: oracledb.AQ_VISIBILITY_IMMEDIATE, // Change the visibility so no explicit commit is required
143+
wait: 25 // seconds it will wait if there are no messages
144+
}
145+
);
146+
const msg = await queue2.deqOne();
147+
if (msg) {
148+
should.strictEqual(msg.payload.toString(), messageString);
149+
}
150+
151+
} catch (err) {
152+
should.not.exist(err);
153+
}
154+
}); // 217.2
155+
156+
it('217.3 examples/aqmulti.js', async () => {
157+
try {
158+
/* Enqueue */
159+
let queue1 = await conn.getQueue(rawQueueName);
160+
queue1.enqOptions.visibility = oracledb.AQ_VISIBILITY_IMMEDIATE;
161+
162+
const messages1 = [
163+
"Message 1",
164+
"Message 2",
165+
{
166+
expiration: 10,
167+
payload: "Message 3"
168+
},
169+
"Message 4"
170+
];
171+
await queue1.enqMany(messages1);
172+
173+
/* Dequeue */
174+
const queue2 = await conn.getQueue(rawQueueName);
175+
queue2.enqOptions.visibility = oracledb.AQ_VISIBILITY_IMMEDIATE;
176+
177+
const messages2 = await queue2.deqMany(5); // get at most 5 messages
178+
if (messages2) {
179+
should.strictEqual(messages2.length, messages1.length);
180+
should.strictEqual(messages2[0].payload.toString(), messages1[0]);
181+
should.strictEqual(messages2[3].payload.toString(), messages1[3]);
182+
should.strictEqual(messages2[2].expiration, 10);
183+
}
184+
185+
} catch (err) {
186+
should.not.exist(err);
187+
}
188+
}); // 217.3
189+
});

0 commit comments

Comments
 (0)