Add AQ tests

This commit is contained in:
Christopher Jones 2019-07-24 10:28:00 +10:00
parent 28e46d11fe
commit ac3f4fa27d
6 changed files with 719 additions and 2 deletions

189
test/aq1.js Normal file
View File

@ -0,0 +1,189 @@
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */
/******************************************************************************
*
* You may not use the identified files except in compliance with the Apache
* License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
* 217. aq1.js
*
* DESCRIPTION
* Test Oracle Advanced Queueing (AQ).
* The test version of examples/aqraw.js and examples/aqoptions.js.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const should = require('should');
const dbconfig = require('./dbconfig.js');
const testsUtil = require('./testsUtil.js');
describe('217. aq1.js', function() {
let isRunnable = true;
let conn;
const AQ_USER = 'NODB_SCHEMA_AQTEST1';
const AQ_USER_PWD = testsUtil.generateRandomPassword();
const rawQueueName = "NODB_RAW_QUEUE";
const RAW_TABLE = 'NODB_RAW_QUEUE_TAB';
before(async function() {
if (!dbconfig.test.DBA_PRIVILEGE) {
isRunnable = false;
}
if (!isRunnable) {
this.skip();
return;
} else {
try {
await testsUtil.createAQtestUser(AQ_USER, AQ_USER_PWD);
let credential = {
user: AQ_USER,
password: AQ_USER_PWD,
connectString: dbconfig.connectString
};
conn = await oracledb.getConnection(credential);
let plsql = `
BEGIN
DBMS_AQADM.CREATE_QUEUE_TABLE(
QUEUE_TABLE => '${AQ_USER}.${RAW_TABLE}',
QUEUE_PAYLOAD_TYPE => 'RAW'
);
DBMS_AQADM.CREATE_QUEUE(
QUEUE_NAME => '${AQ_USER}.${rawQueueName}',
QUEUE_TABLE => '${AQ_USER}.${RAW_TABLE}'
);
DBMS_AQADM.START_QUEUE(
QUEUE_NAME => '${AQ_USER}.${rawQueueName}'
);
END;
`;
await conn.execute(plsql);
} catch (err) {
should.not.exist(err);
}
}
}); // before()
after(async function() {
if (!isRunnable) {
return;
} else {
try {
await conn.close();
await testsUtil.dropAQtestUser(AQ_USER);
} catch (err) {
should.not.exist(err);
}
}
}); // after()
it('217.1 examples/aqraw.js', async () => {
try {
// Enqueue
const queue1 = await conn.getQueue(rawQueueName);
const messageString = 'This is my message';
await queue1.enqOne(messageString);
await conn.commit();
// Dequeue
const queue2 = await conn.getQueue(rawQueueName);
const msg = await queue2.deqOne();
await conn.commit();
should.exist(msg);
should.strictEqual(msg.payload.toString(), messageString);
} catch (err) {
should.not.exist(err);
}
}); // 217.1
it('217.2 examples/aqoptions.js', async () => {
try {
/* Enqueue */
let queue1 = await conn.getQueue(rawQueueName);
// Send a message immediately without requiring a commit
queue1.enqOptions.visibility = oracledb.AQ_VISIBILITY_IMMEDIATE;
const messageString = 'This is my other message';
const message = {
payload: messageString, // the message itself
expiration: 10 // seconds the message will remain in the queue if not dequeued
};
await queue1.enqOne(message);
/* Dequeue */
let queue2 = await conn.getQueue(rawQueueName);
Object.assign(
queue2.deqOptions,
{
visibility: oracledb.AQ_VISIBILITY_IMMEDIATE, // Change the visibility so no explicit commit is required
wait: 25 // seconds it will wait if there are no messages
}
);
const msg = await queue2.deqOne();
if (msg) {
should.strictEqual(msg.payload.toString(), messageString);
}
} catch (err) {
should.not.exist(err);
}
}); // 217.2
it('217.3 examples/aqmulti.js', async () => {
try {
/* Enqueue */
let queue1 = await conn.getQueue(rawQueueName);
queue1.enqOptions.visibility = oracledb.AQ_VISIBILITY_IMMEDIATE;
const messages1 = [
"Message 1",
"Message 2",
{
expiration: 10,
payload: "Message 3"
},
"Message 4"
];
await queue1.enqMany(messages1);
/* Dequeue */
const queue2 = await conn.getQueue(rawQueueName);
queue2.enqOptions.visibility = oracledb.AQ_VISIBILITY_IMMEDIATE;
const messages2 = await queue2.deqMany(5); // get at most 5 messages
if (messages2) {
should.strictEqual(messages2.length, messages1.length);
should.strictEqual(messages2[0].payload.toString(), messages1[0]);
should.strictEqual(messages2[3].payload.toString(), messages1[3]);
should.strictEqual(messages2[2].expiration, 10);
}
} catch (err) {
should.not.exist(err);
}
}); // 217.3
});

218
test/aq2.js Normal file
View File

@ -0,0 +1,218 @@
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */
/******************************************************************************
*
* You may not use the identified files except in compliance with the Apache
* License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
* 218. aq2.js
*
* DESCRIPTION
* Test Oracle Advanced Queueing (AQ).
* The test version of examples/aqobject.js
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const should = require('should');
const dbconfig = require('./dbconfig.js');
const testsUtil = require('./testsUtil.js');
describe('218. aq2.js', function() {
let isRunnable = true;
let conn;
const AQ_USER = 'NODB_SCHEMA_AQTEST2';
const AQ_USER_PWD = testsUtil.generateRandomPassword();
const objQueueName = "NODB_ADDR_QUEUE";
const objType = "NODB_ADDR_TYP";
const objTable = "NODB_TAB_ADDR";
before(async function() {
if (!dbconfig.test.DBA_PRIVILEGE) {
isRunnable = false;
}
if (!isRunnable) {
this.skip();
return;
} else {
try {
await testsUtil.createAQtestUser(AQ_USER, AQ_USER_PWD);
let credential = {
user: AQ_USER,
password: AQ_USER_PWD,
connectString: dbconfig.connectString
};
conn = await oracledb.getConnection(credential);
// Create the Type
let plsql = `
CREATE OR REPLACE TYPE ${objType} AS OBJECT (
NAME VARCHAR2(10),
ADDRESS VARCHAR2(50)
);
`;
await conn.execute(plsql);
// Create and start a queue
plsql = `
BEGIN
DBMS_AQADM.CREATE_QUEUE_TABLE(
QUEUE_TABLE => '${AQ_USER}.${objTable}',
QUEUE_PAYLOAD_TYPE => '${objType}'
);
DBMS_AQADM.CREATE_QUEUE(
QUEUE_NAME => '${AQ_USER}.${objQueueName}',
QUEUE_TABLE => '${AQ_USER}.${objTable}'
);
DBMS_AQADM.START_QUEUE(
QUEUE_NAME => '${AQ_USER}.${objQueueName}'
);
END;
`;
await conn.execute(plsql);
} catch (err) {
should.not.exist(err);
}
}
}); // before()
after(async function() {
if (!isRunnable) {
return;
} else {
try {
await conn.close();
await testsUtil.dropAQtestUser(AQ_USER);
} catch (err) {
should.not.exist(err);
}
}
}); // after()
it('218.1 examples/aqobject.js', async () => {
try {
const addrData = {
NAME: "scott",
ADDRESS: "The Kennel"
};
// Enqueue
const queue1 = await conn.getQueue(
objQueueName,
{ payloadType: objType }
);
const message = new queue1.payloadTypeClass(addrData);
await queue1.enqOne(message);
await conn.commit();
// Dequeue
const queue2 = await conn.getQueue(
objQueueName,
{ payloadType: objType }
);
const msg = await queue2.deqOne();
await conn.commit();
should.exist(msg);
should.strictEqual(msg.payload.NAME, addrData.NAME);
should.strictEqual(msg.payload.ADDRESS, addrData.ADDRESS);
} catch (err) {
should.not.exist(err);
}
}); // 218.1
it.skip('218.2 The read-only property "payloadTypeClass"', async () => {
try {
const queue = await conn.getQueue(objQueueName, { payloadType: objType });
const t = queue.payloadTypeClass;
should.exist(t);
queue.payloadTypeClass = {'foo': 'bar'};
console.log(queue);
} catch (err) {
should.not.exist(err);
}
}); // 218.2
it.skip('218.3 Enqueue a JSON', async () => {
try {
const addrData = {
NAME: "John Smith",
ADDRESS: "100 Oracle Parkway Redwood City, CA US 94065"
};
// Enqueue
const queue1 = await conn.getQueue(
objQueueName,
{ payloadType: objType }
);
// const message = new queue1.payloadTypeClass(addrData);
await queue1.enqOne(addrData);
await conn.commit();
// Dequeue
const queue2 = await conn.getQueue(
objQueueName,
{ payloadType: objType }
);
const msg = await queue2.deqOne();
await conn.commit();
should.exist(msg);
should.strictEqual(msg.payload.NAME, addrData.NAME);
should.strictEqual(msg.payload.ADDRESS, addrData.ADDRESS);
} catch (err) {
should.not.exist(err);
}
}); // 218.3
it.skip('218.4 getQueue() without options', async () => {
try {
const addrData = {
NAME: "Changjie",
ADDRESS: "200 Oracle Parkway Redwood City, CA US 94065"
};
// Enqueue
const queue1 = await conn.getQueue(
objQueueName,
//{ payloadType: objType }
);
const objClass = await conn.getDbObjectClass(objType);
const message = new objClass(addrData);
// const message = new queue1.payloadTypeClass(addrData);
await queue1.enqOne(message);
await conn.commit();
// Dequeue
const queue2 = await conn.getQueue(
objQueueName,
//{ payloadType: objType }
);
const msg = await queue2.deqOne();
await conn.commit();
should.exist(msg);
should.strictEqual(msg.payload.NAME, addrData.NAME);
should.strictEqual(msg.payload.ADDRESS, addrData.ADDRESS);
} catch (err) {
should.not.exist(err);
}
}); // 218.4
});

226
test/aq3.js Normal file
View File

@ -0,0 +1,226 @@
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */
/******************************************************************************
*
* You may not use the identified files except in compliance with the Apache
* License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
* 219. aq3.js
*
* DESCRIPTION
* Test Oracle Advanced Queueing (AQ).
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const should = require('should');
const dbconfig = require('./dbconfig.js');
const testsUtil = require('./testsUtil.js');
describe('219. aq3.js', function() {
let isRunnable = true;
let conn;
const AQ_USER = 'NODB_SCHEMA_AQTEST3';
const AQ_USER_PWD = testsUtil.generateRandomPassword();
const rawQueueName = "NODB_RAW_QUEUE";
const RAW_TABLE = 'NODB_RAW_QUEUE_TAB';
before(async function() {
if (!dbconfig.test.DBA_PRIVILEGE) {
isRunnable = false;
}
if (!isRunnable) {
this.skip();
return;
} else {
try {
await testsUtil.createAQtestUser(AQ_USER, AQ_USER_PWD);
let credential = {
user: AQ_USER,
password: AQ_USER_PWD,
connectString: dbconfig.connectString
};
conn = await oracledb.getConnection(credential);
let plsql = `
BEGIN
DBMS_AQADM.CREATE_QUEUE_TABLE(
QUEUE_TABLE => '${AQ_USER}.${RAW_TABLE}',
QUEUE_PAYLOAD_TYPE => 'RAW'
);
DBMS_AQADM.CREATE_QUEUE(
QUEUE_NAME => '${AQ_USER}.${rawQueueName}',
QUEUE_TABLE => '${AQ_USER}.${RAW_TABLE}'
);
DBMS_AQADM.START_QUEUE(
QUEUE_NAME => '${AQ_USER}.${rawQueueName}'
);
END;
`;
await conn.execute(plsql);
} catch (err) {
should.not.exist(err);
}
}
}); // before()
after(async function() {
if (!isRunnable) {
return;
} else {
try {
await conn.close();
await testsUtil.dropAQtestUser(AQ_USER);
} catch (err) {
should.not.exist(err);
}
}
}); // after()
it('219.1 The read-only property "name" of AqQueue Class', async () => {
try {
const queue = await conn.getQueue(rawQueueName);
const t = queue.name;
should.strictEqual(t, rawQueueName);
should.throws(
() => {
queue.name = 'foobar';
},
"TypeError: Cannot assign to read only property 'name' of object '#<AqQueue>"
);
} catch (err) {
should.not.exist(err);
}
}); // 219.1
it.skip('219.2 The read-only property "payloadType"', async () => {
try {
const queue = await conn.getQueue(rawQueueName);
const t = queue.payloadType;
should.strictEqual(t, oracledb.DB_TYPE_RAW);
// should.throws(
// () => {
// queue.payloadType = oracledb.DB_TYPE_OBJECT;
// },
// "TypeError: Cannot assign to read only property 'payloadType' of object '#<AqQueue>"
// );
queue.payloadType = oracledb.DB_TYPE_OBJECT;
console.log(queue);
} catch (err) {
should.not.exist(err);
}
}); // 219.2
it.skip('219.3 The read-only property "payloadTypeName"', async () => {
try {
const queue = await conn.getQueue(rawQueueName);
const t = queue.payloadTypeName;
should.strictEqual(t, 'RAW');
queue.payloadTypeName = 'Foobar';
console.log(queue);
} catch (err) {
should.not.exist(err);
}
}); // 219.3
it('219.4 Negative - Set "maxMessages" argument to be -5', async () => {
try {
const queue = await conn.getQueue(rawQueueName);
testsUtil.assertThrowsAsync(
async () => {
const messages = await queue.deqMany(-5);
should.not.exist(messages);
},
/NJS-005/
);
} catch (err) {
should.not.exist(err);
}
}); // 219.4
it.skip('219.5 Negative - Set "maxMessages" argument to be 0', async () => {
try {
const queue = await conn.getQueue(rawQueueName);
const messages = await queue.deqMany(0);
} catch (err) {
should.not.exist(err);
}
}); // 219.5
it('219.6 Enqueue a Buffer', async () => {
try {
// Enqueue
const queue1 = await conn.getQueue(rawQueueName);
const messageString = 'This is my message';
const msgBuf = Buffer.from(messageString, 'utf8');
await queue1.enqOne(msgBuf);
await conn.commit();
// Dequeue
const queue2 = await conn.getQueue(rawQueueName);
const msg = await queue2.deqOne();
await conn.commit();
should.exist(msg);
should.strictEqual(msg.payload.toString(), messageString);
} catch (err) {
should.not.exist(err);
}
}); // 219.6
it('219.7 enqMany() mixes enqueuing string and buffer', async () => {
try {
/* Enqueue */
let queue1 = await conn.getQueue(rawQueueName);
const messages1 = [
"Message 1",
Buffer.from("Messege 2", "utf-8"),
Buffer.from("Messege 3", "utf-8"),
"Message 4"
];
await queue1.enqMany(messages1);
await conn.commit();
/* Dequeue */
const queue2 = await conn.getQueue(rawQueueName);
const messages2 = await queue2.deqMany(5); // get at most 5 messages
await conn.commit();
if (messages2) {
should.strictEqual(messages2.length, messages1.length);
should.strictEqual(messages2[0].payload.toString(), messages1[0]);
should.strictEqual(messages2[1].payload.toString(), messages1[1].toString());
should.strictEqual(messages2[2].payload.toString(), messages1[2].toString());
should.strictEqual(messages2[3].payload.toString(), messages1[3]);
}
} catch (err) {
should.not.exist(err);
}
}); // 219.7
});

View File

@ -4589,4 +4589,12 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
215.1 Collection of DATE, named Oracle type binds
216. dbObject17.js
216.1 VARRAY Collection. Object columns contain TS, TSZ and LTZ
216.1 VARRAY Collection. Object columns contain TS, TSZ and LTZ
217. aq1.js
217.1 examples/aqraw.js
217.2 examples/aqoptions.js
217.3 examples/aqmulti.js
218. aq2.js
218.1 examples/aqobject.js

View File

@ -241,4 +241,7 @@ test/dbObject13.js
test/dbObject14.js
test/dbObject15.js
test/dbObject16.js
test/dbObject17.js
test/dbObject17.js
test/aq1.js
test/aq2.js

View File

@ -181,3 +181,76 @@ testsUtil.measureNetworkRoundTripTime = async function() {
}
return new Date() - startTime;
};
testsUtil.createAQtestUser = async function(AQ_USER, AQ_USER_PWD) {
if (!dbconfig.test.DBA_PRIVILEGE) {
let msg = "Note: DBA privilege environment variable is false!\n";
msg += "Without DBA privilege, it could not create schema!";
throw new Error(msg);
} else {
let dbaCredential = {
user: dbconfig.test.DBA_user,
password: dbconfig.test.DBA_password,
connectString: dbconfig.connectString,
privilege: oracledb.SYSDBA
};
let plsql = `
BEGIN
DECLARE
e_user_missing EXCEPTION;
PRAGMA EXCEPTION_INIT(e_user_missing, -01918);
BEGIN
EXECUTE IMMEDIATE('DROP USER ${AQ_USER} CASCADE');
EXCEPTION
WHEN e_user_missing
THEN NULL;
END;
EXECUTE IMMEDIATE ('
CREATE USER ${AQ_USER} IDENTIFIED BY ${AQ_USER_PWD}
');
EXECUTE IMMEDIATE ('
GRANT CONNECT, RESOURCE, UNLIMITED TABLESPACE TO ${AQ_USER}
');
EXECUTE IMMEDIATE ('
GRANT AQ_ADMINISTRATOR_ROLE, AQ_USER_ROLE TO ${AQ_USER}
');
EXECUTE IMMEDIATE ('
GRANT EXECUTE ON DBMS_AQ TO ${AQ_USER}
');
END;
`;
try {
const connAsDBA = await oracledb.getConnection(dbaCredential);
await connAsDBA.execute(plsql);
await connAsDBA.close();
} catch (err) {
should.not.exist(err);
}
}
};
testsUtil.dropAQtestUser = async function(AQ_USER) {
if (!dbconfig.test.DBA_PRIVILEGE) {
let msg = "Without DBA privilege, it could not drop schema!\n";
throw new Error(msg);
} else {
let dbaCredential = {
user: dbconfig.test.DBA_user,
password: dbconfig.test.DBA_password,
connectString: dbconfig.connectString,
privilege: oracledb.SYSDBA
};
try {
const connAsDBA = await oracledb.getConnection(dbaCredential);
let sql =`DROP USER ${AQ_USER} CASCADE`;
await connAsDBA.execute(sql);
} catch (err) {
should.not.exist(err);
}
}
};