Commit db9085e6 authored by Steven Murray's avatar Steven Murray
Browse files

rdbms::ConnPool now protects against being configired with a maximum of zero connections

parent 24df3cc9
......@@ -38,7 +38,7 @@ TEST_F(cta_catalogue_InMemoryCatalogue, createSameSchemaInTwoSeparateInMemoryDat
log::DummyLogger dummyLog("dummy", "dummy");
const uint64_t nbConns = 1;
const uint64_t nbArchiveFileListingConns = 0;
const uint64_t nbArchiveFileListingConns = 1;
// First in-memory database
{
......@@ -56,7 +56,7 @@ TEST_F(cta_catalogue_InMemoryCatalogue, schemaTables) {
log::DummyLogger dummyLog("dummy", "dummy");
const uint64_t nbConns = 1;
const uint64_t nbArchiveFileListingConns = 0;
const uint64_t nbArchiveFileListingConns = 1;
catalogue::InMemoryCatalogue inMemoryCatalogue(dummyLog, nbConns, nbArchiveFileListingConns);
const auto tableNameList = inMemoryCatalogue.getTableNames();
......
......@@ -33,7 +33,9 @@ namespace rdbms {
ConnPool::ConnPool(const Login &login, const uint64_t maxNbConns):
m_connFactory(wrapper::ConnFactoryFactory::create(login)),
m_maxNbConns(maxNbConns),
m_nbConnsOnLoan(0){
m_nbConnsOnLoan(0) {
if(0 == m_maxNbConns) throw MaxNbConnsIsZero("Cannot instantiate ConnPool because maxNbConns=0");
}
//------------------------------------------------------------------------------
......
......@@ -18,6 +18,7 @@
#pragma once
#include "common/exception/Exception.hpp"
#include "common/threading/CondVar.hpp"
#include "common/threading/Mutex.hpp"
#include "rdbms/ConnAndStmts.hpp"
......@@ -39,6 +40,8 @@ class Login;
class ConnPool {
public:
CTA_GENERATE_EXCEPTION_CLASS(MaxNbConnsIsZero);
/**
* Constructor.
*
......@@ -46,6 +49,7 @@ public:
* connections.
* @param maxNbConns The maximum number of database connections within the
* pool.
* @throw MaxNbConnsIsZero if maxNbConns is set to 0.
*/
ConnPool(const Login &login, const uint64_t maxNbConns);
......
......@@ -34,6 +34,14 @@ protected:
}
};
TEST_F(cta_rdbms_ConnPoolTest, MaxNbConnsIsZero) {
using namespace cta::rdbms;
const Login login(Login::DBTYPE_SQLITE, "", "", "file::memory:?cache=shared", "", 0);
const uint64_t nbConns = 0;
ASSERT_THROW(ConnPool pool(login, nbConns), ConnPool::MaxNbConnsIsZero);
}
TEST_F(cta_rdbms_ConnPoolTest, getPooledConn) {
using namespace cta::rdbms;
......
......@@ -55,7 +55,7 @@ const uint32_t TEST_GROUP_2 = 9754;
rdbms::Login catalogueLogin(rdbms::Login::DBTYPE_IN_MEMORY, "", "", "", "", 0);
const uint64_t nbConns = 1;
const uint64_t nbArchiveFileListingConns = 0;
const uint64_t nbArchiveFileListingConns = 1;
auto catalogueFactory = CatalogueFactoryFactory::create(m_dummyLog, catalogueLogin, nbConns,
nbArchiveFileListingConns);
m_catalogue = catalogueFactory->create();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment