Example #1
0
  it('16.4 returns a promise from pool.getConnection', function(done) {
    oracledb.createPool(dbConfig)
      .then(function(pool) {
        pool.should.be.ok();
        var getConnPromise = pool.getConnection();
        getConnPromise.should.be.an.instanceof(oracledb.Promise);
        getConnPromise
          .then(function(conn) {
            conn.release(function(err) {
              if (err) {
                return done(err);
              }

              pool.terminate()
                .then(function() {
                  return done();
                })
                .catch(function(err) {
                  return done(err);
                });
            });
          });
      })
      .catch(function(err) {
        should.not.exist(err);
        return done();
      });
  });
Example #2
0
    function init(config) {

        return oracledb.createPool(config)
            .then(function(pool){
                _pool = pool;
            });  
    }
Example #3
0
    it('2.1.1 testing default values of pool properties', function(done) {

      oracledb.createPool(
        {
          user:          dbConfig.user,
          password:      dbConfig.password,
          connectString: dbConfig.connectString
        },
        function(err, pool) {
          should.not.exist(err);
          pool.should.be.ok();

          var defaultMin = 0;
          var defaultMax = 4;
          var defaultIncrement = 1;
          var defaultTimeout = 60;
          var defaultStmtCacheSize = 30;

          pool.poolMin.should.be.exactly(defaultMin).and.be.a.Number();
          pool.poolMax.should.be.exactly(defaultMax).and.be.a.Number();
          pool.poolIncrement.should.be.exactly(defaultIncrement).and.be.a.Number();
          pool.poolTimeout.should.be.exactly(defaultTimeout).and.be.a.Number();
          pool.stmtCacheSize.should.be.exactly(defaultStmtCacheSize).and.be.a.Number();

          pool.connectionsOpen.should.equal(0);
          pool.connectionsInUse.should.equal(0);

          pool.terminate(function(err){
            should.not.exist(err);
            done();
          });
      }
    );

    });
Example #4
0
// Main entry point.  Creates a connection pool, on callback creates an
// HTTP server that executes a query based on the URL parameter given.
// The pool values shown are the default values.
function init() {
  oracledb.createPool(
    {
      user: dbConfig.user,
      password: dbConfig.password,
      connectString: dbConfig.connectString,
      poolMax: 4, // maximum size of the pool
      poolMin: 0, // let the pool shrink completely
      poolIncrement: 1, // only grow the pool by one connection at a time
      poolTimeout: 0  // never terminate idle connections
    },
    function(err, pool) {
      if (err) {
        console.error("createPool() error: " + err.message);
        return;
      }

      // Create HTTP server and listen on port - httpPort
      http
        .createServer(function(request, response) {
          handleRequest(request, response, pool);
        })
        .listen(httpPort, "localhost");

      console.log("Server running at http://localhost:" + httpPort);
    }
  );
}
  it('pool should be available after failing terminate', function(done) {
    oracledb.createPool(
      {
        user: dbConfig.user,
        password: dbConfig.password,
        connectString: dbConfig.connectString
      },
      function(err, pool) {
        should.not.exist(err);
        pool.getConnection( function(err, connection) {
          should.not.exist(err);
          pool.terminate(
            function(err){
              should.exist(err);
              (err.message).should.startWith('ORA-24422:');

              // console.log("Before release, Open connections: " + pool.connectionsOpen);
              connection.release( function(err){
                should.not.exist(err);

                // console.log("Open connections: " + pool.connectionsOpen);

                // Still need to clean up the pool from this test.
                pool.terminate(function(err) {
                  should.not.exist(err);

                  done();
                });
              });
            }
          );
        });
      }
    );
  })
Example #6
0
    it('2.2.4 (poolMin + poolIncrement) can equal to poolMax', function(done) {

      oracledb.createPool(
        {
          user              : dbConfig.user,
          password          : dbConfig.password,
          connectString     : dbConfig.connectString,
          poolMin           : 1,
          poolMax           : 5,
          poolIncrement     : 4,
          poolTimeout       : 28,
          stmtCacheSize     : 23
        },
        function(err, pool){
          should.not.exist(err);
          pool.should.be.ok();
          should.strictEqual(pool.connectionsInUse, 0);

          pool.terminate(function(err){
            should.not.exist(err);
            done();
          });
        }
      );

    });
Example #7
0
    it('140.7.11 connecionsInUse', function(done) {

      oracledb.createPool(
        dbConfig,
        function(err, pool) {
          should.not.exist(err);

          Object.defineProperty(pool, 'connecionsInUse', {
            get: function() {
              throw 'Property Wrong';
            }
          });
          should.throws(
            function() {
              console.log(pool.connecionsInUse);
            },
            /Property Wrong/
          );

          pool.close(function(err) {
            should.not.exist(err);
            done();
          });
        }
      );
    });
Example #8
0
    it('2.1.1 set properties to default values if not explicitly specified', function(done) {
      oracledb.createPool(dbConfig, function(err, pool) {
        should.not.exist(err);
        pool.should.be.ok;

        var defaultMin = 0;
        var defaultMax = 4;
        var defaultIncrement = 1;
        var defaultTimeout = 60;
        var defaultStmtCacheSize = 30;

        pool.poolMin.should.be.exactly(defaultMin).and.be.a.Number;
        pool.poolMax.should.be.exactly(defaultMax).and.be.a.Number;
        pool.poolIncrement.should.be.exactly(defaultIncrement).and.be.a.Number;
        pool.poolTimeout.should.be.exactly(defaultTimeout).and.be.a.Number;
        pool.stmtCacheSize.should.be.exactly(defaultStmtCacheSize).and.be.a.Number;

        pool.connectionsOpen.should.equal(0);
        pool.connectionsInUse.should.equal(0);

        pool.terminate(function(err){
          should.not.exist(err);
          done();
        });
      });
    })
ClienteOracle.prototype.init = function () {
 		oracledb.createPool (
          {
            user          : "******",
            password      : "******",
            connectString : "swiss01",
            queueRequests : true,  // default is true
            _enableStats  : true,   // default is false
            poolMax       : 120, // maximum size of the pool
            poolMin       : 5, // let the pool shrink completely
            poolIncrement : 2, // only grow the pool by one connection at a time
            poolTimeout   : 0  // never terminate idle connections
          },
          function(err, pool)
          {
              
            if (err) {
              console.error("ERROR AL LLAMAR AL POOL createPool() callback: " + err.message);
              return;
            }
            pool._logStats();
            poolConexion = pool;
             pool.getConnection (
                      function(err, connection)
                      {
                        if (err) {
                          handleError(response, "getConnection() failed ", err);
                          return;
                        }
                      console.log("Conectado a Oracle, entregando variable conexion");
                      conexion = connection;
             });

          });
 };
Example #10
0
    it('2.2.6 (poolMin + poolIncrement) can equal to poolMax', function(done){
      oracledb.createPool(
        {
          externalAuth      : dbConfig.externalAuth,
          user              : dbConfig.user,
          password          : dbConfig.password,
          connectString     : dbConfig.connectString,
          poolMin           : 1,
          poolMax           : 5,
          poolIncrement     : 4,
          poolTimeout       : 28,
          stmtCacheSize     : 23
        },
        function(err, pool){
          should.not.exist(err);
          pool.should.be.ok;
          if(dbConfig.externalAuth){
            pool.connectionsOpen.should.be.exactly(0);
          } else {
            pool.connectionsOpen.should.be.exactly(pool.poolMin);
          }
          pool.connectionsInUse.should.be.exactly(0);

          pool.terminate(function(err){
            should.not.exist(err);
            done();
          });
        }
      );


    })
Example #11
0
    it('2.3.4 poolMax limits the pool capacity', function(done){
      oracledb.createPool(
        {
          externalAuth      : dbConfig.externalAuth,
          user              : dbConfig.user,
          password          : dbConfig.password,
          connectString     : dbConfig.connectString,
          poolMin           : 1,
          poolMax           : 2,
          poolIncrement     : 1,
          poolTimeout       : 28,
          stmtCacheSize     : 23,
          queueRequests     : false
        },
        function(err, pool) {
          should.not.exist(err);
          pool.should.be.ok;
          if(!dbConfig.externalAuth){
            pool.connectionsOpen.should.be.exactly(1);
          } else {
            pool.connectionsOpen.should.be.exactly(0);
          }
          pool.connectionsInUse.should.be.exactly(0);

          pool.getConnection( function(err, conn1){
            should.not.exist(err);
            conn1.should.be.ok;
            pool.connectionsOpen.should.be.exactly(1);
            pool.connectionsInUse.should.be.exactly(1);

            pool.getConnection( function(err, conn2){
              should.not.exist(err);
              conn2.should.be.ok;
              pool.connectionsOpen.should.be.exactly(2);
              pool.connectionsInUse.should.be.exactly(2);

              // Error occurs
              pool.getConnection( function(err, conn3){
                should.exist(err);
                (err.message).should.startWith('ORA-24418:');

                conn2.release( function(err){
                  should.not.exist(err);
                  conn1.release( function(err){
                    should.not.exist(err);
                    pool.terminate( function(err){
                      should.not.exist(err);
                      done();
                    });
                  });
                });
              });
            });
          });

        }
      );
    })
Example #12
0
 return new Promise((resolve, reject) => {
   $oracledb.createPool(_options, (err, pool) => {
     if (err) {
       return reject(err);
     }
     this.pool = wrapPool(pool);
     return resolve(this.pool);
   });
 });
Example #13
0
    it('2.8.4 does not generate NJS-040 if request is queued for less time than queueTimeout', function(done) {
      oracledb.createPool(
        {
          user              : dbConfig.user,
          password          : dbConfig.password,
          connectString     : dbConfig.connectString,
          poolMin           : 0,
          poolMax           : 1,
          poolIncrement     : 1,
          poolTimeout       : 1,
          queueTimeout      : 10000 //10 seconds
        },
        function(err, pool){
          should.not.exist(err);

          async.parallel(
            [
              function(cb) {
                pool.getConnection(function(err, conn) {
                  should.not.exist(err);

                  conn.execute(getBlockingSql(4), function(err) {
                    should.not.exist(err);

                    conn.release(function(err) {
                      should.not.exist(err);
                      cb();
                    });
                  });
                });
              },
              function(cb) {
                //using setTimeout to help ensure this gets to the db last
                setTimeout(function() {
                  pool.getConnection(function(err, conn) {
                    should.not.exist(err);

                    conn.release(function(err) {
                      should.not.exist(err);
                      cb();
                    });
                  });
                }, 100);
              }
            ],
            function(err){
              should.not.exist(err);
              pool.terminate(function(err) {
                should.not.exist(err);
                done();
              });
            }
          );
        }
      );
    });
Example #14
0
    it.skip('2.8.1 generates ORA-24418 when calling getConnection if queueing is disabled', function(done) {
      oracledb.createPool(
        {
          user              : dbConfig.user,
          password          : dbConfig.password,
          connectString     : dbConfig.connectString,
          poolMin           : 0,
          poolMax           : 1,
          poolIncrement     : 1,
          poolTimeout       : 1,
          queueRequests     : false
        },
        function(err, pool){
          should.not.exist(err);

          async.parallel(
            [
              function(cb) {
                pool.getConnection(function(err, conn) {
                  should.not.exist(err);

                  conn.execute(getBlockingSql(3), function(err) {
                    should.not.exist(err);

                    conn.release(function(err) {
                      should.not.exist(err);
                      cb();
                    });
                  });
                });
              },
              function(cb) {
                //using setTimeout to help ensure this gets to the db last
                setTimeout(function() {
                  pool.getConnection(function(err, conn) {
                    should.exist(err);
                    // ORA-24418: Cannot open further sessions
                    (err.message).should.startWith('ORA-24418:');
                    should.not.exist(conn);
                    cb();
                  });
                }, 200);
              }
            ],
            function(err){
              should.not.exist(err);

              pool.terminate(function(err) {
                should.not.exist(err);
                done();
              });
            }
          );
        }
      );
    });
Example #15
0
    it('2.8.2 does not generate ORA-24418 when calling getConnection if queueing is enabled', function(done) {
      oracledb.createPool(
        {
          externalAuth      : dbConfig.externalAuth,
          user              : dbConfig.user,
          password          : dbConfig.password,
          connectString     : dbConfig.connectString,
          poolMin           : 0,
          poolMax           : 1,
          poolIncrement     : 1,
          poolTimeout       : 1,
          queueRequests     : true //default
        },
        function(err, pool){
          should.not.exist(err);

          async.parallel(
            [
              function(cb) {
                pool.getConnection(function(err, conn) {
                  should.not.exist(err);

                  conn.execute(getBlockingSql(3), function(err, result) {
                    should.not.exist(err);

                    conn.release(function(err) {
                      cb();
                    });
                  });
                });
              },
              function(cb) {
                //using setTimeout to help ensure this gets to the db last
                setTimeout(function() {
                  pool.getConnection(function(err, conn) {
                    should.not.exist(err);

                    conn.release(function(err) {
                      should.not.exist(err);

                      cb();
                    });
                  });
                }, 100);
              }
            ],
            function(err, results){
              pool.terminate(function(err) {
                should.not.exist(err);
                done();
              });
            }
          );
        }
      );
    });
 function getPool(cb) {
   oracledb.createPool(
     dbConfig,
     function(err, pooling) {
       should.not.exist(err);
       pool = pooling;
       cb();
     }
   );
 },
Example #17
0
 before(function(done) {
   oracledb.createPool(
     dbConfig,
     function(err, p) {
       should.not.exist(err);
       pool = p;
       done();
     }
   );
 })
Example #18
0
    it('2.8.3 generates NJS-040 if request is queued and queueTimeout expires', function(done) {
      oracledb.createPool(
        {
          user              : dbConfig.user,
          password          : dbConfig.password,
          connectString     : dbConfig.connectString,
          poolMin           : 0,
          poolMax           : 1,
          poolIncrement     : 1,
          poolTimeout       : 1,
          queueTimeout      : 2000 //2 seconds
        },
        function(err, pool){
          should.not.exist(err);

          async.parallel(
            [
              function(cb) {
                pool.getConnection(function(err, conn) {
                  should.not.exist(err);

                  conn.execute(getBlockingSql(4), function(err) {
                    should.not.exist(err);

                    conn.release(function(err) {
                      should.not.exist(err);
                      cb();
                    });
                  });
                });
              },
              function(cb) {
                //using setTimeout to help ensure this gets to the db last
                setTimeout(function() {
                  pool.getConnection(function(err, conn) {
                    should.exist(err);
                    (err.message).should.equal('NJS-040: connection request timeout');

                    should.not.exist(conn);
                    cb();
                  });
                }, 100);
              }
            ],
            function(err){
              should.not.exist(err);
              pool.terminate(function(err) {
                should.not.exist(err);
                done();
              });
            }
          );
        }
      );
    });
Example #19
0
      function(cb) {
        oracledb.createPool(
          dbConfig,
          function(err, pooling) {
            should.not.exist(err);
            pool = pooling;

            should.strictEqual(pool.poolPingInterval, userSetInterval);
            cb();
          }
        );
      },
 return new Promise(function (resolve, reject) {
     oracledb.createPool(
         config,
         function (err, p) {
             if (err) {
                 return reject(err);
             }
             pool = p;
             resolve(pool);
         }
     );
 });
Example #21
0
 function(callback) {
   oracledb.createPool(
     {
       externalAuth:  false,
       user:          dbConfig.user,
       password:      dbConfig.password,
       connectString: dbConfig.connectString
     },
     function(err, pool) {
       callback(err, pool);
     }
   );
 },
Example #22
0
 function(callback) {
   oracledb.createPool(
     {
       externalAuth: true,
       connectString: dbConfig.connectString
     },
     function(err, pool) {
       // verify poolMin value
       (pool.connectionsOpen).should.be.exactly(0);
       callback(err, pool);
     }
   );
 },
Example #23
0
 var getPools = function(id, callback) {
   oracledb.createPool(
     {
       externalAuth:  true,
       connectString: dbConfig.connectString
     },
     function(err, pool) {
       callback(err, {
         num:  id,
         inst: pool
       });
     }
   );
 };
Example #24
0
    return new Promise((resolve, reject) => {
        oracledb.createPool(
            config,
            (err, p) => {
                if (err) {
                    return reject(err);
                }

                pool = p;

                resolve(pool);
            }
        );
    });
Example #25
0
 before(function(done) {
   oracledb.createPool(
     {
       user:          dbConfig.user,
       password:      dbConfig.password,
       connectString: dbConfig.connectString
     },
     function(err, p) {
       should.not.exist(err);
       pool = p;
       done();
     }
   );
 });
Example #26
0
 function(callback) {
   oracledb.createPool(
     {
       externalAuth: true,
       connectString: dbConfig.connectString,
       poolMin: 5,
       poolMax: 20,
       poolIncrement: 2
     },
     function(err, pool) {
       callback(err, pool);
     }
   );
 },
Example #27
0
  this.list_table = function(req,res){
    console.log(req.query);
    console.log(req.params);
    var pool = oracle.createPool({
      user          : "******",
      password      : "******",
      connectString : "nuregist02.nu.local/NUREG",
      poolMax       : 2,
      poolMin       : 1
    },
    function(err,pool)
    {
      if (err) {
        console.error("createPool() callback:" + err.message);
        return;
      }else{
        console.log("test"+pool);
        pool.getConnection(function(err,connection) 
        {
          if (err) {
              console.error(err.message);
              return;
          }
          //console.log(connection);
            
           if(req.query.select) {
             var select_obj = JSON.parse(req.query.select);
             var sql = "SELECT"+ select_obj
                       + " FROM AVSREG.GRAD_"+req.params.table.toUpperCase();
           } else {
             var sql = "SELECT * FROM AVSREG.GRAD_"
                     +req.params.table.toUpperCase();
           }
           if(req.query.where){
             var where_obj = JSON.parse(req.query.where);
             console.log(where_obj)
             //c_db.where(where_obj.str,where_obj.json);
           }
           console.log(sql);
           connection.execute(sql,{},function(err, result) {
             //console.log(result.metaData);
             //console.log(result.rows);
              //res.json(result.rows); 
           });

         });
       }
     });
    }
Example #28
0
        function() {
          oracledb.createPool(
            opt,
            function(err, pool) {
              should.not.exist(err);
              should.exist(pool);

              pool.close(function(err) {

                should.not.exist(err);
                cb();
              });
            }
          );
        },
Example #29
0
 function(cb) {
   var credential = {
     user:             "******",
     password:         "******",
     connectionString: dbConfig.connectString
   };
   oracledb.createPool(
     credential,
     function(err, pool) {
       should.not.exist(err);
       poolInst = pool;
       cb();
     }
   );
 },
Example #30
0
 it('16.3 returns a promise from pool.terminate', function(done) {
   oracledb.createPool(dbConfig)
     .then(function(pool) {
       pool.should.be.ok();
       var promise = pool.terminate();
       promise.should.be.an.instanceof(oracledb.Promise);
       return promise;
     })
     .then(function() {
       return done();
     })
     .catch(function(err) {
       should.not.exist(err);
       return done();
     });
 });