|
Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
|
Mock connection pool for testing pool-related functionality. More...
#include <mock_connection_pool.h>

Classes | |
| struct | config |
| struct | stats |
| Get current pool statistics. More... | |
Public Member Functions | |
| mock_connection_pool (const config &cfg={}) | |
| ~mock_connection_pool () | |
| mock_database * | acquire () |
| Acquire a connection from the pool. | |
| mock_database * | acquire (std::chrono::milliseconds timeout) |
| Acquire a connection with timeout. | |
| void | release (mock_database *conn) |
| Release a connection back to the pool. | |
| stats | get_stats () const |
| void | simulate_exhaustion () |
| Simulate pool exhaustion. | |
| void | reset () |
| Reset pool to normal operation. | |
| void | configure_all (std::function< void(mock_database &)> configurator) |
| Configure all connections with same expectation. | |
Private Member Functions | |
| void | create_connection () |
Private Attributes | |
| config | config_ |
| std::vector< std::unique_ptr< mock_database > > | connections_ |
| std::queue< mock_database * > | available_ |
| std::set< mock_database * > | in_use_ |
| std::mutex | mutex_ |
| std::condition_variable | cv_ |
| std::atomic< bool > | exhausted_ {false} |
| std::atomic< size_t > | total_acquisitions_ {0} |
| std::atomic< size_t > | total_releases_ {0} |
| std::atomic< size_t > | acquisition_timeouts_ {0} |
Mock connection pool for testing pool-related functionality.
Features:
Definition at line 28 of file mock_connection_pool.h.
|
inlineexplicit |
Definition at line 148 of file mock_connection_pool.h.
References config_, create_connection(), and database::testing::mock_connection_pool::config::min_size.

|
inlinedefault |
|
inline |
Acquire a connection from the pool.
Definition at line 164 of file mock_connection_pool.h.
References acquire(), database::testing::mock_connection_pool::config::acquire_timeout, and config_.
Referenced by acquire().


|
inline |
Acquire a connection with timeout.
| timeout | Maximum time to wait |
Definition at line 168 of file mock_connection_pool.h.
References acquisition_timeouts_, available_, config_, connections_, create_connection(), cv_, exhausted_, in_use_, database::testing::mock_connection_pool::config::max_size, mutex_, database::testing::mock_connection_pool::config::simulate_slow_acquire, database::testing::mock_connection_pool::config::slow_acquire_delay, database::timeout, and total_acquisitions_.

|
inline |
Configure all connections with same expectation.
Definition at line 250 of file mock_connection_pool.h.
References connections_, and mutex_.
|
inlineprivate |
Definition at line 158 of file mock_connection_pool.h.
References available_, and connections_.
Referenced by acquire(), and mock_connection_pool().

|
inline |
Definition at line 223 of file mock_connection_pool.h.
References acquisition_timeouts_, available_, connections_, in_use_, mutex_, total_acquisitions_, and total_releases_.
|
inline |
Release a connection back to the pool.
| conn | Connection to release |
Definition at line 214 of file mock_connection_pool.h.
References available_, cv_, in_use_, mutex_, and total_releases_.
Referenced by database::testing::scoped_connection::~scoped_connection().

|
inline |
Reset pool to normal operation.
Definition at line 240 of file mock_connection_pool.h.
References available_, exhausted_, in_use_, and mutex_.
|
inline |
Simulate pool exhaustion.
Definition at line 236 of file mock_connection_pool.h.
References exhausted_.
|
private |
Definition at line 101 of file mock_connection_pool.h.
Referenced by acquire(), and get_stats().
|
private |
Definition at line 92 of file mock_connection_pool.h.
Referenced by acquire(), create_connection(), get_stats(), release(), and reset().
|
private |
Definition at line 90 of file mock_connection_pool.h.
Referenced by acquire(), acquire(), and mock_connection_pool().
|
private |
Definition at line 91 of file mock_connection_pool.h.
Referenced by acquire(), configure_all(), create_connection(), and get_stats().
|
private |
Definition at line 95 of file mock_connection_pool.h.
|
private |
Definition at line 96 of file mock_connection_pool.h.
Referenced by acquire(), reset(), and simulate_exhaustion().
|
private |
Definition at line 93 of file mock_connection_pool.h.
Referenced by acquire(), get_stats(), release(), and reset().
|
mutableprivate |
Definition at line 94 of file mock_connection_pool.h.
Referenced by acquire(), configure_all(), get_stats(), release(), and reset().
|
private |
Definition at line 99 of file mock_connection_pool.h.
Referenced by acquire(), and get_stats().
|
private |
Definition at line 100 of file mock_connection_pool.h.
Referenced by get_stats(), and release().