Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
2c139644
Commit
2c139644
authored
Oct 01, 2020
by
Steven Murray
Browse files
ConnPool::getConn() now throws an exception if the pool was configured with zero connections
parent
0d76da86
Pipeline
#13759
failed with stages
in 7 minutes and 2 seconds
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
rdbms/ConnPool.cpp
View file @
2c139644
...
...
@@ -42,6 +42,11 @@ ConnPool::ConnPool(const Login &login, const uint64_t maxNbConns):
Conn
ConnPool
::
getConn
()
{
threading
::
MutexLocker
locker
(
m_connsAndStmtsMutex
);
if
(
0
==
m_maxNbConns
)
{
throw
ConnPoolConfiguredWithZeroConns
(
std
::
string
(
__FUNCTION__
)
+
" failed: ConnPool is configured with zero connections"
);
}
while
(
m_connsAndStmts
.
size
()
==
0
&&
m_nbConnsOnLoan
==
m_maxNbConns
)
{
m_connsAndStmtsCv
.
wait
(
locker
);
}
...
...
rdbms/ConnPool.hpp
View file @
2c139644
...
...
@@ -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"
...
...
@@ -49,14 +50,20 @@ public:
*/
ConnPool
(
const
Login
&
login
,
const
uint64_t
maxNbConns
);
CTA_GENERATE_EXCEPTION_CLASS
(
ConnPoolConfiguredWithZeroConns
);
/**
* Takes a connection from the pool.
*
* Please note that this method will block if the pool is empty. In such a
* situation this method will unblock when a connection is returned to the
* pool.
* pool. There is one exception to this rule. If the pool was configured
* with maxNbConns set to 0 then calling this method with throw a
* ConnPoolConfiguredWithZeroConns exception.
*
* @return A connection from the pool.
* @throw ConnPoolConfiguredWithZeroConns If this pool was configured with
* maxNbConns set to 0.
*/
Conn
getConn
();
...
...
rdbms/ConnPoolTest.cpp
View file @
2c139644
...
...
@@ -38,18 +38,28 @@ TEST_F(cta_rdbms_ConnPoolTest, getPooledConn) {
using
namespace
cta
::
rdbms
;
const
Login
login
(
Login
::
DBTYPE_SQLITE
,
""
,
""
,
"file::memory:?cache=shared"
,
""
,
0
);
const
uint64_t
n
bConns
=
2
;
ConnPool
pool
(
login
,
n
bConns
);
const
uint64_t
maxN
bConns
=
2
;
ConnPool
pool
(
login
,
maxN
bConns
);
Conn
conn
=
pool
.
getConn
();
}
TEST_F
(
cta_rdbms_ConnPoolTest
,
getPooledConn_maxNbConns_zero
)
{
using
namespace
cta
::
rdbms
;
const
Login
login
(
Login
::
DBTYPE_SQLITE
,
""
,
""
,
"file::memory:?cache=shared"
,
""
,
0
);
const
uint64_t
maxNbConns
=
0
;
ConnPool
pool
(
login
,
maxNbConns
);
ASSERT_THROW
(
Conn
conn
=
pool
.
getConn
(),
ConnPool
::
ConnPoolConfiguredWithZeroConns
);
}
TEST_F
(
cta_rdbms_ConnPoolTest
,
assignment
)
{
using
namespace
cta
::
rdbms
;
const
Login
login
(
Login
::
DBTYPE_SQLITE
,
""
,
""
,
"file::memory:?cache=shared"
,
""
,
0
);
const
uint64_t
n
bConns
=
2
;
ConnPool
pool
(
login
,
n
bConns
);
const
uint64_t
maxN
bConns
=
2
;
ConnPool
pool
(
login
,
maxN
bConns
);
Conn
conn
=
pool
.
getConn
();
...
...
@@ -62,8 +72,8 @@ TEST_F(cta_rdbms_ConnPoolTest, moveConstructor) {
using
namespace
cta
::
rdbms
;
const
Login
login
(
Login
::
DBTYPE_SQLITE
,
""
,
""
,
"file::memory:?cache=shared"
,
""
,
0
);
const
uint64_t
n
bConns
=
2
;
ConnPool
pool
(
login
,
n
bConns
);
const
uint64_t
maxN
bConns
=
2
;
ConnPool
pool
(
login
,
maxN
bConns
);
Conn
conn
=
pool
.
getConn
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment