mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-01-05 20:50:34 -06:00
Add connection methods is_connected() and ping_server() (#528)
* Replace connection handle method check_connection() with is_connected() and ping_server() * When a connections is fetched from a pool perform a validity check which can be one of none, passive or ping. * Add the methods is_connected() and ping_server() to the connection template class. * Remove unused #include and add mising #include. * Add tests for the connection methods is_connected() and ping_server().
This commit is contained in:
@@ -116,6 +116,24 @@ namespace sqlpp
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Pool>
|
||||
void test_conn_check(Pool& pool)
|
||||
{
|
||||
auto check_db = [] (typename Pool::_pooled_connection_t db) {
|
||||
if (db.is_connected() == false)
|
||||
{
|
||||
throw std::runtime_error{"is_connected() returned false"};
|
||||
}
|
||||
if (db.ping_server() == false)
|
||||
{
|
||||
throw std::runtime_error{"ping_server() returned false"};
|
||||
}
|
||||
};
|
||||
check_db(pool.get(connection_check::none));
|
||||
check_db(pool.get(connection_check::passive));
|
||||
check_db(pool.get(connection_check::ping));
|
||||
}
|
||||
|
||||
template <typename Pool>
|
||||
void test_basic(Pool& pool, const std::string& create_table)
|
||||
{
|
||||
@@ -250,15 +268,16 @@ namespace sqlpp
|
||||
void test_connection_pool (typename Pool::_config_ptr_t config, const std::string& create_table, bool test_mt)
|
||||
{
|
||||
auto pool = Pool {config, 5};
|
||||
sqlpp::test::test_conn_move(pool);
|
||||
sqlpp::test::test_basic(pool, create_table);
|
||||
sqlpp::test::test_single_connection(pool);
|
||||
sqlpp::test::test_multiple_connections(pool);
|
||||
test_conn_move(pool);
|
||||
test_basic(pool, create_table);
|
||||
test_conn_check(pool);
|
||||
test_single_connection(pool);
|
||||
test_multiple_connections(pool);
|
||||
if (test_mt)
|
||||
{
|
||||
sqlpp::test::test_multithreaded(pool);
|
||||
test_multithreaded(pool);
|
||||
}
|
||||
sqlpp::test::test_destruction_order<Pool>(config);
|
||||
test_destruction_order<Pool>(config);
|
||||
}
|
||||
} // namespace test
|
||||
} // namespace sqlpp
|
||||
|
||||
Reference in New Issue
Block a user