Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Use driver dll instead of static library for unit test #166

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,7 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT})
# but a dynamic module that will be loaded by ODBC manager. One
# consequence of this is that on Windows import libraries will not
# be generated nor installed.
IF(WIN32)
IF(ENABLE_UNIT_TESTS)
ADD_LIBRARY(${DRIVER_NAME} ${DRIVER_SRCS} ${AWSSDK_LIB_DIR})
ELSE(ENABLE_UNIT_TESTS)
ADD_LIBRARY(${DRIVER_NAME} SHARED ${DRIVER_SRCS} ${AWSSDK_LIB_DIR})
ENDIF(ENABLE_UNIT_TESTS)
ELSE(WIN32)
ADD_LIBRARY(${DRIVER_NAME} SHARED ${DRIVER_SRCS} ${AWSSDK_LIB_DIR})
ENDIF(WIN32)
ADD_LIBRARY(${DRIVER_NAME} SHARED ${DRIVER_SRCS} ${AWSSDK_LIB_DIR})

ADD_COVERAGE(${DRIVER_NAME})

Expand Down
2 changes: 1 addition & 1 deletion driver/cluster_aware_metrics_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
struct DBC;
struct DataSource;

class CLUSTER_AWARE_METRICS_CONTAINER {
class __declspec(dllexport) CLUSTER_AWARE_METRICS_CONTAINER {
public:
CLUSTER_AWARE_METRICS_CONTAINER();
CLUSTER_AWARE_METRICS_CONTAINER(DBC* dbc, DataSource* ds);
Expand Down
2 changes: 1 addition & 1 deletion driver/cluster_topology_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
// This class holds topology information for one cluster.
// Cluster topology consists of an instance endpoint, a set of nodes in the cluster,
// the type of each node in the cluster, and the status of each node in the cluster.
class CLUSTER_TOPOLOGY_INFO {
class __declspec(dllexport) CLUSTER_TOPOLOGY_INFO {
public:
CLUSTER_TOPOLOGY_INFO();
CLUSTER_TOPOLOGY_INFO(const CLUSTER_TOPOLOGY_INFO& src_info); //copy constructor
Expand Down
2 changes: 1 addition & 1 deletion driver/connection_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct DataSource;
class CONNECTION_PROXY;
typedef short SQLRETURN;

class CONNECTION_HANDLER {
class __declspec(dllexport) CONNECTION_HANDLER {
public:
CONNECTION_HANDLER(DBC* dbc);
virtual ~CONNECTION_HANDLER();
Expand Down
4 changes: 2 additions & 2 deletions driver/connection_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
struct DBC;
struct DataSource;

class CONNECTION_PROXY {
public:
class __declspec(dllexport) CONNECTION_PROXY {
public:
CONNECTION_PROXY() = default;
CONNECTION_PROXY(DBC* dbc, DataSource* ds);
virtual ~CONNECTION_PROXY();
Expand Down
2 changes: 1 addition & 1 deletion driver/efm_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "driver.h"
#include "monitor_service.h"

class EFM_PROXY : public CONNECTION_PROXY {
class __declspec(dllexport) EFM_PROXY : public CONNECTION_PROXY {
public:
EFM_PROXY(DBC* dbc, DataSource* ds);
EFM_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy);
Expand Down
18 changes: 9 additions & 9 deletions driver/failover.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include <condition_variable>

struct READER_FAILOVER_RESULT {
struct __declspec(dllexport) READER_FAILOVER_RESULT {
bool connected = false;
std::shared_ptr<HOST_INFO> new_host;
CONNECTION_PROXY* new_connection;
Expand All @@ -53,7 +53,7 @@ struct READER_FAILOVER_RESULT {
};

// FAILOVER_SYNC enables synchronization between threads
class FAILOVER_SYNC {
class __declspec(dllexport) FAILOVER_SYNC {
public:
FAILOVER_SYNC(int num_tasks);
void increment_task();
Expand All @@ -67,7 +67,7 @@ class FAILOVER_SYNC {
std::condition_variable cv;
};

class FAILOVER_READER_HANDLER {
class __declspec(dllexport) FAILOVER_READER_HANDLER {
public:
FAILOVER_READER_HANDLER(
std::shared_ptr<TOPOLOGY_SERVICE> topology_service,
Expand Down Expand Up @@ -109,7 +109,7 @@ class FAILOVER_READER_HANDLER {
};

// This struct holds results of Writer Failover Process.
struct WRITER_FAILOVER_RESULT {
struct __declspec(dllexport) WRITER_FAILOVER_RESULT {
bool connected = false;
bool is_new_host = false; // True if process connected to a new host. False if
// process re-connected to the same host
Expand All @@ -131,7 +131,7 @@ struct WRITER_FAILOVER_RESULT {
new_connection{new_connection} {}
};

class FAILOVER_WRITER_HANDLER {
class __declspec(dllexport) FAILOVER_WRITER_HANDLER {
public:
FAILOVER_WRITER_HANDLER(
std::shared_ptr<TOPOLOGY_SERVICE> topology_service,
Expand All @@ -158,7 +158,7 @@ class FAILOVER_WRITER_HANDLER {
ctpl::thread_pool& thread_pool;
};

class FAILOVER_HANDLER {
class __declspec(dllexport) FAILOVER_HANDLER {
public:
FAILOVER_HANDLER(DBC* dbc, DataSource* ds);
FAILOVER_HANDLER(
Expand Down Expand Up @@ -230,7 +230,7 @@ class FAILOVER_HANDLER {
// file, but here for now
//

class FAILOVER {
class __declspec(dllexport) FAILOVER {
public:
FAILOVER(std::shared_ptr<CONNECTION_HANDLER> connection_handler,
std::shared_ptr<TOPOLOGY_SERVICE> topology_service,
Expand Down Expand Up @@ -264,7 +264,7 @@ class CONNECT_TO_READER_HANDLER : public FAILOVER {
std::shared_ptr<READER_FAILOVER_RESULT> result);
};

class RECONNECT_TO_WRITER_HANDLER : public FAILOVER {
class __declspec(dllexport) RECONNECT_TO_WRITER_HANDLER : public FAILOVER {
public:
RECONNECT_TO_WRITER_HANDLER(
std::shared_ptr<CONNECTION_HANDLER> connection_handler,
Expand All @@ -286,7 +286,7 @@ class RECONNECT_TO_WRITER_HANDLER : public FAILOVER {
std::shared_ptr<CLUSTER_TOPOLOGY_INFO> latest_topology);
};

class WAIT_NEW_WRITER_HANDLER : public FAILOVER {
class __declspec(dllexport) WAIT_NEW_WRITER_HANDLER : public FAILOVER {
public:
WAIT_NEW_WRITER_HANDLER(
std::shared_ptr<CONNECTION_HANDLER> connection_handler,
Expand Down
4 changes: 2 additions & 2 deletions driver/host_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ enum HOST_STATE { UP, DOWN };

// TODO Think about char types. Using strings for now, but should SQLCHAR *, or CHAR * be employed?
// Most of the strings are for internal failover things
class HOST_INFO {
public:
class __declspec(dllexport) HOST_INFO {
public:
HOST_INFO();
//TODO - probably choose one of the following constructors, or more precisely choose which data type they should take
HOST_INFO(std::string host, int port);
Expand Down
5 changes: 5 additions & 0 deletions driver/iam_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,8 @@ bool IAM_PROXY::invoke_func_with_generated_token(std::function<bool(const char*)

return connect_result;
}

std::unordered_map<std::string, TOKEN_INFO>& IAM_PROXY::get_token_cache() {
return token_cache;
}

12 changes: 9 additions & 3 deletions driver/iam_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@

constexpr auto DEFAULT_TOKEN_EXPIRATION_SEC = 15 * 60;

class TOKEN_INFO {
#ifdef UNIT_TEST_BUILD
class TEST_UTILS;
#endif

class __declspec(dllexport) TOKEN_INFO {
public:
TOKEN_INFO() {};
TOKEN_INFO(std::string token) : TOKEN_INFO(token, DEFAULT_TOKEN_EXPIRATION_SEC) {};
Expand All @@ -59,7 +63,7 @@ class TOKEN_INFO {
std::chrono::system_clock::time_point expiration_time;
};

class TOKEN_GENERATOR {
class __declspec(dllexport) TOKEN_GENERATOR {
public:
TOKEN_GENERATOR() {} // Default constructor used only in unit tests
TOKEN_GENERATOR(Aws::Auth::AWSCredentials credentials, Aws::RDS::RDSClientConfiguration client_config) {
Expand All @@ -79,7 +83,7 @@ class TOKEN_GENERATOR {
std::shared_ptr<Aws::RDS::RDSClient> rds_client;
};

class IAM_PROXY : public CONNECTION_PROXY {
class __declspec(dllexport) IAM_PROXY : public CONNECTION_PROXY {
public:
IAM_PROXY() = default;
IAM_PROXY(DBC* dbc, DataSource* ds);
Expand All @@ -106,6 +110,8 @@ class IAM_PROXY : public CONNECTION_PROXY {
const char* user, unsigned int time_until_expiration,
bool force_generate_new_token = false);

static std::unordered_map<std::string, TOKEN_INFO>& get_token_cache();

protected:
static std::unordered_map<std::string, TOKEN_INFO> token_cache;
static std::mutex token_cache_mutex;
Expand Down
7 changes: 4 additions & 3 deletions driver/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <atomic>
#include <list>

struct CONNECTION_STATUS {
struct __declspec(dllexport) CONNECTION_STATUS {
bool is_valid;
std::chrono::milliseconds elapsed_time;
};
Expand All @@ -51,8 +51,9 @@ namespace {
const unsigned int failure_detection_timeout_default = 5;
}

class MONITOR : public std::enable_shared_from_this<MONITOR> {
public:
class __declspec(dllexport) MONITOR
: public std::enable_shared_from_this<MONITOR> {
public:
MONITOR(
std::shared_ptr<HOST_INFO> host_info,
std::shared_ptr<CONNECTION_HANDLER> connection_handler,
Expand Down
4 changes: 2 additions & 2 deletions driver/monitor_connection_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ struct DBC;

// Monitoring context for each connection. This contains each connection's criteria for
// whether a server should be considered unhealthy.
class MONITOR_CONNECTION_CONTEXT {
public:
class __declspec(dllexport) MONITOR_CONNECTION_CONTEXT {
public:
MONITOR_CONNECTION_CONTEXT(DBC* connection_to_abort,
std::set<std::string> node_keys,
std::chrono::milliseconds failure_detection_time,
Expand Down
5 changes: 3 additions & 2 deletions driver/monitor_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@

#include "monitor_thread_container.h"

class MONITOR_SERVICE : public std::enable_shared_from_this<MONITOR_SERVICE> {
public:
class __declspec(dllexport) MONITOR_SERVICE
: public std::enable_shared_from_this<MONITOR_SERVICE> {
public:
MONITOR_SERVICE(bool enable_logging = false);
MONITOR_SERVICE(
std::shared_ptr<MONITOR_THREAD_CONTAINER> monitor_thread_container,
Expand Down
4 changes: 2 additions & 2 deletions driver/monitor_thread_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#include <map>
#include <queue>

class MONITOR_THREAD_CONTAINER {
public:
class __declspec(dllexport) MONITOR_THREAD_CONTAINER {
public:
MONITOR_THREAD_CONTAINER(MONITOR_THREAD_CONTAINER const&) = delete;
MONITOR_THREAD_CONTAINER& operator=(MONITOR_THREAD_CONTAINER const&) = delete;
virtual ~MONITOR_THREAD_CONTAINER() = default;
Expand Down
2 changes: 1 addition & 1 deletion driver/myutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ SQLRETURN SQL_API my_SQLAllocConnect (SQLHENV henv, SQLHDBC *phdbc);
SQLRETURN SQL_API my_SQLFreeConnect (SQLHDBC hdbc);
SQLRETURN SQL_API my_SQLFreeEnv (SQLHENV henv);

void myodbc_end();
void __declspec(dllexport) myodbc_end();
my_bool set_dynamic_result (STMT *stmt);
void set_current_cursor_data (STMT *stmt,SQLUINTEGER irow);
my_bool is_minimum_version (const char *server_version,const char *version);
Expand Down
2 changes: 1 addition & 1 deletion driver/query_parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
#include <string>
#include <vector>

std::vector<std::string> parse_query_into_statements(const char* original_query);
std::vector<std::string> __declspec(dllexport) parse_query_into_statements(const char* original_query);

#endif /* __QUERY_PARSING_H__ */
5 changes: 5 additions & 0 deletions driver/secrets_manager_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,8 @@ bool SECRETS_MANAGER_PROXY::try_parse_region_from_secret(std::string secret, std

return false;
}

std::map<std::pair<Aws::String, Aws::String>, Aws::Utils::Json::JsonValue>& SECRETS_MANAGER_PROXY::get_secrets_cache() {
return secrets_cache;
}

8 changes: 7 additions & 1 deletion driver/secrets_manager_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
#include "connection_proxy.h"
#include "driver.h"

class SECRETS_MANAGER_PROXY : public CONNECTION_PROXY {
#ifdef UNIT_TEST_BUILD
class TEST_UTILS;
#endif

class __declspec(dllexport) SECRETS_MANAGER_PROXY : public CONNECTION_PROXY {
public:
SECRETS_MANAGER_PROXY(DBC* dbc, DataSource* ds);
#ifdef UNIT_TEST_BUILD
Expand All @@ -52,6 +56,8 @@ class SECRETS_MANAGER_PROXY : public CONNECTION_PROXY {
bool change_user(const char* user, const char* passwd,
const char* db) override;

static std::map<std::pair<Aws::String, Aws::String>, Aws::Utils::Json::JsonValue>& get_secrets_cache();

private:
std::shared_ptr<Aws::SecretsManager::SecretsManagerClient> sm_client;
std::pair<Aws::String, Aws::String> secret_key;
Expand Down
4 changes: 2 additions & 2 deletions driver/topology_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
static std::map<std::string, std::shared_ptr<CLUSTER_TOPOLOGY_INFO>> topology_cache;
static std::mutex topology_cache_mutex;

class TOPOLOGY_SERVICE {
public:
class __declspec(dllexport) TOPOLOGY_SERVICE {
public:
TOPOLOGY_SERVICE(unsigned long dbc_id, bool enable_logging = false);
TOPOLOGY_SERVICE(const TOPOLOGY_SERVICE&);
virtual ~TOPOLOGY_SERVICE();
Expand Down
2 changes: 1 addition & 1 deletion setupgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ add_compile_options(${PLATFORM_CFLAGS})

add_library(awsmysqlodbcS SHARED ${SETUP_SRCS})

target_link_libraries(awsmysqlodbcS ${ODBCLIB} ${ODBCINSTLIB})
target_link_libraries(awsmysqlodbcS ${ODBCLIB} ${ODBCINSTLIB} awsmysqlodbca)

# Note: When using GTK+, these libraries will be linked to -gtk modules.

Expand Down
17 changes: 16 additions & 1 deletion unit_testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ FetchContent_Declare(

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(CMAKE_VERBOSE_MAKEFILE ON)
message(STATUS "CMAKE_BINARY_DIR is ${CMAKE_BINARY_DIR}")

FetchContent_MakeAvailable(googletest)

Expand Down Expand Up @@ -70,15 +72,28 @@ add_executable(
topology_service_test.cc
)

file(COPY
${CMAKE_BINARY_DIR}/lib/Release/awsmysqlodbca.dll
${CMAKE_BINARY_DIR}/lib/Release/awsmysqlodbca.lib
${CMAKE_BINARY_DIR}/lib/Release/awsmysqlodbca.exp
${CMAKE_BINARY_DIR}/lib/Release/libcrypto-3-x64.dll
${CMAKE_BINARY_DIR}/lib/Release/libssl-3-x64.dll
DESTINATION ${CMAKE_BINARY_DIR}/unit_testing/bin/Release
)

TARGET_INCLUDE_DIRECTORIES(unit_testing PUBLIC ${AWSSDK_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/driver)
target_link_libraries(
unit_testing
gtest_main
gmock_main
awsmysqlodbca
myodbc-util
${AWSSDK_LINK_LIBRARIES}
)


include(GoogleTest)
gtest_discover_tests(unit_testing PROPERTIES DISCOVERY_TIMEOUT 30)
#gtest_discover_tests(unit_testing PROPERTIES DISCOVERY_TIMEOUT 30)

set_target_properties(unit_testing PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
7 changes: 5 additions & 2 deletions unit_testing/test_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

#include "test_utils.h"

//std::unordered_map<std::string, TOKEN_INFO> IAM_PROXY::token_cache;
//std::map<std::pair<Aws::String, Aws::String>, Aws::Utils::Json::JsonValue> SECRETS_MANAGER_PROXY::secrets_cache;

void allocate_odbc_handles(SQLHENV& env, DBC*& dbc, DataSource*& ds) {
SQLHDBC hdbc = nullptr;

Expand Down Expand Up @@ -116,15 +119,15 @@ std::string TEST_UTILS::build_cache_key(const char* host, const char* region, un
}

bool TEST_UTILS::token_cache_contains_key(std::string cache_key) {
return IAM_PROXY::token_cache.find(cache_key) != IAM_PROXY::token_cache.end();
return IAM_PROXY::get_token_cache().find(cache_key) != IAM_PROXY::get_token_cache().end();
}

void TEST_UTILS::clear_token_cache(IAM_PROXY &iam_proxy) {
iam_proxy.clear_token_cache();
}

std::map<std::pair<Aws::String, Aws::String>, Aws::Utils::Json::JsonValue>& TEST_UTILS::get_secrets_cache() {
return std::ref(SECRETS_MANAGER_PROXY::secrets_cache);
return std::ref(SECRETS_MANAGER_PROXY::get_secrets_cache());
}

bool TEST_UTILS::try_parse_region_from_secret(std::string secret, std::string& region) {
Expand Down