From 0a8aaca837d7681ebc3b32b18868be7e62462c84 Mon Sep 17 00:00:00 2001 From: Yan Wang <68562925+yanw-bq@users.noreply.github.com> Date: Thu, 11 May 2023 10:28:41 -0700 Subject: [PATCH] Fix monitor timeout (#149) * fix monitor timeout * fix login timeout and unit tests * pass monitor flag --- driver/connect.cc | 9 +++- driver/connection_handler.cc | 8 ++-- driver/connection_handler.h | 4 +- driver/driver.h | 2 +- driver/monitor.cc | 4 +- unit_testing/failover_handler_test.cc | 44 ++++++++++---------- unit_testing/failover_reader_handler_test.cc | 30 ++++++------- unit_testing/failover_writer_handler_test.cc | 40 +++++++++--------- unit_testing/mock_objects.h | 14 ++++++- unit_testing/monitor_test.cc | 18 ++++---- version.cmake | 2 +- 11 files changed, 96 insertions(+), 79 deletions(-) diff --git a/driver/connect.cc b/driver/connect.cc index 341bb0c76..0b7443025 100644 --- a/driver/connect.cc +++ b/driver/connect.cc @@ -326,7 +326,7 @@ class dbc_guard @return Standard SQLRETURN code. If it is @c SQL_SUCCESS or @c SQL_SUCCESS_WITH_INFO, a connection has been established. */ -SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) +SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled, bool is_monitor_connection) { SQLRETURN rc = SQL_SUCCESS; unsigned long flags; @@ -385,7 +385,12 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) read_timeout = get_network_timeout(dsrc->network_timeout); write_timeout = read_timeout; } - else + else if (is_monitor_connection) + { + connect_timeout = get_network_timeout(dsrc->read_timeout); + read_timeout = get_network_timeout(dsrc->read_timeout); + write_timeout = get_network_timeout(dsrc->write_timeout); + } else { connect_timeout = get_connect_timeout(login_timeout); read_timeout = get_network_timeout(dsrc->read_timeout); diff --git a/driver/connection_handler.cc b/driver/connection_handler.cc index b2eac55d0..a7adaf557 100644 --- a/driver/connection_handler.cc +++ b/driver/connection_handler.cc @@ -56,11 +56,11 @@ CONNECTION_HANDLER::CONNECTION_HANDLER(DBC* dbc) : dbc{dbc} {} CONNECTION_HANDLER::~CONNECTION_HANDLER() = default; -SQLRETURN CONNECTION_HANDLER::do_connect(DBC* dbc_ptr, DataSource* ds, bool failover_enabled) { - return dbc_ptr->connect(ds, failover_enabled); +SQLRETURN CONNECTION_HANDLER::do_connect(DBC* dbc_ptr, DataSource* ds, bool failover_enabled, bool is_monitor_connection) { + return dbc_ptr->connect(ds, failover_enabled, is_monitor_connection); } -CONNECTION_PROXY* CONNECTION_HANDLER::connect(std::shared_ptr host_info, DataSource* ds) { +CONNECTION_PROXY* CONNECTION_HANDLER::connect(std::shared_ptr host_info, DataSource* ds, bool is_monitor_connection) { if (dbc == nullptr || host_info == nullptr) { return nullptr; @@ -76,7 +76,7 @@ CONNECTION_PROXY* CONNECTION_HANDLER::connect(std::shared_ptr host_in CONNECTION_PROXY* new_connection = nullptr; CLEAR_DBC_ERROR(dbc_clone); - const SQLRETURN rc = do_connect(dbc_clone, ds_to_use, ds_to_use->enable_cluster_failover); + const SQLRETURN rc = do_connect(dbc_clone, ds_to_use, ds_to_use->enable_cluster_failover, is_monitor_connection); if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { new_connection = dbc_clone->connection_proxy; diff --git a/driver/connection_handler.h b/driver/connection_handler.h index 1753c95c0..0c6f3a7d6 100644 --- a/driver/connection_handler.h +++ b/driver/connection_handler.h @@ -51,8 +51,8 @@ class CONNECTION_HANDLER { CONNECTION_HANDLER(DBC* dbc); virtual ~CONNECTION_HANDLER(); - virtual SQLRETURN do_connect(DBC* dbc_ptr, DataSource* ds, bool failover_enabled); - virtual CONNECTION_PROXY* connect(std::shared_ptr host_info, DataSource* ds); + virtual SQLRETURN do_connect(DBC* dbc_ptr, DataSource* ds, bool failover_enabled, bool is_monitor_connection = false); + virtual CONNECTION_PROXY* connect(std::shared_ptr host_info, DataSource* ds, bool is_monitor_connection = false); void update_connection(CONNECTION_PROXY* new_connection, const std::string& new_host_name); private: diff --git a/driver/driver.h b/driver/driver.h index d9f2f6083..21b94ec6a 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -656,7 +656,7 @@ struct DBC void remove_desc(DESC *desc); SQLRETURN set_error(char *state, const char *message, uint errcode); SQLRETURN set_error(char *state); - SQLRETURN connect(DataSource *dsrc, bool failover_enabled); + SQLRETURN connect(DataSource *dsrc, bool failover_enabled, bool is_monitor_connection = false); void execute_prep_stmt(MYSQL_STMT *pstmt, std::string &query, MYSQL_BIND *param_bind, MYSQL_BIND *result_bind); void init_proxy_chain(DataSource *dsrc); diff --git a/driver/monitor.cc b/driver/monitor.cc index 2f261aa86..9e4bfaeb8 100644 --- a/driver/monitor.cc +++ b/driver/monitor.cc @@ -226,12 +226,12 @@ bool MONITOR::connect() { } else { // cannot change login_timeout here because no access to dbc this->ds->read_timeout = timeout_sec; + this->ds->write_timeout = timeout_sec; } - this->ds->enable_cluster_failover = false; this->ds->enable_failure_detection= false; - this->connection_proxy = this->connection_handler->connect(this->host, this->ds); + this->connection_proxy = this->connection_handler->connect(this->host, this->ds, true); if (!this->connection_proxy) { return false; } diff --git a/unit_testing/failover_handler_test.cc b/unit_testing/failover_handler_test.cc index a055e824f..d4a72434b 100644 --- a/unit_testing/failover_handler_test.cc +++ b/unit_testing/failover_handler_test.cc @@ -115,9 +115,9 @@ TEST_F(FailoverHandlerTest, CustomDomain) { .Times(AtLeast(1)); EXPECT_CALL(*mock_ts, set_cluster_id(_)).Times(0); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)) .WillOnce(Return(SQL_SUCCESS)); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, true)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, true, false)) .WillOnce(Return(SQL_SUCCESS)); FAILOVER_HANDLER failover_handler(dbc, ds, mock_connection_handler, mock_ts, mock_metrics); @@ -132,7 +132,7 @@ TEST_F(FailoverHandlerTest, CustomDomain) { TEST_F(FailoverHandlerTest, FailoverDisabled) { ds->enable_cluster_failover = false; - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)).Times(1); + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)).Times(1); FAILOVER_HANDLER failover_handler(dbc, ds, mock_connection_handler, mock_ts, mock_metrics); failover_handler.init_connection(); @@ -145,7 +145,7 @@ TEST_F(FailoverHandlerTest, IP_TopologyAvailable_PatternRequired) { ds_setattr_from_utf8(&ds->server, server); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)) .WillOnce(Return(SQL_SUCCESS)); EXPECT_CALL(*mock_ts, get_topology(_, false)).WillOnce(Return(topology)); @@ -159,7 +159,7 @@ TEST_F(FailoverHandlerTest, IP_TopologyNotAvailable) { ds_setattr_from_utf8(&ds->server, server); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)) .WillOnce(Return(SQL_SUCCESS)); EXPECT_CALL(*mock_ts, get_topology(_, false)) @@ -181,9 +181,9 @@ TEST_F(FailoverHandlerTest, IP_Cluster) { ds_setattr_from_utf8(&ds->server, server); ds_setattr_from_utf8(&ds->host_pattern, host_pattern); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)) .WillOnce(Return(SQL_SUCCESS)); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, true)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, true, false)) .WillOnce(Return(SQL_SUCCESS)); EXPECT_CALL(*mock_ts, get_topology(_, false)).WillOnce(Return(topology)); @@ -208,9 +208,9 @@ TEST_F(FailoverHandlerTest, IP_Cluster_ClusterID) { ds_setattr_from_utf8(&ds->host_pattern, host_pattern); ds_setattr_from_utf8(&ds->cluster_id, cluster_id); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)) .WillOnce(Return(SQL_SUCCESS)); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, true)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, true, false)) .WillOnce(Return(SQL_SUCCESS)); EXPECT_CALL(*mock_ts, get_topology(_, false)).WillOnce(Return(topology)); @@ -232,9 +232,9 @@ TEST_F(FailoverHandlerTest, RDS_Cluster) { ds_setattr_from_utf8(&ds->server, server); ds->port = 1234; - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)) .WillOnce(Return(SQL_SUCCESS)); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, true)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, true, false)) .WillOnce(Return(SQL_SUCCESS)); EXPECT_CALL(*mock_ts, get_topology(_, false)).WillOnce(Return(topology)); @@ -255,9 +255,9 @@ TEST_F(FailoverHandlerTest, RDS_CustomCluster) { ds_setattr_from_utf8(&ds->server, server); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)) .WillOnce(Return(SQL_SUCCESS)); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, true)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, true, false)) .WillOnce(Return(SQL_SUCCESS)); EXPECT_CALL(*mock_ts, get_topology(_, false)).WillOnce(Return(topology)); @@ -278,9 +278,9 @@ TEST_F(FailoverHandlerTest, RDS_Instance) { ds_setattr_from_utf8(&ds->server, server); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)) .WillOnce(Return(SQL_SUCCESS)); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, true)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, true, false)) .WillOnce(Return(SQL_SUCCESS)); EXPECT_CALL(*mock_ts, get_topology(_, false)).WillOnce(Return(topology)); @@ -302,7 +302,7 @@ TEST_F(FailoverHandlerTest, RDS_Proxy) { ds_setattr_from_utf8(&ds->server, server); ds->port = 1234; - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)) .WillOnce(Return(SQL_SUCCESS)); EXPECT_CALL(*mock_ts, get_topology(_, false)).WillOnce(Return(topology)); @@ -324,9 +324,9 @@ TEST_F(FailoverHandlerTest, RDS_ReaderCluster) { ds_setattr_from_utf8(&ds->server, server); ds->port = 1234; - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)) .WillOnce(Return(SQL_SUCCESS)); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, true)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, true, false)) .WillOnce(Return(SQL_SUCCESS)); EXPECT_CALL(*mock_ts, get_topology(_, false)).WillOnce(Return(topology)); @@ -352,7 +352,7 @@ TEST_F(FailoverHandlerTest, RDS_MultiWriterCluster) { ds->port = 1234; ds->enable_cluster_failover = true; - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)).WillOnce(Return(SQL_SUCCESS)); + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)).WillOnce(Return(SQL_SUCCESS)); auto multi_writer_topology = std::make_shared(); multi_writer_topology->add_host(writer_host); @@ -389,10 +389,10 @@ TEST_F(FailoverHandlerTest, ReconnectWithFailoverSettings) { EXPECT_CALL(*mock_ts, set_cluster_instance_template(_)) .Times(AtLeast(1)); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, false)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, false, false)) .WillOnce(Return(SQL_SUCCESS)); - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, true)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, true, false)) .WillOnce(Return(SQL_SUCCESS)); FAILOVER_HANDLER failover_handler(dbc, ds, mock_connection_handler, mock_ts, mock_metrics); @@ -490,7 +490,7 @@ TEST_F(FailoverHandlerTest, GetRdsClusterHostUrl) { TEST_F(FailoverHandlerTest, ConnectToNewWriter) { SQLCHAR server[] = "my-cluster-name.cluster-XYZ.us-east-2.rds.amazonaws.com"; - EXPECT_CALL(*mock_connection_handler, do_connect(dbc, ds, _)) + EXPECT_CALL(*mock_connection_handler, do_connect_impl(dbc, ds, _, false)) .WillOnce(Return(SQL_SUCCESS)) .WillOnce(Return(SQL_SUCCESS)); diff --git a/unit_testing/failover_reader_handler_test.cc b/unit_testing/failover_reader_handler_test.cc index 5b34e2a40..a81c21eea 100644 --- a/unit_testing/failover_reader_handler_test.cc +++ b/unit_testing/failover_reader_handler_test.cc @@ -223,7 +223,7 @@ TEST_F(FailoverReaderHandlerTest, BuildHostsList) { TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Failure) { EXPECT_CALL(*mock_ts, get_topology(_, true)).WillRepeatedly(Return(topology)); - EXPECT_CALL(*mock_connection_handler, connect(_, nullptr)).WillRepeatedly(Return(nullptr)); + EXPECT_CALL(*mock_connection_handler, connect_impl(_, nullptr, false)).WillRepeatedly(Return(nullptr)); EXPECT_CALL(*mock_ts, mark_host_down(reader_a_host)).Times(1); EXPECT_CALL(*mock_ts, mark_host_down(reader_b_host)).Times(1); @@ -247,8 +247,8 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Success_Reader) { EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_connection_handler, connect(_, nullptr)).WillRepeatedly(Return(nullptr)); - EXPECT_CALL(*mock_connection_handler, connect(reader_a_host, nullptr)).WillRepeatedly(Return(mock_reader_a_proxy)); + EXPECT_CALL(*mock_connection_handler, connect_impl(_, nullptr, false)).WillRepeatedly(Return(nullptr)); + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_a_host, nullptr, false)).WillRepeatedly(Return(mock_reader_a_proxy)); // Reader C will not be used as it is put at the end. Will only try to connect to A and B EXPECT_CALL(*mock_ts, mark_host_up(reader_a_host)).Times(1); @@ -274,8 +274,8 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Success_Writer) { EXPECT_CALL(*mock_writer_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_connection_handler, connect(_, nullptr)).WillRepeatedly(Return(nullptr)); - EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)).WillRepeatedly(Return(mock_writer_proxy)); + EXPECT_CALL(*mock_connection_handler, connect_impl(_, nullptr, false)).WillRepeatedly(Return(nullptr)); + EXPECT_CALL(*mock_connection_handler, connect_impl(writer_host, nullptr, false)).WillRepeatedly(Return(mock_writer_proxy)); EXPECT_CALL(*mock_ts, mark_host_up(writer_host)).Times(1); @@ -309,9 +309,9 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_FastestHost) { EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_connection_handler, connect(_, nullptr)).WillRepeatedly(Return(nullptr)); - EXPECT_CALL(*mock_connection_handler, connect(reader_a_host, nullptr)).WillRepeatedly(Return(mock_reader_a_proxy)); - EXPECT_CALL(*mock_connection_handler, connect(reader_b_host, nullptr)).WillRepeatedly(Invoke([&]() { + EXPECT_CALL(*mock_connection_handler, connect_impl(_, nullptr, false)).WillRepeatedly(Return(nullptr)); + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_a_host, nullptr, false)).WillRepeatedly(Return(mock_reader_a_proxy)); + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_b_host, nullptr, false)).WillRepeatedly(Invoke([&]() { std::this_thread::sleep_for(std::chrono::milliseconds(5000)); return mock_reader_b_proxy; })); @@ -342,12 +342,12 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Timeout) { EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_b_proxy, mock_connection_proxy_destructor()); - EXPECT_CALL(*mock_connection_handler, connect(_, nullptr)).WillRepeatedly(Return(nullptr)); - EXPECT_CALL(*mock_connection_handler, connect(reader_a_host, nullptr)).WillRepeatedly(Invoke([&]() { + EXPECT_CALL(*mock_connection_handler, connect_impl(_, nullptr, false)).WillRepeatedly(Return(nullptr)); + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_a_host, nullptr, false)).WillRepeatedly(Invoke([&]() { std::this_thread::sleep_for(std::chrono::milliseconds(5000)); return mock_reader_a_proxy; })); - EXPECT_CALL(*mock_connection_handler, connect(reader_b_host, nullptr)).WillRepeatedly(Invoke([&]() { + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_b_host, nullptr, false)).WillRepeatedly(Invoke([&]() { std::this_thread::sleep_for(std::chrono::milliseconds(5000)); return mock_reader_b_proxy; })); @@ -368,7 +368,7 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Timeout) { TEST_F(FailoverReaderHandlerTest, Failover_Failure) { EXPECT_CALL(*mock_ts, get_topology(_, true)).WillRepeatedly(Return(topology)); - EXPECT_CALL(*mock_connection_handler, connect(_, nullptr)).WillRepeatedly(Return(nullptr)); + EXPECT_CALL(*mock_connection_handler, connect_impl(_, nullptr, false)).WillRepeatedly(Return(nullptr)); EXPECT_CALL(*mock_ts, mark_host_down(reader_a_host)).Times(AtLeast(1)); EXPECT_CALL(*mock_ts, mark_host_down(reader_b_host)).Times(AtLeast(1)); @@ -404,10 +404,10 @@ TEST_F(FailoverReaderHandlerTest, Failover_Success_Reader) { EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_b_proxy, mock_connection_proxy_destructor()); - EXPECT_CALL(*mock_connection_handler, connect(_, nullptr)).WillRepeatedly(Return(nullptr)); - EXPECT_CALL(*mock_connection_handler, connect(reader_a_host, nullptr)).WillRepeatedly( + EXPECT_CALL(*mock_connection_handler, connect_impl(_, nullptr, false)).WillRepeatedly(Return(nullptr)); + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_a_host, nullptr, false)).WillRepeatedly( Return(mock_reader_a_proxy)); - EXPECT_CALL(*mock_connection_handler, connect(reader_b_host, nullptr)).WillRepeatedly(Invoke([=]() { + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_b_host, nullptr, false)).WillRepeatedly(Invoke([=]() { std::this_thread::sleep_for(std::chrono::milliseconds(5000)); return mock_reader_b_proxy; })); diff --git a/unit_testing/failover_writer_handler_test.cc b/unit_testing/failover_writer_handler_test.cc index 77ecbfb7f..0b8fad06b 100644 --- a/unit_testing/failover_writer_handler_test.cc +++ b/unit_testing/failover_writer_handler_test.cc @@ -126,11 +126,11 @@ TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_TaskBEmptyReaderResult) { EXPECT_CALL(*mock_reader_handler, get_reader_connection(_, _)) .WillRepeatedly(Return(std::make_shared(false, nullptr, nullptr))); - EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(writer_host, nullptr, false)) .WillRepeatedly(Return(mock_writer_proxy)); - EXPECT_CALL(*mock_connection_handler, connect(reader_a_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_a_host, nullptr, false)) .WillRepeatedly(Return(nullptr)); - EXPECT_CALL(*mock_connection_handler, connect(reader_b_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_b_host, nullptr, false)) .WillRepeatedly(Return(nullptr)); FAILOVER_WRITER_HANDLER writer_handler( @@ -170,9 +170,9 @@ TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_SlowReaderA) { EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(writer_host, nullptr, false)) .WillRepeatedly(Return(mock_writer_proxy)); - EXPECT_CALL(*mock_connection_handler, connect(reader_b_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_b_host, nullptr, false)) .WillRepeatedly(Return(nullptr)); EXPECT_CALL(*mock_ts, get_topology(mock_writer_proxy, true)) @@ -220,12 +220,12 @@ TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_TaskBDefers) { EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); - EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(writer_host, nullptr, false)) .WillRepeatedly(Invoke([&]() { std::this_thread::sleep_for(std::chrono::milliseconds(5000)); return mock_writer_proxy; })); - EXPECT_CALL(*mock_connection_handler, connect(reader_b_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_b_host, nullptr, false)) .WillRepeatedly(Return(nullptr)); EXPECT_CALL(*mock_ts, get_topology(_, true)) @@ -281,13 +281,13 @@ TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_SlowWriter) { EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); - EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(writer_host, nullptr, false)) .WillRepeatedly(Invoke([&]() { std::this_thread::sleep_for(std::chrono::milliseconds(5000)); return mock_writer_proxy; })); - EXPECT_CALL(*mock_connection_handler, connect(new_writer_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(new_writer_host, nullptr, false)) .WillRepeatedly(Return(mock_new_writer_proxy)); EXPECT_CALL(*mock_ts, get_topology(mock_writer_proxy, true)) @@ -341,12 +341,12 @@ TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_TaskADefers) { EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); - EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(writer_host, nullptr, false)) .WillOnce(Return(mock_writer_proxy)) .WillRepeatedly(Return(nullptr)); // Connection is deleted after first connect - EXPECT_CALL(*mock_connection_handler, connect(reader_a_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_a_host, nullptr, false)) .WillRepeatedly(Return(mock_reader_a_proxy)); - EXPECT_CALL(*mock_connection_handler, connect(new_writer_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(new_writer_host, nullptr, false)) .WillRepeatedly(Invoke([&]() { std::this_thread::sleep_for(std::chrono::milliseconds(5000)); return mock_new_writer_proxy; @@ -403,16 +403,16 @@ TEST_F(FailoverWriterHandlerTest, FailedToConnect_FailoverTimeout) { EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(writer_host, nullptr, false)) .WillRepeatedly(Invoke([&]() { std::this_thread::sleep_for(std::chrono::milliseconds(5000)); return mock_writer_proxy; })); - EXPECT_CALL(*mock_connection_handler, connect(reader_a_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_a_host, nullptr, false)) .WillRepeatedly(Return(mock_reader_a_proxy)); - EXPECT_CALL(*mock_connection_handler, connect(reader_b_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_b_host, nullptr, false)) .WillRepeatedly(Return(mock_reader_b_proxy)); - EXPECT_CALL(*mock_connection_handler, connect(new_writer_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(new_writer_host, nullptr, false)) .WillRepeatedly(Invoke([&]() { std::this_thread::sleep_for(std::chrono::milliseconds(5000)); return mock_new_writer_proxy; @@ -461,13 +461,13 @@ TEST_F(FailoverWriterHandlerTest, FailedToConnect_TaskAFailed_TaskBWriterFailed) EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(writer_host, nullptr, false)) .WillRepeatedly(Return(nullptr)); - EXPECT_CALL(*mock_connection_handler, connect(reader_a_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_a_host, nullptr, false)) .WillRepeatedly(Return(mock_reader_a_proxy)); - EXPECT_CALL(*mock_connection_handler, connect(reader_b_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(reader_b_host, nullptr, false)) .WillRepeatedly(Return(mock_reader_b_proxy)); - EXPECT_CALL(*mock_connection_handler, connect(new_writer_host, nullptr)) + EXPECT_CALL(*mock_connection_handler, connect_impl(new_writer_host, nullptr, false)) .WillRepeatedly(Return(nullptr)); EXPECT_CALL(*mock_ts, get_topology(_, _)) diff --git a/unit_testing/mock_objects.h b/unit_testing/mock_objects.h index 157f44866..9b9ec3997 100644 --- a/unit_testing/mock_objects.h +++ b/unit_testing/mock_objects.h @@ -117,9 +117,19 @@ class MOCK_READER_HANDLER : public FAILOVER_READER_HANDLER { class MOCK_CONNECTION_HANDLER : public CONNECTION_HANDLER { public: + + CONNECTION_PROXY* connect(std::shared_ptr host_info, DataSource* ds, bool is_monitor_connection = false) { + return connect_impl(host_info, ds, is_monitor_connection); + } + + SQLRETURN do_connect(DBC* dbc_ptr, DataSource* ds, bool failover_enabled, bool is_monitor_connection = false) { + return do_connect_impl(dbc_ptr, ds, failover_enabled, is_monitor_connection); + } + MOCK_CONNECTION_HANDLER() : CONNECTION_HANDLER(nullptr) {} - MOCK_METHOD(CONNECTION_PROXY*, connect, (std::shared_ptr, DataSource*)); - MOCK_METHOD(SQLRETURN, do_connect, (DBC*, DataSource*, bool)); + MOCK_METHOD(CONNECTION_PROXY*, connect_impl, (std::shared_ptr, DataSource*, bool)); + MOCK_METHOD(SQLRETURN, do_connect_impl, (DBC*, DataSource*, bool, bool)); + }; class MOCK_FAILOVER_HANDLER : public FAILOVER_HANDLER { diff --git a/unit_testing/monitor_test.cc b/unit_testing/monitor_test.cc index 584cc970c..fce164ca1 100644 --- a/unit_testing/monitor_test.cc +++ b/unit_testing/monitor_test.cc @@ -144,7 +144,7 @@ TEST_F(MonitorTest, StopMonitoringTwiceWithSameContext) { TEST_F(MonitorTest, IsConnectionHealthyWithNoExistingConnection) { mock_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); - EXPECT_CALL(*mock_connection_handler, connect(host, _)) + EXPECT_CALL(*mock_connection_handler, connect_impl(host, _, true)) .WillOnce(Return(mock_proxy)); EXPECT_CALL(*mock_proxy, is_connected()).WillRepeatedly(Return(true)); @@ -158,7 +158,7 @@ TEST_F(MonitorTest, IsConnectionHealthyWithNoExistingConnection) { TEST_F(MonitorTest, IsConnectionHealthyOrUnhealthy) { mock_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); - EXPECT_CALL(*mock_connection_handler, connect(host, _)) + EXPECT_CALL(*mock_connection_handler, connect_impl(host, _, true)) .WillRepeatedly(Return(mock_proxy)); EXPECT_CALL(*mock_proxy, is_connected()) @@ -181,7 +181,7 @@ TEST_F(MonitorTest, IsConnectionHealthyOrUnhealthy) { TEST_F(MonitorTest, IsConnectionHealthyAfterFailedConnection) { mock_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); - EXPECT_CALL(*mock_connection_handler, connect(host, _)) + EXPECT_CALL(*mock_connection_handler, connect_impl(host, _, true)) .WillOnce(Return(mock_proxy)); EXPECT_CALL(*mock_proxy, is_connected()) @@ -226,7 +226,7 @@ TEST_F(MonitorTest, RunWithoutContext) { TEST_F(MonitorTest, RunWithContext) { auto proxy = new MOCK_CONNECTION_PROXY(dbc, ds); - EXPECT_CALL(*mock_connection_handler, connect(host, _)) + EXPECT_CALL(*mock_connection_handler, connect_impl(host, _, true)) .WillOnce(Return(proxy)); EXPECT_CALL(*proxy, is_connected()).WillRepeatedly(Return(true)); @@ -280,10 +280,11 @@ TEST_F(MonitorTest, ZeroEFMTimeout) { EXPECT_CALL(*proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_connection_handler, - connect(host, + connect_impl(host, AllOf( Field("connect_timeout",&DataSource::connect_timeout, Eq(failure_detection_timeout_default)), - Field("network_timeout", &DataSource::network_timeout, Eq(failure_detection_timeout_default))))) + Field("network_timeout", &DataSource::network_timeout, Eq(failure_detection_timeout_default))), + true)) .WillOnce(Return(proxy)); EXPECT_CALL(*proxy, ping()).WillRepeatedly(Return(0)); @@ -305,10 +306,11 @@ TEST_F(MonitorTest, NonZeroEFMTimeout) { EXPECT_CALL(*proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_connection_handler, - connect(host, + connect_impl(host, AllOf( Field("connect_timeout", &DataSource::connect_timeout, Eq(timeout.count())), - Field("network_timeout", &DataSource::network_timeout, Eq(timeout.count()))))) + Field("network_timeout", &DataSource::network_timeout, Eq(timeout.count()))), + true)) .WillOnce(Return(proxy)); EXPECT_CALL(*proxy, ping()).WillRepeatedly(Return(0)); diff --git a/version.cmake b/version.cmake index 5c60680d8..ae930893b 100644 --- a/version.cmake +++ b/version.cmake @@ -30,7 +30,7 @@ SET(CONNECTOR_MAJOR "1") SET(CONNECTOR_MINOR "0") -SET(CONNECTOR_PATCH "0") +SET(CONNECTOR_PATCH "2") SET(CONNECTOR_LEVEL "") SET(CONNECTOR_QUALITY "GA")