Skip to content

Commit fd0fb05

Browse files
committed
test case for adding msgID attribute in callback on AQ subscription
1 parent d0759c6 commit fd0fb05

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

test/aq5.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/* Copyright (c) 2019, 2023, 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+
* 283. aq5.js
27+
*
28+
* DESCRIPTION
29+
* Test Oracle Advanced Queueing (AQ).
30+
* The test cases are for subscribe callback function parameter message
31+
* to have msgId field
32+
*
33+
*****************************************************************************/
34+
'use strict';
35+
36+
const oracledb = require('oracledb');
37+
const dbConfig = require('./dbconfig.js');
38+
const testsUtil = require('./testsUtil.js');
39+
const assert = require('assert');
40+
41+
oracledb.events = true;
42+
43+
// callback for subscribe
44+
function cbSubscribe(message) {
45+
assert(message.msgId.length > 0);
46+
assert(message.msgId instanceof Buffer);
47+
}
48+
49+
50+
describe('283.aq5.js', function() {
51+
52+
let isRunnable = true;
53+
let conn;
54+
55+
const AQ_USER = 'NODB_SCHEMA_AQTEST5';
56+
const AQ_USER_PWD = testsUtil.generateRandomPassword();
57+
58+
const objQueueName = "NODB_ADDR_QUEUE";
59+
const objTable = "NODB_TAB_ADDR";
60+
61+
before(async function() {
62+
if (!dbConfig.test.DBA_PRIVILEGE || oracledb.thin) {
63+
isRunnable = false;
64+
}
65+
66+
if (!isRunnable) {
67+
this.skip();
68+
} else {
69+
await testsUtil.createAQtestUser(AQ_USER, AQ_USER_PWD);
70+
71+
let credential = {
72+
user: AQ_USER,
73+
password: AQ_USER_PWD,
74+
connectString: dbConfig.connectString
75+
};
76+
conn = await oracledb.getConnection(credential);
77+
const plsql = `
78+
BEGIN
79+
DBMS_AQADM.CREATE_QUEUE_TABLE(
80+
QUEUE_TABLE => '${AQ_USER}.${objTable}',
81+
QUEUE_PAYLOAD_TYPE => 'RAW'
82+
);
83+
DBMS_AQADM.CREATE_QUEUE(
84+
QUEUE_NAME => '${AQ_USER}.${objQueueName}',
85+
QUEUE_TABLE => '${AQ_USER}.${objTable}'
86+
);
87+
DBMS_AQADM.START_QUEUE(
88+
QUEUE_NAME => '${AQ_USER}.${objQueueName}'
89+
);
90+
END;
91+
`;
92+
93+
await conn.execute(plsql);
94+
await conn.commit ();
95+
}
96+
}); //before
97+
98+
after(async function () {
99+
if (!isRunnable) {
100+
return;
101+
} else {
102+
await conn.close();
103+
await testsUtil.dropAQtestUser(AQ_USER);
104+
}
105+
});
106+
107+
it('283.1 subscribe dequeue messages', async() => {
108+
const options = {
109+
namespace: oracledb.SUBSCR_NAMESPACE_AQ,
110+
callback: cbSubscribe,
111+
timeout: 300
112+
};
113+
114+
await conn.subscribe(objQueueName, options);
115+
116+
// Enqueue
117+
const queue1 = await conn.getQueue(objQueueName);
118+
const messageString = 'This is my message';
119+
await queue1.enqOne(messageString);
120+
await conn.commit ();
121+
122+
123+
// Dequeue
124+
const queue2 = await conn.getQueue(objQueueName);
125+
const msg = await queue2.deqOne ();
126+
await conn.commit ();
127+
assert(msg);
128+
129+
await conn.unsubscribe(objQueueName);
130+
});
131+
132+
});

0 commit comments

Comments
 (0)