Skip to content

Commit f28bded

Browse files
committed
Enable CQN tests
1 parent aa5c949 commit f28bded

File tree

1 file changed

+84
-22
lines changed

1 file changed

+84
-22
lines changed

test/runCQN.js

Lines changed: 84 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* DESCRIPTION
2222
* Test Continuous Query Notification (CQN).
2323
*
24-
* To keep it simple, this test only run on Linux. Because the database
24+
* To keep it simple, this test will not run on my macOS. Because the database
2525
* must be able to connect to the node-oracledb machine for notifications
2626
* to be received. Typically this means that the machine running node-oracledb
2727
* needs a fixed IP address.
@@ -41,10 +41,9 @@ describe('185. runCQN.js', function() {
4141

4242
let isRunnable = true;
4343
let conn, connAsDBA;
44-
const TABLE = 'nodb_tab_cqn_1';
4544

4645
before(async function() {
47-
if ( (!dbconfig.test.DBA_PRIVILEGE) || (process.platform !== 'linux') ) {
46+
if ( (!dbconfig.test.DBA_PRIVILEGE) || (process.platform == 'darwin') ) {
4847
isRunnable = false;
4948
}
5049

@@ -71,13 +70,6 @@ describe('185. runCQN.js', function() {
7170
events: true
7271
});
7372

74-
sql =
75-
`CREATE TABLE ${TABLE} (
76-
k NUMBER
77-
)`;
78-
let plsql = testsUtil.sqlCreateTable(TABLE, sql);
79-
await conn.execute(plsql);
80-
8173
} catch (err) {
8274
should.not.exist(err);
8375
}
@@ -90,10 +82,8 @@ describe('185. runCQN.js', function() {
9082
return;
9183
} else {
9284
try {
93-
let sql = `DROP TABLE ${TABLE} PURGE`;
94-
await conn.execute(sql);
9585

96-
sql = `REVOKE CHANGE NOTIFICATION FROM ${dbconfig.user}`;
86+
let sql = `REVOKE CHANGE NOTIFICATION FROM ${dbconfig.user}`;
9787
await connAsDBA.execute(sql);
9888

9989
await conn.close();
@@ -107,6 +97,13 @@ describe('185. runCQN.js', function() {
10797
it('185.1 examples/cqn1.js', async () => {
10898

10999
try {
100+
const TABLE = 'nodb_tab_cqn_1';
101+
let sql =
102+
`CREATE TABLE ${TABLE} (
103+
k NUMBER
104+
)`;
105+
let plsql = testsUtil.sqlCreateTable(TABLE, sql);
106+
await conn.execute(plsql);
110107

111108
const myCallback = async function(message) {
112109
// console.log(message);
@@ -128,19 +125,34 @@ describe('185. runCQN.js', function() {
128125

129126
await conn.subscribe('mysub', options);
130127

131-
let sql = `INSERT INTO ${TABLE} VALUES (101)`;
128+
sql = `INSERT INTO ${TABLE} VALUES (101)`;
132129
await conn.execute(sql);
130+
131+
plsql = `BEGIN DBMS_SESSION.SLEEP(2); END;`;
132+
await conn.execute(plsql);
133133
await conn.commit();
134134

135135
await conn.unsubscribe('mysub');
136+
137+
sql = `DROP TABLE ${TABLE} PURGE`;
138+
await conn.execute(sql);
136139
} catch (err) {
137140
should.not.exist(err);
138141
}
139142

140143
}); // 185.1
141144

142-
it.skip('185.2 SQL Delete operation', async () => {
145+
it('185.2 SQL Delete operation', async () => {
143146
try {
147+
148+
const TABLE = 'nodb_tab_cqn_2';
149+
let sql =
150+
`CREATE TABLE ${TABLE} (
151+
k NUMBER
152+
)`;
153+
let plsql = testsUtil.sqlCreateTable(TABLE, sql);
154+
await conn.execute(plsql);
155+
144156
const myCallback = async function(message) {
145157
console.log(message);
146158
should.strictEqual(message.type, oracledb.SUBSCR_EVENT_TYPE_QUERY_CHANGE);
@@ -159,26 +171,42 @@ describe('185. runCQN.js', function() {
159171
};
160172
await conn.subscribe('sub2', options);
161173

162-
let sql = `DELETE FROM ${TABLE} WHERE k > :bv`;
174+
sql = `DELETE FROM ${TABLE} WHERE k > :bv`;
163175
await conn.execute(sql, { bv : 100 });
176+
177+
plsql = `BEGIN DBMS_SESSION.SLEEP(2); END;`;
178+
await conn.execute(plsql);
164179
await conn.commit();
165180

166181
await conn.unsubscribe('sub2');
182+
183+
sql = `DROP TABLE ${TABLE} PURGE`;
184+
await conn.execute(sql);
167185
} catch (err) {
168186
should.not.exist(err);
169187
}
170188
}); // 185.2
171189

172-
it.skip('185.3 Specify the notification only for INSERT operation', async() => {
190+
it('185.3 Specify the notification only for INSERT operation', async() => {
173191
try {
192+
193+
const TABLE = 'nodb_tab_cqn_3';
194+
let sql =
195+
`CREATE TABLE ${TABLE} (
196+
k NUMBER
197+
)`;
198+
let plsql = testsUtil.sqlCreateTable(TABLE, sql);
199+
await conn.execute(plsql);
200+
174201
const myCallback = async function(message) {
175202
// console.log(message);
176203
should.strictEqual(message.type, oracledb.SUBSCR_EVENT_TYPE_QUERY_CHANGE);
177204
should.strictEqual(message.registered, true);
178205
const table = message.queries[0].tables[0];
179206
const tableName = dbconfig.user.toUpperCase() + '.' + TABLE.toUpperCase();
180207
should.strictEqual(table.name, tableName);
181-
should.strictEqual(table.operation, oracledb.CQN_OPCODE_INSERT);
208+
let expect = oracledb.CQN_OPCODE_INSERT | oracledb.CQN_OPCODE_ALL_ROWS;
209+
should.strictEqual(table.operation, expect);
182210
};
183211

184212
const options = {
@@ -191,21 +219,36 @@ describe('185. runCQN.js', function() {
191219

192220
await conn.subscribe('sub3', options);
193221

194-
let sql = `DELETE FROM ${TABLE} WHERE k > :bv`;
222+
sql = `DELETE FROM ${TABLE} WHERE k > :bv`;
195223
await conn.execute(sql, { bv : 100 });
196224

197225
sql = `INSERT INTO ${TABLE} VALUES (103)`;
198226
await conn.execute(sql);
227+
228+
plsql = `BEGIN DBMS_SESSION.SLEEP(2); END;`;
229+
await conn.execute(plsql);
199230
await conn.commit();
200231

201232
await conn.unsubscribe('sub3');
233+
234+
sql = `DROP TABLE ${TABLE} PURGE`;
235+
await conn.execute(sql);
202236
} catch (err) {
203237
should.not.exist(err);
204238
}
205239
}); // 185.3
206240

207241
it.skip('185.4 Negative - provide invalid SQL in CQN option', async() => {
208242
try {
243+
244+
const TABLE = 'nodb_tab_cqn_4';
245+
let sql =
246+
`CREATE TABLE ${TABLE} (
247+
k NUMBER
248+
)`;
249+
let plsql = testsUtil.sqlCreateTable(TABLE, sql);
250+
await conn.execute(plsql);
251+
209252
const myCallback = async function(message) {
210253
console.log(message);
211254
};
@@ -220,11 +263,17 @@ describe('185. runCQN.js', function() {
220263

221264
await conn.subscribe('sub4', options);
222265

223-
let sql = `INSERT INTO ${TABLE} VALUES (103)`;
266+
sql = `INSERT INTO ${TABLE} VALUES (103)`;
224267
await conn.execute(sql);
268+
269+
plsql = `BEGIN DBMS_SESSION.SLEEP(2); END;`;
270+
await conn.execute(plsql);
225271
await conn.commit();
226272

227273
await conn.unsubscribe('sub4');
274+
275+
sql = `DROP TABLE ${TABLE} PURGE`;
276+
await conn.execute(sql);
228277
} catch (err) {
229278
should.not.exist(err);
230279
}
@@ -233,6 +282,14 @@ describe('185. runCQN.js', function() {
233282
it('185.5 examples/cqn2.js', async () => {
234283
try {
235284

285+
const TABLE = 'nodb_tab_cqn_5';
286+
let sql =
287+
`CREATE TABLE ${TABLE} (
288+
k NUMBER
289+
)`;
290+
let plsql = testsUtil.sqlCreateTable(TABLE, sql);
291+
await conn.execute(plsql);
292+
236293
const myCallback = async function(message) {
237294
// console.log(message);
238295
should.strictEqual(message.type, oracledb.SUBSCR_EVENT_TYPE_OBJ_CHANGE);
@@ -253,15 +310,20 @@ describe('185. runCQN.js', function() {
253310

254311
await conn.subscribe('sub5', options);
255312

256-
let sql = `INSERT INTO ${TABLE} VALUES (:1)`;
313+
sql = `INSERT INTO ${TABLE} VALUES (:1)`;
257314
let bindArr = [ [1], [2], [3], [4], [5], [6], [7] ];
258315
for (let i = 0; i < bindArr.length; i++) {
259316
await conn.execute(sql, bindArr[i], { autoCommit: true });
260-
await testsUtil.sleep();
261317
}
318+
319+
plsql = `BEGIN DBMS_SESSION.SLEEP(2); END;`;
320+
await conn.execute(plsql);
262321
await conn.commit();
263322

264323
await conn.unsubscribe('sub5');
324+
325+
sql = `DROP TABLE ${TABLE} PURGE`;
326+
await conn.execute(sql);
265327
} catch (err) {
266328
should.not.exist(err);
267329
}

0 commit comments

Comments
 (0)