|
| 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 | +* implicitPool.js |
| 27 | +* |
| 28 | +* DESCRIPTION |
| 29 | +* Testing implicit pooling |
| 30 | +* stop and start pool before starting test to reset stats for comparision. |
| 31 | +* |
| 32 | +* NODE_ORACLEDB_CONNECTIONSTRING1 |
| 33 | +* 'host/servicename:POOLED?POOL_CONNECTION_CLASS=classname & POOL_BOUNDARY=STATEMENT' |
| 34 | +* '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hostname)(PORT=port))(CONNECT_DATA=(SERVICE_NAME=servicename)(SERVER=POOLED)(POOL_BOUNDARY=STATEMENT)))' |
| 35 | +* |
| 36 | +* NODE_ORACLEDB_CONNECTIONSTRING2 |
| 37 | +* 'host/servicename:POOLED?POOL_CONNECTION_CLASS=classname & POOL_BOUNDARY=TRANSACTION' |
| 38 | +* '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hostname)(PORT=port))(CONNECT_DATA=(SERVICE_NAME=servicename)(SERVER=POOLED)(POOL_BOUNDARY=TRANSACTION)))' |
| 39 | +* |
| 40 | +* NODE_ORACLEDB_CONNECTIONSTRING3 |
| 41 | +* 'host/servicename:POOLED?POOL_CONNECTION_CLASS=classname & POOL_BOUNDARY=STATEMENT & POOL_PURITY=NEW' |
| 42 | +* '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hostname)(PORT=port))(CONNECT_DATA=(SERVICE_NAME=servicename)(SERVER=POOLED)(POOL_BOUNDARY=STATEMENT)(POOL_PURITY=NEW)))' |
| 43 | +* |
| 44 | +* NODE_ORACLEDB_CONNECTIONSTRING4 |
| 45 | +* 'host/servicename:POOLED?POOL_CONNECTION_CLASS=classname & POOL_BOUNDARY=TRANSACTION & POOL_PURITY=NEW' |
| 46 | +* '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hostname)(PORT=port))(CONNECT_DATA=(SERVICE_NAME=servicename)(SERVER=POOLED)(POOL_BOUNDARY=TRANSACTION)(POOL_PURITY=NEW)))' |
| 47 | +* |
| 48 | +* NODE_ORACLEDB_CONNECTIONSTRING5 |
| 49 | +* 'host/servicename:POOLED?POOL_CONNECTION_CLASS=classname & POOL_BOUNDARY=XYZ & POOL_PURITY=NEW' |
| 50 | +* '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hostname)(PORT=port))(CONNECT_DATA=(SERVICE_NAME=servicename)(POOL_BOUNDARY=XYZ)))' |
| 51 | +******************************************************************************/ |
| 52 | +'use strict'; |
| 53 | + |
| 54 | +const oracledb = require('oracledb'); |
| 55 | +const assert = require('assert'); |
| 56 | +const dbConfig = require('./dbconfig.js'); |
| 57 | + |
| 58 | +describe('1. implicitPool.js', function() { |
| 59 | + |
| 60 | + let connection = null; |
| 61 | + let dbaConn = null; |
| 62 | + let pool = null; |
| 63 | + before(async function() { |
| 64 | + |
| 65 | + const dbaCredential = { |
| 66 | + user: dbConfig.test.DBA_user, |
| 67 | + password: dbConfig.test.DBA_password, |
| 68 | + connectString: dbConfig.connectString, |
| 69 | + privilege: oracledb.SYSDBA, |
| 70 | + }; |
| 71 | + dbaConn = await oracledb.getConnection(dbaCredential); |
| 72 | + await dbaConn.execute(`alter session set container=CDB$ROOT`); |
| 73 | + }); |
| 74 | + |
| 75 | + after(async function() { |
| 76 | + await dbaConn.close(); |
| 77 | + }); |
| 78 | + |
| 79 | + it('1.1 pool: execute multiple queries with purity=SELF and POOL_BOUNDARY=TRANSACTION', async function() { |
| 80 | + oracledb.connectionClass = 'obj1'; |
| 81 | + // connect string with SERVER=POOLED, purity=SELF and POOL_BOUNDARY=TRANSACTION |
| 82 | + const config = { |
| 83 | + user: dbConfig.user, |
| 84 | + password: dbConfig.password, |
| 85 | + connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING1 |
| 86 | + }; |
| 87 | + pool = await oracledb.createPool(config); |
| 88 | + connection = await pool.getConnection(); |
| 89 | + let i = 6; |
| 90 | + while (i-- > 0) { |
| 91 | + await connection.execute("SELECT 1 FROM DUAL"); |
| 92 | + } |
| 93 | + const user = config.user.toUpperCase(); |
| 94 | + const result = await dbaConn.execute(`select cclass_name, num_requests, num_hits, num_misses from v$cpool_cc_stats where cclass_name='${user}.obj1'`); |
| 95 | + assert.deepStrictEqual(result.rows[0][2], 5); |
| 96 | + await connection.close(); |
| 97 | + await pool.close(0); |
| 98 | + }); |
| 99 | + |
| 100 | + it('1.2 pool: execute multiple queries with purity=SELF and POOL_BOUNDARY=STATEMENT', async function() { |
| 101 | + oracledb.connectionClass = 'obj2'; |
| 102 | + // connect string with SERVER=POOLED, purity=SELF and POOL_BOUNDARY=STATEMENT |
| 103 | + const config = { |
| 104 | + user: dbConfig.user, |
| 105 | + password: dbConfig.password, |
| 106 | + connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING2 |
| 107 | + }; |
| 108 | + pool = await oracledb.createPool(config); |
| 109 | + connection = await pool.getConnection(); |
| 110 | + let i = 6; |
| 111 | + while (i-- > 0) { |
| 112 | + await connection.execute("SELECT 1 FROM DUAL"); |
| 113 | + } |
| 114 | + const user = config.user.toUpperCase(); |
| 115 | + const result = await dbaConn.execute(`select cclass_name, num_requests, num_hits, num_misses from v$cpool_cc_stats where cclass_name='${user}.obj2'`); |
| 116 | + assert.deepStrictEqual(result.rows[0][2], 5); |
| 117 | + |
| 118 | + await connection.close(); |
| 119 | + await pool.close(0); |
| 120 | + }); |
| 121 | + |
| 122 | + it('1.3 pool: execute multiple queries with purity=NEW and POOL_BOUNDARY=STATEMENT', async function() { |
| 123 | + oracledb.connectionClass = 'obj3'; |
| 124 | + // connect string with SERVER=POOLED, purity=NEW and POOL_BOUNDARY=STATEMENT |
| 125 | + const config = { |
| 126 | + user: dbConfig.user, |
| 127 | + password: dbConfig.password, |
| 128 | + connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING3 |
| 129 | + }; |
| 130 | + pool = await oracledb.createPool(config); |
| 131 | + connection = await pool.getConnection(); |
| 132 | + let i = 6; |
| 133 | + while (i-- > 0) { |
| 134 | + await connection.execute("SELECT 1 FROM DUAL"); |
| 135 | + } |
| 136 | + const user = config.user.toUpperCase(); |
| 137 | + const result = await dbaConn.execute(`select cclass_name, num_requests, num_hits, num_misses from v$cpool_cc_stats where cclass_name='${user}.obj3'`); |
| 138 | + assert.deepStrictEqual(result.rows[0][3], 6); |
| 139 | + |
| 140 | + await connection.close(); |
| 141 | + await pool.close(0); |
| 142 | + }); |
| 143 | + |
| 144 | + it('1.4 pool: execute multiple queries with purity=NEW and POOL_BOUNDARY=TRANSACTION', async function() { |
| 145 | + oracledb.connectionClass = 'obj4'; |
| 146 | + // connect string with SERVER=POOLED, purity=NEW and POOL_BOUNDARY=STATEMENT |
| 147 | + const config = { |
| 148 | + user: dbConfig.user, |
| 149 | + password: dbConfig.password, |
| 150 | + connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING4 |
| 151 | + }; |
| 152 | + pool = await oracledb.createPool(config); |
| 153 | + connection = await pool.getConnection(); |
| 154 | + let i = 6; |
| 155 | + while (i-- > 0) { |
| 156 | + await connection.execute("SELECT 1 FROM DUAL"); |
| 157 | + } |
| 158 | + const user = config.user.toUpperCase(); |
| 159 | + const result = await dbaConn.execute(`select cclass_name, num_requests, num_hits, num_misses from v$cpool_cc_stats where cclass_name='${user}.obj4'`); |
| 160 | + assert.deepStrictEqual(result.rows[0][3], 6); |
| 161 | + await connection.close(); |
| 162 | + await pool.close(0); |
| 163 | + }); |
| 164 | + |
| 165 | + it('1.5 standalone: execute multiple queries with purity=NEW and POOL_BOUNDARY=STATEMENT', async function() { |
| 166 | + oracledb.connectionClass = 'obj5'; |
| 167 | + // connect string with SERVER=POOLED, purity=NEW and POOL_BOUNDARY=STATEMENT |
| 168 | + const config = { |
| 169 | + user: dbConfig.user, |
| 170 | + password: dbConfig.password, |
| 171 | + connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING3 |
| 172 | + }; |
| 173 | + connection = await oracledb.getConnection(config); |
| 174 | + let i = 6; |
| 175 | + while (i-- > 0) { |
| 176 | + await connection.execute("SELECT 1 FROM DUAL"); |
| 177 | + } |
| 178 | + const user = config.user.toUpperCase(); |
| 179 | + const result = await dbaConn.execute(`select cclass_name, num_requests, num_hits, num_misses from v$cpool_cc_stats where cclass_name='${user}.obj5'`); |
| 180 | + assert.deepStrictEqual(result.rows[0][3], 6); |
| 181 | + await connection.close(); |
| 182 | + }); |
| 183 | + |
| 184 | + it('1.6 standalone: execute multiple queries with purity=NEW and POOL_BOUNDARY=TRANSACTION', async function() { |
| 185 | + oracledb.connectionClass = 'obj6'; |
| 186 | + // connect string with SERVER=POOLED, purity=NEW and POOL_BOUNDARY=TRANSACTION |
| 187 | + const config = { |
| 188 | + user: dbConfig.user, |
| 189 | + password: dbConfig.password, |
| 190 | + connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING4 |
| 191 | + }; |
| 192 | + connection = await oracledb.getConnection(config); |
| 193 | + let i = 6; |
| 194 | + while (i-- > 0) { |
| 195 | + await connection.execute("SELECT 1 FROM DUAL"); |
| 196 | + } |
| 197 | + const user = config.user.toUpperCase(); |
| 198 | + const result = await dbaConn.execute(`select cclass_name, num_requests, num_hits, num_misses from v$cpool_cc_stats where cclass_name='${user}.obj6'`); |
| 199 | + assert.deepStrictEqual(result.rows[0][3], 6); |
| 200 | + |
| 201 | + await connection.close(); |
| 202 | + }); |
| 203 | + |
| 204 | + it('1.7 standalone: execute multiple queries with purity=SELF and POOL_BOUNDARY=TRANSACTION', async function() { |
| 205 | + oracledb.connectionClass = 'obj7'; |
| 206 | + // connect string with SERVER=POOLED, purity=SELF and POOL_BOUNDARY=TRANSACTION |
| 207 | + const config = { |
| 208 | + user: dbConfig.user, |
| 209 | + password: dbConfig.password, |
| 210 | + connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING1 |
| 211 | + }; |
| 212 | + connection = await oracledb.getConnection(config); |
| 213 | + let i = 6; |
| 214 | + while (i-- > 0) { |
| 215 | + await connection.execute("SELECT 1 FROM DUAL"); |
| 216 | + } |
| 217 | + const user = config.user.toUpperCase(); |
| 218 | + const result = await dbaConn.execute(`select cclass_name, num_requests, num_hits, num_misses from v$cpool_cc_stats where cclass_name='${user}.obj7'`); |
| 219 | + assert.deepStrictEqual(result.rows[0][2], 5); |
| 220 | + |
| 221 | + await connection.close(); |
| 222 | + }); |
| 223 | + |
| 224 | + it('1.8 standalone: execute multiple queries with purity=SELF and POOL_BOUNDARY=STATEMENT', async function() { |
| 225 | + oracledb.connectionClass = 'obj8'; |
| 226 | + // connect string with SERVER=POOLED, purity=SELF and POOL_BOUNDARY=STATEMENT |
| 227 | + const config = { |
| 228 | + user: dbConfig.user, |
| 229 | + password: dbConfig.password, |
| 230 | + connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING2 |
| 231 | + }; |
| 232 | + connection = await oracledb.getConnection(config); |
| 233 | + let i = 6; |
| 234 | + while (i-- > 0) { |
| 235 | + await connection.execute("SELECT 1 FROM DUAL"); |
| 236 | + } |
| 237 | + const user = config.user.toUpperCase(); |
| 238 | + const result = await dbaConn.execute(`select cclass_name, num_requests, num_hits, num_misses from v$cpool_cc_stats where cclass_name='${user}.obj8'`); |
| 239 | + assert.deepStrictEqual(result.rows[0][2], 5); |
| 240 | + |
| 241 | + await connection.close(); |
| 242 | + }); |
| 243 | + |
| 244 | + it('1.9 standalone: invalid pool boundary', async function() { |
| 245 | + const config = { |
| 246 | + user: dbConfig.user, |
| 247 | + password: dbConfig.password, |
| 248 | + connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING5 |
| 249 | + }; |
| 250 | + |
| 251 | + await assert.rejects( |
| 252 | + async () => await oracledb.getConnection(config), |
| 253 | + /ORA-24545:/); |
| 254 | + }); |
| 255 | + |
| 256 | + it('1.10 pool: invalid pool boundary', async function() { |
| 257 | + const config = { |
| 258 | + user: dbConfig.user, |
| 259 | + password: dbConfig.password, |
| 260 | + connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING5 |
| 261 | + }; |
| 262 | + |
| 263 | + const pool = await oracledb.createPool(config); |
| 264 | + await assert.rejects( |
| 265 | + async () => await pool.getConnection(), /ORA-24545:/); |
| 266 | + }); |
| 267 | +}); |
0 commit comments