diff --git a/.build.sh b/.build.sh index 1070cf9b0..1f9c3fcdb 100644 --- a/.build.sh +++ b/.build.sh @@ -73,6 +73,7 @@ build_driver() { ( cd build cmake -DCMAKE_BUILD_TYPE=Release -D${driver_prefix}_BUILD_SHARED=On -D${driver_prefix}_BUILD_STATIC=On -D${driver_prefix}_BUILD_EXAMPLES=On -D${driver_prefix}_BUILD_UNIT_TESTS=On .. + [[ -x $(which clang-format) ]] && make format-check make -j${PROCS} ) } diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..ac09bb743 --- /dev/null +++ b/.clang-format @@ -0,0 +1,27 @@ +--- +BasedOnStyle: LLVM +Language: Cpp +Standard: Cpp03 +AccessModifierOffset: -2 +IndentWidth: 2 +TabWidth: 8 +ColumnLimit: 100 +UseTab: Never +IndentCaseLabels: true +AlignAfterOpenBracket: true +AlignEscapedNewlines: Left +BreakConstructorInitializers: BeforeComma +AllowShortBlocksOnASingleLine: false +DerivePointerAlignment: false +PointerAlignment: Left +BinPackParameters: true +BinPackArguments: true +AllowShortIfStatementsOnASingleLine: true +CompactNamespaces: true +AlignOperands: true +SpacesInContainerLiterals: true +ConstructorInitializerAllOnOneLineOrOnePerLine: false +Cpp11BracedListStyle: false +AlwaysBreakTemplateDeclarations: true +BreakBeforeInheritanceComma: true +... diff --git a/.gitignore b/.gitignore index 460003e24..0060e3e0f 100644 --- a/.gitignore +++ b/.gitignore @@ -50,7 +50,7 @@ Testing Debug demo/cassandra_demo test/unit_tests/cassandra_test -src/cassconfig.hpp +src/driver_config.hpp # API docs files Doxyfile diff --git a/CHANGELOG.md b/CHANGELOG.md index 997617b72..6482461eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,19 +1,43 @@ +2.13.0 +=========== + +Features +-------- +* [CPP-745] Exponential reconnection policy with jitter +* [CPP-769] Use `clang-format` to fix up formatting +* [CPP-775] Add `clang-format` to Windows + +Other +-------- +* [CPP-743] Move internal components from `namespace cass` to `namespace datastax::internal` +* [CPP-764] Rename namespace from `cass` to `datastax` +* [CPP-766] Allow RPM packaging script to build RPM packages for Amazon Linux +* [CPP-770] Fix header files include guard (\_\_CASS_XXX to DATASTAX_XXX) +* [CPP-772] Remove per cpp file LOG_FILE attribute to speed up Windows builds + +Community +-------- +* Fixed the location of the '[in]' information for Doxygen. (AlexisWilke) +* Added header subdirectory installation capability. (accelerated) +* Changed pkg_config templates to use the library variable name. (accelerated) +* Fix generation of shlib deps file for debian packages. (jirkasilhan) + 2.12.0 =========== Features -------- -[CPP-751] Call host listener callback for the initial set of hosts +* [CPP-751] Call host listener callback for the initial set of hosts Bug Fixes -------- -[CPP-755] UDT metadata not being properly populated/updated +* [CPP-755] UDT metadata not being properly populated/updated Other -------- -[CPP-705] Deprecate DC-aware multi-DC settings (`used_hosts_per_remote_dc` - and `allowRemoteDCsForLocalConsistencyLevel `) -[CPP-720] Streamline custom allocator +* [CPP-705] Deprecate DC-aware multi-DC settings (`used_hosts_per_remote_dc` + and `allowRemoteDCsForLocalConsistencyLevel `) +* [CPP-720] Streamline custom allocator 2.11.0 =========== diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e3e4f10a..523ddcb75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ set(CASS_INCLUDE_DIR "${CASS_ROOT_DIR}/include") list(APPEND CMAKE_MODULE_PATH ${CASS_ROOT_DIR}/cmake/modules) include(CppDriver) +include(ClangFormat) CassInitProject(cassandra) CassPolicies() diff --git a/appveyor.ps1 b/appveyor.ps1 index 72c6022ba..24771dfda 100644 --- a/appveyor.ps1 +++ b/appveyor.ps1 @@ -773,7 +773,7 @@ Function Publish-Artifacts { } # Create the Uri and FilePath components for the upload - $base_uri = "$($Env:ARTIFACTORY_BASE_URI)/origin/$($Env:APPVEYOR_REPO_BRANCH)/$(Get-Commit-Sha)/windows" + $base_uri = "$($Env:ARTIFACTORY_BASE_URI)/$($Env:DRIVER_VERSION)/$(Get-Commit-Sha)/windows" $driver_uri = "$($base_uri)/$($driver_type)/v$($Env:DRIVER_VERSION)/$($Env:DRIVER_ARTIFACT_ARCHIVE)" $driver_archive = "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:DRIVER_ARTIFACT_ARCHIVE)" $libuv_uri = "$($base_uri)/dependencies/libuv/v$($Env:LIBUV_VERSION)/$($Env:LIBUV_ARTIFACT_ARCHIVE)" diff --git a/appveyor.yml b/appveyor.yml index 68e888c4a..71df5120e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -40,10 +40,10 @@ environment: APPVEYOR_IGNORE_COMMIT_FILTERING_ON_TAG: true DRIVER_TYPE: CASS BOOST_VERSION: 1.69.0 - LIBSSH2_VERSION: 1.8.2 - LIBUV_VERSION: 1.28.0 - OPENSSL_1_0_VERSION: 1.0.2r - OPENSSL_1_1_VERSION: 1.1.1b + LIBSSH2_VERSION: 1.9.0 + LIBUV_VERSION: 1.29.1 + OPENSSL_1_0_VERSION: 1.0.2s + OPENSSL_1_1_VERSION: 1.1.1c matrix: - CMAKE_GENERATOR: Visual Studio 10 2010 OPENSSL_MAJOR_MINOR: 1.0 diff --git a/build.yaml b/build.yaml index 1af93b6d9..4d3cce80e 100644 --- a/build.yaml +++ b/build.yaml @@ -19,7 +19,7 @@ os: - centos/7-64/cpp - osx/high-sierra env: - LIBUV_VERSION: 1.28.0 + LIBUV_VERSION: 1.29.1 build: - script: | . .build.sh diff --git a/cmake/modules/ClangFormat.cmake b/cmake/modules/ClangFormat.cmake new file mode 100644 index 000000000..de9d50105 --- /dev/null +++ b/cmake/modules/ClangFormat.cmake @@ -0,0 +1,109 @@ +# +# Format and verify formatting using clang-format +# +cmake_minimum_required(VERSION 2.6.4) + +include(FindPackageHandleStandardArgs) + +if(NOT CLANG_FORMAT_EXE_NAME) + set(CLANG_FORMAT_EXE_NAME clang-format) +endif() + +if(CLANG_FORMAT_ROOT_DIR) + find_program(CLANG_FORMAT_EXE + NAMES ${CLANG_FORMAT_EXE_NAME} + PATHS ${CLANG_FORMAT_ROOT_DIR} + NO_DEFAULT_PATH) +endif() + +find_program(CLANG_FORMAT_EXE NAMES ${CLANG_FORMAT_EXE_NAME}) + +find_package_handle_standard_args(CLANG_FORMAT DEFAULT_MSG CLANG_FORMAT_EXE) + +mark_as_advanced(CLANG_FORMAT_EXE) + +if(CLANG_FORMAT_FOUND) + set(CLANG_FORMAT_FILE_EXTENSIONS ${CLANG_FORMAT_CXX_FILE_EXTENSIONS} *.cpp *.hpp *.c *.h) + file(GLOB_RECURSE CLANG_FORMAT_ALL_SOURCE_FILES ${CLANG_FORMAT_FILE_EXTENSIONS}) + + set(CLANG_FORMAT_EXCLUDE_PATTERNS ${CLANG_FORMAT_EXCLUDE_PATTERNS} "/CMakeFiles/" "cmake" "/build/" "/vendor/" "/third_party/" "cassandra.h" "dse.h") + + foreach(SOURCE_FILE ${CLANG_FORMAT_ALL_SOURCE_FILES}) + foreach(EXCLUDE_PATTERN ${CLANG_FORMAT_EXCLUDE_PATTERNS}) + string(FIND ${SOURCE_FILE} ${EXCLUDE_PATTERN} EXCLUDE_FOUND) + if(NOT ${EXCLUDE_FOUND} EQUAL -1) + list(REMOVE_ITEM CLANG_FORMAT_ALL_SOURCE_FILES ${SOURCE_FILE}) + endif() + endforeach() + endforeach() + + if(WIN32) + set(CLANG_FORMAT_FILENAME "clang-format.files") + set(CLANG_FORMAT_ABSOLUTE_FILENAME "${CMAKE_BINARY_DIR}/${CLANG_FORMAT_FILENAME}") + if (EXISTS ${CLANG_FORMAT_ABSOLUTE_FILENAME}) + file(REMOVE ${CLANG_FORMAT_ABSOLUTE_FILENAME}) + endif() + + set(COUNT 1) + file(TO_NATIVE_PATH ${CMAKE_BINARY_DIR} CMAKE_WINDOWS_BINARY_DIR) + foreach(SOURCE_FILE ${CLANG_FORMAT_ALL_SOURCE_FILES}) + file(RELATIVE_PATH RELATIVE_SOURCE_FILE ${CMAKE_BINARY_DIR} ${SOURCE_FILE}) + file(TO_NATIVE_PATH ${RELATIVE_SOURCE_FILE} NATIVE_RELATIVE_SOURCE_FILE) + + if(COUNT EQUAL 50) + file(APPEND ${CLANG_FORMAT_ABSOLUTE_FILENAME} " ${NATIVE_RELATIVE_SOURCE_FILE}\n") + set(COUNT 1) + else() + file(APPEND ${CLANG_FORMAT_ABSOLUTE_FILENAME} " ${NATIVE_RELATIVE_SOURCE_FILE}") + MATH(EXPR COUNT "${COUNT} + 1") + endif() + endforeach() + + file(TO_NATIVE_PATH ${CLANG_FORMAT_EXE} CLANG_FORMAT_EXE) + file(WRITE "${CMAKE_BINARY_DIR}/clang-format-windows.bat" + "@REM Generated clang-format script for Windows\r\n" + "@ECHO OFF\r\n" + "SETLOCAL ENABLEDELAYEDEXPANSION\r\n" + "SET IS_FAILED_CHECK=0\r\n" + "PUSHD ${CMAKE_WINDOWS_BINARY_DIR}>NUL\r\n" + "FOR /F \"TOKENS=*\" %%A IN (${CLANG_FORMAT_FILENAME}) do (\r\n" + " IF %1 EQU 1 (\r\n" + " \"${CLANG_FORMAT_EXE}\" -i -fallback-style=none -style=file %%A\r\n" + " IF NOT !ERRORLEVEL! EQU 0 (\r\n" + " SET IS_FAILED_CHECK=1\r\n" + " )\r\n" + " )\r\n" + " IF %1 EQU 2 (\r\n" + " \"${CLANG_FORMAT_EXE}\" -output-replacements-xml -fallback-style=none -style=file %%A 2>&1 | FINDSTR /C:\"replacement offset\">NUL\r\n" + " IF !ERRORLEVEL! EQU 0 (\r\n" + " SET IS_FAILED_CHECK=1\r\n" + " )\r\n" + " )\r\n" + ")\r\n" + "IF NOT !IS_FAILED_CHECK! EQU 0 (\r\n" + " POPD\r\n" + " EXIT /B 1\r\n" + ")\r\n" + "POPD\r\n" + "ENDLOCAL\r\n" + "EXIT /B 0\r\n") + + add_custom_target(format + COMMENT "Format source files using clang-format" + COMMAND "${CMAKE_WINDOWS_BINARY_DIR}\\clang-format-windows.bat" 1) + + add_custom_target(format-check + COMMENT "Verify source files formatting using clang-format" + COMMAND "${CMAKE_WINDOWS_BINARY_DIR}\\clang-format-windows.bat" 2) + else() + add_custom_target(format + COMMENT "Format source files using clang-format" + COMMAND ${CLANG_FORMAT_EXE} -i -fallback-style=none -style=file ${CLANG_FORMAT_ALL_SOURCE_FILES}) + + add_custom_target(format-check + COMMENT "Verify source files formatting using clang-format" + COMMAND ! ${CLANG_FORMAT_EXE} -output-replacements-xml -fallback-style=none -style=file ${CLANG_FORMAT_ALL_SOURCE_FILES} | tee replacements.xml | grep -q "replacement offset") + endif() +else() + message(STATUS "Unable to find clang-format. Not creating format targets.") +endif() diff --git a/cmake/modules/CppDriver.cmake b/cmake/modules/CppDriver.cmake index 7eaaf520d..61f16470a 100644 --- a/cmake/modules/CppDriver.cmake +++ b/cmake/modules/CppDriver.cmake @@ -810,25 +810,6 @@ macro(CassSetCompilerFlags) add_definitions("/MP") endif() - # Enable link time optimization for all MSVC build configurations - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL") - set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /LTCG") - set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") - - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL") - string(REGEX REPLACE "[-/]INCREMENTAL" "/INCREMENTAL:NO" CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO}") - set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG") - string(REGEX REPLACE "[-/]INCREMENTAL" "/INCREMENTAL:NO" CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}") - set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /LTCG") - string(REGEX REPLACE "[-/]INCREMENTAL" "/INCREMENTAL:NO" CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}") - set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG") - - set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /GL") - set(CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL "${CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL} /LTCG") - set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL} /LTCG") - set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} /LTCG") - # On Visual C++ -pedantic flag is not used, # -fPIC is not used on Windows platform (all DLLs are # relocable), -Wall generates about 30k stupid warnings @@ -1001,18 +982,12 @@ macro(CassFindSourceFiles) endif() set(CASS_ALL_SOURCE_FILES ${CASS_SRC_FILES} ${CASS_API_HEADER_FILES} ${CASS_INC_FILES}) - - # Shorten the source file pathing for log messages - foreach(SRC_FILE ${CASS_SRC_FILES}) - string(REPLACE "${CASS_ROOT_DIR}/" "" LOG_FILE_ ${SRC_FILE}) - set_source_files_properties(${SRC_FILE} PROPERTIES COMPILE_FLAGS -DLOG_FILE_=\\\"${LOG_FILE_}\\\") - endforeach() endmacro() #------------------------ # CassConfigure # -# Generate cassconfig.hpp from cassconfig.hpp.in +# Generate driver_config.hpp from driver_config.hpp.in # # Input: CASS_ROOT_DIR, CASS_SRC_DIR #------------------------ @@ -1048,6 +1023,6 @@ macro(CassConfigure) check_cxx_source_compiles("int main() { return __builtin_bswap64(42); }" HAVE_BUILTIN_BSWAP64) endif() - # Generate the cassconfig.hpp file - configure_file(${CASS_ROOT_DIR}/cassconfig.hpp.in ${CASS_SRC_DIR}/cassconfig.hpp) + # Generate the driver_config.hpp file + configure_file(${CASS_ROOT_DIR}/driver_config.hpp.in ${CASS_SRC_DIR}/driver_config.hpp) endmacro() diff --git a/cmake/modules/ExternalProject-OpenSSL.cmake b/cmake/modules/ExternalProject-OpenSSL.cmake index d86a7de1d..dff9f0f94 100644 --- a/cmake/modules/ExternalProject-OpenSSL.cmake +++ b/cmake/modules/ExternalProject-OpenSSL.cmake @@ -21,8 +21,8 @@ endif() # OpenSSL related CMake options option(OPENSSL_VERSION "OpenSSL version to build and install") if(NOT OPENSSL_VERSION) - # TODO: Should we default to OpenSSL 1.1 (e.g. 1.1.1b)? - set(OPENSSL_VERSION "1.0.2r") + # TODO: Should we default to OpenSSL 1.1 (e.g. 1.1.1c)? + set(OPENSSL_VERSION "1.0.2s") endif() option(OPENSSL_INSTALL_PREFIX "OpenSSL installation prefix location") if(CASS_USE_ZLIB) diff --git a/cmake/modules/ExternalProject-libssh2.cmake b/cmake/modules/ExternalProject-libssh2.cmake index 4bc3493c8..ae4fa638a 100644 --- a/cmake/modules/ExternalProject-libssh2.cmake +++ b/cmake/modules/ExternalProject-libssh2.cmake @@ -22,7 +22,7 @@ if(NOT LIBSSH2_INSTALL_PREFIX) endif() option(LIBSSH2_VERSION "libssh2 version to build and install") if(NOT LIBSSH2_VERSION) - set(LIBSSH2_VERSION "1.8.2") + set(LIBSSH2_VERSION "1.9.0") endif() set(LIBSSH2_VERSION ${LIBSSH2_VERSION} CACHE STRING "libssh2 version to build and install" FORCE) diff --git a/cmake/modules/ExternalProject-libuv.cmake b/cmake/modules/ExternalProject-libuv.cmake index 71dbc13cf..1d7f4ed3b 100644 --- a/cmake/modules/ExternalProject-libuv.cmake +++ b/cmake/modules/ExternalProject-libuv.cmake @@ -22,7 +22,7 @@ if(NOT LIBUV_INSTALL_PREFIX) endif() option(LIBUV_VERSION "libuv version to build and install") if(NOT LIBUV_VERSION) - set(LIBUV_VERSION "1.28.0") + set(LIBUV_VERSION "1.29.1") endif() set(LIBUV_VERSION ${LIBUV_VERSION} CACHE STRING "libuv version to build and install" FORCE) diff --git a/docs.yaml b/docs.yaml index 47c3f2ab1..bf151fdf4 100644 --- a/docs.yaml +++ b/docs.yaml @@ -52,10 +52,13 @@ rewrites: - ^examples/(.*): https://github.com/datastax/cpp-driver/blob/master/examples/\1 - http://www.datastax.com/documentation/cql/3.1: https://docs.datastax.com/en/archived/cql/3.1 - http://www.datastax.com/documentation/cassandra/2.: https://docs.datastax.com/en/archived/cassandra/2. + - http://downloads.datastax.com/cpp-driver: https://downloads.datastax.com/cpp-driver/ rules: use_path_nav_files_only: true versions: + - name: "2.13" + ref: 2.13.0 - name: "2.12" ref: 2.12.0 - name: "2.11" diff --git a/cassconfig.hpp.in b/driver_config.hpp.in similarity index 78% rename from cassconfig.hpp.in rename to driver_config.hpp.in index a1c1c8b89..43d8a6df2 100644 --- a/cassconfig.hpp.in +++ b/driver_config.hpp.in @@ -1,5 +1,5 @@ -#ifndef __CASSANDRA_CONFIG_HPP_INCLUDED__ -#define __CASSANDRA_CONFIG_HPP_INCLUDED__ +#ifndef DATASTAX_INTERNAL_DRIVER_CONFIG_HPP +#define DATASTAX_INTERNAL_DRIVER_CONFIG_HPP #cmakedefine HAVE_OPENSSL #cmakedefine HAVE_STD_ATOMIC diff --git a/examples/async/async.c b/examples/async/async.c index 50428510f..1c7382a75 100644 --- a/examples/async/async.c +++ b/examples/async/async.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -41,7 +41,6 @@ void print_error(CassFuture* future) { fprintf(stderr, "Error: %.*s\n", (int)message_length, message); } - CassCluster* create_cluster(const char* hosts) { CassCluster* cluster = cass_cluster_new(); cass_cluster_set_contact_points(cluster, hosts); @@ -90,7 +89,7 @@ void insert_into_async(CassSession* session, const char* key) { size_t i; for (i = 0; i < NUM_CONCURRENT_REQUESTS; ++i) { - char key_buffer[64]; + char key_buffer[64]; statement = cass_statement_new(query, 6); sprintf(key_buffer, "%s%u", key, (unsigned int)i); @@ -135,13 +134,10 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' };"); - - execute_query(session, - "CREATE TABLE examples.async (key text, \ + execute_query(session, "CREATE TABLE examples.async (key text, \ bln boolean, \ flt float, dbl double,\ i32 int, i64 bigint, \ diff --git a/examples/auth/auth.c b/examples/auth/auth.c index cdfa27bc7..7cc8491e3 100644 --- a/examples/auth/auth.c +++ b/examples/auth/auth.c @@ -35,8 +35,7 @@ typedef struct Credentials_ { const char* username; } Credentials; -void on_auth_initial(CassAuthenticator* auth, - void* data) { +void on_auth_initial(CassAuthenticator* auth, void* data) { /* * This callback is used to initiate a request to begin an authentication * exchange. Required resources can be acquired and initialized here. @@ -52,7 +51,7 @@ void on_auth_initial(CassAuthenticator* auth, * authentication callbacks were set and is available to all * authentication exchanges. */ - const Credentials* credentials = (const Credentials *)data; + const Credentials* credentials = (const Credentials*)data; size_t username_size = strlen(credentials->username); size_t password_size = strlen(credentials->password); @@ -68,20 +67,14 @@ void on_auth_initial(CassAuthenticator* auth, memcpy(response + username_size + 2, credentials->password, password_size); } -void on_auth_challenge(CassAuthenticator* auth, - void* data, - const char* token, - size_t token_size) { +void on_auth_challenge(CassAuthenticator* auth, void* data, const char* token, size_t token_size) { /* * Not used for plain text authentication, but this is to be used * for handling an authentication challenge initiated by the server. */ } -void on_auth_success(CassAuthenticator* auth, - void* data, - const char* token, - size_t token_size ) { +void on_auth_success(CassAuthenticator* auth, void* data, const char* token, size_t token_size) { /* * Not used for plain text authentication, but this is to be used * for handling the success phase of an exchange. @@ -104,17 +97,10 @@ int main(int argc, char* argv[]) { char* hosts = "127.0.0.1,127.0.0.2,127.0.0.3"; /* Setup authentication callbacks and credentials */ - CassAuthenticatorCallbacks auth_callbacks = { - on_auth_initial, - on_auth_challenge, - on_auth_success, - on_auth_cleanup - }; - - Credentials credentials = { - "cassandra", - "cassandra" - }; + CassAuthenticatorCallbacks auth_callbacks = { on_auth_initial, on_auth_challenge, on_auth_success, + on_auth_cleanup }; + + Credentials credentials = { "cassandra", "cassandra" }; /* Add contact points */ if (argc > 1) { @@ -123,10 +109,7 @@ int main(int argc, char* argv[]) { cass_cluster_set_contact_points(cluster, hosts); /* Set custom authentication callbacks and credentials */ - cass_cluster_set_authenticator_callbacks(cluster, - &auth_callbacks, - NULL, - &credentials); + cass_cluster_set_authenticator_callbacks(cluster, &auth_callbacks, NULL, &credentials); /* Provide the cluster object as configuration to connect the session */ connect_future = cass_session_connect(session, cluster); @@ -138,8 +121,7 @@ int main(int argc, char* argv[]) { const char* message; size_t message_length; cass_future_error_message(connect_future, &message, &message_length); - fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length, - message); + fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length, message); } cass_future_free(connect_future); diff --git a/examples/basic/basic.c b/examples/basic/basic.c index 60cea5566..29fb73f71 100644 --- a/examples/basic/basic.c +++ b/examples/basic/basic.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -92,7 +92,8 @@ CassError insert_into_basic(CassSession* session, const char* key, const Basic* CassError rc = CASS_OK; CassStatement* statement = NULL; CassFuture* future = NULL; - const char* query = "INSERT INTO examples.basic (key, bln, flt, dbl, i32, i64) VALUES (?, ?, ?, ?, ?, ?);"; + const char* query = + "INSERT INTO examples.basic (key, bln, flt, dbl, i32, i64) VALUES (?, ?, ?, ?, ?, ?);"; statement = cass_statement_new(query, 6); @@ -175,13 +176,10 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' };"); - - execute_query(session, - "CREATE TABLE examples.basic (key text, \ + execute_query(session, "CREATE TABLE examples.basic (key text, \ bln boolean, \ flt float, dbl double,\ i32 int, i64 bigint, \ diff --git a/examples/batch/batch.c b/examples/batch/batch.c index e91296e93..e1b0efb9b 100644 --- a/examples/batch/batch.c +++ b/examples/batch/batch.c @@ -26,15 +26,15 @@ */ #include -#include #include #include +#include #include "cassandra.h" struct Pair_ { - const char* key; - const char* value; + const char* key; + const char* value; }; typedef struct Pair_ Pair; @@ -105,7 +105,8 @@ CassError prepare_insert_into_batch(CassSession* session, const CassPrepared** p return rc; } -CassError insert_into_batch_with_prepared(CassSession* session, const CassPrepared* prepared, const Pair* pairs) { +CassError insert_into_batch_with_prepared(CassSession* session, const CassPrepared* prepared, + const Pair* pairs) { CassError rc = CASS_OK; CassFuture* future = NULL; CassBatch* batch = cass_batch_new(CASS_BATCH_TYPE_LOGGED); @@ -120,13 +121,15 @@ CassError insert_into_batch_with_prepared(CassSession* session, const CassPrepar } { - CassStatement* statement = cass_statement_new("INSERT INTO examples.pairs (key, value) VALUES ('c', '3')", 0); + CassStatement* statement = + cass_statement_new("INSERT INTO examples.pairs (key, value) VALUES ('c', '3')", 0); cass_batch_add_statement(batch, statement); cass_statement_free(statement); } { - CassStatement* statement = cass_statement_new("INSERT INTO examples.pairs (key, value) VALUES (?, ?)", 2); + CassStatement* statement = + cass_statement_new("INSERT INTO examples.pairs (key, value) VALUES (?, ?)", 2); cass_statement_bind_string(statement, 0, "d"); cass_statement_bind_string(statement, 1, "4"); cass_batch_add_statement(batch, statement); @@ -147,14 +150,13 @@ CassError insert_into_batch_with_prepared(CassSession* session, const CassPrepar return rc; } - int main(int argc, char* argv[]) { CassCluster* cluster = NULL; CassSession* session = cass_session_new(); const CassPrepared* prepared = NULL; char* hosts = "127.0.0.1"; - Pair pairs[] = { {"a", "1"}, {"b", "2"}, { NULL, NULL} }; + Pair pairs[] = { { "a", "1" }, { "b", "2" }, { NULL, NULL } }; if (argc > 1) { hosts = argv[1]; @@ -167,13 +169,10 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' };"); - - execute_query(session, - "CREATE TABLE examples.pairs (key text, \ + execute_query(session, "CREATE TABLE examples.pairs (key text, \ value text, \ PRIMARY KEY (key));"); diff --git a/examples/bind_by_name/bind_by_name.c b/examples/bind_by_name/bind_by_name.c index b364ba1ce..c5d7c2b83 100644 --- a/examples/bind_by_name/bind_by_name.c +++ b/examples/bind_by_name/bind_by_name.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -106,7 +106,8 @@ CassError prepare_query(CassSession* session, const char* query, const CassPrepa return rc; } -CassError insert_into_basic(CassSession* session, const CassPrepared* prepared, const char* key, const Basic* basic) { +CassError insert_into_basic(CassSession* session, const CassPrepared* prepared, const char* key, + const Basic* basic) { CassError rc = CASS_OK; CassStatement* statement = NULL; CassFuture* future = NULL; @@ -135,7 +136,8 @@ CassError insert_into_basic(CassSession* session, const CassPrepared* prepared, return rc; } -CassError select_from_basic(CassSession* session, const CassPrepared * prepared, const char* key, Basic* basic) { +CassError select_from_basic(CassSession* session, const CassPrepared* prepared, const char* key, + Basic* basic) { CassError rc = CASS_OK; CassStatement* statement = NULL; CassFuture* future = NULL; @@ -183,10 +185,9 @@ int main(int argc, char* argv[]) { const CassPrepared* select_prepared = NULL; char* hosts = "127.0.0.1"; - const char* insert_query - = "INSERT INTO examples.basic (key, bln, flt, dbl, i32, i64) VALUES (?, ?, ?, ?, ?, ?);"; - const char* select_query - = "SELECT * FROM examples.basic WHERE key = ?"; + const char* insert_query = + "INSERT INTO examples.basic (key, bln, flt, dbl, i32, i64) VALUES (?, ?, ?, ?, ?, ?);"; + const char* select_query = "SELECT * FROM examples.basic WHERE key = ?"; if (argc > 1) { hosts = argv[1]; @@ -199,25 +200,21 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' };"); - - execute_query(session, - "CREATE TABLE examples.basic (key text, \ + execute_query(session, "CREATE TABLE examples.basic (key text, \ bln boolean, \ flt float, dbl double,\ i32 int, i64 bigint, \ PRIMARY KEY (key));"); - if (prepare_query(session, insert_query, &insert_prepared) == CASS_OK) { insert_into_basic(session, insert_prepared, "prepared_test", &input); cass_prepared_free(insert_prepared); } - if (prepare_query(session, select_query, &select_prepared) == CASS_OK) { + if (prepare_query(session, select_query, &select_prepared) == CASS_OK) { select_from_basic(session, select_prepared, "prepared_test", &output); assert(input.bln == output.bln); diff --git a/examples/callbacks/callbacks.c b/examples/callbacks/callbacks.c index 28ae3bdbd..d388dcd8e 100644 --- a/examples/callbacks/callbacks.c +++ b/examples/callbacks/callbacks.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include @@ -76,14 +76,14 @@ CassCluster* create_cluster(const char* hosts) { return cluster; } -void connect_session(CassSession* session, const CassCluster* cluster, CassFutureCallback callback) { +void connect_session(CassSession* session, const CassCluster* cluster, + CassFutureCallback callback) { CassFuture* future = cass_session_connect(session, cluster); cass_future_set_callback(future, callback, session); cass_future_free(future); } -void execute_query(CassSession* session, const char* query, - CassFutureCallback callback) { +void execute_query(CassSession* session, const char* query, CassFutureCallback callback) { CassStatement* statement = cass_statement_new(query, 0); CassFuture* future = cass_session_execute(session, statement); cass_future_set_callback(future, callback, session); @@ -113,9 +113,7 @@ void on_create_keyspace(CassFuture* future, void* data) { print_error(future); } - execute_query((CassSession*)data, - "USE examples", - on_set_keyspace); + execute_query((CassSession*)data, "USE examples", on_set_keyspace); } void on_set_keyspace(CassFuture* future, void* data) { @@ -163,10 +161,8 @@ void on_insert(CassFuture* future, void* data) { signal_exit(); } else { const char* select_query = "SELECT * FROM callbacks"; - CassStatement* statement - = cass_statement_new(select_query, 0); - CassFuture* select_future - = cass_session_execute((CassSession*)data, statement); + CassStatement* statement = cass_statement_new(select_query, 0); + CassFuture* select_future = cass_session_execute((CassSession*)data, statement); cass_future_set_callback(select_future, on_select, data); diff --git a/examples/collections/collections.c b/examples/collections/collections.c index cdfee3b0a..9256474b3 100644 --- a/examples/collections/collections.c +++ b/examples/collections/collections.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -175,16 +175,13 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '1' };"); - execute_query(session, - "CREATE TABLE examples.collections (key text, \ + execute_query(session, "CREATE TABLE examples.collections (key text, \ items set, \ PRIMARY KEY (key))"); - insert_into_collections(session, "test", items); select_from_collections(session, "test"); diff --git a/examples/date_time/data_time.c b/examples/date_time/data_time.c index 78d4b9e44..c721bedf3 100644 --- a/examples/date_time/data_time.c +++ b/examples/date_time/data_time.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include #include "cassandra.h" @@ -169,13 +169,10 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' };"); - - execute_query(session, - "CREATE TABLE examples.date_time (key text PRIMARY KEY, d date, t time)"); + execute_query(session, "CREATE TABLE examples.date_time (key text PRIMARY KEY, d date, t time)"); insert_into(session, "test"); select_from(session, "test"); diff --git a/examples/duration/duration.c b/examples/duration/duration.c index 0dc34cf62..d9c161a2c 100644 --- a/examples/duration/duration.c +++ b/examples/duration/duration.c @@ -25,8 +25,8 @@ For more information, please refer to */ -#include #include "cassandra.h" +#include #define NANOS_IN_A_SEC (1000LL * 1000LL * 1000LL) @@ -76,7 +76,8 @@ CassError execute_query(CassSession* session, const char* query) { return rc; } -CassError insert_into(CassSession* session, const char* key, cass_int32_t months, cass_int32_t days, cass_int64_t nanos) { +CassError insert_into(CassSession* session, const char* key, cass_int32_t months, cass_int32_t days, + cass_int64_t nanos) { CassError rc = CASS_OK; CassStatement* statement = NULL; CassFuture* future = NULL; @@ -156,14 +157,11 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE IF NOT EXISTS examples WITH replication = { " - "'class': 'SimpleStrategy', 'replication_factor': '3' };"); - + execute_query(session, "CREATE KEYSPACE IF NOT EXISTS examples WITH replication = { " + "'class': 'SimpleStrategy', 'replication_factor': '3' };"); - execute_query(session, - "CREATE TABLE IF NOT EXISTS examples.duration " - "(key text PRIMARY KEY, d duration)"); + execute_query(session, "CREATE TABLE IF NOT EXISTS examples.duration " + "(key text PRIMARY KEY, d duration)"); /* Insert some rows into the table and read them back out */ diff --git a/examples/execution_profiles/execution_profiles.c b/examples/execution_profiles/execution_profiles.c index fbf322bc7..91b97546e 100644 --- a/examples/execution_profiles/execution_profiles.c +++ b/examples/execution_profiles/execution_profiles.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -98,9 +98,7 @@ CassError execute_query(CassSession* session, const char* query) { return rc; } -CassError insert_into_examples(CassSession* session, - const char* profile_name, - const char* key, +CassError insert_into_examples(CassSession* session, const char* profile_name, const char* key, const cass_bool_t value) { CassError rc = CASS_OK; CassStatement* statement = NULL; @@ -134,9 +132,7 @@ CassError insert_into_examples(CassSession* session, return rc; } -CassError select_from_examples(CassSession* session, - const char* profile_name, - const char* key, +CassError select_from_examples(CassSession* session, const char* profile_name, const char* key, cass_bool_t* return_value) { CassError rc = CASS_OK; CassStatement* statement = NULL; @@ -165,8 +161,7 @@ CassError select_from_examples(CassSession* session, if (row) { const CassValue* value = cass_row_get_column_by_name(row, "value"); cass_value_get_bool(value, return_value); - printf("SELECT: Key = %s | Value = %s\n", - key, + printf("SELECT: Key = %s | Value = %s\n", key, (*return_value == cass_true ? "true" : "false")); } @@ -195,14 +190,10 @@ int main(int argc, char* argv[]) { /* Create and set execution profiles; freeing once added to configuration */ profile = create_reduced_latency_write_execution_profile(); - cass_cluster_set_execution_profile(cluster, - "reduced_latency", - profile); + cass_cluster_set_execution_profile(cluster, "reduced_latency", profile); cass_execution_profile_free(profile); profile = create_quorum_execution_profile(); - cass_cluster_set_execution_profile(cluster, - "quorum", - profile); + cass_cluster_set_execution_profile(cluster, "quorum", profile); cass_execution_profile_free(profile); /* Provide the cluster object as configuration to connect the session */ @@ -213,12 +204,10 @@ int main(int argc, char* argv[]) { } /* Create a keyspace and table for the execution profile example */ - execute_query(session, - "CREATE KEYSPACE IF NOT EXISTS examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE IF NOT EXISTS examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' \ }"); - execute_query(session, - "CREATE TABLE IF NOT EXISTS examples.execution_profiles ( \ + execute_query(session, "CREATE TABLE IF NOT EXISTS examples.execution_profiles ( \ key text PRIMARY KEY, \ value boolean \ )"); diff --git a/examples/host_listener/host_listener.c b/examples/host_listener/host_listener.c index 6186a001c..e7b83ccc3 100644 --- a/examples/host_listener/host_listener.c +++ b/examples/host_listener/host_listener.c @@ -27,13 +27,10 @@ #include - #include #include -void on_signal(uv_signal_t* handle, int signum) { - uv_signal_stop(handle); -} +void on_signal(uv_signal_t* handle, int signum) { uv_signal_stop(handle); } void on_host_listener(CassHostListenerEvent event, CassInet inet, void* data); diff --git a/examples/logging/logging.c b/examples/logging/logging.c index edc0509c0..1643822fb 100644 --- a/examples/logging/logging.c +++ b/examples/logging/logging.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -61,12 +61,9 @@ CassError connect_session(CassSession* session, const CassCluster* cluster) { void on_log(const CassLogMessage* message, void* data) { FILE* log_file = (FILE*)data; - fprintf(log_file, "%u.%03u [%s] (%s:%d:%s): %s\n", - (unsigned int)(message->time_ms / 1000), - (unsigned int)(message->time_ms % 1000), - cass_log_level_string(message->severity), - message->file, message->line, message->function, - message->message); + fprintf(log_file, "%u.%03u [%s] (%s:%d:%s): %s\n", (unsigned int)(message->time_ms / 1000), + (unsigned int)(message->time_ms % 1000), cass_log_level_string(message->severity), + message->file, message->line, message->function, message->message); } int main(int argc, char* argv[]) { diff --git a/examples/maps/maps.c b/examples/maps/maps.c index 2575b6081..b940c20b1 100644 --- a/examples/maps/maps.c +++ b/examples/maps/maps.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -139,9 +139,7 @@ CassError select_from_maps(CassSession* session, const char* key) { if (cass_result_row_count(result) > 0) { const CassRow* row = cass_result_first_row(result); - CassIterator* iterator - = cass_iterator_from_map( - cass_row_get_column(row, 0)); + CassIterator* iterator = cass_iterator_from_map(cass_row_get_column(row, 0)); while (cass_iterator_next(iterator)) { const char* key; @@ -168,7 +166,9 @@ int main(int argc, char* argv[]) { CassSession* session = cass_session_new(); char* hosts = "127.0.0.1"; - const Pair items[] = { { "apple", 1 }, { "orange", 2 }, { "banana", 3 }, { "mango", 4 }, { NULL, 0 } }; + const Pair items[] = { + { "apple", 1 }, { "orange", 2 }, { "banana", 3 }, { "mango", 4 }, { NULL, 0 } + }; if (argc > 1) { hosts = argv[1]; @@ -181,16 +181,13 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' };"); - execute_query(session, - "CREATE TABLE examples.maps (key text, \ + execute_query(session, "CREATE TABLE examples.maps (key text, \ items map, \ PRIMARY KEY (key))"); - insert_into_maps(session, "test", items); select_from_maps(session, "test"); diff --git a/examples/named_parameters/named_parameters.c b/examples/named_parameters/named_parameters.c index de6774fd0..67892f5b4 100644 --- a/examples/named_parameters/named_parameters.c +++ b/examples/named_parameters/named_parameters.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -92,8 +92,8 @@ CassError insert_into_basic(CassSession* session, const char* key, const Basic* CassStatement* statement = NULL; CassFuture* future = NULL; - const char* query - = "INSERT INTO examples.basic (key, bln, flt, dbl, i32, i64) VALUES (:k, :b, :f, :d, :i32, :i64);"; + const char* query = "INSERT INTO examples.basic (key, bln, flt, dbl, i32, i64) VALUES (:k, :b, " + ":f, :d, :i32, :i64);"; statement = cass_statement_new(query, 6); @@ -124,8 +124,7 @@ CassError select_from_basic(CassSession* session, const char* key, Basic* basic) CassStatement* statement = NULL; CassFuture* future = NULL; - const char* query - = "SELECT * FROM examples.basic WHERE key = ?"; + const char* query = "SELECT * FROM examples.basic WHERE key = ?"; statement = cass_statement_new(query, 1); @@ -178,19 +177,15 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' };"); - - execute_query(session, - "CREATE TABLE examples.basic (key text, \ + execute_query(session, "CREATE TABLE examples.basic (key text, \ bln boolean, \ flt float, dbl double,\ i32 int, i64 bigint, \ PRIMARY KEY (key));"); - insert_into_basic(session, "named_parameters", &input); select_from_basic(session, "named_parameters", &output); diff --git a/examples/paging/paging.c b/examples/paging/paging.c index 5f46d6a2f..4276c02fa 100644 --- a/examples/paging/paging.c +++ b/examples/paging/paging.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -183,13 +183,10 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' };"); - - execute_query(session, - "CREATE TABLE examples.paging (key timeuuid, \ + execute_query(session, "CREATE TABLE examples.paging (key timeuuid, \ value text, \ PRIMARY KEY (key));"); diff --git a/examples/perf/perf.c b/examples/perf/perf.c index 90004b8fb..ec90c2455 100644 --- a/examples/perf/perf.c +++ b/examples/perf/perf.c @@ -26,10 +26,10 @@ */ #include -#include +#include #include #include -#include +#include #include @@ -51,12 +51,12 @@ #if defined(_MSC_VER) && defined(_DEBUG) #include const DWORD MS_VC_EXCEPTION = 0x406D1388; -#pragma pack(push,8) +#pragma pack(push, 8) typedef struct tagTHREADNAME_INFO { - DWORD dwType; /* Must be 0x1000. */ - LPCSTR szName; /* Pointer to name (in user addr space). */ + DWORD dwType; /* Must be 0x1000. */ + LPCSTR szName; /* Pointer to name (in user addr space). */ DWORD dwThreadID; /* Thread ID (-1=caller thread). */ - DWORD dwFlags; /* Reserved for future use, must be zero. */ + DWORD dwFlags; /* Reserved for future use, must be zero. */ } THREADNAME_INFO; #pragma pack(pop) void set_thread_name(const char* thread_name) { @@ -66,13 +66,11 @@ void set_thread_name(const char* thread_name) { info.dwThreadID = -1; info.dwFlags = 0; #pragma warning(push) -#pragma warning(disable: 6320 6322) +#pragma warning(disable : 6320 6322) __try { - RaiseException(MS_VC_EXCEPTION, - 0, - sizeof(info) / sizeof(ULONG_PTR), - (ULONG_PTR*) &info); - } __except (EXCEPTION_EXECUTE_HANDLER) { } + RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info); + } __except (EXCEPTION_EXECUTE_HANDLER) { + } #pragma warning(pop) } #endif @@ -256,7 +254,8 @@ void run_insert_queries(void* data) { CassSession* session = (CassSession*)data; const CassPrepared* insert_prepared = NULL; - const char* insert_query = "INSERT INTO stress.songs (id, title, album, artist, tags) VALUES (?, ?, ?, ?, ?);"; + const char* insert_query = + "INSERT INTO stress.songs (id, title, album, artist, tags) VALUES (?, ?, ?, ?, ?);"; #if USE_PREPARED if (prepare_query(session, insert_query, &insert_prepared) == CASS_OK) { @@ -310,11 +309,12 @@ void run_select_queries(void* data) { int i; CassSession* session = (CassSession*)data; const CassPrepared* select_prepared = NULL; - const char* select_query = "SELECT * FROM stress.songs WHERE id = a98d21b2-1900-11e4-b97b-e5e358e71e0d"; + const char* select_query = + "SELECT * FROM stress.songs WHERE id = a98d21b2-1900-11e4-b97b-e5e358e71e0d"; #if defined(_MSC_VER) && defined(_DEBUG) char thread_name[32]; - sprintf(thread_name, "Perf - %lu", (unsigned long) (GetThreadId(uv_thread_self()))); + sprintf(thread_name, "Perf - %lu", (unsigned long)(GetThreadId(uv_thread_self()))); set_thread_name(thread_name); #endif @@ -367,11 +367,11 @@ int main(int argc, char* argv[]) { "title text, album text, artist text, " "tags set, data blob)"); - execute_query(session, - "INSERT INTO stress.songs (id, title, album, artist, tags) VALUES " - "(a98d21b2-1900-11e4-b97b-e5e358e71e0d, " - "'La Petite Tonkinoise', 'Bye Bye Blackbird', 'Joséphine Baker', { 'jazz', '2013' });"); - + execute_query( + session, + "INSERT INTO stress.songs (id, title, album, artist, tags) VALUES " + "(a98d21b2-1900-11e4-b97b-e5e358e71e0d, " + "'La Petite Tonkinoise', 'Bye Bye Blackbird', 'Joséphine Baker', { 'jazz', '2013' });"); for (i = 0; i < NUM_THREADS; ++i) { #if DO_SELECTS @@ -383,19 +383,21 @@ int main(int argc, char* argv[]) { while (status_wait(&status, 5) > 0) { cass_session_get_metrics(session, &metrics); - printf("rate stats (requests/second): mean %f 1m %f 5m %f 10m %f\n", - metrics.requests.mean_rate, - metrics.requests.one_minute_rate, - metrics.requests.five_minute_rate, + printf("rate stats (requests/second): mean %f 1m %f 5m %f 10m %f\n", metrics.requests.mean_rate, + metrics.requests.one_minute_rate, metrics.requests.five_minute_rate, metrics.requests.fifteen_minute_rate); } cass_session_get_metrics(session, &metrics); - printf("final stats (microseconds): min %llu max %llu median %llu 75th %llu 95th %llu 98th %llu 99th %llu 99.9th %llu\n", + printf("final stats (microseconds): min %llu max %llu median %llu 75th %llu 95th %llu 98th %llu " + "99th %llu 99.9th %llu\n", (unsigned long long int)metrics.requests.min, (unsigned long long int)metrics.requests.max, - (unsigned long long int)metrics.requests.median, (unsigned long long int)metrics.requests.percentile_75th, - (unsigned long long int)metrics.requests.percentile_95th, (unsigned long long int)metrics.requests.percentile_98th, - (unsigned long long int)metrics.requests.percentile_99th, (unsigned long long int)metrics.requests.percentile_999th); + (unsigned long long int)metrics.requests.median, + (unsigned long long int)metrics.requests.percentile_75th, + (unsigned long long int)metrics.requests.percentile_95th, + (unsigned long long int)metrics.requests.percentile_98th, + (unsigned long long int)metrics.requests.percentile_99th, + (unsigned long long int)metrics.requests.percentile_999th); for (i = 0; i < NUM_THREADS; ++i) { uv_thread_join(&threads[i]); diff --git a/examples/prepared/prepared.c b/examples/prepared/prepared.c index a11a37686..6d21fff30 100644 --- a/examples/prepared/prepared.c +++ b/examples/prepared/prepared.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -91,7 +91,8 @@ CassError insert_into_basic(CassSession* session, const char* key, const Basic* CassError rc = CASS_OK; CassStatement* statement = NULL; CassFuture* future = NULL; - const char* query = "INSERT INTO examples.basic (key, bln, flt, dbl, i32, i64) VALUES (?, ?, ?, ?, ?, ?);"; + const char* query = + "INSERT INTO examples.basic (key, bln, flt, dbl, i32, i64) VALUES (?, ?, ?, ?, ?, ?);"; statement = cass_statement_new(query, 6); @@ -137,7 +138,8 @@ CassError prepare_select_from_basic(CassSession* session, const CassPrepared** p return rc; } -CassError select_from_basic(CassSession* session, const CassPrepared * prepared, const char* key, Basic* basic) { +CassError select_from_basic(CassSession* session, const CassPrepared* prepared, const char* key, + Basic* basic) { CassError rc = CASS_OK; CassStatement* statement = NULL; CassFuture* future = NULL; @@ -194,13 +196,10 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' };"); - - execute_query(session, - "CREATE TABLE examples.basic (key text, \ + execute_query(session, "CREATE TABLE examples.basic (key text, \ bln boolean, \ flt float, dbl double,\ i32 int, i64 bigint, \ diff --git a/examples/schema_meta/schema_meta.c b/examples/schema_meta/schema_meta.c index 4647ef82e..7f0927833 100644 --- a/examples/schema_meta/schema_meta.c +++ b/examples/schema_meta/schema_meta.c @@ -25,8 +25,8 @@ For more information, please refer to */ -#include #include +#include void print_keyspace_meta(const CassKeyspaceMeta* meta, int indent); void print_table_meta(const CassTableMeta* meta, int indent); @@ -64,12 +64,14 @@ void print_table(CassSession* session, const char* keyspace, const char* table) cass_schema_meta_free(schema_meta); } -void print_function(CassSession* session, const char* keyspace, const char* function, const char* arguments) { +void print_function(CassSession* session, const char* keyspace, const char* function, + const char* arguments) { const CassSchemaMeta* schema_meta = cass_session_get_schema_meta(session); const CassKeyspaceMeta* keyspace_meta = cass_schema_meta_keyspace_by_name(schema_meta, keyspace); if (keyspace_meta != NULL) { - const CassFunctionMeta* function_meta = cass_keyspace_meta_function_by_name(keyspace_meta, function, arguments); + const CassFunctionMeta* function_meta = + cass_keyspace_meta_function_by_name(keyspace_meta, function, arguments); if (function_meta != NULL) { print_function_meta(function_meta, 0); } else { @@ -82,12 +84,14 @@ void print_function(CassSession* session, const char* keyspace, const char* func cass_schema_meta_free(schema_meta); } -void print_aggregate(CassSession* session, const char* keyspace, const char* aggregate, const char* arguments) { +void print_aggregate(CassSession* session, const char* keyspace, const char* aggregate, + const char* arguments) { const CassSchemaMeta* schema_meta = cass_session_get_schema_meta(session); const CassKeyspaceMeta* keyspace_meta = cass_schema_meta_keyspace_by_name(schema_meta, keyspace); if (keyspace_meta != NULL) { - const CassAggregateMeta* aggregate_meta = cass_keyspace_meta_aggregate_by_name(keyspace_meta, aggregate, arguments); + const CassAggregateMeta* aggregate_meta = + cass_keyspace_meta_aggregate_by_name(keyspace_meta, aggregate, arguments); if (aggregate_meta != NULL) { print_aggregate_meta(aggregate_meta, 0); } else { @@ -144,23 +148,19 @@ int main(int argc, char* argv[]) { execute_query(session, "DROP KEYSPACE IF EXISTS examples;"); - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' }"); print_keyspace(session, "examples"); - execute_query(session, - "CREATE TABLE examples.schema_meta (key text, \ + execute_query(session, "CREATE TABLE examples.schema_meta (key text, \ value bigint, \ PRIMARY KEY (key))"); - execute_query(session, - "CREATE INDEX schema_meta_idx \ + execute_query(session, "CREATE INDEX schema_meta_idx \ ON examples.schema_meta (value)"); - execute_query(session, - "CREATE FUNCTION \ + execute_query(session, "CREATE FUNCTION \ examples.avg_state(state tuple, val int) \ CALLED ON NULL INPUT RETURNS tuple \ LANGUAGE java AS \ @@ -169,8 +169,7 @@ int main(int argc, char* argv[]) { state.setLong(1, state.getLong(1) + val.intValue()); \ } \ return state;'"); - execute_query(session, - "CREATE FUNCTION \ + execute_query(session, "CREATE FUNCTION \ examples.avg_final (state tuple) \ CALLED ON NULL INPUT RETURNS double \ LANGUAGE java AS \ @@ -180,8 +179,7 @@ int main(int argc, char* argv[]) { r /= state.getInt(0); \ return Double.valueOf(r);'"); - execute_query(session, - "CREATE AGGREGATE examples.average(int) \ + execute_query(session, "CREATE AGGREGATE examples.average(int) \ SFUNC avg_state STYPE tuple FINALFUNC avg_final \ INITCOND(0, 0)"); @@ -292,7 +290,8 @@ void print_schema_bytes(const CassValue* value) { cass_value_get_bytes(value, &bytes, &b_length); printf("0x"); - for (i = 0; i < b_length; ++i) printf("%02x", bytes[i]); + for (i = 0; i < b_length; ++i) + printf("%02x", bytes[i]); } void print_schema_list(const CassValue* value) { diff --git a/examples/simple/simple.c b/examples/simple/simple.c index 93fd86209..bd7176707 100644 --- a/examples/simple/simple.c +++ b/examples/simple/simple.c @@ -25,8 +25,8 @@ For more information, please refer to */ -#include #include +#include int main(int argc, char* argv[]) { /* Setup and connect to cluster */ @@ -62,8 +62,7 @@ int main(int argc, char* argv[]) { const char* release_version; size_t release_version_length; cass_value_get_string(value, &release_version, &release_version_length); - printf("release_version: '%.*s'\n", (int)release_version_length, - release_version); + printf("release_version: '%.*s'\n", (int)release_version_length, release_version); } cass_result_free(result); @@ -72,8 +71,7 @@ int main(int argc, char* argv[]) { const char* message; size_t message_length; cass_future_error_message(result_future, &message, &message_length); - fprintf(stderr, "Unable to run query: '%.*s'\n", (int)message_length, - message); + fprintf(stderr, "Unable to run query: '%.*s'\n", (int)message_length, message); } cass_statement_free(statement); @@ -83,8 +81,7 @@ int main(int argc, char* argv[]) { const char* message; size_t message_length; cass_future_error_message(connect_future, &message, &message_length); - fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length, - message); + fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length, message); } cass_future_free(connect_future); diff --git a/examples/ssl/ssl.c b/examples/ssl/ssl.c index 3cc7d68af..c6c4b6b1d 100644 --- a/examples/ssl/ssl.c +++ b/examples/ssl/ssl.c @@ -25,9 +25,9 @@ For more information, please refer to */ -#include -#include #include +#include +#include int load_trusted_cert_file(const char* file, CassSsl* ssl) { CassError rc; @@ -35,7 +35,7 @@ int load_trusted_cert_file(const char* file, CassSsl* ssl) { long cert_size; size_t bytes_read; - FILE *in = fopen(file, "rb"); + FILE* in = fopen(file, "rb"); if (in == NULL) { fprintf(stderr, "Error loading certificate file '%s'\n", file); return 0; @@ -49,7 +49,7 @@ int load_trusted_cert_file(const char* file, CassSsl* ssl) { bytes_read = fread(cert, 1, cert_size, in); fclose(in); - if (bytes_read == (size_t) cert_size) { + if (bytes_read == (size_t)cert_size) { rc = cass_ssl_add_trusted_cert_n(ssl, cert, cert_size); if (rc != CASS_OK) { fprintf(stderr, "Error loading SSL certificate: %s\n", cass_error_desc(rc)); @@ -105,8 +105,7 @@ int main(int argc, char* argv[]) { const char* release_version; size_t release_version_length; cass_value_get_string(value, &release_version, &release_version_length); - printf("release_version: '%.*s'\n", (int)release_version_length, - release_version); + printf("release_version: '%.*s'\n", (int)release_version_length, release_version); } cass_result_free(result); @@ -115,19 +114,17 @@ int main(int argc, char* argv[]) { const char* message; size_t message_length; cass_future_error_message(result_future, &message, &message_length); - fprintf(stderr, "Unable to run query: '%.*s'\n", (int)message_length, - message); + fprintf(stderr, "Unable to run query: '%.*s'\n", (int)message_length, message); } cass_statement_free(statement); cass_future_free(result_future); } else { - /* Handle error */ - const char* message; - size_t message_length; - cass_future_error_message(connect_future, &message, &message_length); - fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length, - message); + /* Handle error */ + const char* message; + size_t message_length; + cass_future_error_message(connect_future, &message, &message_length); + fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length, message); } cass_future_free(connect_future); diff --git a/examples/tracing/tracing.c b/examples/tracing/tracing.c index 573b20d3f..4c4c94091 100644 --- a/examples/tracing/tracing.c +++ b/examples/tracing/tracing.c @@ -25,8 +25,8 @@ For more information, please refer to */ -#include #include +#include void print_error(const char* context, CassFuture* future) { const char* message; @@ -35,9 +35,7 @@ void print_error(const char* context, CassFuture* future) { fprintf(stderr, "%s: %.*s\n", context, (int)message_length, message); } -const CassResult* run_tracing_query(CassSession* session, - const char* query, - CassUuid tracing_id) { +const CassResult* run_tracing_query(CassSession* session, const char* query, CassUuid tracing_id) { CassError rc = CASS_OK; CassFuture* future = NULL; const CassResult* result = NULL; @@ -74,8 +72,7 @@ void print_tracing_data(CassSession* session, CassFuture* future) { /* Query the tracing tables using the retrieved tracing ID */ /* Get information for the tracing session */ - result = run_tracing_query(session, - "SELECT * FROM system_traces.sessions WHERE session_id = ?", + result = run_tracing_query(session, "SELECT * FROM system_traces.sessions WHERE session_id = ?", tracing_id); if (result) { @@ -86,13 +83,10 @@ void print_tracing_data(CassSession* session, CassFuture* future) { const CassRow* row = cass_result_first_row(result); /* Get the command type that was run and how long it took */ - cass_value_get_string(cass_row_get_column_by_name(row, "command"), - &command, &command_length); - cass_value_get_int32(cass_row_get_column_by_name(row, "duration"), - &duration); + cass_value_get_string(cass_row_get_column_by_name(row, "command"), &command, &command_length); + cass_value_get_int32(cass_row_get_column_by_name(row, "duration"), &duration); - printf("Request command \"%.*s\" took %f milliseconds:\n", - (int)command_length, command, + printf("Request command \"%.*s\" took %f milliseconds:\n", (int)command_length, command, duration / 1000.0); } @@ -100,8 +94,7 @@ void print_tracing_data(CassSession* session, CassFuture* future) { } /* Get the events that happened during the tracing session */ - result = run_tracing_query(session, - "SELECT * FROM system_traces.events WHERE session_id = ?", + result = run_tracing_query(session, "SELECT * FROM system_traces.events WHERE session_id = ?", tracing_id); if (result) { @@ -120,18 +113,14 @@ void print_tracing_data(CassSession* session, CassFuture* future) { /* Get the activity for the event which host happened on, and how long * it took. */ - cass_value_get_string(cass_row_get_column_by_name(row, "activity"), - &activity, &activity_length); - cass_value_get_inet(cass_row_get_column_by_name(row, "source"), - &source); - cass_value_get_int32(cass_row_get_column_by_name(row, "source_elapsed"), - &source_elapsed); + cass_value_get_string(cass_row_get_column_by_name(row, "activity"), &activity, + &activity_length); + cass_value_get_inet(cass_row_get_column_by_name(row, "source"), &source); + cass_value_get_int32(cass_row_get_column_by_name(row, "source_elapsed"), &source_elapsed); cass_inet_string(source, source_str); - printf("%2d) Event on host %s (%f milliseconds): \"%.*s\"\n", - event_count++, - source_str, source_elapsed / 1000.0, - (int)activity_length, activity); + printf("%2d) Event on host %s (%f milliseconds): \"%.*s\"\n", event_count++, source_str, + source_elapsed / 1000.0, (int)activity_length, activity); } cass_iterator_free(iterator); @@ -181,8 +170,7 @@ int main(int argc, char* argv[]) { const char* release_version; size_t release_version_length; cass_value_get_string(value, &release_version, &release_version_length); - printf("release_version: '%.*s'\n", (int)release_version_length, - release_version); + printf("release_version: '%.*s'\n", (int)release_version_length, release_version); } else { printf("No rows returned\n"); } diff --git a/examples/tuple/tuple.c b/examples/tuple/tuple.c index 516586c5b..d2522792d 100644 --- a/examples/tuple/tuple.c +++ b/examples/tuple/tuple.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -160,7 +160,7 @@ CassError select_from_tuple(CassSession* session) { result = cass_future_get_result(future); rows = cass_iterator_from_result(result); - while(cass_iterator_next(rows)) { + while (cass_iterator_next(rows)) { CassUuid id; char id_str[CASS_UUID_STRING_LENGTH]; const CassRow* row = cass_iterator_get_row(rows); @@ -173,7 +173,7 @@ CassError select_from_tuple(CassSession* session) { printf("id %s ", id_str); - while(cass_iterator_next(item)) { + while (cass_iterator_next(item)) { const CassValue* value = cass_iterator_get_value(item); if (!cass_value_is_null(value)) { @@ -224,12 +224,11 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' }"); - execute_query(session, - "CREATE TABLE examples.tuples (id timeuuid, item frozen>, PRIMARY KEY(id))"); + execute_query(session, "CREATE TABLE examples.tuples (id timeuuid, item frozen>, PRIMARY KEY(id))"); insert_into_tuple(session); select_from_tuple(session); diff --git a/examples/udt/udt.c b/examples/udt/udt.c index f49c76daf..391deb3bb 100644 --- a/examples/udt/udt.c +++ b/examples/udt/udt.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -166,7 +166,7 @@ CassError select_from_udt(CassSession* session) { result = cass_future_get_result(future); rows = cass_iterator_from_result(result); - while(cass_iterator_next(rows)) { + while (cass_iterator_next(rows)) { CassUuid id; char id_str[CASS_UUID_STRING_LENGTH]; const CassRow* row = cass_iterator_get_row(rows); @@ -179,7 +179,7 @@ CassError select_from_udt(CassSession* session) { printf("id %s ", id_str); - while(fields != NULL && cass_iterator_next(fields)) { + while (fields != NULL && cass_iterator_next(fields)) { const char* field_name; size_t field_name_length; const CassValue* field_value = NULL; @@ -204,7 +204,8 @@ CassError select_from_udt(CassSession* session) { CassIterator* phone_fields = cass_iterator_fields_from_user_type(phone_value); assert(cass_value_type(phone_value) == CASS_VALUE_TYPE_UDT); while (cass_iterator_next(phone_fields)) { - const CassValue* phone_number_value = cass_iterator_get_user_type_field_value(phone_fields); + const CassValue* phone_number_value = + cass_iterator_get_user_type_field_value(phone_fields); cass_int32_t i; cass_value_get_int32(phone_number_value, &i); printf("%d ", i); @@ -248,18 +249,16 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' }"); - execute_query(session, - "CREATE TYPE examples.phone_numbers (phone1 int, phone2 int)"); + execute_query(session, "CREATE TYPE examples.phone_numbers (phone1 int, phone2 int)"); - execute_query(session, - "CREATE TYPE examples.address (street text, city text, zip int, phone set>)"); + execute_query(session, "CREATE TYPE examples.address (street text, city text, zip int, phone " + "set>)"); - execute_query(session, - "CREATE TABLE examples.udt (id timeuuid, address frozen
, PRIMARY KEY(id))"); + execute_query( + session, "CREATE TABLE examples.udt (id timeuuid, address frozen
, PRIMARY KEY(id))"); schema_meta = cass_session_get_schema_meta(session); diff --git a/examples/uuids/uuids.c b/examples/uuids/uuids.c index 36e5c2cbd..7161ec06f 100644 --- a/examples/uuids/uuids.c +++ b/examples/uuids/uuids.c @@ -26,9 +26,9 @@ */ #include -#include #include #include +#include #include "cassandra.h" @@ -150,9 +150,7 @@ CassError select_from_log(CassSession* session, const char* key) { cass_uuid_string(time, time_str); - printf("%.*s %s %.*s\n", (int)key_length, key, - time_str, - (int)entry_length, entry); + printf("%.*s %s %.*s\n", (int)key_length, key, time_str, (int)entry_length, entry); } cass_result_free(result); @@ -182,16 +180,12 @@ int main(int argc, char* argv[]) { return -1; } - execute_query(session, - "CREATE KEYSPACE examples WITH replication = { \ + execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' };"); - - execute_query(session, - "CREATE TABLE examples.log (key text, time timeuuid, entry text, \ + execute_query(session, "CREATE TABLE examples.log (key text, time timeuuid, entry text, \ PRIMARY KEY (key, time));"); - cass_uuid_gen_time(uuid_gen, &uuid); insert_into_log(session, "test", uuid, "Log entry #1"); diff --git a/gtests/src/integration/bignumber.hpp b/gtests/src/integration/bignumber.hpp index 5caf8f99a..9b4dfe80a 100644 --- a/gtests/src/integration/bignumber.hpp +++ b/gtests/src/integration/bignumber.hpp @@ -24,8 +24,7 @@ #include -namespace test { -namespace driver { +namespace test { namespace driver { /** * Helper class for working with Java byte arrays (e.g. BigInteger and @@ -34,11 +33,11 @@ namespace driver { class BigNumber { public: BigNumber() - : scale_(0) { } + : scale_(0) {} BigNumber(const std::string& big_number) - : big_number_(BN_new()) - , scale_(0) { + : big_number_(BN_new()) + , scale_(0) { BIGNUM* bignum = big_number_.get(); std::string copy = test::Utils::trim(big_number); @@ -61,8 +60,8 @@ class BigNumber { } BigNumber(const unsigned char* bytes, size_t bytes_length, int32_t scale) - : big_number_(BN_new()) - , scale_(scale) { + : big_number_(BN_new()) + , scale_(scale) { if (bytes && bytes_length > 0) { // Determine if value is negative and handle two's complement bool is_negative = ((bytes[0] & 0x80) != 0); @@ -141,9 +140,7 @@ class BigNumber { * * @return Scale for number */ - int32_t scale() const { - return scale_; - } + int32_t scale() const { return scale_; } /** * Get the string representation of the big number @@ -158,7 +155,7 @@ class BigNumber { result.assign(decimal); OPENSSL_free(decimal); - //Normalize - strip leading zeros + // Normalize - strip leading zeros result.erase(0, result.find_first_not_of('0')); if (result.size() == 0) { result = "0"; @@ -167,9 +164,7 @@ class BigNumber { // Return the value as integer or decimal (depending) if (scale_ > 0) { size_t decimal_location = result.size() - scale_; - return result.substr(0, decimal_location) - + "." - + result.substr(decimal_location); + return result.substr(0, decimal_location) + "." + result.substr(decimal_location); } return result; } @@ -217,7 +212,6 @@ class BigNumber { } }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_BIG_NUMBER_HPP__ diff --git a/gtests/src/integration/driver_utils.cpp b/gtests/src/integration/driver_utils.cpp index 3c0ba2cfa..b507d3e87 100644 --- a/gtests/src/integration/driver_utils.cpp +++ b/gtests/src/integration/driver_utils.cpp @@ -24,16 +24,18 @@ #include "request_handler.hpp" #include "statement.hpp" -std::vector test::driver::internals::Utils::attempted_hosts( - CassFuture* future) { +using namespace datastax::internal; +using namespace datastax::internal::core; + +std::vector test::driver::internals::Utils::attempted_hosts(CassFuture* future) { std::vector attempted_hosts; if (future) { - cass::Future* cass_future = static_cast(future); - if (cass_future->type() == cass::Future::FUTURE_TYPE_RESPONSE) { - cass::ResponseFuture* response = static_cast(cass_future); - cass::AddressVec attempted_addresses = response->attempted_addresses(); - for (cass::AddressVec::iterator iterator = attempted_addresses.begin(); - iterator != attempted_addresses.end(); ++iterator) { + Future* cass_future = static_cast(future); + if (cass_future->type() == Future::FUTURE_TYPE_RESPONSE) { + ResponseFuture* response = static_cast(cass_future); + AddressVec attempted_addresses = response->attempted_addresses(); + for (AddressVec::iterator iterator = attempted_addresses.begin(); + iterator != attempted_addresses.end(); ++iterator) { attempted_hosts.push_back(iterator->to_string().c_str()); } std::sort(attempted_hosts.begin(), attempted_hosts.end()); @@ -48,9 +50,8 @@ unsigned int test::driver::internals::Utils::connect_timeout(CassCluster* cluste std::string test::driver::internals::Utils::contact_points(CassCluster* cluster) { std::string contact_points; - const cass::ContactPointList& contact_points_list = - cluster->config().contact_points(); - for (cass::ContactPointList::const_iterator it = contact_points_list.begin(); + const ContactPointList& contact_points_list = cluster->config().contact_points(); + for (ContactPointList::const_iterator it = contact_points_list.begin(); it != contact_points_list.end(); ++it) { if (contact_points.size() > 0) { contact_points.push_back(','); @@ -61,36 +62,32 @@ std::string test::driver::internals::Utils::contact_points(CassCluster* cluster) } std::string test::driver::internals::Utils::driver_name() { - return cass::driver_name(); + return datastax::internal::driver_name(); } std::string test::driver::internals::Utils::driver_version() { - return cass::driver_version(); + return datastax::internal::driver_version(); } std::string test::driver::internals::Utils::host(CassFuture* future) { if (future) { - cass::Future* cass_future = static_cast(future); - if (cass_future->type() == cass::Future::FUTURE_TYPE_RESPONSE) { - return static_cast(cass_future)->address().to_string().c_str(); + Future* cass_future = static_cast(future); + if (cass_future->type() == Future::FUTURE_TYPE_RESPONSE) { + return static_cast(cass_future)->address().to_string().c_str(); } } return ""; } -int64_t test::driver::internals::Utils::murmur3_hash( - const std::string& value) { - return cass::MurmurHash3_x64_128(value.data(), value.size(), 0); +int64_t test::driver::internals::Utils::murmur3_hash(const std::string& value) { + return MurmurHash3_x64_128(value.data(), value.size(), 0); } -int test::driver::internals::Utils::port(CassCluster* cluster) { - return cluster->config().port(); -} +int test::driver::internals::Utils::port(CassCluster* cluster) { return cluster->config().port(); } -void test::driver::internals::Utils::set_record_attempted_hosts( - CassStatement* statement, bool enable) { +void test::driver::internals::Utils::set_record_attempted_hosts(CassStatement* statement, + bool enable) { if (statement) { - static_cast(statement) - ->set_record_attempted_addresses(enable); + static_cast(statement)->set_record_attempted_addresses(enable); } } diff --git a/gtests/src/integration/driver_utils.hpp b/gtests/src/integration/driver_utils.hpp index fd86730a3..f86620ef4 100644 --- a/gtests/src/integration/driver_utils.hpp +++ b/gtests/src/integration/driver_utils.hpp @@ -23,9 +23,7 @@ #include #include -namespace test { -namespace driver { -namespace internals { +namespace test { namespace driver { namespace internals { class Utils { public: @@ -101,8 +99,6 @@ class Utils { static void set_record_attempted_hosts(CassStatement* statement, bool enable); }; -} // namespace internals -} // namespace driver -} // namespace test +}}} // namespace test::driver::internals #endif // __TEST_DRIVER_UTILS_HPP__ diff --git a/gtests/src/integration/exception.hpp b/gtests/src/integration/exception.hpp index a0b32d669..2500d8991 100644 --- a/gtests/src/integration/exception.hpp +++ b/gtests/src/integration/exception.hpp @@ -35,7 +35,7 @@ class Exception : public std::runtime_error { * @param message Exception message */ Exception(const std::string& message) - : std::runtime_error(message) {} + : std::runtime_error(message) {} /** * Destructor @@ -55,8 +55,8 @@ class CassException : public Exception { * @param error_code Error code */ CassException(const std::string& message, const CassError error_code) - : Exception(message) - , error_code_(error_code) {} + : Exception(message) + , error_code_(error_code) {} /** * Exception class that contains an error code @@ -67,14 +67,14 @@ class CassException : public Exception { */ CassException(const std::string& message, const CassError error_code, const std::string& error_message) - : Exception(message) - , error_code_(error_code) - , error_message_(error_message) { } + : Exception(message) + , error_code_(error_code) + , error_message_(error_message) {} /** * Destructor */ - virtual ~CassException() throw() { } + virtual ~CassException() throw() {} /** * Get the error code associated with the exception @@ -88,9 +88,7 @@ class CassException : public Exception { * * @return Error description */ - const std::string error_description() { - return std::string(cass_error_desc(error_code())); - } + const std::string error_description() { return std::string(cass_error_desc(error_code())); } /** * Get the error message associated with the exception diff --git a/gtests/src/integration/integration.cpp b/gtests/src/integration/integration.cpp index 827d28f69..3d08f52ab 100644 --- a/gtests/src/integration/integration.cpp +++ b/gtests/src/integration/integration.cpp @@ -34,32 +34,32 @@ bool Integration::skipped_message_displayed_ = false; Integration::Integration() - : ccm_(NULL) - , session_() - , keyspace_name_("") - , table_name_("") - , system_schema_keyspaces_("system.schema_keyspaces") - , uuid_generator_() - , server_version_(Options::server_version()) - , number_dc1_nodes_(1) - , number_dc2_nodes_(0) - , replication_factor_(0) - , replication_strategy_("") - , contact_points_("") - , is_password_authenticator_(false) - , is_client_authentication_(false) - , is_ssl_(false) - , is_with_vnodes_(false) - , is_randomized_contact_points_(false) - , is_schema_metadata_(false) - , is_ccm_start_requested_(true) - , is_ccm_start_node_individually_(false) - , is_session_requested_(true) - , is_test_chaotic_(false) - , is_beta_protocol_(Options::is_beta_protocol()) - , protocol_version_(CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION) - , create_keyspace_query_("") - , start_time_(0ull) { + : ccm_(NULL) + , session_() + , keyspace_name_("") + , table_name_("") + , system_schema_keyspaces_("system.schema_keyspaces") + , uuid_generator_() + , server_version_(Options::server_version()) + , number_dc1_nodes_(1) + , number_dc2_nodes_(0) + , replication_factor_(0) + , replication_strategy_("") + , contact_points_("") + , is_password_authenticator_(false) + , is_client_authentication_(false) + , is_ssl_(false) + , is_with_vnodes_(false) + , is_randomized_contact_points_(false) + , is_schema_metadata_(false) + , is_ccm_start_requested_(true) + , is_ccm_start_node_individually_(false) + , is_session_requested_(true) + , is_test_chaotic_(false) + , is_beta_protocol_(Options::is_beta_protocol()) + , protocol_version_(CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION) + , create_keyspace_query_("") + , start_time_(0ull) { // Determine if the schema keyspaces table should be updated // TODO: Make cass_version (and dse_version) available for all tests CCM::CassVersion cass_version = server_version_; @@ -79,7 +79,7 @@ Integration::Integration() if (type_param) { std::vector tokens = explode(test_information->test_case_name(), '/'); for (std::vector::const_iterator iterator = tokens.begin(); - iterator < tokens.end(); ++iterator) { + iterator < tokens.end(); ++iterator) { std::string token = *iterator; // Determine if we are looking at the last token @@ -89,9 +89,7 @@ Integration::Integration() if (!(tokenStream >> number).fail()) { std::vector type_param_tokens = explode(type_param, ':'); size_t size = type_param_tokens.size(); - test_case_name_ += test::Utils::replace_all(type_param_tokens[size - 1], - ">", - ""); + test_case_name_ += test::Utils::replace_all(type_param_tokens[size - 1], ">", ""); } } else { test_case_name_ += token + "_"; @@ -110,7 +108,8 @@ Integration::Integration() Integration::~Integration() { try { session_.close(false); - } catch (...) {} + } catch (...) { + } // Reset the skipped message displayed state skipped_message_displayed_ = false; @@ -130,11 +129,9 @@ void Integration::SetUp() { } replication_strategy_ = default_replication_strategy(); - // Generate the keyspace query - create_keyspace_query_ = format_string(SIMPLE_KEYSPACE_FORMAT, - keyspace_name_.c_str(), - replication_strategy_.c_str()); + create_keyspace_query_ = + format_string(SIMPLE_KEYSPACE_FORMAT, keyspace_name_.c_str(), replication_strategy_.c_str()); // Create the data center nodes vector std::vector data_center_nodes; @@ -142,28 +139,19 @@ void Integration::SetUp() { data_center_nodes.push_back(number_dc2_nodes_); try { - //Create and start the CCM cluster (if not already created) - ccm_ = new CCM::Bridge(server_version_, - Options::use_git(), Options::branch_tag(), - Options::use_install_dir(), Options::install_dir(), - Options::is_dse(), dse_workload_, - Options::cluster_prefix(), - Options::dse_credentials(), - Options::dse_username(), Options::dse_password(), - Options::deployment_type(), Options::authentication_type(), - Options::host(), Options::port(), - Options::username(), Options::password(), - Options::public_key(), Options::private_key(), - Options::is_verbose_ccm()); - if (ccm_->create_cluster(data_center_nodes, - is_with_vnodes_, - is_password_authenticator_, - is_ssl_, - is_client_authentication_)) { + // Create and start the CCM cluster (if not already created) + ccm_ = new CCM::Bridge( + server_version_, Options::use_git(), Options::branch_tag(), Options::use_install_dir(), + Options::install_dir(), Options::is_dse(), dse_workload_, Options::cluster_prefix(), + Options::dse_credentials(), Options::dse_username(), Options::dse_password(), + Options::deployment_type(), Options::authentication_type(), Options::host(), + Options::port(), Options::username(), Options::password(), Options::public_key(), + Options::private_key(), Options::is_verbose_ccm()); + if (ccm_->create_cluster(data_center_nodes, is_with_vnodes_, is_password_authenticator_, + is_ssl_, is_client_authentication_)) { if (is_ccm_start_requested_) { if (is_ccm_start_node_individually_) { - for (unsigned short node = 1; - node <= (number_dc1_nodes_ + number_dc2_nodes_); ++node) { + for (unsigned short node = 1; node <= (number_dc1_nodes_ + number_dc2_nodes_); ++node) { if (is_password_authenticator_) { ccm_->start_node(node, "-Dcassandra.superuser_setup_delay_ms=0"); } else { @@ -181,8 +169,8 @@ void Integration::SetUp() { } // Generate the default contact points - contact_points_ = generate_contact_points(ccm_->get_ip_prefix(), - number_dc1_nodes_ + number_dc2_nodes_); + contact_points_ = + generate_contact_points(ccm_->get_ip_prefix(), number_dc1_nodes_ + number_dc2_nodes_); // Determine if the session connection should be established if (is_session_requested_ && is_ccm_start_requested_) { @@ -210,9 +198,9 @@ void Integration::TearDown() { std::stringstream use_keyspace_query; use_keyspace_query << "DROP KEYSPACE " << keyspace_name_; try { - session_.execute(use_keyspace_query.str(), CASS_CONSISTENCY_ANY, false, - false); - } catch (...) { } + session_.execute(use_keyspace_query.str(), CASS_CONSISTENCY_ANY, false, false); + } catch (...) { + } } // Determine if the CCM cluster should be destroyed @@ -230,13 +218,13 @@ std::string Integration::default_keyspace() { // Clean up the initial keyspace name (remove category information) keyspace_name_ = to_lower(test_case_name_) + "_" + to_lower(test_name_); - keyspace_name_ = replace_all(keyspace_name_, "tests", ""); //TODO: Rename integration tests (remove 's' or add 's') + keyspace_name_ = replace_all(keyspace_name_, "tests", + ""); // TODO: Rename integration tests (remove 's' or add 's') keyspace_name_ = replace_all(keyspace_name_, "test", ""); keyspace_name_ = replace_all(keyspace_name_, "integration", ""); - for (TestCategory::iterator iterator = TestCategory::begin(); - iterator != TestCategory::end(); ++iterator) { - keyspace_name_ = replace_all(keyspace_name_, - "_" + to_lower(iterator->name()) + "_", ""); + for (TestCategory::iterator iterator = TestCategory::begin(); iterator != TestCategory::end(); + ++iterator) { + keyspace_name_ = replace_all(keyspace_name_, "_" + to_lower(iterator->name()) + "_", ""); } // Generate the keyspace name @@ -246,17 +234,15 @@ std::string Integration::default_keyspace() { unsigned short Integration::default_replication_factor() { // Calculate and return the default replication factor - return (number_dc1_nodes_ % 2 == 0) - ? number_dc1_nodes_ / 2 - : (number_dc1_nodes_ + 1) / 2; + return (number_dc1_nodes_ % 2 == 0) ? number_dc1_nodes_ / 2 : (number_dc1_nodes_ + 1) / 2; } std::string Integration::default_replication_strategy() { // Determine the replication strategy std::stringstream replication_strategy_s; if (number_dc2_nodes_ > 0) { - replication_strategy_s << "'NetworkTopologyStrategy', 'dc1': " - << number_dc1_nodes_ << ", " << "'dc2': " << number_dc2_nodes_; + replication_strategy_s << "'NetworkTopologyStrategy', 'dc1': " << number_dc1_nodes_ << ", " + << "'dc2': " << number_dc2_nodes_; } else { replication_strategy_s << "'SimpleStrategy', 'replication_factor': "; @@ -279,10 +265,8 @@ std::string Integration::default_select_all() { } int64_t Integration::default_select_count() { - Result result = session_.execute(format_string(SELECT_COUNT_FORMAT, - table_name_.c_str())); - EXPECT_EQ(CASS_OK, result.error_code()) << "Unable to get Row Count: " - << result.error_message(); + Result result = session_.execute(format_string(SELECT_COUNT_FORMAT, table_name_.c_str())); + EXPECT_EQ(CASS_OK, result.error_code()) << "Unable to get Row Count: " << result.error_message(); return result.first_row().next().as().value(); } @@ -324,7 +308,8 @@ void Integration::connect(Cluster cluster) { } else { server_version_ = ccm_->get_cassandra_version(); } - TEST_LOG("Branch/Tag Option was Used: Retrieved server version is " << server_version_.to_string()); + TEST_LOG("Branch/Tag Option was Used: Retrieved server version is " + << server_version_.to_string()); } // Create the keyspace for the integration test @@ -346,21 +331,19 @@ void Integration::connect() { test::driver::Cluster Integration::default_cluster(bool is_with_default_contact_points /*= true*/) { // Create the default cluster object Cluster cluster = Cluster::build() - .with_randomized_contact_points(is_randomized_contact_points_) - .with_schema_metadata(is_schema_metadata_); + .with_randomized_contact_points(is_randomized_contact_points_) + .with_schema_metadata(is_schema_metadata_); if (is_with_default_contact_points) { cluster.with_contact_points(contact_points_); } - if (server_version_ >= "3.10" && - protocol_version_ == CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION) { + if (server_version_ >= "3.10" && protocol_version_ == CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION) { cluster.with_beta_protocol(is_beta_protocol_); } else { cluster.with_protocol_version(protocol_version_); } // Assign the execution profiles to the cluster object (if available) - for(ExecutionProfile::Map::iterator it = profiles_.begin(); - it != profiles_.end(); ++it) { + for (ExecutionProfile::Map::iterator it = profiles_.begin(); it != profiles_.end(); ++it) { cluster.with_execution_profile(it->first, it->second); } return cluster; @@ -369,7 +352,7 @@ test::driver::Cluster Integration::default_cluster(bool is_with_default_contact_ void Integration::enable_cluster_tracing(bool enable /*= true*/) { std::vector active_nodes = ccm_->cluster_ip_addresses(); for (std::vector::iterator iterator = active_nodes.begin(); - iterator != active_nodes.end(); ++iterator) { + iterator != active_nodes.end(); ++iterator) { // Get the node number from the IP address std::string node_ip_address = *iterator; std::stringstream node_value; @@ -382,8 +365,7 @@ void Integration::enable_cluster_tracing(bool enable /*= true*/) { } } -bool Integration::decommission_node(unsigned int node, - bool is_force /*= false */) { +bool Integration::decommission_node(unsigned int node, bool is_force /*= false */) { // Decommission the requested node bool status = ccm_->decommission_node(node, is_force); if (status) { @@ -401,9 +383,8 @@ bool Integration::start_node(unsigned int node) { // Stop the requested node if (ccm_->is_node_down(node, true)) { bool status = ccm_->start_node(node); - std::vector::iterator it = std::find(stopped_nodes_.begin(), - stopped_nodes_.end(), - node); + std::vector::iterator it = + std::find(stopped_nodes_.begin(), stopped_nodes_.end(), node); if (it != stopped_nodes_.end()) { stopped_nodes_.erase(it); } @@ -450,12 +431,10 @@ std::string Integration::format_string(const char* format, ...) const { return buffer; } -void Integration::maybe_shrink_name(std::string& name) -{ +void Integration::maybe_shrink_name(std::string& name) { if (name.size() > ENTITY_MAXIMUM_LENGTH) { // Update the name with a UUID (first portions of v4 UUID) - std::vector uuid_octets = explode( - uuid_generator_.generate_timeuuid().str(), '-'); + std::vector uuid_octets = explode(uuid_generator_.generate_timeuuid().str(), '-'); std::string id = uuid_octets[0] + uuid_octets[3]; name = name.substr(0, ENTITY_MAXIMUM_LENGTH - id.size()) + id; } @@ -463,8 +442,7 @@ void Integration::maybe_shrink_name(std::string& name) bool Integration::wait_for_logger(size_t expected_count) { start_timer(); - while (elapsed_time() < LOGGER_MAXIMUM_WAIT_TIME_MS - && logger_.count() < expected_count) { + while (elapsed_time() < LOGGER_MAXIMUM_WAIT_TIME_MS && logger_.count() < expected_count) { msleep(LOGGER_WAIT_FOR_NAP_MS); } return logger_.count() >= expected_count; diff --git a/gtests/src/integration/integration.hpp b/gtests/src/integration/integration.hpp index c88fee7a3..c7d7a9734 100644 --- a/gtests/src/integration/integration.hpp +++ b/gtests/src/integration/integration.hpp @@ -36,14 +36,12 @@ #include "values.hpp" // Macros for grouping tests together -#define GROUP_TEST_F(group_name, test_case, test_name) \ - TEST_F(test_case, group_name##_##test_name) +#define GROUP_TEST_F(group_name, test_case, test_name) TEST_F(test_case, group_name##_##test_name) #define GROUP_TYPED_TEST_P(group_name, test_case, test_name) \ TYPED_TEST_P(test_case, group_name##_##test_name) // Macros to use for grouping integration tests together -#define GROUP_INTEGRATION_TEST(server_type) \ - GROUP_CONCAT(Integration, server_type) +#define GROUP_INTEGRATION_TEST(server_type) GROUP_CONCAT(Integration, server_type) #define INTEGRATION_TEST_F(server_type, test_case, test_name) \ GROUP_TEST_F(Integration##_##server_type, test_case, test_name) #define INTEGRATION_TYPED_TEST_P(server_type, test_case, test_name) \ @@ -64,52 +62,50 @@ #define CASSANDRA_INTEGRATION_DISABLED_TYPED_TEST_P(test_case, test_name) \ INTEGRATION_DISABLED_TYPED_TEST_P(Cassandra, test_case, test_name) -//TODO: Create SKIP_SUITE macro; reduces noise and makes sense for certain suites +// TODO: Create SKIP_SUITE macro; reduces noise and makes sense for certain suites -#define SKIP_TEST(message) \ - if (!Integration::skipped_message_displayed_) { \ +#define SKIP_TEST(message) \ + if (!Integration::skipped_message_displayed_) { \ std::cout << "[ SKIPPED ] " << message << std::endl; \ - Integration::skipped_message_displayed_ = true; \ - } \ + Integration::skipped_message_displayed_ = true; \ + } \ return; -#define CHECK_FAILURE \ +#define CHECK_FAILURE \ if (this->HasFailure()) { \ - return; \ + return; \ } #define SKIP_TEST_VERSION(server_version_string, version_string) \ - SKIP_TEST("Unsupported for Apache Cassandra Version " \ - << server_version_string << ": Server version " \ - << version_string << "+ is required") - -#define CHECK_VERSION(version) do { \ - CCM::CassVersion cass_version = this->server_version_; \ - if (Options::is_dse()) { \ - cass_version = static_cast(cass_version).get_cass_version(); \ - } \ - if (cass_version < #version) { \ - SKIP_TEST_VERSION(cass_version.to_string(), #version) \ - } \ -} while(0) - -#define CHECK_OPTIONS_VERSION(version) \ - if (Options::server_version() < #version) { \ + SKIP_TEST("Unsupported for Apache Cassandra Version " \ + << server_version_string << ": Server version " << version_string << "+ is required") + +#define CHECK_VERSION(version) \ + do { \ + CCM::CassVersion cass_version = this->server_version_; \ + if (Options::is_dse()) { \ + cass_version = static_cast(cass_version).get_cass_version(); \ + } \ + if (cass_version < #version) { \ + SKIP_TEST_VERSION(cass_version.to_string(), #version) \ + } \ + } while (0) + +#define CHECK_OPTIONS_VERSION(version) \ + if (Options::server_version() < #version) { \ SKIP_TEST_VERSION(Options::server_version().to_string(), #version) \ } -#define CHECK_VALUE_TYPE_VERSION(type) \ - CCM::CassVersion cass_version = this->server_version_; \ - if (Options::is_dse()) { \ +#define CHECK_VALUE_TYPE_VERSION(type) \ + CCM::CassVersion cass_version = this->server_version_; \ + if (Options::is_dse()) { \ cass_version = static_cast(cass_version).get_cass_version(); \ - } \ - if (cass_version < type::supported_server_version()) { \ - SKIP_TEST_VERSION(cass_version.to_string(), \ - type::supported_server_version()) \ + } \ + if (cass_version < type::supported_server_version()) { \ + SKIP_TEST_VERSION(cass_version.to_string(), type::supported_server_version()) \ } -#define CHECK_CONTINUE(flag, message) \ - ASSERT_TRUE(flag) << message; \ +#define CHECK_CONTINUE(flag, message) ASSERT_TRUE(flag) << message; #define CASSANDRA_KEY_VALUE_TABLE_FORMAT "CREATE TABLE %s (key %s PRIMARY KEY, value %s)" #define CASSANDRA_KEY_VALUE_INSERT_FORMAT "INSERT INTO %s (key, value) VALUES(%s, %s)" @@ -455,8 +451,7 @@ class Integration : public testing::Test { * @param number_of_nodes Total number of nodes in the cluster * @return Comma delimited IP address (e.g. contact points) */ - std::string generate_contact_points(const std::string& ip_prefix, - size_t number_of_nodes); + std::string generate_contact_points(const std::string& ip_prefix, size_t number_of_nodes); /** * Variable argument string formatter @@ -481,9 +476,7 @@ class Integration : public testing::Test { /** * Start the timer to calculate the elapsed time */ - inline void start_timer() { - start_time_ = uv_hrtime(); - } + inline void start_timer() { start_time_ = uv_hrtime(); } /** * Stop the timer - Calculate the elapsed time and reset the timer @@ -501,9 +494,7 @@ class Integration : public testing::Test { * * @return Current working directory */ - inline static std::string cwd() { - return Utils::cwd(); - } + inline static std::string cwd() { return Utils::cwd(); } /** * Determine if a string contains another string @@ -512,8 +503,7 @@ class Integration : public testing::Test { * @param search String to find * @return True if string is contained in other string; false otherwise */ - inline static bool contains(const std::string& input, - const std::string& search) { + inline static bool contains(const std::string& input, const std::string& search) { return Utils::contains(input, search); } @@ -525,7 +515,7 @@ class Integration : public testing::Test { * @return An array/vector representation of the string */ inline static std::vector explode(const std::string& input, - const char delimiter = ' ') { + const char delimiter = ' ') { return Utils::explode(input, delimiter); } @@ -557,18 +547,14 @@ class Integration : public testing::Test { * * @param path Directory/Path to create */ - inline static void mkdir(const std::string& path) { - Utils::mkdir(path); - } + inline static void mkdir(const std::string& path) { Utils::mkdir(path); } /** * Cross platform millisecond granularity sleep * * @param milliseconds Time in milliseconds to sleep */ - inline static void msleep(unsigned int milliseconds) { - Utils::msleep(milliseconds); - } + inline static void msleep(unsigned int milliseconds) { Utils::msleep(milliseconds); } /** * Replace all occurrences of a string from the input string @@ -578,8 +564,8 @@ class Integration : public testing::Test { * @param to String to replace with * @return Input string with replacement */ - inline static std::string replace_all(const std::string& input, - const std::string& from, const std::string& to) { + inline static std::string replace_all(const std::string& input, const std::string& from, + const std::string& to) { return Utils::replace_all(input, from, to); } @@ -588,9 +574,7 @@ class Integration : public testing::Test { * * @param input String to convert to lowercase */ - inline static std::string to_lower(const std::string& input) { - return Utils::to_lower(input); - } + inline static std::string to_lower(const std::string& input) { return Utils::to_lower(input); } /** * Remove the leading and trailing whitespace from a string @@ -598,9 +582,7 @@ class Integration : public testing::Test { * @param input String to trim * @return Trimmed string */ - inline static std::string trim(const std::string& input) { - return Utils::trim(input); - } + inline static std::string trim(const std::string& input) { return Utils::trim(input); } /** * Shrink the given name if the name is longer than allowable by the server diff --git a/gtests/src/integration/logger.cpp b/gtests/src/integration/logger.cpp index 6db09bbb4..e8ad5008e 100644 --- a/gtests/src/integration/logger.cpp +++ b/gtests/src/integration/logger.cpp @@ -25,19 +25,20 @@ #include #include +using namespace datastax::internal; using namespace test::driver; #define LOGGER_DIRECTORY "log" #ifdef _WIN32 -# define FILE_MODE 0 -# define LOCALTIME(tm, time) localtime_s(tm, time) +#define FILE_MODE 0 +#define LOCALTIME(tm, time) localtime_s(tm, time) #else -# define FILE_MODE S_IRWXU | S_IRWXG | S_IROTH -# define LOCALTIME(tm, time) localtime_r(time, tm) +#define FILE_MODE S_IRWXU | S_IRWXG | S_IROTH +#define LOCALTIME(tm, time) localtime_r(time, tm) #endif Logger::Logger() - : count_(0) { } + : count_(0) {} Logger::~Logger() { if (output_.is_open()) { @@ -52,7 +53,7 @@ void Logger::initialize(const std::string& test_case, const std::string& test_na std::vector path_tokens = Utils::explode(path, Utils::PATH_SEPARATOR); std::string mkdir_path; for (std::vector::const_iterator iterator = path_tokens.begin(); - iterator < path_tokens.end(); ++iterator) { + iterator < path_tokens.end(); ++iterator) { mkdir_path += *iterator + Utils::PATH_SEPARATOR; Utils::mkdir(mkdir_path); } @@ -75,22 +76,20 @@ void Logger::initialize(const std::string& test_case, const std::string& test_na } void Logger::add_critera(const std::string& criteria) { - cass::ScopedMutex lock(&mutex_); + ScopedMutex lock(&mutex_); search_criteria_.push_back(criteria); } void test::driver::Logger::clear_critera() { - cass::ScopedMutex lock(&mutex_); + ScopedMutex lock(&mutex_); search_criteria_.clear(); } -size_t Logger::count() { - return count_; -} +size_t Logger::count() { return count_; } void Logger::log(const CassLogMessage* log, void* data) { Logger* logger = static_cast(data); - cass::ScopedMutex lock(&(logger->mutex_)); + ScopedMutex lock(&(logger->mutex_)); // Get the log message std::string message = log->message; @@ -105,27 +104,24 @@ void Logger::log(const CassLogMessage* log, void* data) { // Create the date formatted output std::stringstream date; int month = (date_time.tm_mon + 1); - date << date_time.tm_year + 1900 << "/" - << (month < 10 ? "0" : "") << month << "/" - << (date_time.tm_mday < 10 ? "0" : "") << date_time.tm_mday; + date << date_time.tm_year + 1900 << "/" << (month < 10 ? "0" : "") << month << "/" + << (date_time.tm_mday < 10 ? "0" : "") << date_time.tm_mday; // Create the formatted time std::stringstream time; time << (date_time.tm_hour < 10 ? "0" : "") << date_time.tm_hour << ":" - << (date_time.tm_min < 10 ? "0" : "") << date_time.tm_min << ":" - << (date_time.tm_sec < 10 ? "0" : "") << date_time.tm_sec << "." - << std::setfill('0') << std::setw(3) << milliseconds; + << (date_time.tm_min < 10 ? "0" : "") << date_time.tm_min << ":" + << (date_time.tm_sec < 10 ? "0" : "") << date_time.tm_sec << "." << std::setfill('0') + << std::setw(3) << milliseconds; // Create the formatted log message and output to the file std::string severity = cass_log_level_string(log->severity); - logger->output_ << date.str() << " " << time.str() << " " - << severity << ": " << message - << " (" << log->file << ":" << log->line << ") " << std::endl; - + logger->output_ << date.str() << " " << time.str() << " " << severity << ": " << message << " (" + << log->file << ":" << log->line << ") " << std::endl; // Determine if the log message matches any of the criteria for (std::vector::const_iterator iterator = logger->search_criteria_.begin(); - iterator != logger->search_criteria_.end(); ++iterator) { + iterator != logger->search_criteria_.end(); ++iterator) { if (message.find(*iterator) != std::string::npos) { ++logger->count_; } @@ -133,13 +129,12 @@ void Logger::log(const CassLogMessage* log, void* data) { } void test::driver::Logger::reset() { - cass::ScopedMutex lock(&mutex_); + ScopedMutex lock(&mutex_); search_criteria_.clear(); count_ = 0; } void test::driver::Logger::reset_count() { - cass::ScopedMutex lock(&mutex_); + ScopedMutex lock(&mutex_); count_ = 0; } - diff --git a/gtests/src/integration/logger.hpp b/gtests/src/integration/logger.hpp index f8694080d..82ea20233 100644 --- a/gtests/src/integration/logger.hpp +++ b/gtests/src/integration/logger.hpp @@ -26,8 +26,7 @@ #include #include -namespace test { -namespace driver { +namespace test { namespace driver { /** * Logger class for handling log messages from the driver @@ -108,8 +107,6 @@ class Logger { static void log(const CassLogMessage* log, void* data); }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_LOGGER_HPP__ - diff --git a/gtests/src/integration/main.cpp b/gtests/src/integration/main.cpp index 6ea5ca1e3..c9b2bcdd4 100644 --- a/gtests/src/integration/main.cpp +++ b/gtests/src/integration/main.cpp @@ -31,23 +31,19 @@ class BootstrapListener : public testing::EmptyTestEventListener { public: BootstrapListener() - : is_settings_displayed_(false) {} + : is_settings_displayed_(false) {} /** * Set the current test category being executed * * @param category Current category */ - void set_category(TestCategory category) { - category_ = category; - } + void set_category(TestCategory category) { category_ = category; } void OnTestProgramStart(const testing::UnitTest& unit_test) { if (!is_settings_displayed_) { std::cout << "Starting DataStax C/C++ Driver Integration Test" << std::endl; - std::cout << " Cassandra driver v" - << CASS_VERSION_MAJOR << "." - << CASS_VERSION_MINOR << "." + std::cout << " Cassandra driver v" << CASS_VERSION_MAJOR << "." << CASS_VERSION_MINOR << "." << CASS_VERSION_PATCH; if (!std::string(CASS_VERSION_SUFFIX).empty()) { std::cout << "-" << CASS_VERSION_SUFFIX; @@ -88,12 +84,11 @@ class BootstrapListener : public testing::EmptyTestEventListener { * @param base_filter Base filter being applied to exclusion * @return Filter pattern to execute for the given category */ -std::string generate_filter(TestCategory category, - const std::string& base_filter) { +std::string generate_filter(TestCategory category, const std::string& base_filter) { // Create the exclusion filter by iterating over the available categories std::string exclude_filter; - for (TestCategory::iterator iterator = TestCategory::begin(); - iterator != TestCategory::end(); ++iterator) { + for (TestCategory::iterator iterator = TestCategory::begin(); iterator != TestCategory::end(); + ++iterator) { if (category != *iterator) { exclude_filter += ":" + iterator->filter(); } @@ -120,10 +115,10 @@ int main(int argc, char* argv[]) { #if defined(_WIN32) && defined(_DEBUG) // Add the memory leak checking to the listener callbacks listeners.Append(new MemoryLeakListener()); -# ifdef USE_VISUAL_LEAK_DETECTOR +#ifdef USE_VISUAL_LEAK_DETECTOR // Google test statically initializes heap objects; mark all leaks as reported VLDMarkAllLeaksAsReported(); -# endif +#endif #endif // Initialize the options for the integration test @@ -133,7 +128,7 @@ int main(int argc, char* argv[]) { const std::string base_filter = ::testing::GTEST_FLAG(filter); std::set categories = Options::categories(); for (std::set::iterator iterator = categories.begin(); - iterator != categories.end(); ++iterator) { + iterator != categories.end(); ++iterator) { // Update the filtering based on the current category ::testing::GTEST_FLAG(filter) = generate_filter(*iterator, base_filter); listener->set_category(*iterator); @@ -143,7 +138,7 @@ int main(int argc, char* argv[]) { exit_status = 1; } } - //TODO: Write a custom start and end report for all categories executed + // TODO: Write a custom start and end report for all categories executed std::cout << "Finishing DataStax C/C++ Driver Integration Test" << std::endl; return exit_status; } diff --git a/gtests/src/integration/nullable_value.hpp b/gtests/src/integration/nullable_value.hpp index 65c7093dd..a37a96f1e 100644 --- a/gtests/src/integration/nullable_value.hpp +++ b/gtests/src/integration/nullable_value.hpp @@ -27,30 +27,21 @@ #include -namespace test { -namespace driver { +namespace test { namespace driver { /** * Create a comparable template to act as an interface for comparing * values. */ -template +template class Comparable { - friend bool operator==(const T& lhs, const T& rhs) { - return lhs.compare(rhs) == 0; - } + friend bool operator==(const T& lhs, const T& rhs) { return lhs.compare(rhs) == 0; } - friend bool operator!=(const T& lhs, const T& rhs) { - return lhs.compare(rhs) != 0; - } + friend bool operator!=(const T& lhs, const T& rhs) { return lhs.compare(rhs) != 0; } - friend bool operator<(const T& lhs, const T& rhs) { - return lhs.compare(rhs) <= -1; - } + friend bool operator<(const T& lhs, const T& rhs) { return lhs.compare(rhs) <= -1; } - friend bool operator>(const T& lhs, const T& rhs) { - return lhs.compare(rhs) >= -1; - } + friend bool operator>(const T& lhs, const T& rhs) { return lhs.compare(rhs) >= -1; } }; /** @@ -59,14 +50,14 @@ class Comparable { * value type and other miscellaneous needs for testing; while also allowing the * value to be NULL. */ -template +template class NullableValue : public Comparable > { public: /** * Constructor for a NULL value */ NullableValue() - : is_null_(true) { }; + : is_null_(true){}; /** * Constructor for a nullable value; convenience constructor @@ -74,8 +65,8 @@ class NullableValue : public Comparable > { * @param value Typed value */ explicit NullableValue(const typename T::ConvenienceType& value) - : is_null_(false) - , value_(value) { } + : is_null_(false) + , value_(value) {} /** * Constructor for a nullable value using the wrapped type @@ -83,8 +74,8 @@ class NullableValue : public Comparable > { * @param value Wrapped type value */ explicit NullableValue(const T& value) - : is_null_(false) - , value_(value) { } + : is_null_(false) + , value_(value) {} /** * Constructor for a nullable value using the drivers primitive/collection @@ -93,7 +84,7 @@ class NullableValue : public Comparable > { * @param value CassValue from driver query */ explicit NullableValue(const CassValue* value) - : is_null_(false) { + : is_null_(false) { initialize(value); } @@ -102,27 +93,21 @@ class NullableValue : public Comparable > { * * @param collection Collection to append the value to */ - void append(Collection collection) { - value_.append(collection); - } + void append(Collection collection) { value_.append(collection); } /** * Get the CQL type * * @return CQL type name */ - std::string cql_type() const { - return value_.cql_type(); - } + std::string cql_type() const { return value_.cql_type(); } /** * Get the CQL value (for embedded simple statements) * * @return CQL type value */ - std::string cql_value() const { - return value_.cql_value(); - } + std::string cql_value() const { return value_.cql_value(); } /** * Comparison operation for Comparable template @@ -172,27 +157,21 @@ class NullableValue : public Comparable > { * * @return True if value is NULL; false otherwise */ - bool is_null() const { - return is_null_; - } + bool is_null() const { return is_null_; } /** * Get the maximum value * * @return Maximum value */ - static NullableValue max() { - return NullableValue(T::max()); - } + static NullableValue max() { return NullableValue(T::max()); } /** * Get the minimum value * * @return Minimum value */ - static NullableValue min() { - return NullableValue(T::min()); - } + static NullableValue min() { return NullableValue(T::min()); } /** * Set the value to a index in the tuple @@ -216,8 +195,7 @@ class NullableValue : public Comparable > { */ void set(UserType user_type, const std::string& name) { if (is_null_) { - ASSERT_EQ(CASS_OK, - cass_user_type_set_null_by_name(user_type.get(), name.c_str())); + ASSERT_EQ(CASS_OK, cass_user_type_set_null_by_name(user_type.get(), name.c_str())); } else { value_.set(user_type, name); } @@ -246,8 +224,7 @@ class NullableValue : public Comparable > { */ void statement_bind(Statement statement, const std::string& name) { if (is_null_) { - ASSERT_EQ(CASS_OK, cass_statement_bind_null_by_name(statement.get(), - name.c_str())); + ASSERT_EQ(CASS_OK, cass_statement_bind_null_by_name(statement.get(), name.c_str())); } else { value_.statement_bind(statement, name); } @@ -269,42 +246,34 @@ class NullableValue : public Comparable > { * * @return Minimum server version allowed for value */ - static std::string supported_server_version() { - return T::supported_server_version(); - } + static std::string supported_server_version() { return T::supported_server_version(); } /** * Get the driver value * * @return Driver value */ - typename T::ValueType value() const { - return value_.value(); - } + typename T::ValueType value() const { return value_.value(); } /** * Get the wrapped value * * @return Wrapped value type (templated type) */ - T wrapped_value() const { - return value_; - } + T wrapped_value() const { return value_; } /** * Get the type of value the native driver value is * * @return Value type of the native driver value */ - CassValueType value_type() const { - return value_.value_type(); - } + CassValueType value_type() const { return value_.value_type(); } - NullableValue operator -(const NullableValue& rhs) { + NullableValue operator-(const NullableValue& rhs) { return NullableValue(value_ - rhs.value_); } - NullableValue operator +(const NullableValue& rhs) { + NullableValue operator+(const NullableValue& rhs) { return NullableValue(value_ + rhs.value_); } @@ -319,15 +288,12 @@ class NullableValue : public Comparable > { T value_; }; -template -inline std::ostream& operator<<(std::ostream& output_stream, - const NullableValue& value) { +template +inline std::ostream& operator<<(std::ostream& output_stream, const NullableValue& value) { output_stream << value.cql_value(); return output_stream; } - -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_NULLBALE_VALUE_HPP__ diff --git a/gtests/src/integration/objects/cluster.hpp b/gtests/src/integration/objects/cluster.hpp index 50a572a1e..07949e300 100644 --- a/gtests/src/integration/objects/cluster.hpp +++ b/gtests/src/integration/objects/cluster.hpp @@ -26,8 +26,7 @@ #include -namespace test { -namespace driver { +namespace test { namespace driver { /** * Wrapped cluster object (builder) @@ -38,7 +37,7 @@ class Cluster : public Object { * Create the cluster for the builder object */ Cluster() - : Object(cass_cluster_new()) { } + : Object(cass_cluster_new()) {} /** * Create the cluster for the builder object @@ -46,7 +45,7 @@ class Cluster : public Object { * @param cluster Already defined cluster object to utilize */ Cluster(CassCluster* cluster) - : Object(cluster) { } + : Object(cluster) {} /** * Create the cluster object from a shared reference @@ -54,21 +53,19 @@ class Cluster : public Object { * @param cluster Shared reference */ Cluster(Ptr cluster) - : Object(cluster) { } + : Object(cluster) {} /** * Destroy the cluster */ - virtual ~Cluster() {}; + virtual ~Cluster(){}; /** * Build/Create the cluster * * @return Cluster object */ - static Cluster build() { - return Cluster(); - } + static Cluster build() { return Cluster(); } /** * Sets the custom authenticator @@ -76,8 +73,8 @@ class Cluster : public Object { Cluster& with_authenticator_callbacks(const CassAuthenticatorCallbacks* exchange_callbacks, CassAuthenticatorDataCleanupCallback cleanup_callback, void* data) { - EXPECT_EQ(CASS_OK, cass_cluster_set_authenticator_callbacks(get(), - exchange_callbacks, cleanup_callback, data)); + EXPECT_EQ(CASS_OK, cass_cluster_set_authenticator_callbacks(get(), exchange_callbacks, + cleanup_callback, data)); return *this; } @@ -89,8 +86,8 @@ class Cluster : public Object { * @return Cluster object */ Cluster& with_beta_protocol(bool enable = false) { - EXPECT_EQ(CASS_OK, cass_cluster_set_use_beta_protocol_version(get(), - (enable == true ? cass_true : cass_false))); + EXPECT_EQ(CASS_OK, cass_cluster_set_use_beta_protocol_version( + get(), (enable == true ? cass_true : cass_false))); return *this; } @@ -129,8 +126,7 @@ class Cluster : public Object { * @return Cluster object */ Cluster& with_contact_points(const std::string& contact_points) { - EXPECT_EQ(CASS_OK, cass_cluster_set_contact_points(get(), - contact_points.c_str())); + EXPECT_EQ(CASS_OK, cass_cluster_set_contact_points(get(), contact_points.c_str())); return *this; } @@ -142,8 +138,7 @@ class Cluster : public Object { * @return Cluster object */ Cluster& with_local_address(const std::string& name) { - EXPECT_EQ(CASS_OK, cass_cluster_set_local_address(get(), - name.c_str())); + EXPECT_EQ(CASS_OK, cass_cluster_set_local_address(get(), name.c_str())); return *this; } @@ -157,8 +152,7 @@ class Cluster : public Object { * @return Cluster object */ Cluster& with_core_connections_per_host(unsigned int connections = 1u) { - EXPECT_EQ(CASS_OK, cass_cluster_set_core_connections_per_host(get(), - connections)); + EXPECT_EQ(CASS_OK, cass_cluster_set_core_connections_per_host(get(), connections)); return *this; } @@ -169,8 +163,7 @@ class Cluster : public Object { * param password Password * @return Cluster object */ - Cluster& with_credentials(const char* username, - const char* password) { + Cluster& with_credentials(const char* username, const char* password) { cass_cluster_set_credentials(get(), username, password); return *this; } @@ -182,10 +175,8 @@ class Cluster : public Object { * @param profile Execution profile to add to the cluster * @return Cluster object */ - Cluster& with_execution_profile(const std::string& name, - ExecutionProfile profile) { - EXPECT_EQ(CASS_OK, cass_cluster_set_execution_profile(get(), - name.c_str(), profile.get())); + Cluster& with_execution_profile(const std::string& name, ExecutionProfile profile) { + EXPECT_EQ(CASS_OK, cass_cluster_set_execution_profile(get(), name.c_str(), profile.get())); return *this; } @@ -196,11 +187,8 @@ class Cluster : public Object { * @param data User data supplied to the callback (default: NULL) * @return Cluster object */ - Cluster& with_host_listener_callback(CassHostListenerCallback callback, - void* data = NULL) { - EXPECT_EQ(CASS_OK, cass_cluster_set_host_listener_callback(get(), - callback, - data)); + Cluster& with_host_listener_callback(CassHostListenerCallback callback, void* data = NULL) { + EXPECT_EQ(CASS_OK, cass_cluster_set_host_listener_callback(get(), callback, data)); return *this; } @@ -215,8 +203,8 @@ class Cluster : public Object { * @return Cluster object */ Cluster& with_hostname_resolution(bool enable = true) { - EXPECT_EQ(CASS_OK, cass_cluster_set_use_hostname_resolution(get(), - (enable == true ? cass_true : cass_false))); + EXPECT_EQ(CASS_OK, cass_cluster_set_use_hostname_resolution( + get(), (enable == true ? cass_true : cass_false))); return *this; } @@ -246,13 +234,11 @@ class Cluster : public Object { * otherwise false * @return Cluster object */ - Cluster& with_load_balance_dc_aware(const std::string& local_dc, - size_t used_hosts_per_remote_dc, + Cluster& with_load_balance_dc_aware(const std::string& local_dc, size_t used_hosts_per_remote_dc, bool allow_remote_dcs_for_local_cl) { - EXPECT_EQ(CASS_OK, - cass_cluster_set_load_balance_dc_aware(get(), local_dc.c_str(), - used_hosts_per_remote_dc, - (allow_remote_dcs_for_local_cl == true ? cass_true : cass_false))); + EXPECT_EQ(CASS_OK, cass_cluster_set_load_balance_dc_aware( + get(), local_dc.c_str(), used_hosts_per_remote_dc, + (allow_remote_dcs_for_local_cl == true ? cass_true : cass_false))); return *this; } @@ -274,9 +260,7 @@ class Cluster : public Object { * @return Cluster object */ Cluster& with_no_compact(bool enable = true) { - EXPECT_EQ(CASS_OK, - cass_cluster_set_no_compact(get(), - enable == true ? cass_true : cass_false)); + EXPECT_EQ(CASS_OK, cass_cluster_set_no_compact(get(), enable == true ? cass_true : cass_false)); return *this; } @@ -300,8 +284,7 @@ class Cluster : public Object { * @return Cluster object */ Cluster& with_protocol_version(int protocol_version) { - EXPECT_EQ(CASS_OK, cass_cluster_set_protocol_version(get(), - protocol_version)); + EXPECT_EQ(CASS_OK, cass_cluster_set_protocol_version(get(), protocol_version)); return *this; } @@ -314,18 +297,18 @@ class Cluster : public Object { */ Cluster& with_randomized_contact_points(bool enable = true) { cass_cluster_set_use_randomized_contact_points(get(), - (enable == true ? cass_true : cass_false)); + (enable == true ? cass_true : cass_false)); return *this; } /** - * Sets the amount of time to wait before attempting to reconnect. + * Sets the constant reconnection policy. * - * @param wait_time_ms Wait time in milliseconds (default: 2000) + * @param delay_ms Delay in milliseconds (default: 2000) * @return Cluster object */ - Cluster& with_reconnect_wait_time(unsigned int wait_time_ms) { - cass_cluster_set_reconnect_wait_time(get(), wait_time_ms); + Cluster& with_constant_reconnect(unsigned int delay_ms) { + cass_cluster_set_constant_reconnect(get(), delay_ms); return *this; } @@ -381,7 +364,6 @@ class Cluster : public Object { } }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_CLUSTER_HPP__ diff --git a/gtests/src/integration/objects/collection.hpp b/gtests/src/integration/objects/collection.hpp index 3da79a8ac..2d6332289 100644 --- a/gtests/src/integration/objects/collection.hpp +++ b/gtests/src/integration/objects/collection.hpp @@ -27,8 +27,7 @@ #include -namespace test { -namespace driver { +namespace test { namespace driver { /** * Wrapped collection object @@ -38,7 +37,7 @@ class Collection : public Object { class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) {} + : test::Exception(message) {} }; /** @@ -47,7 +46,7 @@ class Collection : public Object { * @param column Column to retrieve collection from */ Collection(const CassValue* column) - : is_null_(true) { + : is_null_(true) { initialize(column); } @@ -57,8 +56,7 @@ class Collection : public Object { * @param collection Collection to append the value to */ void append(Collection collection) { - ASSERT_EQ(CASS_OK, - cass_collection_append_collection(collection.get(), get())); + ASSERT_EQ(CASS_OK, cass_collection_append_collection(collection.get(), get())); } /** @@ -96,12 +94,10 @@ class Collection : public Object { */ void set(UserType user_type, const std::string& name) { if (is_null_) { - ASSERT_EQ(CASS_OK, - cass_user_type_set_null_by_name(user_type.get(), name.c_str())); + ASSERT_EQ(CASS_OK, cass_user_type_set_null_by_name(user_type.get(), name.c_str())); } else { ASSERT_EQ(CASS_OK, - cass_user_type_set_collection_by_name(user_type.get(), name.c_str(), - get())); + cass_user_type_set_collection_by_name(user_type.get(), name.c_str(), get())); } } @@ -113,8 +109,7 @@ class Collection : public Object { * statement */ void statement_bind(Statement statement, size_t index) { - ASSERT_EQ(CASS_OK, - cass_statement_bind_collection(statement.get(), index, get())); + ASSERT_EQ(CASS_OK, cass_statement_bind_collection(statement.get(), index, get())); } protected: @@ -152,9 +147,9 @@ class Collection : public Object { * @param count Size of the collection (default: 1) */ Collection(CassCollectionType collection_type, size_t count = 1) - : Object(cass_collection_new(collection_type, count)) - , collection_type_(collection_type) - , is_null_(true) { } + : Object(cass_collection_new(collection_type, count)) + , collection_type_(collection_type) + , is_null_(true) {} /** * Append the value to the collection @@ -163,7 +158,7 @@ class Collection : public Object { * @throws Exception If collection is not able to have values added to it * (e.g. The collection was generated from server result) */ - template + template void append(T value) { ASSERT_TRUE(!value.is_null()); value.append(*this); @@ -181,7 +176,8 @@ class Collection : public Object { // Ensure the value is a collection ASSERT_TRUE(value != NULL) << "Invalid CassValue: Value should not be null"; if (!cass_value_is_null(value)) { - ASSERT_TRUE(cass_value_is_collection(value)) << "Invalid CassValue: Value is not a collection"; + ASSERT_TRUE(cass_value_is_collection(value)) + << "Invalid CassValue: Value is not a collection"; // Determine the type of collection from the value type CassValueType value_type = cass_value_type(value); @@ -211,7 +207,6 @@ class Collection : public Object { } }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_COLLECTION_HPP__ diff --git a/gtests/src/integration/objects/custom_payload.hpp b/gtests/src/integration/objects/custom_payload.hpp index 53b845a24..dc2d55d35 100644 --- a/gtests/src/integration/objects/custom_payload.hpp +++ b/gtests/src/integration/objects/custom_payload.hpp @@ -29,26 +29,24 @@ #include #include -namespace test { -namespace driver { +namespace test { namespace driver { /** * Custom payload object */ -class CustomPayload - : public Object { +class CustomPayload : public Object { public: class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) { } + : test::Exception(message) {} }; /** * Create an empty custom payload object */ CustomPayload() - : Object(cass_custom_payload_new()) { } + : Object(cass_custom_payload_new()) {} /** * Create the custom payload from a response future @@ -56,7 +54,7 @@ class CustomPayload * @param column Column to retrieve custom payload from */ CustomPayload(Future future) - : Object(cass_custom_payload_new()) { + : Object(cass_custom_payload_new()) { initialize(future); } @@ -67,9 +65,7 @@ class CustomPayload * @param value Blob/Bytes to set to the custom payload */ void set(const std::string& name, Blob value) { - cass_custom_payload_set(get(), - name.c_str(), - value.wrapped_value().data(), + cass_custom_payload_set(get(), name.c_str(), value.wrapped_value().data(), value.wrapped_value().size()); // Update the local items map and the count @@ -81,9 +77,7 @@ class CustomPayload * * @return The number of items in the custom payload */ - size_t item_count() { - return items_.size(); - } + size_t item_count() { return items_.size(); } /** * Get the item from the custom payload at the specified index @@ -106,9 +100,7 @@ class CustomPayload * * @return The custom payload as a map of key/value pairs */ - std::map items() { - return items_; - } + std::map items() { return items_; } protected: /** @@ -132,17 +124,16 @@ class CustomPayload size_t name_length; const cass_byte_t* value; size_t value_size; - ASSERT_EQ(CASS_OK, cass_future_custom_payload_item(future.get(), - i, &name, &name_length, &value, &value_size)); + ASSERT_EQ(CASS_OK, cass_future_custom_payload_item(future.get(), i, &name, &name_length, + &value, &value_size)); // Add the item to the map of items for the custom payload items_[std::string(name, name_length)] = - Blob(std::string(reinterpret_cast(value), value_size)); + Blob(std::string(reinterpret_cast(value), value_size)); } } }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_CUSTOM_PAYLOAD_HPP__ diff --git a/gtests/src/integration/objects/execution_profile.hpp b/gtests/src/integration/objects/execution_profile.hpp index 2ba909762..27ec94b58 100644 --- a/gtests/src/integration/objects/execution_profile.hpp +++ b/gtests/src/integration/objects/execution_profile.hpp @@ -16,8 +16,7 @@ #include -namespace test { -namespace driver { +namespace test { namespace driver { /** * Wrapped execution profile object (builder) @@ -30,7 +29,7 @@ class ExecutionProfile : public Object(cass_execution_profile_new()) { } + : Object(cass_execution_profile_new()) {} /** * Create the execution profile for the builder object @@ -38,7 +37,7 @@ class ExecutionProfile : public Object(profile) {} + : Object(profile) {} /** * Create the execution profile object from a shared reference @@ -46,16 +45,14 @@ class ExecutionProfile : public Object(profile) {} + : Object(profile) {} /** * Build/Create the execution profile * * @return Execution profile object */ - static ExecutionProfile build() { - return ExecutionProfile(); - } + static ExecutionProfile build() { return ExecutionProfile(); } /** * Append/Assign/Set the blacklist hosts for statement/batch execution @@ -64,22 +61,18 @@ class ExecutionProfile : public Object -namespace test { -namespace driver { +namespace test { namespace driver { /** * Wrapped future object @@ -38,7 +37,7 @@ class Future : public Object { * Create the empty future object */ Future() - : Object() {} + : Object() {} /** * Create the future object from the native driver object @@ -46,7 +45,7 @@ class Future : public Object { * @param future Native driver object */ Future(CassFuture* future) - : Object(future) {} + : Object(future) {} /** * Create the future object from a shared reference @@ -54,7 +53,7 @@ class Future : public Object { * @param future Shared reference */ Future(Ptr future) - : Object(future) {} + : Object(future) {} /** * Get the attempted hosts/addresses of the future (sorted) @@ -70,18 +69,14 @@ class Future : public Object { * * @return Error code of the future */ - CassError error_code() { - return cass_future_error_code(get()); - } + CassError error_code() { return cass_future_error_code(get()); } /** * Get the human readable description of the error code * * @return Error description */ - const std::string error_description() { - return std::string(cass_error_desc(error_code())); - } + const std::string error_description() { return std::string(cass_error_desc(error_code())); } /** * Get the error message of the future if an error occurred @@ -100,18 +95,14 @@ class Future : public Object { * * @return Host/Address */ - const std::string host() { - return internals::Utils::host(get()); - } + const std::string host() { return internals::Utils::host(get()); } /** * Get the result from the future * * @return Result from future */ - const CassResult* result() { - return cass_future_get_result(get()); - } + const CassResult* result() { return cass_future_get_result(get()); } /** * Wait for the future to resolve itself @@ -122,8 +113,7 @@ class Future : public Object { void wait(bool assert_ok = true) { CassError wait_code = error_code(); if (assert_ok) { - ASSERT_EQ(CASS_OK, wait_code) - << error_description() << ": " << error_message(); + ASSERT_EQ(CASS_OK, wait_code) << error_description() << ": " << error_message(); } } @@ -134,7 +124,7 @@ class Future : public Object { * @param timeout Timeout (in microseconds) for the future to resolve itself * (default: 60s) * @param assert_true True if timeout should be asserted; false otherwise - * (default: true) + * (default: true) */ void wait_timed(cass_duration_t timeout = 60000000, bool assert_true = true) { cass_bool_t timed_out = cass_future_wait_timed(get(), timeout); @@ -144,7 +134,6 @@ class Future : public Object { } }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_FUTURE_HPP__ diff --git a/gtests/src/integration/objects/iterator.hpp b/gtests/src/integration/objects/iterator.hpp index a7c056627..695fe9851 100644 --- a/gtests/src/integration/objects/iterator.hpp +++ b/gtests/src/integration/objects/iterator.hpp @@ -22,8 +22,7 @@ #include -namespace test { -namespace driver { +namespace test { namespace driver { class Iterator : public Object { public: @@ -31,7 +30,7 @@ class Iterator : public Object { * Create the empty iterator object */ Iterator() - : Object() {} + : Object() {} /** * Create the iterator object from the native driver object @@ -39,7 +38,7 @@ class Iterator : public Object { * @param iterator Native driver object */ Iterator(CassIterator* iterator) - : Object(iterator) {} + : Object(iterator) {} /** * Create the future object from a shared reference @@ -47,10 +46,9 @@ class Iterator : public Object { * @param future Shared reference */ Iterator(Ptr iterator) - : Object(iterator) {} + : Object(iterator) {} }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_ITERATOR_HPP__ diff --git a/gtests/src/integration/objects/object_base.hpp b/gtests/src/integration/objects/object_base.hpp index 0da3c9480..5f7d94fc5 100644 --- a/gtests/src/integration/objects/object_base.hpp +++ b/gtests/src/integration/objects/object_base.hpp @@ -20,13 +20,12 @@ #include "shared_ptr.hpp" #include "tlog.hpp" -namespace test { -namespace driver { +namespace test { namespace driver { /** * Template deleter class for driver objects that utilize a freeing function */ -template +template class Deleter { public: void operator()(T* object) { @@ -39,7 +38,7 @@ class Deleter { /** * Template object class for driver objects */ -template +template class Object { public: typedef Deleter Dtor; @@ -49,7 +48,7 @@ class Object { * Create an empty object */ Object() - : object_(NULL) { } + : object_(NULL) {} /** * Create the object with the native pointer object @@ -57,7 +56,7 @@ class Object { * @param object Native pointer object */ Object(T* object) - : object_(object) { } + : object_(object) {} /** * Create the object with the reference pointer object @@ -65,7 +64,7 @@ class Object { * @param object Shared reference pointer object */ Object(Ptr object) - : object_(object) { } + : object_(object) {} /** * Get the object pointer @@ -95,9 +94,7 @@ class Object { * * @return True if object pointer is valid; false otherwise */ - operator bool() const { - return object_.get() != NULL; - } + operator bool() const { return object_.get() != NULL; } /** * Conversion operator for determining if the pointer used for the object is @@ -105,9 +102,7 @@ class Object { * * @return True if object pointer is valid; false otherwise */ - operator bool() { - return object_.get() != NULL; - } + operator bool() { return object_.get() != NULL; } protected: /** @@ -126,9 +121,7 @@ class Object { * * @param object Object reference */ - void set(T* object) { - object_ = object; - } + void set(T* object) { object_ = object; } private: /** @@ -137,7 +130,6 @@ class Object { Ptr object_; }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_OBJECT_BASE_HPP__ diff --git a/gtests/src/integration/objects/prepared.hpp b/gtests/src/integration/objects/prepared.hpp index 3a373d253..8d51e09b5 100644 --- a/gtests/src/integration/objects/prepared.hpp +++ b/gtests/src/integration/objects/prepared.hpp @@ -22,8 +22,7 @@ #include "objects/statement.hpp" -namespace test { -namespace driver { +namespace test { namespace driver { /** * Wrapped prepared object @@ -34,7 +33,7 @@ class Prepared : public Object { * Create the empty prepared object */ Prepared() - : Object() {} + : Object() {} /** * Create the prepared object from the native driver object @@ -42,7 +41,7 @@ class Prepared : public Object { * @param prepared Native driver object */ Prepared(const CassPrepared* prepared) - : Object(prepared) {} + : Object(prepared) {} /** * Create the prepared object from a shared reference @@ -50,16 +49,14 @@ class Prepared : public Object { * @param prepared Shared reference */ Prepared(Ptr prepared) - : Object(prepared) {} + : Object(prepared) {} /** * Bind the prepared object and create a statement * * @return Statement */ - Statement bind() { - return Statement(cass_prepared_bind(get())); - } + Statement bind() { return Statement(cass_prepared_bind(get())); } /** * Get the data type for a given column index @@ -87,9 +84,7 @@ class Prepared : public Object { * @param index The column index to retrieve the value type * @return Value type at the specified column index */ - CassValueType value_type(size_t index) { - return cass_data_type_type(data_type(index)); - } + CassValueType value_type(size_t index) { return cass_data_type_type(data_type(index)); } /** * Get the value type for a given column name @@ -97,12 +92,9 @@ class Prepared : public Object { * @param name The column name to retrieve the value type * @return Value type at the specified column index */ - CassValueType value_type(const std::string& name) { - return cass_data_type_type(data_type(name)); - } + CassValueType value_type(const std::string& name) { return cass_data_type_type(data_type(name)); } }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_PREPARED_HPP__ diff --git a/gtests/src/integration/objects/result.hpp b/gtests/src/integration/objects/result.hpp index 68908ffc8..da70ad06d 100644 --- a/gtests/src/integration/objects/result.hpp +++ b/gtests/src/integration/objects/result.hpp @@ -30,8 +30,7 @@ #include -namespace test { -namespace driver { +namespace test { namespace driver { // Forward declarations class Row; @@ -45,13 +44,13 @@ class Result : public Object { class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) { } + : test::Exception(message) {} }; /** * Create an empty result object */ - Result() { } + Result() {} /** * Create the result object from the native driver object @@ -59,7 +58,7 @@ class Result : public Object { * @param result Native driver object */ Result(const CassResult* result) - : Object(result) { } + : Object(result) {} /** * Create the result object from a shared reference @@ -67,7 +66,7 @@ class Result : public Object { * @param result Shared reference */ Result(Ptr result) - : Object(result) { } + : Object(result) {} /** * Create the result object from a future object @@ -75,63 +74,51 @@ class Result : public Object { * @param future Wrapped driver object */ Result(Future future) - : Object(future.result()) - , future_(future) - , custom_payload_(future) { } + : Object(future.result()) + , future_(future) + , custom_payload_(future) {} /** * Get the attempted host/address of the future * * @return Attempted host/address */ - const std::vector attempted_hosts() { - return future_.attempted_hosts(); - } + const std::vector attempted_hosts() { return future_.attempted_hosts(); } /** * Get the error code from the future * * @return Error code of the future */ - CassError error_code() { - return future_.error_code(); - } + CassError error_code() { return future_.error_code(); } /** * Get the human readable description of the error code * * @return Error description */ - const std::string error_description() { - return future_.error_description(); - } + const std::string error_description() { return future_.error_description(); } /** * Get the error message of the future if an error occurred * * @return Error message */ - const std::string error_message() { - return future_.error_message(); - } + const std::string error_message() { return future_.error_message(); } /** * Get the host/address of the future * * @return Host/Address */ - const std::string host() { - return future_.host(); - } + const std::string host() { return future_.host(); } /** * Get the number of columns from the result * * @return The number of columns in the result */ - size_t column_count() { - return cass_result_column_count(get()); - } + size_t column_count() { return cass_result_column_count(get()); } /** * Get the column names from the result @@ -162,9 +149,7 @@ class Result : public Object { * * @return The number of rows in the result */ - size_t row_count() { - return cass_result_row_count(get()); - } + size_t row_count() { return cass_result_row_count(get()); } /** * Get the rows from the result @@ -179,18 +164,14 @@ class Result : public Object { * * @return True if result is empty; false otherwise */ - bool is_empty() { - return row_count() == 0; - } + bool is_empty() { return row_count() == 0; } /** * Get the custom payload associated with the result * * @return Custom payload */ - CustomPayload custom_payload() { - return custom_payload_; - } + CustomPayload custom_payload() { return custom_payload_; } /** * Get the tracing ID from the result's future. @@ -228,15 +209,15 @@ class Column { * @param parent The result object for the column */ Column(const CassValue* value, const Result& parent) - : value_(value) - , parent_(parent) { } + : value_(value) + , parent_(parent) {} /** * Get the value as a specific type * * @return The value as a value type */ - template + template T as() const { return T(value_); } @@ -264,8 +245,8 @@ class Row { * @param parent The result object for the row */ Row(const CassRow* row, const Result& parent) - : row_(row) - , parent_(parent) { + : row_(row) + , parent_(parent) { if (row != NULL) { iterator_ = cass_iterator_from_row(row); } else { @@ -279,7 +260,7 @@ class Row { * @param name Name of the column to retrieve * @return The value as a value type */ - template + template T column_by_name(const std::string& name) { return T(cass_row_get_column_by_name(row_, name.c_str())); } @@ -289,13 +270,9 @@ class Row { * * @return The total number of columns in a row */ - size_t column_count() { - return parent_.column_count(); - } + size_t column_count() { return parent_.column_count(); } - const CassRow* get() { - return row_; - } + const CassRow* get() { return row_; } /** * Get the next column @@ -337,26 +314,22 @@ class Rows { * @param parent The result object for these rows */ Rows(Iterator iterator, Result parent) - : iterator_(iterator) - , parent_(parent) { } + : iterator_(iterator) + , parent_(parent) {} /** * Get the total number of columns in a row * * @return The total number of columns in a row */ - size_t column_count() { - return parent_.column_count(); - } + size_t column_count() { return parent_.column_count(); } /** * Get the total number of rows * * @return The total number of rows */ - size_t row_count() { - return parent_.row_count(); - } + size_t row_count() { return parent_.row_count(); } /** * Get the next row @@ -382,7 +355,6 @@ class Rows { Result parent_; }; - inline Row Result::first_row() { if (cass_result_row_count(get()) == 0) { throw Exception("No first row available"); @@ -390,11 +362,8 @@ inline Row Result::first_row() { return Row(cass_result_first_row(get()), *this); } -inline Rows Result::rows() { - return Rows(cass_iterator_from_result(get()), *this); -} +inline Rows Result::rows() { return Rows(cass_iterator_from_result(get()), *this); } -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_RESULT_HPP__ diff --git a/gtests/src/integration/objects/retry_policy.hpp b/gtests/src/integration/objects/retry_policy.hpp index ef59e1402..0d51d0486 100644 --- a/gtests/src/integration/objects/retry_policy.hpp +++ b/gtests/src/integration/objects/retry_policy.hpp @@ -20,8 +20,7 @@ #include "objects/object_base.hpp" -namespace test { -namespace driver { +namespace test { namespace driver { /** * Wrapped retry policy object @@ -34,7 +33,7 @@ class RetryPolicy : public Object { * @param retry_policy Native driver object */ RetryPolicy(CassRetryPolicy* retry_policy) - : Object(retry_policy) {} + : Object(retry_policy) {} /** * Create the retry policy object from the shared reference @@ -42,7 +41,7 @@ class RetryPolicy : public Object { * @param retry_policy Shared reference */ RetryPolicy(Ptr retry_policy) - : Object(retry_policy) {} + : Object(retry_policy) {} }; /** @@ -55,7 +54,7 @@ class DefaultRetryPolicy : public RetryPolicy { * policy object */ DefaultRetryPolicy() - : RetryPolicy(cass_retry_policy_default_new()) {} + : RetryPolicy(cass_retry_policy_default_new()) {} }; /** @@ -68,7 +67,7 @@ class DowngradingConsistencyRetryPolicy : public RetryPolicy { * driver downgrading consistency retry policy object */ DowngradingConsistencyRetryPolicy() - : RetryPolicy(cass_retry_policy_downgrading_consistency_new()) {} + : RetryPolicy(cass_retry_policy_downgrading_consistency_new()) {} }; /** @@ -81,7 +80,7 @@ class FallthroughRetryPolicy : public RetryPolicy { * fallthrough retry policy object */ FallthroughRetryPolicy() - : RetryPolicy(cass_retry_policy_fallthrough_new()) {} + : RetryPolicy(cass_retry_policy_fallthrough_new()) {} }; /** @@ -96,10 +95,9 @@ class LoggingRetryPolicy : public RetryPolicy { * @param child_policy Child retry policy being logged (CASS_LOG_INFO) */ LoggingRetryPolicy(RetryPolicy child_policy) - : RetryPolicy(cass_retry_policy_logging_new(child_policy.get())) {} + : RetryPolicy(cass_retry_policy_logging_new(child_policy.get())) {} }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_RETRY_POLICY_HPP__ diff --git a/gtests/src/integration/objects/schema.hpp b/gtests/src/integration/objects/schema.hpp index dc22bf512..e5273d63f 100644 --- a/gtests/src/integration/objects/schema.hpp +++ b/gtests/src/integration/objects/schema.hpp @@ -21,8 +21,7 @@ #include "objects/object_base.hpp" -namespace test { -namespace driver { +namespace test { namespace driver { // Forward declarations class Keyspace; @@ -37,13 +36,14 @@ class Schema : public Object { class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) {} + : test::Exception(message) {} }; /** * Default constructor */ - Schema() : Object(NULL) {} + Schema() + : Object(NULL) {} /** * Create a schema object @@ -51,7 +51,7 @@ class Schema : public Object { * @param schema_meta Native driver object */ Schema(const CassSchemaMeta* schema_meta) - : Object(schema_meta) {} + : Object(schema_meta) {} /** * Get the keyspace metadata for a given keyspace @@ -62,9 +62,7 @@ class Schema : public Object { */ Keyspace keyspace(const std::string& name); - const CassVersion version() const { - return cass_schema_meta_version(get()); - } + const CassVersion version() const { return cass_schema_meta_version(get()); } }; /** @@ -75,14 +73,14 @@ class Keyspace { class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) {} + : test::Exception(message) {} }; /** * Default constructor */ Keyspace() - : keyspace_meta_(NULL) {} + : keyspace_meta_(NULL) {} /** * Create the keyspace object @@ -91,18 +89,15 @@ class Keyspace { * @param parent The schema object for the keyspace metadata */ Keyspace(const CassKeyspaceMeta* keyspace_meta, const Schema& parent) - : keyspace_meta_(keyspace_meta) - , parent_(parent) {} - + : keyspace_meta_(keyspace_meta) + , parent_(parent) {} /** * Determine if the keyspace is virtual * * @return true if virtual, otherwise false */ - bool is_virtual() const { - return cass_keyspace_meta_is_virtual(keyspace_meta_) == cass_true; - } + bool is_virtual() const { return cass_keyspace_meta_is_virtual(keyspace_meta_) == cass_true; } /** * Get the UserType type object for a given user type @@ -144,7 +139,7 @@ class Table { * Default constructor */ Table() - : table_meta_(NULL) {} + : table_meta_(NULL) {} /** * Create the table object @@ -153,17 +148,15 @@ class Table { * @param parent The keyspace object that owns the table */ Table(const CassTableMeta* table_meta, const Keyspace& parent) - : table_meta_(table_meta) - , parent_(parent) {} + : table_meta_(table_meta) + , parent_(parent) {} /** * Determine if the table is virtual * * @return true if virtual, otherwise false */ - bool is_virtual() const { - return cass_table_meta_is_virtual(table_meta_) == cass_true; - } + bool is_virtual() const { return cass_table_meta_is_virtual(table_meta_) == cass_true; } const CassTableMeta* get() const { return table_meta_; } @@ -192,17 +185,15 @@ class UserTypeType { * @param parent The keyspace object for the UserType type */ UserTypeType(const CassDataType* data_type, const Keyspace& parent) - : data_type_(data_type) - , parent_(parent) {} + : data_type_(data_type) + , parent_(parent) {} /** * Get the data type * * @return Native driver data type */ - const CassDataType* data_type() const { - return data_type_; - } + const CassDataType* data_type() const { return data_type_; } private: /** @@ -215,10 +206,8 @@ class UserTypeType { Keyspace parent_; }; - inline Keyspace Schema::keyspace(const std::string& name) { - const CassKeyspaceMeta* keyspace_meta - = cass_schema_meta_keyspace_by_name(get(), name.c_str()); + const CassKeyspaceMeta* keyspace_meta = cass_schema_meta_keyspace_by_name(get(), name.c_str()); if (keyspace_meta == NULL) { throw Exception("Unable to get metadata for keyspace: " + name); } @@ -226,8 +215,8 @@ inline Keyspace Schema::keyspace(const std::string& name) { } inline UserTypeType Keyspace::user_type(const std::string& name) { - const CassDataType* data_type - = cass_keyspace_meta_user_type_by_name(keyspace_meta_, name.c_str()); + const CassDataType* data_type = + cass_keyspace_meta_user_type_by_name(keyspace_meta_, name.c_str()); if (data_type == NULL) { throw Exception("Unable to get metadata for user type: " + name); } @@ -235,15 +224,13 @@ inline UserTypeType Keyspace::user_type(const std::string& name) { } inline Table Keyspace::table(const std::string& name) { - const CassTableMeta* table = - cass_keyspace_meta_table_by_name(keyspace_meta_, name.c_str()); + const CassTableMeta* table = cass_keyspace_meta_table_by_name(keyspace_meta_, name.c_str()); if (table == NULL) { throw Exception("Unable to get metadata for table: " + name); } return Table(table, *this); } -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_SCHEMA_HPP__ diff --git a/gtests/src/integration/objects/session.hpp b/gtests/src/integration/objects/session.hpp index 706a6ac6f..f15e3e2f6 100644 --- a/gtests/src/integration/objects/session.hpp +++ b/gtests/src/integration/objects/session.hpp @@ -28,27 +28,27 @@ #include "exception.hpp" -namespace test { -namespace driver { +namespace test { namespace driver { /** * Wrapped session object */ class Session : public Object { -friend class Cluster; + friend class Cluster; + public: class Exception : public test::CassException { public: Exception(const std::string& message, const CassError error_code, const std::string& error_message) - : test::CassException(message, error_code, error_message) { } + : test::CassException(message, error_code, error_message) {} }; /** * Create the default session object */ Session() - : Object(cass_session_new()) { } + : Object(cass_session_new()) {} /** * Create the session object from the native driver object @@ -56,7 +56,7 @@ friend class Cluster; * @param session Native driver object */ Session(CassSession* session) - : Object(session) { } + : Object(session) {} /** * Create the session object from a shared reference @@ -64,7 +64,7 @@ friend class Cluster; * @param session Shared reference */ Session(Ptr session) - : Object(session) { } + : Object(session) {} /** * Close the active session @@ -82,27 +82,21 @@ friend class Cluster; * * @return Error code of the future */ - CassError connect_error_code() { - return connect_future_.error_code(); - } + CassError connect_error_code() { return connect_future_.error_code(); } /** * Get the human readable description of the error code during the connection * * @return Error description */ - const std::string connect_error_description() { - return connect_future_.error_description(); - } + const std::string connect_error_description() { return connect_future_.error_description(); } /** * Get the error message that occurred during the connection * * @return Error message */ - const std::string connect_error_message() { - return connect_future_.error_message(); - } + const std::string connect_error_message() { return connect_future_.error_message(); } /** * Execute a batch statement synchronously @@ -144,9 +138,8 @@ friend class Cluster; * CASS_OK; false otherwise (default: true) * @return Result object */ - Result execute(const std::string& query, - CassConsistency consistency = CASS_CONSISTENCY_LOCAL_ONE, - bool is_idempotent = false, bool assert_ok = true) { + Result execute(const std::string& query, CassConsistency consistency = CASS_CONSISTENCY_LOCAL_ONE, + bool is_idempotent = false, bool assert_ok = true) { Statement statement(query); statement.set_consistency(consistency); statement.set_idempotent(is_idempotent); @@ -184,8 +177,8 @@ friend class Cluster; * @return Future object */ Future execute_async(const std::string& query, - CassConsistency consistency = CASS_CONSISTENCY_LOCAL_ONE, - bool is_idempotent = false) { + CassConsistency consistency = CASS_CONSISTENCY_LOCAL_ONE, + bool is_idempotent = false) { Statement statement(query); statement.set_consistency(consistency); statement.set_idempotent(is_idempotent); @@ -235,15 +228,14 @@ friend class Cluster; if (keyspace.empty()) { session.connect_future_ = cass_session_connect(session.get(), cluster); } else { - session.connect_future_ = cass_session_connect_keyspace(session.get(), - cluster, keyspace.c_str()); + session.connect_future_ = + cass_session_connect_keyspace(session.get(), cluster, keyspace.c_str()); } session.connect_future_.wait(false); if (assert_ok && session.connect_error_code() != CASS_OK) { - throw Exception("Unable to Establish Session Connection: " - + session.connect_error_description(), - session.connect_error_code(), - session.connect_error_message()); + throw Exception("Unable to Establish Session Connection: " + + session.connect_error_description(), + session.connect_error_code(), session.connect_error_message()); } return session; } @@ -252,7 +244,6 @@ friend class Cluster; Future connect_future_; }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_SESSION_HPP__ diff --git a/gtests/src/integration/objects/statement.cpp b/gtests/src/integration/objects/statement.cpp index 2f9940b60..b00a663b0 100644 --- a/gtests/src/integration/objects/statement.cpp +++ b/gtests/src/integration/objects/statement.cpp @@ -19,7 +19,5 @@ #include "objects/custom_payload.hpp" void test::driver::Statement::set_custom_payload(CustomPayload custom_payload) { - ASSERT_EQ(CASS_OK, cass_statement_set_custom_payload(get(), - custom_payload.get())); + ASSERT_EQ(CASS_OK, cass_statement_set_custom_payload(get(), custom_payload.get())); } - diff --git a/gtests/src/integration/objects/statement.hpp b/gtests/src/integration/objects/statement.hpp index 6d444ef67..4a80e3402 100644 --- a/gtests/src/integration/objects/statement.hpp +++ b/gtests/src/integration/objects/statement.hpp @@ -28,8 +28,7 @@ #include -namespace test { -namespace driver { +namespace test { namespace driver { // Forward declaration for circular dependency class CustomPayload; @@ -43,14 +42,14 @@ class Statement : public Object { * Create an empty statement */ Statement() - : Object() { } + : Object() {} /** * Create the statement object from the native driver statement object * * @param statement Native driver object */ Statement(CassStatement* statement) - : Object(statement) { } + : Object(statement) {} /** * Create the statement object from the shared reference @@ -58,7 +57,7 @@ class Statement : public Object { * @param statement Shared reference */ Statement(Ptr statement) - : Object(statement) { } + : Object(statement) {} /** * Create the statement object from a query @@ -68,8 +67,8 @@ class Statement : public Object { * (default: 0) */ Statement(const std::string& query, size_t parameter_count = 0) - : Object(cass_statement_new(query.c_str(), - parameter_count)) { } + : Object( + cass_statement_new(query.c_str(), parameter_count)) {} /** * Add a key index specifier to the statement. @@ -90,7 +89,7 @@ class Statement : public Object { * @param index Index to bind the value to * @param value Value to bind to the statement at given index */ - template + template void bind(size_t index, T value) { value.statement_bind(*this, index); } @@ -101,7 +100,7 @@ class Statement : public Object { * @param name Column name to bind the value to * @param value Value to bind to the statement at given index */ - template + template void bind(const std::string& name, T value) { value.statement_bind(*this, name); } @@ -139,8 +138,7 @@ class Statement : public Object { * @param enable True if statement is idempotent; false otherwise */ void set_idempotent(bool enable) { - ASSERT_EQ(CASS_OK, cass_statement_set_is_idempotent(get(), - enable ? cass_true : cass_false)); + ASSERT_EQ(CASS_OK, cass_statement_set_is_idempotent(get(), enable ? cass_true : cass_false)); } /** @@ -159,8 +157,7 @@ class Statement : public Object { * @param enable True if attempted host should be recorded; false otherwise */ void set_record_attempted_hosts(bool enable) { - return internals::Utils::set_record_attempted_hosts(get(), - enable); + return internals::Utils::set_record_attempted_hosts(get(), enable); } /** @@ -169,8 +166,7 @@ class Statement : public Object { * @param timeout_ms Timeout in milliseconds */ void set_request_timeout(uint64_t timeout_ms) { - ASSERT_EQ(CASS_OK, cass_statement_set_request_timeout(get(), - timeout_ms)); + ASSERT_EQ(CASS_OK, cass_statement_set_request_timeout(get(), timeout_ms)); } /** @@ -179,8 +175,7 @@ class Statement : public Object { * @param retry_policy Retry policy to use for the statement */ void set_retry_policy(RetryPolicy retry_policy) { - ASSERT_EQ(CASS_OK, cass_statement_set_retry_policy(get(), - retry_policy.get())); + ASSERT_EQ(CASS_OK, cass_statement_set_retry_policy(get(), retry_policy.get())); } /** @@ -189,8 +184,7 @@ class Statement : public Object { * @param serial_consistency Serial consistency to use for the statement */ void set_serial_consistency(CassConsistency serial_consistency) { - ASSERT_EQ(CASS_OK, cass_statement_set_serial_consistency(get(), - serial_consistency)); + ASSERT_EQ(CASS_OK, cass_statement_set_serial_consistency(get(), serial_consistency)); } /** @@ -199,8 +193,7 @@ class Statement : public Object { * @param enabled */ void set_tracing(bool enabled) { - ASSERT_EQ(CASS_OK, - cass_statement_set_tracing(get(), enabled ? cass_true : cass_false)); + ASSERT_EQ(CASS_OK, cass_statement_set_tracing(get(), enabled ? cass_true : cass_false)); } /** @@ -210,8 +203,7 @@ class Statement : public Object { * @param port */ void set_host(const std::string& host, int port) { - ASSERT_EQ(CASS_OK, - cass_statement_set_host(get(), host.c_str(), port)); + ASSERT_EQ(CASS_OK, cass_statement_set_host(get(), host.c_str(), port)); } /** @@ -221,8 +213,7 @@ class Statement : public Object { * @param port */ void set_host(const CassInet* host, int port) { - ASSERT_EQ(CASS_OK, - cass_statement_set_host_inet(get(), host, port)); + ASSERT_EQ(CASS_OK, cass_statement_set_host_inet(get(), host, port)); } }; @@ -237,7 +228,7 @@ class Batch : public Object { * @param batch_type Type of batch to create (default: Unlogged) */ Batch(CassBatchType batch_type = CASS_BATCH_TYPE_UNLOGGED) - : Object(cass_batch_new(batch_type)) {} + : Object(cass_batch_new(batch_type)) {} /** * Create the batch object from the native driver batch object @@ -245,7 +236,7 @@ class Batch : public Object { * @param batch Native driver object */ Batch(CassBatch* batch) - : Object(batch) {} + : Object(batch) {} /** * Create the batch object from the shared reference @@ -253,7 +244,7 @@ class Batch : public Object { * @param batch Shared reference */ Batch(Ptr batch) - : Object(batch) {} + : Object(batch) {} /** * Add a statement (query or bound) to the batch @@ -263,11 +254,10 @@ class Batch : public Object { * CASS_OK; false otherwise (default: true) */ void add(Statement statement, bool assert_ok = true) { - CassError error_code = cass_batch_add_statement(get(), - statement.get()); + CassError error_code = cass_batch_add_statement(get(), statement.get()); if (assert_ok) { ASSERT_EQ(CASS_OK, error_code) - << "Unable to Add Statement to Batch: " << cass_error_desc(error_code); + << "Unable to Add Statement to Batch: " << cass_error_desc(error_code); } } @@ -297,8 +287,7 @@ class Batch : public Object { * @param enable True if statement in a batch is idempotent; false otherwise */ void set_idempotent(bool enable) { - ASSERT_EQ(CASS_OK, cass_batch_set_is_idempotent(get(), - enable ? cass_true : cass_false)); + ASSERT_EQ(CASS_OK, cass_batch_set_is_idempotent(get(), enable ? cass_true : cass_false)); } /** @@ -307,8 +296,7 @@ class Batch : public Object { * @param timeout_ms Timeout in milliseconds */ void set_request_timeout(uint64_t timeout_ms) { - ASSERT_EQ(CASS_OK, cass_batch_set_request_timeout(get(), - timeout_ms)); + ASSERT_EQ(CASS_OK, cass_batch_set_request_timeout(get(), timeout_ms)); } /** @@ -326,12 +314,10 @@ class Batch : public Object { * @param serial_consistency Serial consistency to use for the batch */ void set_serial_consistency(CassConsistency serial_consistency) { - ASSERT_EQ(CASS_OK, cass_batch_set_serial_consistency(get(), - serial_consistency)); + ASSERT_EQ(CASS_OK, cass_batch_set_serial_consistency(get(), serial_consistency)); } }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_STATEMENT_HPP__ diff --git a/gtests/src/integration/objects/tuple.hpp b/gtests/src/integration/objects/tuple.hpp index 3be7985d8..313927baf 100644 --- a/gtests/src/integration/objects/tuple.hpp +++ b/gtests/src/integration/objects/tuple.hpp @@ -25,8 +25,7 @@ #include -namespace test { -namespace driver { +namespace test { namespace driver { /** * Tuple object @@ -38,7 +37,7 @@ class Tuple : public Object { class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) {} + : test::Exception(message) {} }; /** @@ -47,9 +46,9 @@ class Tuple : public Object { * @param size Number of elements in the tuple */ Tuple(size_t size) - : Object(cass_tuple_new(size)) - , size_(size) - , is_null_(true) {} + : Object(cass_tuple_new(size)) + , size_(size) + , is_null_(true) {} /** * Create the tuple from a particular column @@ -57,8 +56,8 @@ class Tuple : public Object { * @param column Column to retrieve tuple from */ Tuple(const CassValue* column) - : size_(0) - , is_null_(true) { + : size_(0) + , is_null_(true) { initialize(column); } @@ -67,9 +66,7 @@ class Tuple : public Object { * * @return True if tuple is NULL; false otherwise */ - bool is_null() { - return is_null_; - } + bool is_null() { return is_null_; } /** * Get the next value @@ -92,7 +89,7 @@ class Tuple : public Object { * @throws Exception If tuple is not able to have values added to it (e.g. * The tuple was generated from server result) */ - template + template void set(T value, size_t index) { value.set(*this, index); is_null_ = false; @@ -103,9 +100,7 @@ class Tuple : public Object { * * @return The number of elements in the tuple */ - size_t size() { - return size_; - } + size_t size() { return size_; } /** * Get the current value from the tuple iterator (retrieved from server) @@ -113,7 +108,7 @@ class Tuple : public Object { * @return Current value in the tuple * @throws Exception If iterator is not valid */ - template + template T value() { if (iterator_) { return T(cass_iterator_get_value(iterator_.get())); @@ -126,7 +121,7 @@ class Tuple : public Object { * * @return The tuple as a vector of a single type */ - template + template std::vector values() { std::vector result; const CassValue* value; @@ -144,8 +139,7 @@ class Tuple : public Object { * statement */ void statement_bind(Statement statement, size_t index) { - ASSERT_EQ(CASS_OK, - cass_statement_bind_tuple(statement.get(), index, get())); + ASSERT_EQ(CASS_OK, cass_statement_bind_tuple(statement.get(), index, get())); } protected: @@ -184,7 +178,6 @@ class Tuple : public Object { } }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_TUPLE_HPP__ diff --git a/gtests/src/integration/objects/user_type.hpp b/gtests/src/integration/objects/user_type.hpp index daac83473..8aae29528 100644 --- a/gtests/src/integration/objects/user_type.hpp +++ b/gtests/src/integration/objects/user_type.hpp @@ -25,8 +25,7 @@ #include -namespace test { -namespace driver { +namespace test { namespace driver { /** * User type object @@ -41,7 +40,7 @@ class UserType : public Object { * @param data_type The data type that makes up the user type */ UserType(const CassDataType* data_type) - : is_null_(true) { + : is_null_(true) { initialize(data_type); } @@ -51,8 +50,8 @@ class UserType : public Object { * @param column Column to retrieve user type from */ UserType(const CassValue* column) - : size_(0) - , is_null_(true) { + : size_(0) + , is_null_(true) { initialize(column); } @@ -61,9 +60,7 @@ class UserType : public Object { * * @return True if user type is NULL; false otherwise */ - bool is_null() { - return is_null_; - } + bool is_null() { return is_null_; } /** * Set the value in the user type @@ -73,7 +70,7 @@ class UserType : public Object { * @throws Exception If user type is not able to have values added to it (e.g. * The user type was generated from server result) */ - template + template void set(T value, const std::string& name) { value.set(*this, name); is_null_ = false; @@ -84,9 +81,7 @@ class UserType : public Object { * * @return The number of elements in the user type */ - size_t size() { - return size_; - } + size_t size() { return size_; } /** * Get a field value from the user type @@ -94,7 +89,7 @@ class UserType : public Object { * @return Value of the field in the user type * @throws Exception If value is not available */ - template + template T value(const std::string& name) { ValuesMap::iterator iterator = values_.find(name); if (iterator != values_.end()) { @@ -108,7 +103,7 @@ class UserType : public Object { * * @return A map of all the fields where the value is a single type */ - template + template std::map values() { std::map result; while (cass_iterator_next(iterator_.get())) { @@ -124,7 +119,6 @@ class UserType : public Object { return result; } - /** * Bind the user type to a statement at the given index * @@ -133,8 +127,7 @@ class UserType : public Object { * statement */ void statement_bind(Statement statement, size_t index) { - ASSERT_EQ(CASS_OK, - cass_statement_bind_user_type(statement.get(), index, get())); + ASSERT_EQ(CASS_OK, cass_statement_bind_user_type(statement.get(), index, get())); } protected: @@ -173,7 +166,6 @@ class UserType : public Object { iterator_ = cass_iterator_fields_from_user_type(value); } - /** * Initialize the user type from the data type * @@ -188,8 +180,7 @@ class UserType : public Object { // Get the user type field name const char* name; size_t name_length; - ASSERT_EQ(CASS_OK, - cass_data_type_sub_type_name(data_type, i, &name, &name_length)); + ASSERT_EQ(CASS_OK, cass_data_type_sub_type_name(data_type, i, &name, &name_length)); // Create a temporary place holder for the field value std::string field(name, name_length); @@ -198,12 +189,10 @@ class UserType : public Object { } // Create the user type from the data type - Object::set( - cass_user_type_new_from_data_type(data_type)); + Object::set(cass_user_type_new_from_data_type(data_type)); } }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_USER_DATA_TYPE_HPP__ diff --git a/gtests/src/integration/objects/uuid_gen.hpp b/gtests/src/integration/objects/uuid_gen.hpp index 3082e3867..129c080bd 100644 --- a/gtests/src/integration/objects/uuid_gen.hpp +++ b/gtests/src/integration/objects/uuid_gen.hpp @@ -22,8 +22,7 @@ #include "values.hpp" -namespace test { -namespace driver { +namespace test { namespace driver { /** * Wrapped UUID generator object @@ -34,7 +33,7 @@ class UuidGen : public Object { * Create the UUID generator object */ UuidGen() - : Object(cass_uuid_gen_new()) {} + : Object(cass_uuid_gen_new()) {} /** * Create the UUID generator object with custom node information @@ -42,7 +41,7 @@ class UuidGen : public Object { * @param node Node to use for custom node information */ UuidGen(cass_uint64_t node) - : Object(cass_uuid_gen_new_with_node(node)) {} + : Object(cass_uuid_gen_new_with_node(node)) {} /** * Create the UUID generator object from the native driver object @@ -50,7 +49,7 @@ class UuidGen : public Object { * @param uuid_gen Native driver object */ UuidGen(CassUuidGen* uuid_gen) - : Object(uuid_gen) {} + : Object(uuid_gen) {} /** * Create the UUID generator object from a shared reference @@ -58,7 +57,7 @@ class UuidGen : public Object { * @param uuid_gen Shared reference */ UuidGen(Ptr uuid_gen) - : Object(uuid_gen) {} + : Object(uuid_gen) {} virtual ~UuidGen() {} @@ -97,7 +96,6 @@ class UuidGen : public Object { } }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __TEST_UUID_GEN_HPP__ diff --git a/gtests/src/integration/options.cpp b/gtests/src/integration/options.cpp index 33e351d9d..fc371c7da 100644 --- a/gtests/src/integration/options.cpp +++ b/gtests/src/integration/options.cpp @@ -23,8 +23,8 @@ #include #include -#define DEFAULT_OPTIONS_CASSSANDRA_VERSION CCM::CassVersion("3.11.3") -#define DEFAULT_OPTIONS_DSE_VERSION CCM::DseVersion("6.0.4") +#define DEFAULT_OPTIONS_CASSSANDRA_VERSION CCM::CassVersion("3.11.4") +#define DEFAULT_OPTIONS_DSE_VERSION CCM::DseVersion("6.0.8") // Initialize the defaults for all the options bool Options::is_initialized_ = false; @@ -91,8 +91,7 @@ bool Options::initialize(int argc, char* argv[]) { // Integration test options if (key == "--keep-clusters") { is_keep_clusters_ = true; - } - else if (key == "--log-tests") { + } else if (key == "--log-tests") { if (!value.empty()) { is_log_tests_ = bool_value(value); } else { @@ -104,7 +103,8 @@ bool Options::initialize(int argc, char* argv[]) { if (!value.empty()) { server_version_ = CCM::CassVersion(value); } else { - std::cerr << "Missing Server Version: Using default " << server_version_.to_string() << std::endl; + std::cerr << "Missing Server Version: Using default " << server_version_.to_string() + << std::endl; } } else if (key == "--dse") { is_dse_ = true; @@ -119,7 +119,8 @@ bool Options::initialize(int argc, char* argv[]) { } else if (key == "--dse-credentials") { bool is_found = false; if (!value.empty()) { - for (CCM::DseCredentialsType::iterator iterator = CCM::DseCredentialsType::begin(); iterator != CCM::DseCredentialsType::end(); ++iterator) { + for (CCM::DseCredentialsType::iterator iterator = CCM::DseCredentialsType::begin(); + iterator != CCM::DseCredentialsType::end(); ++iterator) { if (*iterator == value) { dse_credentials_type_ = *iterator; is_found = true; @@ -128,7 +129,8 @@ bool Options::initialize(int argc, char* argv[]) { } } if (!is_found) { - std::cerr << "Invalid DSE Credentials Type: Using default " << dse_credentials_type_.to_string() << std::endl; + std::cerr << "Invalid DSE Credentials Type: Using default " + << dse_credentials_type_.to_string() << std::endl; } } else if (key == "--git") { use_git_ = true; @@ -138,7 +140,9 @@ bool Options::initialize(int argc, char* argv[]) { } else if (key == "--install-dir") { use_install_dir_ = true; if (value.empty()) { - std::cerr << "Disabling the Use of the Installation Directory: Installation directory must not be empty" << std::endl; + std::cerr << "Disabling the Use of the Installation Directory: Installation directory " + "must not be empty" + << std::endl; use_install_dir_ = false; } else { install_dir_ = value; @@ -153,12 +157,12 @@ bool Options::initialize(int argc, char* argv[]) { if (!value.empty()) { std::vector categories = test::Utils::explode(value, ':'); for (std::vector::iterator iterator = categories.begin(); - iterator != categories.end(); ++iterator) { + iterator != categories.end(); ++iterator) { try { categories_.insert(*iterator); } catch (TestCategory::Exception& tce) { std::cerr << "Invalid Category: " << *iterator << " will be ignored" - << " (" << tce.what() << ")" << std::endl; + << " (" << tce.what() << ")" << std::endl; } } } else { @@ -167,15 +171,16 @@ bool Options::initialize(int argc, char* argv[]) { } else if (key == "--verbose") { if (!value.empty() && !bool_value(value)) { std::vector components = test::Utils::explode(value, ','); - for (std::vector::iterator it = components.begin(), - end = components.end(); it != end; ++it) { + for (std::vector::iterator it = components.begin(), end = components.end(); + it != end; ++it) { std::string component = test::Utils::to_lower(*it); if (component == "ccm") { is_verbose_ccm_ = true; } else if (component == "integration") { is_verbose_integration_ = true; } else { - std::cerr << "Invalid Component \"" << *it << "\": Available components are [ccm, integration]" << std::endl; + std::cerr << "Invalid Component \"" << *it + << "\": Available components are [ccm, integration]" << std::endl; } } } else { @@ -189,7 +194,8 @@ bool Options::initialize(int argc, char* argv[]) { else if (key == "--authentication") { bool is_found = false; if (!value.empty()) { - for (CCM::AuthenticationType::iterator iterator = CCM::AuthenticationType::begin(); iterator != CCM::AuthenticationType::end(); ++iterator) { + for (CCM::AuthenticationType::iterator iterator = CCM::AuthenticationType::begin(); + iterator != CCM::AuthenticationType::end(); ++iterator) { if (*iterator == value) { authentication_type_ = *iterator; is_found = true; @@ -198,12 +204,14 @@ bool Options::initialize(int argc, char* argv[]) { } } if (!is_found) { - std::cerr << "Invalid Authentication Type: Using default " << authentication_type_.to_string() << std::endl; + std::cerr << "Invalid Authentication Type: Using default " + << authentication_type_.to_string() << std::endl; } } else if (key == "--deployment") { bool is_found = false; if (!value.empty()) { - for (CCM::DeploymentType::iterator iterator = CCM::DeploymentType::begin(); iterator != CCM::DeploymentType::end(); ++iterator) { + for (CCM::DeploymentType::iterator iterator = CCM::DeploymentType::begin(); + iterator != CCM::DeploymentType::end(); ++iterator) { if (*iterator == value) { deployment_type_ = *iterator; is_found = true; @@ -212,7 +220,8 @@ bool Options::initialize(int argc, char* argv[]) { } } if (!is_found) { - std::cerr << "Invalid Deployment Type: Using default " << deployment_type_.to_string() << std::endl; + std::cerr << "Invalid Deployment Type: Using default " << deployment_type_.to_string() + << std::endl; } } else if (key == "--host") { if (!value.empty()) { @@ -221,7 +230,7 @@ bool Options::initialize(int argc, char* argv[]) { std::cerr << "Missing Host: Using default " << host_ << std::endl; } } else if (key == "--port") { - //Convert the value + // Convert the value if (!value.empty()) { std::stringstream ss(value); if (!(ss >> port_).fail()) { @@ -260,8 +269,8 @@ bool Options::initialize(int argc, char* argv[]) { // Determine if the options should have their defaults reset if (categories_.empty()) { - for (TestCategory::iterator iterator = TestCategory::begin(); - iterator != TestCategory::end(); ++iterator) { + for (TestCategory::iterator iterator = TestCategory::begin(); iterator != TestCategory::end(); + ++iterator) { // Only add the DSE test category if DSE is enabled if (*iterator != TestCategory::DSE || is_dse_) { categories_.insert(*iterator); @@ -277,7 +286,8 @@ bool Options::initialize(int argc, char* argv[]) { // Determine if the DSE credentials type should be updated if (dse_credentials_type_ == CCM::DseCredentialsType::USERNAME_PASSWORD) { if (dse_username_.empty() || dse_password_.empty()) { - std::cerr << "Invalid Username and/or Password: Default to INI_FILE DSE credentials" << std::endl; + std::cerr << "Invalid Username and/or Password: Default to INI_FILE DSE credentials" + << std::endl; dse_credentials_type_ = CCM::DseCredentialsType::INI_FILE; } } @@ -292,75 +302,102 @@ bool Options::initialize(int argc, char* argv[]) { void Options::print_help() { std::cout << std::endl << "Integration Test Options:" << std::endl; - std::cout << " --log-tests=(yes|no)" << std::endl << " " - << "Enable/Disable logging of driver messages per test to a file." << std::endl - << " The default is " << (log_tests() ? "yes" : "no") << "." << std::endl; + std::cout << " --log-tests=(yes|no)" << std::endl + << " " + << "Enable/Disable logging of driver messages per test to a file." << std::endl + << " The default is " << (log_tests() ? "yes" : "no") << "." << std::endl; std::cout << std::endl << "CCM Options:" << std::endl; - std::cout << " --version=[VERSION]" << std::endl << " " - << "Cassandra/DSE version to use." << std::endl - << " Default:" << std::endl - << " Cassandra Version: " << server_version().to_string() << std::endl - << " DSE Version: " << DEFAULT_OPTIONS_DSE_VERSION.to_string() << std::endl; + std::cout << " --version=[VERSION]" << std::endl + << " " + << "Cassandra/DSE version to use." << std::endl + << " Default:" << std::endl + << " Cassandra Version: " << server_version().to_string() << std::endl + << " DSE Version: " << DEFAULT_OPTIONS_DSE_VERSION.to_string() << std::endl; std::string categories; - for (TestCategory::iterator iterator = TestCategory::begin(); - iterator != TestCategory::end(); ++iterator) { + for (TestCategory::iterator iterator = TestCategory::begin(); iterator != TestCategory::end(); + ++iterator) { if (iterator != TestCategory::begin()) { categories += "|"; } categories += iterator->name(); } - std::cout << " --category=[" << categories << "]" << std::endl << " " - << "Run only the categories whose name matches one of the available" << std::endl - << " categories; ':' separates two categories. The default is all categories" << std::endl - << " being executed." << std::endl; - std::cout << " --dse" << std::endl << " " - << "Indicate server version supplied is DSE." << std::endl; - std::cout << " --dse-credentials=(USERNAME_PASSWORD|INI_FILE)" << std::endl << " " - << "DSE credentials to use for download authentication. The default is " << std::endl - << " " << dse_credentials().to_string() << "." << std::endl; - std::cout << " --dse-username=[USERNAME]" << std::endl << " " - << "Username to use for DSE download authentication." << std::endl; - std::cout << " --dse-password=[PASSWORD]" << std::endl << " " - << "Password to use for DSE download authentication." << std::endl; - std::cout << " --git" << std::endl << " " - << "Indicate Cassandra/DSE server download should be obtained from" << std::endl - << " ASF/GitHub." << std::endl; - std::cout << " --git=[BRANCH_OR_TAG]" << std::endl << " " - << "Indicate Cassandra/DSE server branch/tag should be obtained from" << std::endl - << " ASF/GitHub." << std::endl; - std::cout << " --install-dir=[INSTALL_DIR]" << std::endl << " " - << "Indicate Cassandra/DSE installation directory to use." << std::endl; - std::cout << " --prefix=[PREFIX]" << std::endl << " " - << "CCM cluster prefix. The default is " << cluster_prefix() << "." << std::endl; + std::cout << " --category=[" << categories << "]" << std::endl + << " " + << "Run only the categories whose name matches one of the available" << std::endl + << " categories; ':' separates two categories. The default is all categories" + << std::endl + << " being executed." << std::endl; + std::cout << " --dse" << std::endl + << " " + << "Indicate server version supplied is DSE." << std::endl; + std::cout << " --dse-credentials=(USERNAME_PASSWORD|INI_FILE)" << std::endl + << " " + << "DSE credentials to use for download authentication. The default is " << std::endl + << " " << dse_credentials().to_string() << "." << std::endl; + std::cout << " --dse-username=[USERNAME]" << std::endl + << " " + << "Username to use for DSE download authentication." << std::endl; + std::cout << " --dse-password=[PASSWORD]" << std::endl + << " " + << "Password to use for DSE download authentication." << std::endl; + std::cout << " --git" << std::endl + << " " + << "Indicate Cassandra/DSE server download should be obtained from" << std::endl + << " ASF/GitHub." << std::endl; + std::cout << " --git=[BRANCH_OR_TAG]" << std::endl + << " " + << "Indicate Cassandra/DSE server branch/tag should be obtained from" << std::endl + << " ASF/GitHub." << std::endl; + std::cout << " --install-dir=[INSTALL_DIR]" << std::endl + << " " + << "Indicate Cassandra/DSE installation directory to use." << std::endl; + std::cout << " --prefix=[PREFIX]" << std::endl + << " " + << "CCM cluster prefix. The default is " << cluster_prefix() << "." << std::endl; #ifdef CASS_USE_LIBSSH2 - std::cout << " --authentication=(USERNAME_PASSWORD|PUBLIC_KEY)" << std::endl << " " - << "Authentication to use for remote deployment. The default is" << std::endl - << " " << authentication_type().to_string() << "." << std::endl; - std::cout << " --deployment=(LOCAL|REMOTE)" << std::endl << " " - << "Deployment to use. The default is " << deployment_type().to_string() << "." << std::endl; - std::cout << " --host=[IP_ADDRESS]" << std::endl << " " - << "IP address to use for remote deployment. The default is " << host() << "." << std::endl; - std::cout << " --port=[PORT]" << std::endl << " " - << "Port to use for remote deployment. The default is " << port() << "." << std::endl; - std::cout << " --username=[USERNAME]" << std::endl << " " - << "Username to use for remote deployment. The default is " << username() << "." << std::endl; - std::cout << " --password=[PASSWORD]" << std::endl << " " - << "Password to use for remote deployment. The default is " << password() << "." << std::endl; - std::cout << " --public-key=[FILENAME]" << std::endl << " " - << "Public key filename to use for remote deployment. The default is" << std::endl - << " " << public_key() << "." << std::endl; - std::cout << " --private-key=[FILENAME]" << std::endl << " " - << "Private key filename to use for remote deployment. The default is" << std::endl - << " " << private_key() << "." << std::endl; + std::cout << " --authentication=(USERNAME_PASSWORD|PUBLIC_KEY)" << std::endl + << " " + << "Authentication to use for remote deployment. The default is" << std::endl + << " " << authentication_type().to_string() << "." << std::endl; + std::cout << " --deployment=(LOCAL|REMOTE)" << std::endl + << " " + << "Deployment to use. The default is " << deployment_type().to_string() << "." + << std::endl; + std::cout << " --host=[IP_ADDRESS]" << std::endl + << " " + << "IP address to use for remote deployment. The default is " << host() << "." + << std::endl; + std::cout << " --port=[PORT]" << std::endl + << " " + << "Port to use for remote deployment. The default is " << port() << "." << std::endl; + std::cout << " --username=[USERNAME]" << std::endl + << " " + << "Username to use for remote deployment. The default is " << username() << "." + << std::endl; + std::cout << " --password=[PASSWORD]" << std::endl + << " " + << "Password to use for remote deployment. The default is " << password() << "." + << std::endl; + std::cout << " --public-key=[FILENAME]" << std::endl + << " " + << "Public key filename to use for remote deployment. The default is" << std::endl + << " " << public_key() << "." << std::endl; + std::cout << " --private-key=[FILENAME]" << std::endl + << " " + << "Private key filename to use for remote deployment. The default is" << std::endl + << " " << private_key() << "." << std::endl; #endif - std::cout << " --keep-clusters" << std::endl << " " - << "Indicate CCM clusters should not be removed after tests terminate." - << std::endl; - std::cout << " --verbose(=ccm,integration)" << std::endl << " " - << "Enable verbose output for component(s)." << std::endl; - std::cout << " --disable-beta-protocol" << std::endl << " " - << "Disable beta protocol use by default." << std::endl << " " - << "NOTE: Individual tests may override this setting." << std::endl; + std::cout << " --keep-clusters" << std::endl + << " " + << "Indicate CCM clusters should not be removed after tests terminate." << std::endl; + std::cout << " --verbose(=ccm,integration)" << std::endl + << " " + << "Enable verbose output for component(s)." << std::endl; + std::cout << " --disable-beta-protocol" << std::endl + << " " + << "Disable beta protocol use by default." << std::endl + << " " + << "NOTE: Individual tests may override this setting." << std::endl; std::cout << std::endl; } @@ -411,25 +448,15 @@ void Options::print_settings() { #endif } -bool Options::is_help() { - return is_help_; -} +bool Options::is_help() { return is_help_; } -bool Options::keep_clusters() { - return is_keep_clusters_; -} +bool Options::keep_clusters() { return is_keep_clusters_; } -bool Options::log_tests() { - return is_log_tests_; -} +bool Options::log_tests() { return is_log_tests_; } -CCM::CassVersion Options::server_version() { - return server_version_; -} +CCM::CassVersion Options::server_version() { return server_version_; } -bool Options::is_dse() { - return is_dse_; -} +bool Options::is_dse() { return is_dse_; } CCM::DseCredentialsType Options::dse_credentials() { // Static initialization cannot be guaranteed @@ -439,33 +466,19 @@ CCM::DseCredentialsType Options::dse_credentials() { return dse_credentials_type_; } -const std::string& Options::dse_username() { - return dse_username_; -} +const std::string& Options::dse_username() { return dse_username_; } -const std::string& Options::dse_password() { - return dse_password_; -} +const std::string& Options::dse_password() { return dse_password_; } -bool Options::use_git() { - return use_git_; -} +bool Options::use_git() { return use_git_; } -const std::string& Options::branch_tag() { - return branch_tag_; -} +const std::string& Options::branch_tag() { return branch_tag_; } -bool Options::use_install_dir() { - return use_install_dir_; -} +bool Options::use_install_dir() { return use_install_dir_; } -const std::string& Options::install_dir() { - return install_dir_; -} +const std::string& Options::install_dir() { return install_dir_; } -const std::string& Options::cluster_prefix() { - return cluster_prefix_; -} +const std::string& Options::cluster_prefix() { return cluster_prefix_; } CCM::DeploymentType Options::deployment_type() { // Static initialization cannot be guaranteed @@ -483,73 +496,44 @@ CCM::AuthenticationType Options::authentication_type() { return authentication_type_; } -std::set Options::categories() { - return categories_; -} +std::set Options::categories() { return categories_; } -const std::string& Options::host() { - return host_; -} +const std::string& Options::host() { return host_; } -std::string Options::host_prefix() { - return host_.substr(0, host_.size() - 1); -} +std::string Options::host_prefix() { return host_.substr(0, host_.size() - 1); } -short Options::port() { - return port_; -} +short Options::port() { return port_; } -const std::string& Options::username() { - return username_; -} +const std::string& Options::username() { return username_; } -const std::string& Options::password() { - return password_; -} +const std::string& Options::password() { return password_; } -const std::string& Options::public_key() { - return public_key_; -} +const std::string& Options::public_key() { return public_key_; } -const std::string& Options::private_key() { - return private_key_; -} +const std::string& Options::private_key() { return private_key_; } SharedPtr > Options::ccm() { - return new CCM::Bridge( \ - Options::server_version(), - Options::use_git(), Options::branch_tag(), \ - Options::use_install_dir(), Options::install_dir(), \ - Options::is_dse(), CCM::Bridge::DEFAULT_DSE_WORKLOAD, \ - Options::cluster_prefix(), \ - Options::dse_credentials(), \ - Options::dse_username(), Options::dse_password(), \ - Options::deployment_type(), Options::authentication_type(), \ - Options::host(), Options::port(), \ - Options::username(), Options::password(), \ - Options::public_key(), Options::private_key(), - Options::is_verbose_ccm()); + return new CCM::Bridge(Options::server_version(), Options::use_git(), Options::branch_tag(), + Options::use_install_dir(), Options::install_dir(), Options::is_dse(), + CCM::Bridge::DEFAULT_DSE_WORKLOAD, Options::cluster_prefix(), + Options::dse_credentials(), Options::dse_username(), + Options::dse_password(), Options::deployment_type(), + Options::authentication_type(), Options::host(), Options::port(), + Options::username(), Options::password(), Options::public_key(), + Options::private_key(), Options::is_verbose_ccm()); } -bool Options::is_verbose_ccm() { - return is_verbose_ccm_; -} +bool Options::is_verbose_ccm() { return is_verbose_ccm_; } -bool Options::is_verbose_integration() { - return is_verbose_integration_; -} +bool Options::is_verbose_integration() { return is_verbose_integration_; } -bool Options::is_beta_protocol() { - return is_beta_protocol_; -} +bool Options::is_beta_protocol() { return is_beta_protocol_; } -Options::Options() { -} +Options::Options() {} bool Options::bool_value(const std::string& value) { std::string lower_value = test::Utils::to_lower(value); - if (lower_value == "yes" || lower_value == "true" || - lower_value == "on" || lower_value == "0") { + if (lower_value == "yes" || lower_value == "true" || lower_value == "on" || lower_value == "0") { return true; } return false; diff --git a/gtests/src/integration/options.hpp b/gtests/src/integration/options.hpp index 583797bcc..fa1600b35 100644 --- a/gtests/src/integration/options.hpp +++ b/gtests/src/integration/options.hpp @@ -354,4 +354,3 @@ class Options { }; #endif // __OPTIONS_HPP__ - diff --git a/gtests/src/integration/policies.hpp b/gtests/src/integration/policies.hpp index 61a66c87b..0a7f3a5f9 100644 --- a/gtests/src/integration/policies.hpp +++ b/gtests/src/integration/policies.hpp @@ -21,4 +21,3 @@ #include "policies/next_host_retry_policy.hpp" #endif // __TEST_POLICIES_HPP__ - diff --git a/gtests/src/integration/policies/ignore_retry_policy.hpp b/gtests/src/integration/policies/ignore_retry_policy.hpp index 6f928466a..c22f9be13 100644 --- a/gtests/src/integration/policies/ignore_retry_policy.hpp +++ b/gtests/src/integration/policies/ignore_retry_policy.hpp @@ -21,16 +21,15 @@ #include "retry_policy.hpp" -namespace test { -namespace driver { +namespace test { namespace driver { /** * Retry policy that will create an ignore decision for retry */ -class IgnoreRetryPolicy : public cass::DefaultRetryPolicy { +class IgnoreRetryPolicy : public datastax::internal::core::DefaultRetryPolicy { public: IgnoreRetryPolicy() - : cass::DefaultRetryPolicy() { } + : datastax::internal::core::DefaultRetryPolicy() {} /** * Create an instance of the retry policy for use with the driver @@ -38,43 +37,34 @@ class IgnoreRetryPolicy : public cass::DefaultRetryPolicy { * @return Driver ready retry policy */ static ::test::driver::RetryPolicy policy() { - cass::RetryPolicy* policy = new IgnoreRetryPolicy(); + datastax::internal::core::RetryPolicy* policy = new IgnoreRetryPolicy(); policy->inc_ref(); return CassRetryPolicy::to(policy); } - RetryDecision on_read_timeout(const cass::Request* request, - CassConsistency cl, - int received, - int required, - bool data_recevied, + RetryDecision on_read_timeout(const datastax::internal::core::Request* request, + CassConsistency cl, int received, int required, bool data_recevied, int num_retries) const { return RetryDecision::ignore(); } - RetryDecision on_write_timeout(const cass::Request* request, - CassConsistency cl, - int received, - int required, - CassWriteType write_type, - int num_retries) const { + RetryDecision on_write_timeout(const datastax::internal::core::Request* request, + CassConsistency cl, int received, int required, + CassWriteType write_type, int num_retries) const { return RetryDecision::ignore(); } - virtual RetryDecision on_unavailable(const cass::Request* request, - CassConsistency cl, - int required, - int alive, + virtual RetryDecision on_unavailable(const datastax::internal::core::Request* request, + CassConsistency cl, int required, int alive, int num_retries) const { return RetryDecision::ignore(); } - virtual RetryDecision on_request_error(const cass::Request* request, + virtual RetryDecision on_request_error(const datastax::internal::core::Request* request, CassConsistency cl, - const cass::ErrorResponse* error, + const datastax::internal::core::ErrorResponse* error, int num_retries) const { return RetryDecision::ignore(); } }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __ALWAYS_IGNORE_RETRY_POLICY_HPP__ diff --git a/gtests/src/integration/policies/next_host_retry_policy.hpp b/gtests/src/integration/policies/next_host_retry_policy.hpp index 8974ecbf1..59d3fe90d 100644 --- a/gtests/src/integration/policies/next_host_retry_policy.hpp +++ b/gtests/src/integration/policies/next_host_retry_policy.hpp @@ -21,16 +21,15 @@ #include "retry_policy.hpp" -namespace test { -namespace driver { +namespace test { namespace driver { /** * Retry policy that will retry the statement on the next host */ -class NextHostRetryPolicy : public cass::DefaultRetryPolicy { +class NextHostRetryPolicy : public datastax::internal::core::DefaultRetryPolicy { public: NextHostRetryPolicy() - : cass::DefaultRetryPolicy() { } + : datastax::internal::core::DefaultRetryPolicy() {} /** * Create an instance of the retry policy for use with the driver @@ -38,43 +37,34 @@ class NextHostRetryPolicy : public cass::DefaultRetryPolicy { * @return Driver ready retry policy */ static ::test::driver::RetryPolicy policy() { - cass::RetryPolicy* policy = new NextHostRetryPolicy(); + datastax::internal::core::RetryPolicy* policy = new NextHostRetryPolicy(); policy->inc_ref(); return CassRetryPolicy::to(policy); } - RetryDecision on_read_timeout(const cass::Request* request, - CassConsistency cl, - int received, - int required, - bool data_recevied, + RetryDecision on_read_timeout(const datastax::internal::core::Request* request, + CassConsistency cl, int received, int required, bool data_recevied, int num_retries) const { return RetryDecision::retry_next_host(cl); } - RetryDecision on_write_timeout(const cass::Request* request, - CassConsistency cl, - int received, - int required, - CassWriteType write_type, - int num_retries) const { + RetryDecision on_write_timeout(const datastax::internal::core::Request* request, + CassConsistency cl, int received, int required, + CassWriteType write_type, int num_retries) const { return RetryDecision::retry_next_host(cl); } - virtual RetryDecision on_unavailable(const cass::Request* request, - CassConsistency cl, - int required, - int alive, + virtual RetryDecision on_unavailable(const datastax::internal::core::Request* request, + CassConsistency cl, int required, int alive, int num_retries) const { return RetryDecision::retry_next_host(cl); } - virtual RetryDecision on_request_error(const cass::Request* request, + virtual RetryDecision on_request_error(const datastax::internal::core::Request* request, CassConsistency cl, - const cass::ErrorResponse* error, + const datastax::internal::core::ErrorResponse* error, int num_retries) const { return RetryDecision::retry_next_host(cl); } }; -} // namespace driver -} // namespace test +}} // namespace test::driver #endif // __NEXT_HOST_RETRY_POLICY_HPP__ diff --git a/gtests/src/integration/rest_client.cpp b/gtests/src/integration/rest_client.cpp index a50a2febb..2e36de389 100644 --- a/gtests/src/integration/rest_client.cpp +++ b/gtests/src/integration/rest_client.cpp @@ -25,6 +25,8 @@ #define HTTP_EOL "\r\n" #define OUTPUT_BUFFER_SIZE 10240ul +using namespace datastax::internal::core; + // Static initializations uv_buf_t RestClient::write_buf_; uv_write_t RestClient::write_req_; @@ -48,12 +50,11 @@ struct HttpRequest { }; const Response RestClient::send_request(const Request& request) { - // Initialize the loop + // Initialize the loop uv_loop_t loop; int error_code = uv_loop_init(&loop); - if(error_code != 0) { - throw Exception("Unable to Send Request: " + - std::string(uv_strerror(error_code))); + if (error_code != 0) { + throw Exception("Unable to Send Request: " + std::string(uv_strerror(error_code))); }; // Initialize the HTTP request @@ -62,40 +63,33 @@ const Response RestClient::send_request(const Request& request) { http_request.loop = &loop; // Create the IPv4 socket address - const cass::Address address(request.address.c_str(), - static_cast(request.port)); + const Address address(request.address.c_str(), static_cast(request.port)); // Initialize the client TCP request uv_tcp_t tcp; tcp.data = &http_request; error_code = uv_tcp_init(&loop, &tcp); if (error_code != 0) { - TEST_LOG_ERROR("Unable to Initialize TCP Request: " + - std::string(uv_strerror(error_code))); + TEST_LOG_ERROR("Unable to Initialize TCP Request: " + std::string(uv_strerror(error_code))); } error_code = uv_tcp_keepalive(&tcp, 1, 60); if (error_code != 0) { - TEST_LOG_ERROR("Unable to Set TCP KeepAlive: " + - std::string(uv_strerror(error_code))); + TEST_LOG_ERROR("Unable to Set TCP KeepAlive: " + std::string(uv_strerror(error_code))); } // Start the request and attach the HTTP request to send to the REST server uv_connect_t connect; connect.data = &http_request; - uv_tcp_connect(&connect, &tcp, - address.addr(), - handle_connected); + uv_tcp_connect(&connect, &tcp, address.addr(), handle_connected); - uv_run(&loop, UV_RUN_DEFAULT); - uv_loop_close(&loop); + uv_run(&loop, UV_RUN_DEFAULT); + uv_loop_close(&loop); // Return the response from the request return http_request.response; } -void RestClient::handle_allocation(uv_handle_t* handle, - size_t suggested_size, - uv_buf_t* buffer) { +void RestClient::handle_allocation(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buffer) { buffer->base = new char[OUTPUT_BUFFER_SIZE]; buffer->len = OUTPUT_BUFFER_SIZE; } @@ -104,8 +98,7 @@ void RestClient::handle_connected(uv_connect_t* req, int status) { HttpRequest* request = static_cast(req->data); if (status < 0) { - TEST_LOG_ERROR("Unable to Connect to HTTP Server: " - << uv_strerror(status)); + TEST_LOG_ERROR("Unable to Connect to HTTP Server: " << uv_strerror(status)); uv_close(reinterpret_cast(req->handle), NULL); } else { // Create the buffer to write to the stream @@ -118,8 +111,7 @@ void RestClient::handle_connected(uv_connect_t* req, int status) { } } -void RestClient::handle_response(uv_stream_t* stream, - ssize_t buffer_length, +void RestClient::handle_response(uv_stream_t* stream, ssize_t buffer_length, const uv_buf_t* buffer) { HttpRequest* request = static_cast(stream->data); @@ -170,12 +162,10 @@ const std::string RestClient::generate_http_message(const Request& request) { // Generate the headers bool is_post = request.method == Request::HTTP_METHOD_POST; - message - << "Host: " << request.address << ":" << request.port << HTTP_EOL - << (is_post ? "Content-Type: application/json" HTTP_EOL : "") - << "Content-Length: "<< ((is_post) ? request.content.size() : 0) << HTTP_EOL - << "Connection: close" << HTTP_EOL << HTTP_EOL - << (is_post ? request.content : ""); + message << "Host: " << request.address << ":" << request.port << HTTP_EOL + << (is_post ? "Content-Type: application/json" HTTP_EOL : "") + << "Content-Length: " << ((is_post) ? request.content.size() : 0) << HTTP_EOL + << "Connection: close" << HTTP_EOL << HTTP_EOL << (is_post ? request.content : ""); // Return the HTTP message TEST_LOG("[HTTP Message]: " << message.str()); diff --git a/gtests/src/integration/rest_client.hpp b/gtests/src/integration/rest_client.hpp index 99a18b165..76638818b 100644 --- a/gtests/src/integration/rest_client.hpp +++ b/gtests/src/integration/rest_client.hpp @@ -30,11 +30,7 @@ struct Request { /** * HTTP request method */ - enum Method { - HTTP_METHOD_DELETE = 0, - HTTP_METHOD_GET, - HTTP_METHOD_POST - }; + enum Method { HTTP_METHOD_DELETE = 0, HTTP_METHOD_GET, HTTP_METHOD_POST }; /** * Host address IPv4 @@ -72,7 +68,7 @@ struct Response { int status_code; Response() - : status_code(200 /* OK */) { } + : status_code(200 /* OK */) {} }; /** @@ -84,7 +80,7 @@ class RestClient { class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) { } + : test::Exception(message) {} }; /** @@ -117,8 +113,7 @@ class RestClient { * @param suggested_size The size (in bytes) to allocate for the buffer * @param buf Buffer to be allocated */ - static void handle_allocation(uv_handle_t* handle, size_t suggested_size, - uv_buf_t* buffer); + static void handle_allocation(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buffer); /** * Handle the connect (callback) when the connection has been established to @@ -138,9 +133,7 @@ class RestClient { * will equal UV_EOF * @param buf Buffer to read from */ - static void handle_response(uv_stream_t* stream, - ssize_t nread, - const uv_buf_t* buf); + static void handle_response(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf); /** * Generate the HTTP message for the REST request. @@ -149,7 +142,6 @@ class RestClient { * @return String representing the REST request HTTP message */ static const std::string generate_http_message(const Request& request); - }; #endif // __TEST_REST_CLIENT_HPP__ diff --git a/gtests/src/integration/shared_ptr.hpp b/gtests/src/integration/shared_ptr.hpp index 7174bf2f2..50aefd106 100644 --- a/gtests/src/integration/shared_ptr.hpp +++ b/gtests/src/integration/shared_ptr.hpp @@ -16,8 +16,8 @@ #ifndef __SHARED_PTR_HPP__ #define __SHARED_PTR_HPP__ -#include "scoped_ptr.hpp" #include "ref_counted.hpp" +#include "scoped_ptr.hpp" template struct StdDeleter { @@ -27,24 +27,20 @@ struct StdDeleter { /** * Reference counted objects container */ -template > -class ObjectRef : public cass::RefCounted< ObjectRef > { +template > +class ObjectRef : public datastax::internal::RefCounted > { public: ObjectRef(T* ptr) - : ptr_(ptr) {} + : ptr_(ptr) {} - virtual ~ObjectRef() { - D()(ptr_); - } + virtual ~ObjectRef() { D()(ptr_); } /** * Get the native object * * @return The native object */ - T* get() { - return ptr_; - } + T* get() { return ptr_; } private: /** @@ -56,28 +52,22 @@ class ObjectRef : public cass::RefCounted< ObjectRef > { /** * Shared pointer for object references */ -template > +template > class SharedPtr { public: SharedPtr(T* ptr = NULL) - : object_(NULL) { + : object_(NULL) { if (ptr) { ObjectRef* object_ref = new ObjectRef(ptr); - object_ = cass::SharedRefPtr >(object_ref); + object_ = datastax::internal::SharedRefPtr >(object_ref); } } - T* operator->() { - return get(); - } + T* operator->() { return get(); } - T& operator*() { - return *get(); - } + T& operator*() { return *get(); } - operator bool() const { - return object_; - } + operator bool() const { return object_; } /** * Get the native object from the object reference @@ -97,11 +87,12 @@ class SharedPtr { } return NULL; } + private: /** * Object reference */ - cass::SharedRefPtr > object_; + datastax::internal::SharedRefPtr > object_; }; #endif // __SHARED_PTR_HPP__ diff --git a/gtests/src/integration/simulacron/priming_requests.hpp b/gtests/src/integration/simulacron/priming_requests.hpp index 9ab1716ee..f5bb950ba 100644 --- a/gtests/src/integration/simulacron/priming_requests.hpp +++ b/gtests/src/integration/simulacron/priming_requests.hpp @@ -35,11 +35,11 @@ class Request { class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) { } + : test::Exception(message) {} }; Request() - : then_(new Success()) { }; + : then_(new Success()){}; /** * Generate the JSON for the priming request @@ -80,8 +80,7 @@ class Request { * @param consistency Consistency levels for the request * @return PrimingRequest instance */ - Request& with_consistencies( - const std::vector& consistency) { + Request& with_consistencies(const std::vector& consistency) { when_.with_consistencies(consistency); return *this; } @@ -98,11 +97,11 @@ class Request { } /** - * Set a response for the request - * - * @param result Response to the request - * @return PrimingRequest instance - */ + * Set a response for the request + * + * @param result Response to the request + * @return PrimingRequest instance + */ Request& with_result(Result* result) { then_ = result; return *this; @@ -110,7 +109,8 @@ class Request { private: class When { - friend class Request; + friend class Request; + private: /** * Consistency levels @@ -121,7 +121,7 @@ class Request { */ std::string query_; - When() {}; + When(){}; /** * Build the when section for the priming request @@ -136,7 +136,7 @@ class Request { writer.Key("consistency"); writer.StartArray(); for (std::vector::iterator iterator = consistencies_.begin(); - iterator != consistencies_.end(); ++iterator) { + iterator != consistencies_.end(); ++iterator) { writer.String(cass_consistency_string(*iterator)); } writer.EndArray(); @@ -171,9 +171,7 @@ class Request { * * @param query Query for the request */ - void with_query(const std::string& query) { - query_ = query; - } + void with_query(const std::string& query) { query_ = query; } }; private: diff --git a/gtests/src/integration/simulacron/priming_rows.hpp b/gtests/src/integration/simulacron/priming_rows.hpp index 41d2d5b41..e9791b029 100644 --- a/gtests/src/integration/simulacron/priming_rows.hpp +++ b/gtests/src/integration/simulacron/priming_rows.hpp @@ -22,12 +22,12 @@ #include "cassandra.h" -#include #include +#include #include -#include #include +#include #include namespace prime { @@ -38,16 +38,17 @@ class Rows; * Priming row */ class Row { -friend class Rows; + friend class Rows; + public: class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) { } + : test::Exception(message) {} }; typedef std::pair Column; - Row() { }; + Row(){}; /** * Add a column|value pair @@ -57,22 +58,19 @@ friend class Rows; * @param value Value for the column * @return PrimingRow instance */ - Row& add_column(const std::string& name, - const CassValueType value_type, + Row& add_column(const std::string& name, const CassValueType value_type, const std::string& value) { std::string cql_type = test::Utils::scalar_cql_type(value_type); - if (value_type == CASS_VALUE_TYPE_LIST || - value_type == CASS_VALUE_TYPE_MAP || - value_type == CASS_VALUE_TYPE_SET) { - throw Exception("Value Type " + cql_type + "Needs to be Parameterized: " - "Use add_column(string name, string cql_value_type, string value) instead"); - } - - //TODO: Add types when supported by Simulacron - if (value_type == CASS_VALUE_TYPE_CUSTOM || - value_type == CASS_VALUE_TYPE_UDT) { - throw Exception("Value Type is not Supported by Simulacron: " - + cql_type); + if (value_type == CASS_VALUE_TYPE_LIST || value_type == CASS_VALUE_TYPE_MAP || + value_type == CASS_VALUE_TYPE_SET) { + throw Exception("Value Type " + cql_type + + "Needs to be Parameterized: " + "Use add_column(string name, string cql_value_type, string value) instead"); + } + + // TODO: Add types when supported by Simulacron + if (value_type == CASS_VALUE_TYPE_CUSTOM || value_type == CASS_VALUE_TYPE_UDT) { + throw Exception("Value Type is not Supported by Simulacron: " + cql_type); } return add_column(name, cql_type, value); @@ -86,10 +84,9 @@ friend class Rows; * @param value Value for the column * @return PrimingRow instance */ - Row& add_column(const std::string& name, - const std::string& cql_value_type, + Row& add_column(const std::string& name, const std::string& cql_value_type, const std::string& value) { - //TODO: Add validation (mainly for parameterized types) + // TODO: Add validation (mainly for parameterized types) // Ensure the column doesn't already exist if (columns_.find(name) != columns_.end()) { throw Exception("Unable to Add Column: Already Exists [" + name + "]"); @@ -107,13 +104,10 @@ friend class Rows; * otherwise */ bool operator==(const Row& rhs) const { - return columns_.size() == rhs.columns_.size() - && std::equal(columns_.begin(), columns_.end(), rhs.columns_.begin(), - ColumnsKeyEquality()); - } - bool operator!=(const Row& rhs) const { - return !(*this == rhs); + return columns_.size() == rhs.columns_.size() && + std::equal(columns_.begin(), columns_.end(), rhs.columns_.begin(), ColumnsKeyEquality()); } + bool operator!=(const Row& rhs) const { return !(*this == rhs); } protected: /** @@ -125,8 +119,7 @@ friend class Rows; writer.Key("column_types"); writer.StartObject(); - for (Map::iterator iterator = columns_.begin(); iterator != columns_.end(); - ++iterator) { + for (Map::iterator iterator = columns_.begin(); iterator != columns_.end(); ++iterator) { std::string name = iterator->first; std::string cql_type = iterator->second.first; writer.Key(name.c_str()); @@ -144,21 +137,19 @@ friend class Rows; void build_row(rapidjson::PrettyWriter& writer) { writer.StartObject(); - for (Map::iterator iterator = columns_.begin(); iterator != columns_.end(); - ++iterator) { + for (Map::iterator iterator = columns_.begin(); iterator != columns_.end(); ++iterator) { std::string name = iterator->first; std::string value = iterator->second.second; // Add the column|value pair writer.Key(name.c_str()); - bool is_array = value.compare(0, 1, "[") == 0 && - value.compare(value.size() - 1, 1, "]") == 0; + bool is_array = value.compare(0, 1, "[") == 0 && value.compare(value.size() - 1, 1, "]") == 0; if (is_array) { value = value.substr(1, value.size() - 2); writer.StartArray(); std::vector values = test::Utils::explode(value, ','); - for (std::vector::iterator iterator = values.begin(); - iterator != values.end(); ++iterator) { + for (std::vector::iterator iterator = values.begin(); iterator != values.end(); + ++iterator) { writer.String((*iterator).c_str()); } writer.EndArray(); @@ -200,15 +191,16 @@ friend class Rows; * Priming rows */ class Rows { -friend class Success; + friend class Success; + public: class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) { } + : test::Exception(message) {} }; - Rows() { }; + Rows(){}; /** * Add a row @@ -219,8 +211,7 @@ friend class Success; */ Rows& add_row(const Row& columns) { if (!rows_.empty() && rows_.front() != columns) { - throw Exception( - "Unable to Add Row: Columns are incompatible with previous row(s)"); + throw Exception("Unable to Add Row: Columns are incompatible with previous row(s)"); } rows_.push_back(columns); return *this; @@ -231,9 +222,7 @@ friend class Success; * * @return True if rows are empty; false otherwise */ - bool empty() const { - return rows_.empty(); - } + bool empty() const { return rows_.empty(); } protected: /** @@ -254,8 +243,7 @@ friend class Success; // Iterate over the rows and add each row to the rows object array rows.Key("rows"); rows.StartArray(); - for (std::vector::iterator iterator = rows_.begin(); - iterator != rows_.end(); ++iterator) { + for (std::vector::iterator iterator = rows_.begin(); iterator != rows_.end(); ++iterator) { iterator->build_row(rows); } rows.EndArray(); diff --git a/gtests/src/integration/simulacron/results/close_connection.hpp b/gtests/src/integration/simulacron/results/close_connection.hpp index 1182baaa6..52305e0ff 100644 --- a/gtests/src/integration/simulacron/results/close_connection.hpp +++ b/gtests/src/integration/simulacron/results/close_connection.hpp @@ -26,11 +26,7 @@ /** * Enumeration for 'close_type' property */ -enum CloseType { - CLOSE_TYPE_DISCONNECT, - CLOSE_TYPE_SHUTDOWN_READ, - CLOSE_TYPE_SHUTDOWN_WRITE -}; +enum CloseType { CLOSE_TYPE_DISCONNECT, CLOSE_TYPE_SHUTDOWN_READ, CLOSE_TYPE_SHUTDOWN_WRITE }; /** * Enumeration for disconnect 'scope' property @@ -55,13 +51,13 @@ class CloseConnection : public Result { class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) { } + : test::Exception(message) {} }; CloseConnection() - : Result("close_connection") - , close_type_(CLOSE_TYPE_DISCONNECT) - , scope_(DISCONNECT_SCOPE_CONNECTION) { } + : Result("close_connection") + , close_type_(CLOSE_TYPE_DISCONNECT) + , scope_(DISCONNECT_SCOPE_CONNECTION) {} /** * Fully construct the 'close_connection' result @@ -71,12 +67,10 @@ class CloseConnection : public Result { * @param scope The scope (connection, node, data center, cluster) at which to * close the associated connection(s) */ - CloseConnection(unsigned long delay_in_ms, - CloseType close_type, - DisconnectScope scope) - : Result("close_connection", delay_in_ms) - , close_type_(close_type) - , scope_(scope) { } + CloseConnection(unsigned long delay_in_ms, CloseType close_type, DisconnectScope scope) + : Result("close_connection", delay_in_ms) + , close_type_(close_type) + , scope_(scope) {} /** * Set a fixed delay to the response time of a result @@ -135,7 +129,7 @@ class CloseConnection : public Result { * @return String representation of the close type property */ std::string get_close_type(CloseType type) const { - switch(type) { + switch (type) { case CLOSE_TYPE_DISCONNECT: return "disconnect"; case CLOSE_TYPE_SHUTDOWN_READ: @@ -144,11 +138,10 @@ class CloseConnection : public Result { return "shutdown_write"; default: std::stringstream message; - message << "Unsupported Close Type: " << type - << " will need to be added"; + message << "Unsupported Close Type: " << type << " will need to be added"; throw Exception(message.str()); break; - } + } } /** @@ -158,7 +151,7 @@ class CloseConnection : public Result { * @return String representation of the disconnect scope property */ std::string get_disconnect_scope(DisconnectScope disconnect_scope) const { - switch(disconnect_scope) { + switch (disconnect_scope) { case DISCONNECT_SCOPE_CONNECTION: return "connection"; case DISCONNECT_SCOPE_NODE: @@ -169,11 +162,10 @@ class CloseConnection : public Result { return "cluster"; default: std::stringstream message; - message << "Unsupported Disconnect Scope: " << disconnect_scope - << " will need to be added"; + message << "Unsupported Disconnect Scope: " << disconnect_scope << " will need to be added"; throw Exception(message.str()); break; - } + } } private: diff --git a/gtests/src/integration/simulacron/results/result.hpp b/gtests/src/integration/simulacron/results/result.hpp index f5380ec42..ba303c7df 100644 --- a/gtests/src/integration/simulacron/results/result.hpp +++ b/gtests/src/integration/simulacron/results/result.hpp @@ -19,8 +19,8 @@ #include -#include #include +#include namespace prime { @@ -29,7 +29,7 @@ namespace prime { */ class Result { public: - virtual ~Result() { } + virtual ~Result() {} /** * Generate the JSON for the base result @@ -55,8 +55,8 @@ class Result { * @param result String value for the JSON result value */ Result(const std::string& result) - : delay_in_ms_(0) - , result_(result) { } + : delay_in_ms_(0) + , result_(result) {} /** * Protected constructor for base result type @@ -65,8 +65,8 @@ class Result { * @param delay_in_ms Delay in milliseconds before forwarding result */ Result(const std::string& result, unsigned long delay_in_ms) - : delay_in_ms_(delay_in_ms) - , result_(result) { } + : delay_in_ms_(delay_in_ms) + , result_(result) {} private: /** diff --git a/gtests/src/integration/simulacron/results/success.hpp b/gtests/src/integration/simulacron/results/success.hpp index 85f3e4584..891e7eae8 100644 --- a/gtests/src/integration/simulacron/results/success.hpp +++ b/gtests/src/integration/simulacron/results/success.hpp @@ -41,11 +41,11 @@ class Row { class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) { } + : test::Exception(message) {} }; typedef std::pair Column; - Row() { } + Row() {} /** * Add a column|value pair @@ -55,22 +55,19 @@ class Row { * @param value Value for the column * @return PrimingRow instance */ - Row& add_column(const std::string& name, - const CassValueType value_type, + Row& add_column(const std::string& name, const CassValueType value_type, const std::string& value) { std::string cql_type = test::Utils::scalar_cql_type(value_type); - if (value_type == CASS_VALUE_TYPE_LIST || - value_type == CASS_VALUE_TYPE_MAP || - value_type == CASS_VALUE_TYPE_SET) { - throw Exception("Value Type " + cql_type + "Needs to be Parameterized: " - "Use add_column(string name, string cql_value_type, string value) instead"); - } - - //TODO: Add types when supported by Simulacron - if (value_type == CASS_VALUE_TYPE_CUSTOM || - value_type == CASS_VALUE_TYPE_UDT) { - throw Exception("Value Type is not Supported by Simulacron: " - + cql_type); + if (value_type == CASS_VALUE_TYPE_LIST || value_type == CASS_VALUE_TYPE_MAP || + value_type == CASS_VALUE_TYPE_SET) { + throw Exception("Value Type " + cql_type + + "Needs to be Parameterized: " + "Use add_column(string name, string cql_value_type, string value) instead"); + } + + // TODO: Add types when supported by Simulacron + if (value_type == CASS_VALUE_TYPE_CUSTOM || value_type == CASS_VALUE_TYPE_UDT) { + throw Exception("Value Type is not Supported by Simulacron: " + cql_type); } return add_column(name, cql_type, value); @@ -84,10 +81,9 @@ class Row { * @param value Value for the column * @return PrimingRow instance */ - Row& add_column(const std::string& name, - const std::string& cql_value_type, + Row& add_column(const std::string& name, const std::string& cql_value_type, const std::string& value) { - //TODO: Add validation (mainly for parameterized types) + // TODO: Add validation (mainly for parameterized types) // Ensure the column doesn't already exist if (columns_.find(name) != columns_.end()) { throw Exception("Unable to Add Column: Already Exists [" + name + "]"); @@ -105,15 +101,10 @@ class Row { * otherwise */ bool operator==(const Row& rhs) const { - return columns_.size() == rhs.columns_.size() - && std::equal(columns_.begin(), - columns_.end(), - rhs.columns_.begin(), - ColumnsKeyEquality()); - } - bool operator!=(const Row& rhs) const { - return !(*this == rhs); + return columns_.size() == rhs.columns_.size() && + std::equal(columns_.begin(), columns_.end(), rhs.columns_.begin(), ColumnsKeyEquality()); } + bool operator!=(const Row& rhs) const { return !(*this == rhs); } /** * Build the column types for the column used by the row @@ -124,8 +115,7 @@ class Row { writer.Key("column_types"); writer.StartObject(); - for (Map::const_iterator iterator = columns_.begin(); iterator != columns_.end(); - ++iterator) { + for (Map::const_iterator iterator = columns_.begin(); iterator != columns_.end(); ++iterator) { std::string name = iterator->first; std::string cql_type = iterator->second.first; writer.Key(name.c_str()); @@ -143,21 +133,19 @@ class Row { void build_row(rapidjson::PrettyWriter& writer) const { writer.StartObject(); - for (Map::const_iterator iterator = columns_.begin(); iterator != columns_.end(); - ++iterator) { + for (Map::const_iterator iterator = columns_.begin(); iterator != columns_.end(); ++iterator) { std::string name = iterator->first; std::string value = iterator->second.second; // Add the column|value pair writer.Key(name.c_str()); - bool is_array = value.compare(0, 1, "[") == 0 && - value.compare(value.size() - 1, 1, "]") == 0; + bool is_array = value.compare(0, 1, "[") == 0 && value.compare(value.size() - 1, 1, "]") == 0; if (is_array) { value = value.substr(1, value.size() - 2); writer.StartArray(); std::vector values = test::Utils::explode(value, ','); - for (std::vector::iterator iterator = values.begin(); - iterator != values.end(); ++iterator) { + for (std::vector::iterator iterator = values.begin(); iterator != values.end(); + ++iterator) { writer.String((*iterator).c_str()); } writer.EndArray(); @@ -204,10 +192,10 @@ class Rows { class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) {} + : test::Exception(message) {} }; - Rows() { } + Rows() {} /** * Add a row @@ -218,8 +206,7 @@ class Rows { */ Rows& add_row(const Row& columns) { if (!rows_.empty() && rows_.front() != columns) { - throw Exception( - "Unable to Add Row: Columns are incompatible with previous row(s)"); + throw Exception("Unable to Add Row: Columns are incompatible with previous row(s)"); } rows_.push_back(columns); return *this; @@ -230,9 +217,7 @@ class Rows { * * @return True if rows are empty; false otherwise */ - bool empty() const { - return rows_.empty(); - } + bool empty() const { return rows_.empty(); } /** * Build the column types for the column used by the rows @@ -251,8 +236,8 @@ class Rows { void build_rows(rapidjson::PrettyWriter& rows) const { rows.Key("rows"); rows.StartArray(); - for (std::vector::const_iterator iterator = rows_.begin(); - iterator != rows_.end(); ++iterator) { + for (std::vector::const_iterator iterator = rows_.begin(); iterator != rows_.end(); + ++iterator) { iterator->build_row(rows); } rows.EndArray(); @@ -271,7 +256,7 @@ class Rows { class Success : public Result { public: Success() - : Result("success") { } + : Result("success") {} /** * Fully construct the 'success' result @@ -279,10 +264,9 @@ class Success : public Result { * @param delay_in_ms Delay in milliseconds before forwarding result * @param rows Rows to return when responding to the request */ - Success(unsigned long delay_in_ms, - const Rows& rows) - : Result("success", delay_in_ms) - , rows_(rows) { } + Success(unsigned long delay_in_ms, const Rows& rows) + : Result("success", delay_in_ms) + , rows_(rows) {} /** * Set a fixed delay to the response time of a result diff --git a/gtests/src/integration/simulacron/results/write_timeout.hpp b/gtests/src/integration/simulacron/results/write_timeout.hpp index a899d2df1..4509aaec7 100644 --- a/gtests/src/integration/simulacron/results/write_timeout.hpp +++ b/gtests/src/integration/simulacron/results/write_timeout.hpp @@ -23,7 +23,6 @@ #include "cassandra.h" - namespace prime { /** @@ -32,11 +31,11 @@ namespace prime { class WriteTimeout : public Result { public: WriteTimeout() - : Result("write_timeout") - , consistency_(CASS_CONSISTENCY_LOCAL_ONE) - , received_responses_(0) - , required_responses_(1) - , write_type_(CASS_WRITE_TYPE_SIMPLE) { } + : Result("write_timeout") + , consistency_(CASS_CONSISTENCY_LOCAL_ONE) + , received_responses_(0) + , required_responses_(1) + , write_type_(CASS_WRITE_TYPE_SIMPLE) {} /** * Fully construct the 'write_timeout' result @@ -47,16 +46,14 @@ class WriteTimeout : public Result { * @param required_responses Number of responses required from replicas * @param write_type The type of write that resulted in write timeout */ - WriteTimeout(unsigned long delay_in_ms, - CassConsistency consistency, - unsigned int received_responses, - unsigned int required_responses, + WriteTimeout(unsigned long delay_in_ms, CassConsistency consistency, + unsigned int received_responses, unsigned int required_responses, CassWriteType write_type) - : Result("write_timeout", delay_in_ms) - , consistency_(consistency) - , received_responses_(received_responses) - , required_responses_(required_responses) - , write_type_(write_type) { } + : Result("write_timeout", delay_in_ms) + , consistency_(consistency) + , received_responses_(received_responses) + , required_responses_(required_responses) + , write_type_(write_type) {} /** * Set a fixed delay to the response time of a result diff --git a/gtests/src/integration/simulacron/simulacron_cluster.cpp b/gtests/src/integration/simulacron/simulacron_cluster.cpp index 24c0dcbaa..31632dc52 100644 --- a/gtests/src/integration/simulacron/simulacron_cluster.cpp +++ b/gtests/src/integration/simulacron/simulacron_cluster.cpp @@ -19,10 +19,10 @@ #include "test_utils.hpp" #include "tlog.hpp" +#include "objects/uuid_gen.hpp" #include "scoped_lock.hpp" #include "tsocket.hpp" #include "values/uuid.hpp" -#include "objects/uuid_gen.hpp" #include #include @@ -35,10 +35,12 @@ #define OUTPUT_BUFFER_SIZE 10240ul #define SIMULACRON_NAP 100 #define SIMULACRON_CONNECTION_RETRIES 600 // Up to 60 seconds for retry based on SIMULACRON_NAP -#define SIMULACRON_PROCESS_RETRIS 100 // Up to 10 seconds for retry based on SIMULACRON_NAP +#define SIMULACRON_PROCESS_RETRIS 100 // Up to 10 seconds for retry based on SIMULACRON_NAP #define MAX_TOKEN static_cast(INT64_MAX) - 1 #define DATA_CENTER_PREFIX "dc" +using datastax::internal::ScopedMutex; + // Initialize the mutex, running status, thread, and default data center nodes uv_mutex_t test::SimulacronCluster::mutex_; bool test::SimulacronCluster::is_ready_ = false; @@ -46,21 +48,19 @@ bool test::SimulacronCluster::is_running_ = false; uv_thread_t test::SimulacronCluster::thread_; const unsigned int DEFAULT_NODE[] = { 1 }; const std::vector test::SimulacronCluster::DEFAULT_DATA_CENTER_NODES( - DEFAULT_NODE, DEFAULT_NODE + sizeof(DEFAULT_NODE) / sizeof(DEFAULT_NODE[0])); + DEFAULT_NODE, DEFAULT_NODE + sizeof(DEFAULT_NODE) / sizeof(DEFAULT_NODE[0])); test::SimulacronCluster::SimulacronCluster() - : dse_version_("") - , cassandra_version_("") - , current_cluster_id_(-1) -{ + : dse_version_("") + , cassandra_version_("") + , current_cluster_id_(-1) { // Initialize the mutex uv_mutex_init(&mutex_); // Determine if Simulacron file exists if (!test::Utils::file_exists(SIMULACRON_SERVER_JAR)) { std::stringstream message; - message << "Unable to find Simulacron JAR file [" - << SIMULACRON_SERVER_JAR << "]"; + message << "Unable to find Simulacron JAR file [" << SIMULACRON_SERVER_JAR << "]"; throw Exception(message.str()); } @@ -72,11 +72,9 @@ test::SimulacronCluster::SimulacronCluster() if (cassandra_version == "0.0.0") { throw Exception("Unable to determine Cassandra version from DSE version"); } - dse_version_ = test::Utils::replace_all(dse_version.to_string(), "-", - "."); + dse_version_ = test::Utils::replace_all(dse_version.to_string(), "-", "."); } - cassandra_version_ = test::Utils::replace_all(cassandra_version.to_string(), - "-", "."); + cassandra_version_ = test::Utils::replace_all(cassandra_version.to_string(), "-", "."); // Create Simulacron process (threaded) and wait for completely availability uv_thread_create(&thread_, handle_thread_create, NULL); @@ -91,17 +89,15 @@ test::SimulacronCluster::SimulacronCluster() test::Utils::wait_for_port(SIMULACRON_LISTEN_ADDRESS, SIMULACRON_ADMIN_PORT); } -test::SimulacronCluster::~SimulacronCluster() { - remove_cluster(); -} +test::SimulacronCluster::~SimulacronCluster() { remove_cluster(); } std::string test::SimulacronCluster::cluster_contact_points(bool is_all /*= true*/) { // Iterate over each node and collect the list of active contact points std::vector cluster_nodes = nodes(); size_t index = 1; std::stringstream contact_points; - for (std::vector::iterator it = - cluster_nodes.begin(); it != cluster_nodes.end(); ++it) { + for (std::vector::iterator it = cluster_nodes.begin(); + it != cluster_nodes.end(); ++it) { if (is_all || is_node_up(index++)) { if (!contact_points.str().empty()) { contact_points << ","; @@ -112,16 +108,16 @@ std::string test::SimulacronCluster::cluster_contact_points(bool is_all /*= true return contact_points.str(); } -void test::SimulacronCluster::create_cluster(const std::vector& data_center_nodes /*= DEFAULT_DATA_CENTER_NODES*/, - bool with_vnodes /*= false */) { +void test::SimulacronCluster::create_cluster( + const std::vector& data_center_nodes /*= DEFAULT_DATA_CENTER_NODES*/, + bool with_vnodes /*= false */) { std::stringstream paramters; std::stringstream cluster_name; cluster_name << DEFAULT_CLUSTER_PREFIX << "_"; // Add the data centers, Cassandra version, and token/vnodes parameters - paramters << "data_centers=" - << test::Utils::implode(data_center_nodes, ',') - << "&cassandra_version=" << cassandra_version_; + paramters << "data_centers=" << test::Utils::implode(data_center_nodes, ',') + << "&cassandra_version=" << cassandra_version_; // Update the cluster configuration (set num_tokens) if (with_vnodes) { // Maximum number of tokens is 1536 @@ -139,8 +135,7 @@ void test::SimulacronCluster::create_cluster(const std::vector& da } // Add the cluster name - cluster_name << "_" - << test::Utils::implode(data_center_nodes, '-'); + cluster_name << "_" << test::Utils::implode(data_center_nodes, '-'); if (with_vnodes) { cluster_name << "-vnodes"; } @@ -155,8 +150,8 @@ void test::SimulacronCluster::create_cluster(const std::vector& da } void test::SimulacronCluster::create_cluster(unsigned int data_center_one_nodes, - unsigned int data_center_two_nodes /*= 0*/, - bool with_vnodes /*=false */) { + unsigned int data_center_two_nodes /*= 0*/, + bool with_vnodes /*=false */) { std::vector data_center_nodes; if (data_center_one_nodes > 0) { data_center_nodes.push_back(data_center_one_nodes); @@ -167,9 +162,7 @@ void test::SimulacronCluster::create_cluster(unsigned int data_center_one_nodes, create_cluster(data_center_nodes, with_vnodes); } -void test::SimulacronCluster::remove_cluster() { - send_delete("cluster"); -} +void test::SimulacronCluster::remove_cluster() { send_delete("cluster"); } std::string test::SimulacronCluster::get_ip_address(unsigned int node) { std::vector current_nodes = nodes(); @@ -186,9 +179,8 @@ bool test::SimulacronCluster::is_node_down(unsigned int node) { if (!is_node_available(node)) { return true; } else { - TEST_LOG("Connected to Node " << node - << " in Cluster: Rechecking node down status [" - << number_of_retries << "]"); + TEST_LOG("Connected to Node " << node << " in Cluster: Rechecking node down status [" + << number_of_retries << "]"); test::Utils::msleep(SIMULACRON_NAP); } } @@ -204,9 +196,8 @@ bool test::SimulacronCluster::is_node_up(unsigned int node) { if (is_node_available(node)) { return true; } else { - TEST_LOG("Unable to Connect to Node " << node - << " in Cluster: Rechecking node up status [" - << number_of_retries << "]"); + TEST_LOG("Unable to Connect to Node " << node << " in Cluster: Rechecking node up status [" + << number_of_retries << "]"); test::Utils::msleep(SIMULACRON_NAP); } } @@ -233,14 +224,13 @@ std::vector test::SimulacronCluste return current_cluster.data_centers; } -std::vector -test::SimulacronCluster::nodes() { +std::vector test::SimulacronCluster::nodes() { // Get the cluster object and retrieve the nodes from the data center(s) Cluster current_cluster = cluster(); std::vector nodes; std::vector data_centers = current_cluster.data_centers; - for (std::vector::iterator it = - data_centers.begin(); it != data_centers.end(); ++it) { + for (std::vector::iterator it = data_centers.begin(); + it != data_centers.end(); ++it) { std::vector dc_nodes = it->nodes; nodes.insert(nodes.end(), dc_nodes.begin(), dc_nodes.end()); } @@ -255,12 +245,9 @@ unsigned int test::SimulacronCluster::active_connections(unsigned int node) { return 0; } -unsigned int test::SimulacronCluster::active_connections() { - return cluster().active_connections; -} +unsigned int test::SimulacronCluster::active_connections() { return cluster().active_connections; } -void test::SimulacronCluster::prime_query(prime::Request& request, - unsigned int node /*= 0*/) { +void test::SimulacronCluster::prime_query(prime::Request& request, unsigned int node /*= 0*/) { std::stringstream endpoint; endpoint << "prime/" << current_cluster_id_ << generate_node_endpoint(node); send_post(endpoint.str(), request.json()); @@ -272,18 +259,16 @@ void test::SimulacronCluster::remove_primed_queries(unsigned int node /*= 0*/) { send_delete(endpoint.str()); } -void test::SimulacronCluster::handle_exit(uv_process_t* process, - int64_t error_code, +void test::SimulacronCluster::handle_exit(uv_process_t* process, int64_t error_code, int term_signal) { - cass::ScopedMutex lock(&mutex_); + ScopedMutex lock(&mutex_); TEST_LOG("Process " << process->pid << " Terminated: " << error_code); uv_close(reinterpret_cast(process), NULL); } -void test::SimulacronCluster::handle_allocation(uv_handle_t* handle, - size_t suggested_size, +void test::SimulacronCluster::handle_allocation(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buffer) { - cass::ScopedMutex lock(&mutex_); + ScopedMutex lock(&mutex_); buffer->base = new char[OUTPUT_BUFFER_SIZE]; buffer->len = OUTPUT_BUFFER_SIZE; } @@ -291,9 +276,9 @@ void test::SimulacronCluster::handle_allocation(uv_handle_t* handle, void test::SimulacronCluster::handle_thread_create(void* arg) { // Initialize the loop and process arguments uv_loop_t loop; - if(uv_loop_init(&loop) != 0) { - throw Exception("Unable to Create Simulacron Process: libuv loop " \ - "initialization failed"); + if (uv_loop_init(&loop) != 0) { + throw Exception("Unable to Create Simulacron Process: libuv loop " + "initialization failed"); }; uv_process_options_t options; memset(&options, 0, sizeof(uv_process_options_t)); @@ -308,9 +293,9 @@ void test::SimulacronCluster::handle_thread_create(void* arg) { options.stdio = stdio; options.stdio[0].flags = UV_IGNORE; options.stdio[1].flags = static_cast(UV_CREATE_PIPE | UV_WRITABLE_PIPE); - options.stdio[1].data.stream = (uv_stream_t*) &standard_output; + options.stdio[1].data.stream = (uv_stream_t*)&standard_output; options.stdio[2].flags = static_cast(UV_CREATE_PIPE | UV_WRITABLE_PIPE); - options.stdio[2].data.stream = (uv_stream_t*) &error_output; + options.stdio[2].data.stream = (uv_stream_t*)&error_output; // Generate the spawn command for use with uv_spawn const char* spawn_command[7]; @@ -331,14 +316,11 @@ void test::SimulacronCluster::handle_thread_create(void* arg) { uv_process_t process; int error_code = uv_spawn(&loop, &process, &options); if (error_code == 0) { - TEST_LOG("Launched " << spawn_command[0] << " with ID " - << process.pid); + TEST_LOG("Launched " << spawn_command[0] << " with ID " << process.pid); // Start the output thread loops - uv_read_start(reinterpret_cast(&standard_output), - handle_allocation, handle_read); - uv_read_start(reinterpret_cast(&error_output), - handle_allocation, handle_read); + uv_read_start(reinterpret_cast(&standard_output), handle_allocation, handle_read); + uv_read_start(reinterpret_cast(&error_output), handle_allocation, handle_read); // Start the process loop is_running_ = true; @@ -350,9 +332,9 @@ void test::SimulacronCluster::handle_thread_create(void* arg) { } } -void test::SimulacronCluster::handle_read(uv_stream_t* stream, - ssize_t buffer_length, const uv_buf_t* buffer) { - cass::ScopedMutex lock(&mutex_); +void test::SimulacronCluster::handle_read(uv_stream_t* stream, ssize_t buffer_length, + const uv_buf_t* buffer) { + ScopedMutex lock(&mutex_); if (buffer_length > 0) { // Process the buffer and log it std::string message(buffer->base, buffer_length); @@ -375,39 +357,36 @@ void test::SimulacronCluster::send_delete(const std::string& endpoint) { if (response.status_code != 202) { std::stringstream message; message << "DELETE Operation " << endpoint - << " did not Complete Successfully: " << response.status_code; + << " did not Complete Successfully: " << response.status_code; throw Exception(message.str()); } } -const std::string test::SimulacronCluster::send_get( - const std::string& endpoint) { +const std::string test::SimulacronCluster::send_get(const std::string& endpoint) { Response response = send_request(Request::HTTP_METHOD_GET, endpoint); if (response.status_code != 200) { std::stringstream message; message << "GET Operation " << endpoint - << " did not Complete Successfully: " << response.status_code; + << " did not Complete Successfully: " << response.status_code; throw Exception(message.str()); } return response.message; } -const std::string test::SimulacronCluster::send_post( - const std::string& endpoint, const std::string& content /*= ""*/) { - Response response = send_request(Request::HTTP_METHOD_POST, endpoint, - content); +const std::string test::SimulacronCluster::send_post(const std::string& endpoint, + const std::string& content /*= ""*/) { + Response response = send_request(Request::HTTP_METHOD_POST, endpoint, content); if (response.status_code != 201) { std::stringstream message; message << "POST Operation " << endpoint - << " did not Complete Successfully: " << response.status_code; + << " did not Complete Successfully: " << response.status_code; throw Exception(message.str()); } return response.message; } -Response test::SimulacronCluster::send_request(Request::Method method, - const std::string& endpoint, - const std::string& content /*= ""*/) { +Response test::SimulacronCluster::send_request(Request::Method method, const std::string& endpoint, + const std::string& content /*= ""*/) { // Create and send the request to the REST server Request request; request.method = method; @@ -425,8 +404,7 @@ bool test::SimulacronCluster::is_node_available(unsigned int node) { std::vector cluster_nodes = nodes(); if (node > cluster_nodes.size()) { std::stringstream message; - message << "Unable to Check Availability of Node: Node " << node - << " is not a valid node"; + message << "Unable to Check Availability of Node: Node " << node << " is not a valid node"; throw test::Exception(message.str()); } @@ -438,7 +416,7 @@ bool test::SimulacronCluster::is_node_available(unsigned int node) { } bool test::SimulacronCluster::is_node_available(const std::string& ip_address, - unsigned short port) { + unsigned short port) { Socket socket; try { socket.establish_connection(ip_address, port); @@ -457,12 +435,11 @@ const std::string test::SimulacronCluster::generate_node_endpoint(unsigned int n std::vector current_nodes = nodes(); if (node > current_nodes.size()) { std::stringstream message; - message << "Insufficient Nodes in Cluster: Cluster contains " - << current_nodes.size() << "; " << node << " is invalid"; + message << "Insufficient Nodes in Cluster: Cluster contains " << current_nodes.size() << "; " + << node << " is invalid"; throw Exception(message.str()); } - endpoint << "/" << current_nodes[node - 1].data_center_id << "/" - << current_nodes[node - 1].id; + endpoint << "/" << current_nodes[node - 1].data_center_id << "/" << current_nodes[node - 1].id; } return endpoint.str(); } diff --git a/gtests/src/integration/simulacron/simulacron_cluster.hpp b/gtests/src/integration/simulacron/simulacron_cluster.hpp index 9dd06904f..3a8ac4708 100644 --- a/gtests/src/integration/simulacron/simulacron_cluster.hpp +++ b/gtests/src/integration/simulacron/simulacron_cluster.hpp @@ -21,11 +21,11 @@ #ifdef USE_SIMULACRON_SERVER #include "exception.hpp" #include "priming_requests.hpp" -#include "shared_ptr.hpp" #include "rest_client.hpp" +#include "shared_ptr.hpp" #ifdef _CRT_SECURE_NO_WARNINGS -# undef _CRT_SECURE_NO_WARNINGS +#undef _CRT_SECURE_NO_WARNINGS #endif #include #include @@ -33,8 +33,8 @@ #include #include #include -#include #include +#include #include namespace test { @@ -47,7 +47,7 @@ class SimulacronCluster { class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) { } + : test::Exception(message) {} }; /** @@ -59,7 +59,7 @@ class SimulacronCluster { struct PeerInfo { std::vector tokens; - PeerInfo() { }; + PeerInfo(){}; PeerInfo(const rapidjson::Value& peer_info) { if (peer_info.IsObject()) { if (peer_info.HasMember("tokens")) { @@ -83,18 +83,17 @@ class SimulacronCluster { PeerInfo peer_info; Node(const rapidjson::Value& node, unsigned int dc_id) - : data_center_id(dc_id) { + : data_center_id(dc_id) { if (node.IsObject()) { if (node.HasMember("name") && node.HasMember("id") && - node.HasMember("active_connections") && - node.HasMember("address") && node.HasMember("peer_info")) { + node.HasMember("active_connections") && node.HasMember("address") && + node.HasMember("peer_info")) { name = node["name"].GetString(); id = node["id"].GetUint(); active_connections = node["active_connections"].GetUint(); const rapidjson::Value& address = node["address"]; - std::vector tokens = test::Utils::explode( - address.GetString(), ':'); + std::vector tokens = test::Utils::explode(address.GetString(), ':'); if (tokens.size() == 2) { ip_address = tokens[0]; std::stringstream valueStream(tokens[1]); @@ -114,9 +113,7 @@ class SimulacronCluster { } } - bool operator< (const Node& rhs) const { - return id < rhs.id; - } + bool operator<(const Node& rhs) const { return id < rhs.id; } }; std::string name; @@ -127,7 +124,7 @@ class SimulacronCluster { DataCenter(const rapidjson::Value& data_center) { if (data_center.IsObject()) { if (data_center.HasMember("name") && data_center.HasMember("id") && - data_center.HasMember("active_connections")) { + data_center.HasMember("active_connections")) { name = data_center["name"].GetString(); id = data_center["id"].GetUint(); active_connections = data_center["active_connections"].GetUint(); @@ -137,8 +134,7 @@ class SimulacronCluster { if (dc_nodes.IsArray()) { for (rapidjson::SizeType i = 0; i < dc_nodes.Size(); ++i) { Node node(dc_nodes[i], id); - nodes.insert(std::lower_bound(nodes.begin(), nodes.end(), - node), node); + nodes.insert(std::lower_bound(nodes.begin(), nodes.end(), node), node); } } else { throw Exception("Nodes are not valid for the data center object"); @@ -152,9 +148,7 @@ class SimulacronCluster { } } - bool operator< (const DataCenter& rhs) const { - return id < rhs.id; - } + bool operator<(const DataCenter& rhs) const { return id < rhs.id; } }; std::string name; @@ -164,12 +158,11 @@ class SimulacronCluster { std::string dse_version; std::vector data_centers; - Cluster(const rapidjson::Document *cluster) { + Cluster(const rapidjson::Document* cluster) { if (cluster) { if (cluster->IsObject()) { if (cluster->HasMember("name") && cluster->HasMember("id") && - cluster->HasMember("active_connections") && - cluster->HasMember("data_centers")) { + cluster->HasMember("active_connections") && cluster->HasMember("data_centers")) { name = (*cluster)["name"].GetString(); id = (*cluster)["id"].GetUint(); active_connections = (*cluster)["active_connections"].GetUint(); @@ -185,12 +178,12 @@ class SimulacronCluster { if (dcs.IsArray()) { for (rapidjson::SizeType i = 0; i < dcs.Size(); ++i) { DataCenter dc(dcs[i]); - data_centers.insert(std::lower_bound(data_centers.begin(), - data_centers.end(), dc), dc); + data_centers.insert(std::lower_bound(data_centers.begin(), data_centers.end(), dc), + dc); } } else { - throw Exception("Data centers are not valid for the cluster " \ - "object"); + throw Exception("Data centers are not valid for the cluster " + "object"); } } else { throw Exception("JSON object is not a cluster object"); @@ -241,8 +234,9 @@ class SimulacronCluster { * @param with_vnode True if vnodes should be enabled; false otherwise * (default: false) */ - void create_cluster(const std::vector& data_center_nodes = DEFAULT_DATA_CENTER_NODES, - bool with_vnodes = false); + void + create_cluster(const std::vector& data_center_nodes = DEFAULT_DATA_CENTER_NODES, + bool with_vnodes = false); /** * Create the Simulacron cluster; number of nodes in data center 1 and 2 @@ -252,8 +246,7 @@ class SimulacronCluster { * @param with_vnode True if vnodes should be enabled; false otherwise * (default: false) */ - void create_cluster(unsigned int data_center_one_nodes, - unsigned int data_center_two_nodes = 0, + void create_cluster(unsigned int data_center_one_nodes, unsigned int data_center_two_nodes = 0, bool with_vnodes = false); /** @@ -383,9 +376,7 @@ class SimulacronCluster { * @param suggested_size Suggested size for the buffer * @param buffer Buffer to allocate bytes for */ - static void handle_allocation(uv_handle_t* handle, - size_t suggested_size, - uv_buf_t* buffer); + static void handle_allocation(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buffer); /** * uv_spawn callback for handling the completion of the process @@ -394,9 +385,7 @@ class SimulacronCluster { * @param error_code Error/Exit code * @param term_signal Terminating signal */ - static void handle_exit(uv_process_t* process, - int64_t error_code, - int term_signal); + static void handle_exit(uv_process_t* process, int64_t error_code, int term_signal); /** * uv_read_start callback for processing the buffer in the pipe @@ -405,9 +394,7 @@ class SimulacronCluster { * @param buffer_length Length of the buffer * @param buffer Buffer to process */ - static void handle_read(uv_stream_t* stream, - ssize_t buffer_length, - const uv_buf_t* buffer); + static void handle_read(uv_stream_t* stream, ssize_t buffer_length, const uv_buf_t* buffer); /** * uv_thread_create callback for executing the Simulacron process @@ -440,8 +427,7 @@ class SimulacronCluster { * @return REST server response * @throws SimulacronCluster::Exception If status code is not 201 */ - const std::string send_post(const std::string& endpoint, - const std::string& content = ""); + const std::string send_post(const std::string& endpoint, const std::string& content = ""); /** * Send the request to the Simulacron REST server @@ -452,8 +438,7 @@ class SimulacronCluster { * @return REST server response * @throws SimulacronCluster::Exception */ - Response send_request(Request::Method method, - const std::string& endpoint, + Response send_request(Request::Method method, const std::string& endpoint, const std::string& content = ""); /** diff --git a/gtests/src/integration/simulacron/simulacron_integration.cpp b/gtests/src/integration/simulacron/simulacron_integration.cpp index 3eec4ac56..cbb02bceb 100644 --- a/gtests/src/integration/simulacron/simulacron_integration.cpp +++ b/gtests/src/integration/simulacron/simulacron_integration.cpp @@ -24,12 +24,10 @@ SharedPtr SimulacronIntegration::sc_ = NULL; bool SimulacronIntegration::is_sc_started_ = false; SimulacronIntegration::SimulacronIntegration() - : is_sc_start_requested_(true) - , is_sc_for_test_case_(false) { -} + : is_sc_start_requested_(true) + , is_sc_for_test_case_(false) {} -SimulacronIntegration::~SimulacronIntegration() { -} +SimulacronIntegration::~SimulacronIntegration() {} void SimulacronIntegration::SetUpTestCase() { try { @@ -74,8 +72,7 @@ void SimulacronIntegration::TearDown() { } test::driver::Cluster SimulacronIntegration::default_cluster() { - return Integration::default_cluster() - .with_connection_heartbeat_interval(0); + return Integration::default_cluster().with_connection_heartbeat_interval(0); } void SimulacronIntegration::default_start_sc() { @@ -86,7 +83,9 @@ void SimulacronIntegration::default_start_sc() { start_sc(data_center_nodes); } -void SimulacronIntegration::start_sc(const std::vector& data_center_nodes /*= SimulacronCluster::DEFAULT_DATA_CENTER_NODES*/) { +void SimulacronIntegration::start_sc( + const std::vector& + data_center_nodes /*= SimulacronCluster::DEFAULT_DATA_CENTER_NODES*/) { // Ensure the SC is only started once (process handling) if (!is_sc_started_) { // Create and start the SC @@ -97,26 +96,22 @@ void SimulacronIntegration::start_sc(const std::vector& data_cente } } -test::driver::Result SimulacronIntegration::execute_mock_query( - CassConsistency consistency /*= CASS_CONSISTENCY_ONE*/) { +test::driver::Result +SimulacronIntegration::execute_mock_query(CassConsistency consistency /*= CASS_CONSISTENCY_ONE*/) { return session_.execute("mock query", consistency, false, false); } void SimulacronIntegration::prime_mock_query(unsigned int node /*= 0*/) { prime::Success success = prime::Success(); - success.with_rows(prime::Rows() - .add_row(prime::Row() - .add_column("SUCCESS", CASS_VALUE_TYPE_BOOLEAN, "TRUE"))); + success.with_rows( + prime::Rows().add_row(prime::Row().add_column("SUCCESS", CASS_VALUE_TYPE_BOOLEAN, "TRUE"))); prime_mock_query_with_result(&success, node); } - void SimulacronIntegration::prime_mock_query_with_result(prime::Result* result, unsigned int node /*= 0*/) { // Create the mock query - prime::Request mock_query = prime::Request() - .with_query("mock query") - .with_result(result); + prime::Request mock_query = prime::Request().with_query("mock query").with_result(result); // Prime the mock query with the given error sc_->prime_query(mock_query, node); diff --git a/gtests/src/integration/simulacron/simulacron_integration.hpp b/gtests/src/integration/simulacron/simulacron_integration.hpp index a48cc59a6..03b6c69ba 100644 --- a/gtests/src/integration/simulacron/simulacron_integration.hpp +++ b/gtests/src/integration/simulacron/simulacron_integration.hpp @@ -29,12 +29,12 @@ INTEGRATION_TYPED_TEST_P(simulacron, test_case, test_name) #define CHECK_SIMULACRON_AVAILABLE \ - if (!sc_) { \ - return; \ + if (!sc_) { \ + return; \ } #define SKIP_TEST_IF_SIMULACRON_UNAVAILABLE \ - if (!sc_) { \ + if (!sc_) { \ SKIP_TEST("Simulacron is unavailable"); \ } @@ -89,7 +89,8 @@ class SimulacronIntegration : public Integration { * @param data_center_nodes Data center(s) to create in the Simulacron cluster * (default: 1 data center with 1 node) */ - void start_sc(const std::vector& data_center_nodes = SimulacronCluster::DEFAULT_DATA_CENTER_NODES); + void start_sc(const std::vector& data_center_nodes = + SimulacronCluster::DEFAULT_DATA_CENTER_NODES); /** * Execute a mock query at a given consistency level @@ -102,7 +103,8 @@ class SimulacronIntegration : public Integration { * remaining nodes with a successful mock * query */ - virtual test::driver::Result execute_mock_query(CassConsistency consistency = CASS_CONSISTENCY_ONE); + virtual test::driver::Result + execute_mock_query(CassConsistency consistency = CASS_CONSISTENCY_ONE); /** * Prime the successful mock query on the given node @@ -123,8 +125,7 @@ class SimulacronIntegration : public Integration { * result will be applied to all nodes in the Simulacron cluster * (DEFAULT: 0 - Apply mock query with result to all nodes) */ - void prime_mock_query_with_result(prime::Result* result, - unsigned int node = 0); + void prime_mock_query_with_result(prime::Result* result, unsigned int node = 0); private: /** diff --git a/gtests/src/integration/strptime.cpp b/gtests/src/integration/strptime.cpp index 6389979d3..a1d28ec8c 100644 --- a/gtests/src/integration/strptime.cpp +++ b/gtests/src/integration/strptime.cpp @@ -1,8 +1,8 @@ #include "strptime.hpp" -#include #include #include +#include #include #ifndef _WIN32 @@ -37,147 +37,155 @@ namespace test { /* A restricted form of strptime() that doesn't support any locale based format options */ -char *strptime(const char * s, const char * f, struct tm * v) -{ +char* strptime(const char* s, const char* f, struct tm* v) { int i, w, neg, adj, min, range, *dest, dummy; int want_century = 0, century = 0, relyear = 0; while (*f) { if (*f != '%') { - if (isspace(*f)) for (; *s && isspace(*s); s++); - else if (*s != *f) return 0; - else s++; + if (isspace(*f)) + for (; *s && isspace(*s); s++) + ; + else if (*s != *f) + return 0; + else + s++; f++; continue; } f++; if (*f == '+') f++; if (isdigit(*f)) { - char *new_f; - w=strtoul(f, &new_f, 10); + char* new_f; + w = strtoul(f, &new_f, 10); f = new_f; } else { - w=-1; + w = -1; } - adj=0; + adj = 0; switch (*f++) { - case 'C': - dest = ¢ury; - if (w<0) w=2; - want_century |= 2; - goto numeric_digits; - case 'd': case 'e': - dest = &v->tm_mday; - min = 1; - range = 31; - goto numeric_range; - case 'D': - s = test::strptime(s, "%m/%d/%y", v); - if (!s) return 0; - break; - case 'H': - dest = &v->tm_hour; - min = 0; - range = 24; - goto numeric_range; - case 'I': - dest = &v->tm_hour; - min = 1; - range = 12; - goto numeric_range; - case 'j': - dest = &v->tm_yday; - min = 1; - range = 366; - adj = 1; - goto numeric_range; - case 'm': - dest = &v->tm_mon; - min = 1; - range = 12; - adj = 1; - goto numeric_range; - case 'M': - dest = &v->tm_min; - min = 0; - range = 60; - goto numeric_range; - case 'n': case 't': - for (; *s && isspace(*s); s++); - break; - case 'R': - s = test::strptime(s, "%H:%M", v); - if (!s) return 0; - break; - case 'S': - dest = &v->tm_sec; - min = 0; - range = 61; - goto numeric_range; - case 'T': - s = test::strptime(s, "%H:%M:%S", v); - if (!s) return 0; - break; - case 'U': - case 'W': - /* Throw away result, for now. (FIXME?) */ - dest = &dummy; - min = 0; - range = 54; - goto numeric_range; - case 'w': - dest = &v->tm_wday; - min = 0; - range = 7; - goto numeric_range; - case 'y': - dest = &relyear; - w = 2; - want_century |= 1; - goto numeric_digits; - case 'Y': - dest = &v->tm_year; - if (w<0) w=4; - adj = 1900; - want_century = 0; - goto numeric_digits; - case '%': - if (*s++ != '%') return 0; - break; - default: - return 0; - numeric_range: - if (!isdigit(*s)) return 0; - *dest = 0; - for (i=1; i<=min+range && isdigit(*s); i*=10) - *dest = *dest * 10 + *s++ - '0'; - if (*dest - min >= (unsigned)range) return 0; - *dest -= adj; - switch((char *)dest - (char *)v) { - case offsetof(struct tm, tm_yday): - ; - } - goto update; - numeric_digits: - neg = 0; - if (*s == '+') s++; - else if (*s == '-') neg=1, s++; - if (!isdigit(*s)) return 0; - for (*dest=i=0; itm_mday; + min = 1; + range = 31; + goto numeric_range; + case 'D': + s = test::strptime(s, "%m/%d/%y", v); + if (!s) return 0; + break; + case 'H': + dest = &v->tm_hour; + min = 0; + range = 24; + goto numeric_range; + case 'I': + dest = &v->tm_hour; + min = 1; + range = 12; + goto numeric_range; + case 'j': + dest = &v->tm_yday; + min = 1; + range = 366; + adj = 1; + goto numeric_range; + case 'm': + dest = &v->tm_mon; + min = 1; + range = 12; + adj = 1; + goto numeric_range; + case 'M': + dest = &v->tm_min; + min = 0; + range = 60; + goto numeric_range; + case 'n': + case 't': + for (; *s && isspace(*s); s++) + ; + break; + case 'R': + s = test::strptime(s, "%H:%M", v); + if (!s) return 0; + break; + case 'S': + dest = &v->tm_sec; + min = 0; + range = 61; + goto numeric_range; + case 'T': + s = test::strptime(s, "%H:%M:%S", v); + if (!s) return 0; + break; + case 'U': + case 'W': + /* Throw away result, for now. (FIXME?) */ + dest = &dummy; + min = 0; + range = 54; + goto numeric_range; + case 'w': + dest = &v->tm_wday; + min = 0; + range = 7; + goto numeric_range; + case 'y': + dest = &relyear; + w = 2; + want_century |= 1; + goto numeric_digits; + case 'Y': + dest = &v->tm_year; + if (w < 0) w = 4; + adj = 1900; + want_century = 0; + goto numeric_digits; + case '%': + if (*s++ != '%') return 0; + break; + default: + return 0; + numeric_range: + if (!isdigit(*s)) return 0; + *dest = 0; + for (i = 1; i <= min + range && isdigit(*s); i *= 10) + *dest = *dest * 10 + *s++ - '0'; + if (*dest - min >= (unsigned)range) return 0; + *dest -= adj; + switch ((char*)dest - (char*)v) { case offsetof(struct tm, tm_yday):; } + goto update; + numeric_digits: + neg = 0; + if (*s == '+') + s++; + else if (*s == '-') + neg = 1, s++; + if (!isdigit(*s)) return 0; + for (*dest = i = 0; i < w && isdigit(*s); i++) + *dest = *dest * 10 + *s++ - '0'; + if (neg) *dest = -*dest; + *dest -= adj; + goto update; + update + : + // FIXME + ; } } if (want_century) { v->tm_year = relyear; - if (want_century & 2) v->tm_year += century * 100 - 1900; - else if (v->tm_year <= 68) v->tm_year += 100; + if (want_century & 2) + v->tm_year += century * 100 - 1900; + else if (v->tm_year <= 68) + v->tm_year += 100; } - return (char *)s; + return (char*)s; } } // namespace test diff --git a/gtests/src/integration/strptime.hpp b/gtests/src/integration/strptime.hpp index ffb9d1b2b..7b8330ab4 100644 --- a/gtests/src/integration/strptime.hpp +++ b/gtests/src/integration/strptime.hpp @@ -29,7 +29,7 @@ namespace test { * @param tm The resulting time struct * @return NULL if an error occurred */ -char *strptime(const char *s, const char *f, struct tm *tm); +char* strptime(const char* s, const char* f, struct tm* tm); } // namespace test diff --git a/gtests/src/integration/test_category.cpp b/gtests/src/integration/test_category.cpp index a4de871d4..50990b1a0 100644 --- a/gtests/src/integration/test_category.cpp +++ b/gtests/src/integration/test_category.cpp @@ -22,7 +22,8 @@ // Constant value definitions for test type const TestCategory TestCategory::CASSANDRA("CASSANDRA", 0, "Cassandra", "*_Cassandra_*"); const TestCategory TestCategory::DSE("DSE", 1, "DataStax Enterprise", "*_DSE_*"); -const TestCategory TestCategory::SIMULACRON("SIMULACRON", SHRT_MAX, "Simulated DSE (and Cassandra)", "*_simulacron_*"); +const TestCategory TestCategory::SIMULACRON("SIMULACRON", SHRT_MAX, "Simulated DSE (and Cassandra)", + "*_simulacron_*"); // Static declarations for test type std::set TestCategory::constants_; @@ -33,40 +34,28 @@ std::ostream& operator<<(std::ostream& os, const TestCategory& object) { } TestCategory::TestCategory() - : name_("INVALID") - , ordinal_(-1) - , display_name_("Invalid test category") - , filter_("*") {} + : name_("INVALID") + , ordinal_(-1) + , display_name_("Invalid test category") + , filter_("*") {} -TestCategory::TestCategory(const std::string& name) { - *this = name; -} +TestCategory::TestCategory(const std::string& name) { *this = name; } -const std::string& TestCategory::name() const { - return name_; -} +const std::string& TestCategory::name() const { return name_; } -short TestCategory::ordinal() const { - return ordinal_; -} +short TestCategory::ordinal() const { return ordinal_; } -const std::string& TestCategory::display_name() const { - return display_name_; -} +const std::string& TestCategory::display_name() const { return display_name_; } -const std::string& TestCategory::filter() const { - return filter_; -} +const std::string& TestCategory::filter() const { return filter_; } -void TestCategory::operator =(const TestCategory& object) { +void TestCategory::operator=(const TestCategory& object) { name_ = object.name_; ordinal_ = object.ordinal_; display_name_ = object.display_name_; } -void TestCategory::operator=(const std::string& name) { - *this = get_enumeration(name); -} +void TestCategory::operator=(const std::string& name) { *this = get_enumeration(name); } bool TestCategory::operator<(const TestCategory& object) const { return ordinal_ < object.ordinal_; @@ -91,28 +80,20 @@ bool TestCategory::operator==(const std::string& object) const { return lhs.compare(rhs) == 0; } -bool TestCategory::operator !=(const TestCategory& object) const { - return !(*this == object); -} +bool TestCategory::operator!=(const TestCategory& object) const { return !(*this == object); } -bool TestCategory::operator !=(const std::string& object) const { - return !(*this == object); -} +bool TestCategory::operator!=(const std::string& object) const { return !(*this == object); } -TestCategory::iterator TestCategory::begin() { - return get_constants().begin(); - } +TestCategory::iterator TestCategory::begin() { return get_constants().begin(); } -TestCategory::iterator TestCategory::end() { - return get_constants().end(); -} +TestCategory::iterator TestCategory::end() { return get_constants().end(); } -TestCategory::TestCategory(const std::string& name, short ordinal, - const std::string& display_name, const std::string& filter) - : name_(name) - , ordinal_(ordinal) - , display_name_(display_name) - , filter_(filter) {} +TestCategory::TestCategory(const std::string& name, short ordinal, const std::string& display_name, + const std::string& filter) + : name_(name) + , ordinal_(ordinal) + , display_name_(display_name) + , filter_(filter) {} const std::set& TestCategory::get_constants() { if (constants_.empty()) { @@ -124,7 +105,7 @@ const std::set& TestCategory::get_constants() { return constants_; } -TestCategory TestCategory::get_enumeration(const std::string& name) const{ +TestCategory TestCategory::get_enumeration(const std::string& name) const { // Iterator over the constants and find the corresponding enumeration if (!name.empty()) { for (iterator iterator = begin(); iterator != end(); ++iterator) { diff --git a/gtests/src/integration/test_category.hpp b/gtests/src/integration/test_category.hpp index d507a3923..95136a47b 100644 --- a/gtests/src/integration/test_category.hpp +++ b/gtests/src/integration/test_category.hpp @@ -30,7 +30,7 @@ class TestCategory { class Exception : public test::Exception { public: Exception(const std::string& message) - : test::Exception(message) {} + : test::Exception(message) {} }; /** * Iterator @@ -184,8 +184,8 @@ class TestCategory { * @param display_name Display name for enumeration * @param filter Filter for enumeration */ - TestCategory(const std::string& name, short ordinal, - const std::string& display_name, const std::string& filter); + TestCategory(const std::string& name, short ordinal, const std::string& display_name, + const std::string& filter); /** * Get the enumeration constants * diff --git a/gtests/src/integration/test_utils.cpp b/gtests/src/integration/test_utils.cpp index ce088948a..b0ba3579d 100644 --- a/gtests/src/integration/test_utils.cpp +++ b/gtests/src/integration/test_utils.cpp @@ -26,13 +26,13 @@ #include #include #ifndef _WIN32 -# include +#include #endif #ifdef _WIN32 -# define FILE_MODE 0 +#define FILE_MODE 0 #else -# define FILE_MODE S_IRWXU | S_IRWXG | S_IROTH +#define FILE_MODE S_IRWXU | S_IRWXG | S_IROTH #endif #define FILE_PATH_SIZE 1024 @@ -45,7 +45,7 @@ const char test::Utils::PATH_SEPARATOR = '\\'; const char test::Utils::PATH_SEPARATOR = '/'; #endif -template +template T* test::Utils::addressof(T& value) { return reinterpret_cast(&const_cast(reinterpret_cast(value))); } @@ -128,14 +128,13 @@ std::string test::Utils::scalar_cql_type(CassValueType value_type) { break; default: std::stringstream message; - message << "Unable to Retrieve CQL Type: CassValueType [" << - value_type << "] is not valid"; + message << "Unable to Retrieve CQL Type: CassValueType [" << value_type << "] is not valid"; throw test::Exception(message.str()); } } std::vector test::Utils::explode(const std::string& input, - const char delimiter /*= ' '*/) { + const char delimiter /*= ' '*/) { // Iterate over the input line and parse the tokens std::vector result; std::istringstream parser(input); @@ -159,8 +158,8 @@ std::string test::Utils::indent(const std::string& input, unsigned int indent) { // Iterate over each line in the input string and indent std::vector lines = explode(input, '\n'); - for (std::vector::iterator iterator = lines.begin(); - iterator < lines.end(); ++iterator) { + for (std::vector::iterator iterator = lines.begin(); iterator < lines.end(); + ++iterator) { output << std::setw(indent) << "" << *iterator; if ((iterator + 1) != lines.end()) { output << std::endl; @@ -194,12 +193,12 @@ void test::Utils::msleep(unsigned int milliseconds) { #ifdef _WIN32 Sleep(milliseconds); #else - //Convert the milliseconds into a proper timespec structure + // Convert the milliseconds into a proper timespec structure struct timespec requested; time_t seconds = static_cast(milliseconds / 1000); long int nanoseconds = static_cast((milliseconds - (seconds * 1000)) * 1000000); - //Assign the requested time and perform sleep + // Assign the requested time and perform sleep requested.tv_sec = seconds; requested.tv_nsec = nanoseconds; while (nanosleep(&requested, &requested) == -1) { @@ -208,11 +207,11 @@ void test::Utils::msleep(unsigned int milliseconds) { #endif } -std::string test::Utils::replace_all(const std::string& input, - const std::string& from, const std::string& to) { +std::string test::Utils::replace_all(const std::string& input, const std::string& from, + const std::string& to) { size_t position = 0; std::string result = input; - while((position = result.find(from, position)) != std::string::npos) { + while ((position = result.find(from, position)) != std::string::npos) { result.replace(position, from.length(), to); // Handle the case where 'to' is a substring of 'from' position += to.length(); @@ -221,13 +220,13 @@ std::string test::Utils::replace_all(const std::string& input, } std::string test::Utils::shorten(const std::string& input, - bool add_space_after_newline /*= true*/) { + bool add_space_after_newline /*= true*/) { std::string result = input; // Iterate over each trim delimiter std::string delimiters = TRIM_DELIMETERS; - for (std::string::iterator iterator = delimiters.begin(); - iterator < delimiters.end(); ++iterator) { + for (std::string::iterator iterator = delimiters.begin(); iterator < delimiters.end(); + ++iterator) { // Replace the trim delimiter with empty string (space if EOL) std::string delimiter(1, *iterator); std::string newline_replacement = add_space_after_newline ? " " : ""; @@ -259,8 +258,8 @@ std::string test::Utils::trim(const std::string& input) { } bool test::Utils::wait_for_port(const std::string& ip_address, unsigned short port, - unsigned int number_of_retries /*= 100*/, - unsigned int retry_delay_ms /*= 100*/) { + unsigned int number_of_retries /*= 100*/, + unsigned int retry_delay_ms /*= 100*/) { // Attempt establish a connection to the IP address and port of the node for (unsigned int n = 0; n < number_of_retries; ++n) { Socket socket; diff --git a/gtests/src/integration/test_utils.hpp b/gtests/src/integration/test_utils.hpp index 305c5a8c4..fdf28e80e 100644 --- a/gtests/src/integration/test_utils.hpp +++ b/gtests/src/integration/test_utils.hpp @@ -77,8 +77,7 @@ class Utils { * @param delimiter Character to use split into elements (default: ) * @return An array/vector representation of the string */ - static std::vector explode(const std::string& input, - const char delimiter = ' '); + static std::vector explode(const std::string& input, const char delimiter = ' '); /** * Check to see if a file exists @@ -105,13 +104,12 @@ class Utils { * @return A string concatenating all the vector elements with delimiter * separation */ - template - inline static std::string implode(const std::vector& elements, - const char delimiter = ' ') { + template + inline static std::string implode(const std::vector& elements, const char delimiter = ' ') { // Iterate through each element in the vector and concatenate the string std::stringstream result; for (typename std::vector::const_iterator iterator = elements.begin(); - iterator < elements.end(); ++iterator) { + iterator < elements.end(); ++iterator) { result << *iterator; if ((iterator + 1) != elements.end()) { result << delimiter; @@ -144,8 +142,8 @@ class Utils { * @param to String to replace with * @return Input string with replacement */ - static std::string replace_all(const std::string& input, - const std::string& from, const std::string& to); + static std::string replace_all(const std::string& input, const std::string& from, + const std::string& to); /** * Reduce/Shorten a multi-line string into a single line string @@ -156,8 +154,7 @@ class Utils { * otherwise * @return Single line string converted from multi-line string */ - static std::string shorten(const std::string& input, - bool add_space_after_newline = true); + static std::string shorten(const std::string& input, bool add_space_after_newline = true); /** * Convert a string to lowercase @@ -186,8 +183,8 @@ class Utils { * @return True if port on IP address is available; false otherwise */ static bool wait_for_port(const std::string& ip_address, unsigned short port, - unsigned int number_of_retries = 100, - unsigned int retry_delay_ms = 100); + unsigned int number_of_retries = 100, + unsigned int retry_delay_ms = 100); }; } // namespace test diff --git a/gtests/src/integration/tests/simulacron/test_simulacron_connect.cpp b/gtests/src/integration/tests/simulacron/test_simulacron_connect.cpp index f1484b6b5..59a6f19b3 100644 --- a/gtests/src/integration/tests/simulacron/test_simulacron_connect.cpp +++ b/gtests/src/integration/tests/simulacron/test_simulacron_connect.cpp @@ -22,7 +22,8 @@ * Connection integration tests using Simulacron */ class ConnectionTest : public SimulacronIntegration { -using SimulacronIntegration::connect; + using SimulacronIntegration::connect; + public: void SetUp() { is_sc_start_requested_ = false; @@ -37,8 +38,7 @@ using SimulacronIntegration::connect; * @param is_across_dcs True if connections are going to be made on all DCs; * false otherwise. */ - void assert_active_connections(int host_connections = 1, - bool is_across_dcs = true) { + void assert_active_connections(int host_connections = 1, bool is_across_dcs = true) { std::vector data_centers = sc_->data_centers(); for (std::vector::iterator it = data_centers.begin(); it != data_centers.end(); ++it) { @@ -65,8 +65,7 @@ using SimulacronIntegration::connect; * @param cluster Cluster configuration to use when establishing the * connection (default: NULL; uses default configuration) */ - void connect(std::vector data_center_nodes, - test::driver::Cluster cluster = NULL) { + void connect(std::vector data_center_nodes, test::driver::Cluster cluster = NULL) { // Start the SC, prime the tables, and establish a connection start_sc(data_center_nodes); contact_points_ = sc_->get_ip_address(1); @@ -88,7 +87,7 @@ using SimulacronIntegration::connect; * connection (default: NULL; uses default configuration) */ void connect(unsigned int number_dc1_nodes, unsigned int number_dc2_nodes, - test::driver::Cluster cluster = NULL) { + test::driver::Cluster cluster = NULL) { // Initialize the number of nodes in the standard data centers std::vector data_center_nodes; number_dc1_nodes_ = number_dc1_nodes; @@ -189,13 +188,11 @@ SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, ConnectOneNodeTwoDataCenters) { * @expected_result Successful connection and validation of active connections * across the data centers */ -SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, - ConnectOneNodeTwoDataCentersAcrossDCs) { +SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, ConnectOneNodeTwoDataCentersAcrossDCs) { SKIP_TEST_IF_SIMULACRON_UNAVAILABLE; // Ensure the control connection and normal node connection is established - test::driver::Cluster cluster = default_cluster() - .with_load_balance_round_robin(); + test::driver::Cluster cluster = default_cluster().with_load_balance_round_robin(); connect(1, 1, cluster); assert_active_connections(); } @@ -231,13 +228,11 @@ SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, ConnectThreeNodesTwoDataCenters) { * @expected_result Successful connection and validation of active connections * across the data centers */ -SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, - ConnectThreeNodesTwoDataCentersAcrossDCs) { +SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, ConnectThreeNodesTwoDataCentersAcrossDCs) { SKIP_TEST_IF_SIMULACRON_UNAVAILABLE; // Ensure the control connection and normal node connection is established - test::driver::Cluster cluster = default_cluster() - .with_load_balance_round_robin(); + test::driver::Cluster cluster = default_cluster().with_load_balance_round_robin(); connect(3, 3, cluster); assert_active_connections(); } @@ -253,8 +248,7 @@ SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, * @since 1.0.0 * @expected_result Successful connection and validation of active connections */ -SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, - ConnectFiveHundredNodesTwoDataCenters) { +SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, ConnectFiveHundredNodesTwoDataCenters) { SKIP_TEST_IF_SIMULACRON_UNAVAILABLE; // Ensure the control connection and normal node connection is established @@ -274,13 +268,11 @@ SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, * @expected_result Successful connection and validation of active connections * across the data centers */ -SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, - ConnectFiveHundredNodesTwoDataCentersAcrossDCs) { +SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, ConnectFiveHundredNodesTwoDataCentersAcrossDCs) { SKIP_TEST_IF_SIMULACRON_UNAVAILABLE; // Ensure the control connection and normal node connection is established - test::driver::Cluster cluster = default_cluster() - .with_load_balance_round_robin(); + test::driver::Cluster cluster = default_cluster().with_load_balance_round_robin(); connect(500, 500, cluster); assert_active_connections(); } @@ -322,8 +314,7 @@ SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, ConnectOneNodeNineDataCenters) { * @expected_result Successful connection and validation of active connections * across the data centers */ -SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, - ConnectOneNodeNineDataCentersAcrossDCs) { +SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, ConnectOneNodeNineDataCentersAcrossDCs) { SKIP_TEST_IF_SIMULACRON_UNAVAILABLE; // Create the nine data centers @@ -333,8 +324,7 @@ SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, } // Ensure the control connection and normal node connection is established - test::driver::Cluster cluster = default_cluster() - .with_load_balance_round_robin(); + test::driver::Cluster cluster = default_cluster().with_load_balance_round_robin(); connect(data_center_nodes, cluster); assert_active_connections(); } @@ -350,13 +340,12 @@ SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, * @since 1.0.0 * @expected_result Successful connection and validation of active connections */ -SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, - ConnectOneNodeMultipleConnectionsPerHost) { +SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, ConnectOneNodeMultipleConnectionsPerHost) { SKIP_TEST_IF_SIMULACRON_UNAVAILABLE; // Ensure the control connection and normal node connection is established - test::driver::Cluster cluster = default_cluster() - .with_core_connections_per_host(CORE_CONNECTIONS_PER_HOST); + test::driver::Cluster cluster = + default_cluster().with_core_connections_per_host(CORE_CONNECTIONS_PER_HOST); connect(1, 0, cluster); assert_active_connections(CORE_CONNECTIONS_PER_HOST); } @@ -372,13 +361,12 @@ SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, * @since 1.0.0 * @expected_result Successful connection and validation of active connections */ -SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, - ConnectThreeNodesMultipleConnectionsPerHost) { +SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, ConnectThreeNodesMultipleConnectionsPerHost) { SKIP_TEST_IF_SIMULACRON_UNAVAILABLE; // Ensure the control connection and normal node connection is established - test::driver::Cluster cluster = default_cluster() - .with_core_connections_per_host(CORE_CONNECTIONS_PER_HOST); + test::driver::Cluster cluster = + default_cluster().with_core_connections_per_host(CORE_CONNECTIONS_PER_HOST); connect(3, 0, cluster); assert_active_connections(CORE_CONNECTIONS_PER_HOST); } @@ -399,8 +387,8 @@ SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, SKIP_TEST_IF_SIMULACRON_UNAVAILABLE; // Ensure the control connection and normal node connection is established - test::driver::Cluster cluster = default_cluster() - .with_core_connections_per_host(CORE_CONNECTIONS_PER_HOST); + test::driver::Cluster cluster = + default_cluster().with_core_connections_per_host(CORE_CONNECTIONS_PER_HOST); connect(1, 1, cluster); assert_active_connections(CORE_CONNECTIONS_PER_HOST, false); } @@ -421,8 +409,8 @@ SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, SKIP_TEST_IF_SIMULACRON_UNAVAILABLE; // Ensure the control connection and normal node connection is established - test::driver::Cluster cluster = default_cluster() - .with_core_connections_per_host(CORE_CONNECTIONS_PER_HOST); + test::driver::Cluster cluster = + default_cluster().with_core_connections_per_host(CORE_CONNECTIONS_PER_HOST); connect(3, 3, cluster); assert_active_connections(CORE_CONNECTIONS_PER_HOST, false); } @@ -449,8 +437,8 @@ SIMULACRON_INTEGRATION_TEST_F(ConnectionTest, } // Ensure the control connection and normal node connection is established - test::driver::Cluster cluster = default_cluster() - .with_core_connections_per_host(CORE_CONNECTIONS_PER_HOST); + test::driver::Cluster cluster = + default_cluster().with_core_connections_per_host(CORE_CONNECTIONS_PER_HOST); connect(data_center_nodes, cluster); assert_active_connections(CORE_CONNECTIONS_PER_HOST, false); } diff --git a/gtests/src/integration/tests/simulacron/test_simulacron_idempotent.cpp b/gtests/src/integration/tests/simulacron/test_simulacron_idempotent.cpp index b7e0bd296..8c02a78b4 100644 --- a/gtests/src/integration/tests/simulacron/test_simulacron_idempotent.cpp +++ b/gtests/src/integration/tests/simulacron/test_simulacron_idempotent.cpp @@ -22,7 +22,8 @@ * Idempotent integration tests */ class IdempotentTest : public SimulacronIntegration { -using SimulacronIntegration::execute_mock_query; + using SimulacronIntegration::execute_mock_query; + public: void SetUp() { number_dc1_nodes_ = 3; @@ -44,8 +45,7 @@ using SimulacronIntegration::execute_mock_query; * should be enabled; false otherwise * @return Result from the executed mock query; see Result::error_code() */ - test::driver::Result execute_mock_query(bool is_idempotent, - bool apply_custom_retry_policy) { + test::driver::Result execute_mock_query(bool is_idempotent, bool apply_custom_retry_policy) { // Create the statement with the desired idempotence and custom retry policy test::driver::Statement statement("mock query"); statement.set_consistency(CASS_CONSISTENCY_ONE); @@ -54,8 +54,8 @@ using SimulacronIntegration::execute_mock_query; // Determine if the custom or default retry policy should be applied test::driver::RetryPolicy policy((apply_custom_retry_policy - ? NextHostRetryPolicy::policy() - : test::driver::DefaultRetryPolicy())); + ? NextHostRetryPolicy::policy() + : test::driver::DefaultRetryPolicy())); test::driver::LoggingRetryPolicy logging_policy(policy); statement.set_retry_policy(logging_policy); @@ -92,7 +92,6 @@ SIMULACRON_INTEGRATION_TEST_F(IdempotentTest, WriteTimeoutNonIdempotentNoRetry) } } - /** * Perform query using a idempotent statement; no errors should occur * @@ -154,7 +153,6 @@ SIMULACRON_INTEGRATION_TEST_F(IdempotentTest, ClosedConnectionNonIdempotentNoRet } } - /** * Perform query using a idempotent statement while a connection is closed * diff --git a/gtests/src/integration/tests/test_async.cpp b/gtests/src/integration/tests/test_async.cpp index 1e73d0229..1ccf51175 100644 --- a/gtests/src/integration/tests/test_async.cpp +++ b/gtests/src/integration/tests/test_async.cpp @@ -28,8 +28,8 @@ class AsyncTests : public Integration { Integration::SetUp(); // Create the table - session_.execute("CREATE TABLE " + table_name_ - + " (key timeuuid PRIMARY KEY, value_number int, value_text text)"); + session_.execute("CREATE TABLE " + table_name_ + + " (key timeuuid PRIMARY KEY, value_number int, value_text text)"); } /** @@ -44,7 +44,8 @@ class AsyncTests : public Integration { for (size_t i = 0; i < NUMBER_OF_CONCURRENT_REQUESTS; ++i) { // Create the insert statement Statement insert("INSERT INTO " + table_name_ + - " (key, value_number, value_text) VALUES (?, ?, ?) IF NOT EXISTS", 3); + " (key, value_number, value_text) VALUES (?, ?, ?) IF NOT EXISTS", + 3); // Bind the values to the insert statement TimeUuid key = uuid_generator_.generate_timeuuid(); diff --git a/gtests/src/integration/tests/test_auth.cpp b/gtests/src/integration/tests/test_auth.cpp index 8776914bf..f37b6d3ff 100644 --- a/gtests/src/integration/tests/test_auth.cpp +++ b/gtests/src/integration/tests/test_auth.cpp @@ -43,12 +43,10 @@ class AuthenticationTests : public Integration { * @param password Password credentials * @return Session instance */ - Session connect_using_credentials(int protocol_version, - const char* username, - const char* password) { + Session connect_using_credentials(int protocol_version, const char* username, + const char* password) { // Establish a connection using the protocol version - cluster_.with_protocol_version(protocol_version) - .with_credentials(username, password); + cluster_.with_protocol_version(protocol_version).with_credentials(username, password); return cluster_.connect("", false); } @@ -59,8 +57,7 @@ class AuthenticationTests : public Integration { * @param authenticator Driver authenticator * @oaram data Data associated with the callback */ - static void handle_authenticator_initial(CassAuthenticator* authuenticator, - void* data) { + static void handle_authenticator_initial(CassAuthenticator* authuenticator, void* data) { cass_authenticator_set_error(authuenticator, NULL); } }; @@ -80,12 +77,11 @@ CASSANDRA_INTEGRATION_TEST_F(AuthenticationTests, ProtocolVersions) { CHECK_FAILURE; // Iterate over all known/supported protocol versions - for (int i = CASS_LOWEST_SUPPORTED_PROTOCOL_VERSION; - i <= CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION; ++i) { + for (int i = CASS_LOWEST_SUPPORTED_PROTOCOL_VERSION; i <= CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION; + ++i) { // Establish a connection using the protocol version Session session = connect_using_credentials(i, "cassandra", "cassandra"); - ASSERT_EQ(CASS_OK, session.connect_error_code()) - << session.connect_error_description(); + ASSERT_EQ(CASS_OK, session.connect_error_code()) << session.connect_error_description(); // Execute a query against the schema keyspaces table Result result = session.execute("SELECT * FROM " + system_schema_keyspaces_); @@ -111,8 +107,8 @@ CASSANDRA_INTEGRATION_TEST_F(AuthenticationTests, InvalidEmptyCredentials) { // Iterate over all known/supported protocol versions logger_.add_critera("Key may not be empty"); - for (int i = CASS_LOWEST_SUPPORTED_PROTOCOL_VERSION; - i <= CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION; ++i) { + for (int i = CASS_LOWEST_SUPPORTED_PROTOCOL_VERSION; i <= CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION; + ++i) { /* * This is a case that could be guarded in the API entry point, or error out * in connection. However, auth is subject to major changes and this is just @@ -142,8 +138,8 @@ CASSANDRA_INTEGRATION_TEST_F(AuthenticationTests, InvalidNullUsernameCredentials // Iterate over all known/supported protocol versions logger_.add_critera("Key may not be empty"); - for (int i = CASS_LOWEST_SUPPORTED_PROTOCOL_VERSION; - i <= CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION; ++i) { + for (int i = CASS_LOWEST_SUPPORTED_PROTOCOL_VERSION; i <= CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION; + ++i) { /* * This is a case that could be guarded in the API entry point, or error out * in connection. However, auth is subject to major changes and this is just @@ -173,8 +169,8 @@ CASSANDRA_INTEGRATION_TEST_F(AuthenticationTests, InvalidNullPasswordCredentials // Iterate over all known/supported protocol versions logger_.add_critera("and/or password are incorrect"); - for (int i = CASS_LOWEST_SUPPORTED_PROTOCOL_VERSION; - i <= CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION; ++i) { + for (int i = CASS_LOWEST_SUPPORTED_PROTOCOL_VERSION; i <= CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION; + ++i) { /* * This is a case that could be guarded in the API entry point, or error out * in connection. However, auth is subject to major changes and this is just @@ -214,8 +210,8 @@ CASSANDRA_INTEGRATION_TEST_F(AuthenticationTests, BadCredentials) { } // Iterate over all known/supported protocol versions - for (int i = CASS_LOWEST_SUPPORTED_PROTOCOL_VERSION; - i <= CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION; ++i) { + for (int i = CASS_LOWEST_SUPPORTED_PROTOCOL_VERSION; i <= CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION; + ++i) { /* * This is a case that could be guarded in the API entry point, or error out * in connection. However, auth is subject to major changes and this is just @@ -257,14 +253,11 @@ CASSANDRA_INTEGRATION_TEST_F(AuthenticationTests, AuthenticatorSetErrorNull) { // Attempt to establish session connection using authentication callback CassAuthenticatorCallbacks authentication_callbacks = { - AuthenticationTests::handle_authenticator_initial, - NULL, - NULL, - NULL + AuthenticationTests::handle_authenticator_initial, NULL, NULL, NULL }; cluster_.with_authenticator_callbacks(&authentication_callbacks, NULL, NULL); - Session session = connect_using_credentials(CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION, - "invalid", "invalid"); + Session session = + connect_using_credentials(CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION, "invalid", "invalid"); ASSERT_EQ(session.connect_error_code(), CASS_ERROR_SERVER_BAD_CREDENTIALS); ASSERT_GE(logger_.count(), 1u); } diff --git a/gtests/src/integration/tests/test_basics.cpp b/gtests/src/integration/tests/test_basics.cpp index f71c2ca18..6145b4393 100644 --- a/gtests/src/integration/tests/test_basics.cpp +++ b/gtests/src/integration/tests/test_basics.cpp @@ -19,7 +19,7 @@ /** * Basics integration tests; common operations */ -class BasicsTests : public Integration { }; +class BasicsTests : public Integration {}; /** * Perform inserts and validate the timestamps from the server @@ -36,12 +36,11 @@ CASSANDRA_INTEGRATION_TEST_F(BasicsTests, Timestamps) { CHECK_FAILURE; // Create the table, insert and select queries for the test - session_.execute(format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, - table_name_.c_str(), "int", "int")); - std::string insert_query = format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, - table_name_.c_str(), "?", "?"); - Statement select_query = Statement("SELECT WRITETIME (value) FROM " - + table_name_); + session_.execute( + format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, table_name_.c_str(), "int", "int")); + std::string insert_query = + format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, table_name_.c_str(), "?", "?"); + Statement select_query = Statement("SELECT WRITETIME (value) FROM " + table_name_); // Insert a value and get the timestamp from the server Statement statement(insert_query, 2); @@ -69,8 +68,7 @@ CASSANDRA_INTEGRATION_TEST_F(BasicsTests, Timestamps) { // Validate the timestamps ASSERT_NE(timestamp_1, timestamp_2); - ASSERT_LT(timestamp_2 - timestamp_1 - BigInteger(pause_duration * 1000), - BigInteger(100000)); + ASSERT_LT(timestamp_2 - timestamp_1 - BigInteger(pause_duration * 1000), BigInteger(100000)); } /** @@ -87,15 +85,13 @@ CASSANDRA_INTEGRATION_TEST_F(BasicsTests, Counters) { CHECK_FAILURE; // Create the table and update/upsert queries for the test - session_.execute(format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, - table_name_.c_str(), "int", "counter")); - std::string update_query = "UPDATE " + table_name_ - + " SET value=value %s ? WHERE key=0"; + session_.execute( + format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, table_name_.c_str(), "int", "counter")); + std::string update_query = "UPDATE " + table_name_ + " SET value=value %s ? WHERE key=0"; // Perform multiple upserts against the counter value for (int step = 0; step < 100; ++step) { - Statement statement(format_string(update_query.c_str(), - (step % 2 == 0 ? "-" : "+")), 1); + Statement statement(format_string(update_query.c_str(), (step % 2 == 0 ? "-" : "+")), 1); statement.bind(0, Counter(step)); session_.execute(statement); } @@ -125,14 +121,15 @@ CASSANDRA_INTEGRATION_TEST_F(BasicsTests, RowsInRowsOut) { CHECK_FAILURE; // Create the table, insert, and select statements for the test - session_.execute("CREATE TABLE " + table_name_ - + " (key bigint PRIMARY KEY, " \ + session_.execute("CREATE TABLE " + table_name_ + + " (key bigint PRIMARY KEY, " "value_1 bigint, value_2 bigint, value_3 bigint)"); - Statement insert_statement("INSERT INTO " + table_name_ - + " (key, value_1, value_2, value_3) " \ - "VALUES (?, ?, ?, ?)", 4); - Statement select_statement("SELECT key, value_1, value_2, value_3 FROM " - + table_name_ + " LIMIT 1000"); + Statement insert_statement("INSERT INTO " + table_name_ + + " (key, value_1, value_2, value_3) " + "VALUES (?, ?, ?, ?)", + 4); + Statement select_statement("SELECT key, value_1, value_2, value_3 FROM " + table_name_ + + " LIMIT 1000"); // Create multiple rows with varying data for (int i = 0; i < 1000; ++i) { @@ -177,8 +174,8 @@ CASSANDRA_INTEGRATION_TEST_F(BasicsTests, ColumnNames) { CHECK_FAILURE; // Create the table for the test - session_.execute("CREATE TABLE " + table_name_ - + " (key bigint PRIMARY KEY, " \ + session_.execute("CREATE TABLE " + table_name_ + + " (key bigint PRIMARY KEY, " "value_1 text, value_2 int, value_3 bigint, value_4 float)"); // Validate the column names @@ -210,18 +207,17 @@ CASSANDRA_INTEGRATION_TEST_F(BasicsTests, EmptyResults) { CHECK_FAILURE; // Create the table - Result result = session_.execute(format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, - table_name_.c_str(), "int", "int")); + Result result = session_.execute( + format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, table_name_.c_str(), "int", "int")); ASSERT_TRUE(result.is_empty()); // Insert data into the table - result = session_.execute(format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, - table_name_.c_str(), "0", "0")); + result = session_.execute( + format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, table_name_.c_str(), "0", "0")); ASSERT_TRUE(result.is_empty()); // Delete data from the table - result = session_.execute(format_string(CASSANDRA_DELETE_ROW_FORMAT, - table_name_.c_str(), "0")); + result = session_.execute(format_string(CASSANDRA_DELETE_ROW_FORMAT, table_name_.c_str(), "0")); ASSERT_TRUE(result.is_empty()); // Select data from the table (all rows have been deleted) @@ -246,12 +242,11 @@ CASSANDRA_INTEGRATION_TEST_F(BasicsTests, UnsetParameters) { CHECK_FAILURE; // Create the table, insert a known value, and create insert statement for the test - session_.execute(format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, - table_name_.c_str(), "int", "int")); - session_.execute(format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, - table_name_.c_str(), "0", "1")); - Prepared insert_prepared = session_.prepare(format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, - table_name_.c_str(), "?", "?")); + session_.execute( + format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, table_name_.c_str(), "int", "int")); + session_.execute(format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, table_name_.c_str(), "0", "1")); + Prepared insert_prepared = session_.prepare( + format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, table_name_.c_str(), "?", "?")); // Bind a single value and leave one unset Statement insert_statement = insert_prepared.bind(); @@ -287,17 +282,17 @@ CASSANDRA_INTEGRATION_TEST_F(BasicsTests, UnsetParameters) { * @test_category queries:basic * @since core:2.3.0 * @expected_result String will be bound/inserted into blob and values will be - * validated + * validated */ CASSANDRA_INTEGRATION_TEST_F(BasicsTests, BindBlobAsString) { CHECK_FAILURE; // Create the table, prepared and insert statement for the test - session_.execute(format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, - table_name_.c_str(), "int", "blob")); + session_.execute( + format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, table_name_.c_str(), "int", "blob")); // Prepared needed to validate bind type information - Prepared insert_prepared = session_.prepare(format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, - table_name_.c_str(), "?", "?")); + Prepared insert_prepared = session_.prepare( + format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, table_name_.c_str(), "?", "?")); Statement insert_statement = insert_prepared.bind(); // Bind and insert the data into the table @@ -341,33 +336,32 @@ CASSANDRA_INTEGRATION_TEST_F(BasicsTests, NoCompactEnabledConnection) { CCM::CassVersion cass_version = server_version_; if (Options::is_dse()) { if (server_version_ >= "6.0.0") { - SKIP_TEST("Unsupported for DataStax Enterprise Version " << server_version_.to_string() + SKIP_TEST("Unsupported for DataStax Enterprise Version " + << server_version_.to_string() << ": Apache Cassandra server version must be used and less than" << " v4.0.0 and either 3.0.16+ or 3.11.2+ in order to execute"); } cass_version = static_cast(cass_version).get_cass_version(); } if (cass_version >= "4.0.0") { - SKIP_TEST("Unsupported for Apache Cassandra Version " << cass_version.to_string() + SKIP_TEST("Unsupported for Apache Cassandra Version " + << cass_version.to_string() << ": Server version must be less than v4.0.0 and either 3.0.16+" << " or 3.11.2+ in order to execute"); } // Create a session where the NO_COMPACT option is set - Session no_compact_session = default_cluster() - .with_no_compact() - .connect(default_keyspace()); + Session no_compact_session = default_cluster().with_no_compact().connect(default_keyspace()); // Create the table and insert data using the NO_COMPACT session no_compact_session.execute(format_string( - "CREATE TABLE %s (k int PRIMARY KEY, v int) WITH COMPACT STORAGE", - table_name_.c_str())); - no_compact_session.execute(format_string("INSERT INTO %s (k, v) VALUES(%s, %s)", - table_name_.c_str(), "1", "1")); - no_compact_session.execute(format_string("INSERT INTO %s (k, v) VALUES(%s, %s)", - table_name_.c_str(), "2", "2")); - no_compact_session.execute(format_string("INSERT INTO %s (k, v) VALUES(%s, %s)", - table_name_.c_str(), "3", "3")); + "CREATE TABLE %s (k int PRIMARY KEY, v int) WITH COMPACT STORAGE", table_name_.c_str())); + no_compact_session.execute( + format_string("INSERT INTO %s (k, v) VALUES(%s, %s)", table_name_.c_str(), "1", "1")); + no_compact_session.execute( + format_string("INSERT INTO %s (k, v) VALUES(%s, %s)", table_name_.c_str(), "2", "2")); + no_compact_session.execute( + format_string("INSERT INTO %s (k, v) VALUES(%s, %s)", table_name_.c_str(), "3", "3")); // Validate the default session with compact storage enabled Result result = session_.execute(default_select_all()); diff --git a/gtests/src/integration/tests/test_batch.cpp b/gtests/src/integration/tests/test_batch.cpp index c42b8258d..62cfce295 100644 --- a/gtests/src/integration/tests/test_batch.cpp +++ b/gtests/src/integration/tests/test_batch.cpp @@ -24,15 +24,15 @@ class BatchSingleNodeClusterTests : public Integration { public: BatchSingleNodeClusterTests() - : value_cql_data_type_("text") { } + : value_cql_data_type_("text") {} virtual void SetUp() { // Call the parent setup function Integration::SetUp(); // Create the table, insert and select statements for the test - session_.execute(format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, - table_name_.c_str(), "int", value_cql_data_type_.c_str())); + session_.execute(format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, table_name_.c_str(), "int", + value_cql_data_type_.c_str())); create_queries_select_statements(); } @@ -58,12 +58,11 @@ class BatchSingleNodeClusterTests : public Integration { * Create the queries and select statement for the test */ virtual void create_queries_select_statements() { - insert_query_ = format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, - table_name_.c_str(), "?", "?"); - update_query_ = format_string(CASSANDRA_UPDATE_VALUE_FORMAT, - table_name_.c_str(), "value + ?", "?"); - select_prepared_ = session_.prepare(format_string(CASSANDRA_SELECT_VALUE_FORMAT, - table_name_.c_str(), "?")); + insert_query_ = format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, table_name_.c_str(), "?", "?"); + update_query_ = + format_string(CASSANDRA_UPDATE_VALUE_FORMAT, table_name_.c_str(), "value + ?", "?"); + select_prepared_ = + session_.prepare(format_string(CASSANDRA_SELECT_VALUE_FORMAT, table_name_.c_str(), "?")); } /** @@ -84,8 +83,7 @@ class BatchSingleNodeClusterTests : public Integration { Result result = session_.execute(statement); // Validate the result - ASSERT_EQ(Text(format_string("test data %d", i)), - result.first_row().next().as()); + ASSERT_EQ(Text(format_string("test data %d", i)), result.first_row().next().as()); } } @@ -96,8 +94,7 @@ class BatchSingleNodeClusterTests : public Integration { * @param index The index/row being validated */ virtual void validate_result(Result result, int index) { - ASSERT_EQ(Text(format_string("test data %d", index)), - result.first_row().next().as()); + ASSERT_EQ(Text(format_string("test data %d", index)), result.first_row().next().as()); } }; @@ -108,9 +105,7 @@ class BatchSingleNodeClusterTests : public Integration { */ class BatchCounterSingleNodeClusterTests : public BatchSingleNodeClusterTests { public: - BatchCounterSingleNodeClusterTests() { - value_cql_data_type_ = "counter"; - } + BatchCounterSingleNodeClusterTests() { value_cql_data_type_ = "counter"; } /** * Validate the result for the text data type @@ -264,13 +259,15 @@ CASSANDRA_INTEGRATION_TEST_F(BatchCounterSingleNodeClusterTests, InvalidBatchTyp // Create and add the insert statement Statement statement(insert_query_, 2); - statement.bind(0, Integer(37)); // Attempt to insert a counter value inside a batch statement + statement.bind( + 0, Integer(37)); // Attempt to insert a counter value inside a batch statement statement.bind(1, Counter(37)); batch.add(statement); // Execute the batch statement and verify the server response Result result = session_.execute(batch, false); - ASSERT_EQ(CASS_ERROR_SERVER_INVALID_QUERY, result.error_code()); // Cannot include a counter statement in a logged batch + ASSERT_EQ(CASS_ERROR_SERVER_INVALID_QUERY, + result.error_code()); // Cannot include a counter statement in a logged batch } /** @@ -315,8 +312,7 @@ CASSANDRA_INTEGRATION_TEST_F(BatchCounterThreeNodeClusterTests, MixedPreparedAnd session_.execute(batch); // Validate the updates - Result result = session_.execute(default_select_all(), - CASS_CONSISTENCY_QUORUM); + Result result = session_.execute(default_select_all(), CASS_CONSISTENCY_QUORUM); ASSERT_EQ(number_of_rows, result.row_count()); ASSERT_EQ(2u, result.column_count()); Rows rows = result.rows(); diff --git a/gtests/src/integration/tests/test_by_name.cpp b/gtests/src/integration/tests/test_by_name.cpp index 3025112df..17dc07b32 100644 --- a/gtests/src/integration/tests/test_by_name.cpp +++ b/gtests/src/integration/tests/test_by_name.cpp @@ -16,27 +16,31 @@ #include "integration.hpp" -#define TABLE_FORMAT "CREATE TABLE %s (" \ - "key timeuuid PRIMARY KEY, " \ - "a int, " \ - "b boolean, " \ - "c text, " \ - "abc float, " \ - "\"ABC\" float, " \ - "\"aBc\" float" \ - ")" -#define TABLE_BYTES_FORMAT "CREATE TABLE %s (" \ - "key timeuuid PRIMARY KEY, " \ - "blobs blob, " \ - "varints varint" \ - ")" +#define TABLE_FORMAT \ + "CREATE TABLE %s (" \ + "key timeuuid PRIMARY KEY, " \ + "a int, " \ + "b boolean, " \ + "c text, " \ + "abc float, " \ + "\"ABC\" float, " \ + "\"aBc\" float" \ + ")" +#define TABLE_BYTES_FORMAT \ + "CREATE TABLE %s (" \ + "key timeuuid PRIMARY KEY, " \ + "blobs blob, " \ + "varints varint" \ + ")" #define INSERT_FORMAT "INSERT INTO %s (key, a, b, c) VALUES (?, ?, ?, ?)" -#define INSERT_CASE_SENSITIVE_FORMAT "INSERT INTO %s " \ - "(key, abc, \"ABC\", \"aBc\") " \ - "VALUES (?, ?, ?, ?)" -#define INSERT_ALL_FORMAT "INSERT INTO %s " \ - "(key, a, b, c, abc, \"ABC\", \"aBc\") " \ - "VALUES (?, ?, ?, ?, ?, ?, ?)" +#define INSERT_CASE_SENSITIVE_FORMAT \ + "INSERT INTO %s " \ + "(key, abc, \"ABC\", \"aBc\") " \ + "VALUES (?, ?, ?, ?)" +#define INSERT_ALL_FORMAT \ + "INSERT INTO %s " \ + "(key, a, b, c, abc, \"ABC\", \"aBc\") " \ + "VALUES (?, ?, ?, ?, ?, ?, ?)" #define INSERT_BYTES_FORMAT "INSERT INTO %s (key, blobs, varints) VALUES (?, ?, ?)" /** @@ -199,8 +203,7 @@ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, Prepared) { CHECK_FAILURE; // Prepare, create, insert and validate - Prepared prepared = session_.prepare(format_string(INSERT_FORMAT, - table_name_.c_str())); + Prepared prepared = session_.prepare(format_string(INSERT_FORMAT, table_name_.c_str())); insert_and_validate(prepared.bind()); } @@ -238,8 +241,8 @@ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, PreparedCaseSensitive) { CHECK_FAILURE; // Prepare, create, insert and validate - Prepared prepared = session_.prepare(format_string(INSERT_CASE_SENSITIVE_FORMAT, - table_name_.c_str())); + Prepared prepared = + session_.prepare(format_string(INSERT_CASE_SENSITIVE_FORMAT, table_name_.c_str())); insert_and_validate_case_sensitive(prepared.bind()); } @@ -261,8 +264,7 @@ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, SimpleCaseSensitive) { CHECK_VERSION(2.1.0); // Prepare, create, insert and validate - Statement statement(format_string(INSERT_CASE_SENSITIVE_FORMAT, - table_name_.c_str()), 4); + Statement statement(format_string(INSERT_CASE_SENSITIVE_FORMAT, table_name_.c_str()), 4); insert_and_validate_case_sensitive(statement); } @@ -282,8 +284,8 @@ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, MultipleBinds) { CHECK_FAILURE; // Prepare, bind, and insert the values into the table - Prepared prepared = session_.prepare(format_string(INSERT_CASE_SENSITIVE_FORMAT, - table_name_.c_str())); + Prepared prepared = + session_.prepare(format_string(INSERT_CASE_SENSITIVE_FORMAT, table_name_.c_str())); Statement statement = prepared.bind(); TimeUuid key = uuid_generator_.generate_timeuuid(); statement.bind("key", key); @@ -311,14 +313,13 @@ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, MultipleBinds) { * @test_category queries:prepared * @since core:1.0.0 * @expected_result Driver error will occur when binding value to invalid column - * name + * name */ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, BindUsingInvalidName) { CHECK_FAILURE; // Prepare and create the insert statement - Prepared prepared = session_.prepare(format_string(INSERT_ALL_FORMAT, - table_name_.c_str())); + Prepared prepared = session_.prepare(format_string(INSERT_ALL_FORMAT, table_name_.c_str())); Statement statement = prepared.bind(); // Bind values to invalid columns name and validate error @@ -339,14 +340,13 @@ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, BindUsingInvalidName) { * @test_category queries:basic * @since core:1.0.0 * @expected_result Driver error will occur when retrieving value from invalid - * column name + * column name */ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, RetrieveInvalidName) { CHECK_FAILURE; // Prepare, create, insert and validate (all) - Prepared prepared = session_.prepare(format_string(INSERT_ALL_FORMAT, - table_name_.c_str())); + Prepared prepared = session_.prepare(format_string(INSERT_ALL_FORMAT, table_name_.c_str())); Statement statement = prepared.bind(); insert_and_validate_all(statement); @@ -373,8 +373,7 @@ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, NullPrepared) { CHECK_FAILURE; // Prepare, create, insert and validate - Prepared prepared = session_.prepare(format_string(INSERT_ALL_FORMAT, - table_name_.c_str())); + Prepared prepared = session_.prepare(format_string(INSERT_ALL_FORMAT, table_name_.c_str())); insert_and_validate_all_null(prepared.bind()); } @@ -423,8 +422,7 @@ CASSANDRA_INTEGRATION_TEST_F(ByNameBytesTests, Prepared) { Varint varints("1234567890123456789012345678901234567890"); // Prepare, bind, and insert the values into the table - Prepared prepared = session_.prepare(format_string(INSERT_BYTES_FORMAT, - table_name_.c_str())); + Prepared prepared = session_.prepare(format_string(INSERT_BYTES_FORMAT, table_name_.c_str())); Statement statement = prepared.bind(); statement.bind("key", key); statement.bind("blobs", blobs); diff --git a/gtests/src/integration/tests/test_cassandra_types.cpp b/gtests/src/integration/tests/test_cassandra_types.cpp index e84f8c0a9..87f63cbb1 100644 --- a/gtests/src/integration/tests/test_cassandra_types.cpp +++ b/gtests/src/integration/tests/test_cassandra_types.cpp @@ -19,7 +19,7 @@ /** * Cassandra type integration tests */ -template +template class CassandraTypesTest : public Integration { public: /** @@ -28,7 +28,7 @@ class CassandraTypesTest : public Integration { static const std::vector values_; CassandraTypesTest() - : is_key_allowed_(true) { } + : is_key_allowed_(true) {} void SetUp() { // Enable schema metadata to easily create user type (when needed) @@ -76,11 +76,11 @@ class CassandraTypesTest : public Integration { */ void initialize(const std::string& cql_type) { if (is_key_allowed_) { - session_.execute(format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, - table_name_.c_str(), cql_type.c_str(), cql_type.c_str())); + session_.execute(format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, table_name_.c_str(), + cql_type.c_str(), cql_type.c_str())); } else { - session_.execute(format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, - table_name_.c_str(), "int", cql_type.c_str())); + session_.execute(format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, table_name_.c_str(), "int", + cql_type.c_str())); } insert_query_ = format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, table_name_.c_str(), "?", "?"); select_query_ = format_string(CASSANDRA_SELECT_VALUE_FORMAT, table_name_.c_str(), "?"); @@ -92,7 +92,7 @@ TYPED_TEST_CASE_P(CassandraTypesTest); /** * Specialized duration integration test extension */ -class CassandraTypesDurationTest : public CassandraTypesTest { }; +class CassandraTypesDurationTest : public CassandraTypesTest {}; /** * Perform insert using a simple and prepared statement operation @@ -114,16 +114,14 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, Basic) { const std::vector& values = CassandraTypesTest::values_; // Iterate over all the Cassandra type values - for (typename std::vector::const_iterator it = values.begin(); - it != values.end(); ++it) { + for (typename std::vector::const_iterator it = values.begin(); it != values.end(); + ++it) { // Get the current value const TypeParam& value = *it; // Create both simple and prepared statements - Statement statements[] = { - Statement(this->insert_query_, 2), - this->prepared_statement_.bind() - }; + Statement statements[] = { Statement(this->insert_query_, 2), + this->prepared_statement_.bind() }; // Iterate over all the statements for (size_t i = 0; i < ARRAY_LEN(statements); ++i) { @@ -173,16 +171,14 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, BasicByName) { const std::vector& values = CassandraTypesTest::values_; // Iterate over all the Cassandra type values - for (typename std::vector::const_iterator it = values.begin(); - it != values.end(); ++it) { + for (typename std::vector::const_iterator it = values.begin(); it != values.end(); + ++it) { // Get the current value const TypeParam& value = *it; // Create both simple and prepared statements - Statement statements[] = { - Statement(this->insert_query_, 2), - this->prepared_statement_.bind() - }; + Statement statements[] = { Statement(this->insert_query_, 2), + this->prepared_statement_.bind() }; // Iterate over all the statements for (size_t i = 0; i < ARRAY_LEN(statements); ++i) { @@ -230,10 +226,7 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, BasicNullValues) { this->default_setup(); // Create both simple and prepared statements - Statement statements[] = { - Statement(this->insert_query_, 2), - this->prepared_statement_.bind() - }; + Statement statements[] = { Statement(this->insert_query_, 2), this->prepared_statement_.bind() }; // Iterate over all the statements for (size_t i = 0; i < ARRAY_LEN(statements); ++i) { @@ -276,10 +269,7 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, BasicNullList) { this->default_setup(); // Create both simple and prepared statements - Statement statements[] = { - Statement(this->insert_query_, 2), - this->prepared_statement_.bind() - }; + Statement statements[] = { Statement(this->insert_query_, 2), this->prepared_statement_.bind() }; // Iterate over all the statements for (size_t i = 0; i < ARRAY_LEN(statements); ++i) { @@ -297,7 +287,7 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, BasicNullList) { Result result = this->session_.execute(select_statement); ASSERT_EQ(1u, result.row_count()); test::driver::List select_value = - result.first_row().next().as >(); + result.first_row().next().as >(); ASSERT_EQ(value, select_value); ASSERT_TRUE(select_value.is_null()); } @@ -323,10 +313,7 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, BasicNullMap) { this->default_setup(); // Create both simple and prepared statements - Statement statements[] = { - Statement(this->insert_query_, 2), - this->prepared_statement_.bind() - }; + Statement statements[] = { Statement(this->insert_query_, 2), this->prepared_statement_.bind() }; // Iterate over all the statements for (size_t i = 0; i < ARRAY_LEN(statements); ++i) { @@ -344,7 +331,7 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, BasicNullMap) { Result result = this->session_.execute(select_statement); ASSERT_EQ(1u, result.row_count()); test::driver::Map select_value = - result.first_row().next().as >(); + result.first_row().next().as >(); ASSERT_EQ(value, select_value); ASSERT_TRUE(select_value.is_null()); } @@ -370,10 +357,7 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, BasicNullSet) { this->default_setup(); // Create both simple and prepared statements - Statement statements[] = { - Statement(this->insert_query_, 2), - this->prepared_statement_.bind() - }; + Statement statements[] = { Statement(this->insert_query_, 2), this->prepared_statement_.bind() }; // Iterate over all the statements for (size_t i = 0; i < ARRAY_LEN(statements); ++i) { @@ -391,7 +375,7 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, BasicNullSet) { Result result = this->session_.execute(select_statement); ASSERT_EQ(1u, result.row_count()); test::driver::Set select_value = - result.first_row().next().as >(); + result.first_row().next().as >(); ASSERT_EQ(value, select_value); ASSERT_TRUE(select_value.is_null()); } @@ -419,10 +403,7 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, List) { this->initialize("frozen<" + list.cql_type() + ">"); // Create both simple and prepared statements - Statement statements[] = { - Statement(this->insert_query_, 2), - this->prepared_statement_.bind() - }; + Statement statements[] = { Statement(this->insert_query_, 2), this->prepared_statement_.bind() }; // Iterate over all the statements for (size_t i = 0; i < ARRAY_LEN(statements); ++i) { @@ -476,10 +457,7 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, Set) { this->initialize("frozen<" + set.cql_type() + ">"); // Create both simple and prepared statements - Statement statements[] = { - Statement(this->insert_query_, 2), - this->prepared_statement_.bind() - }; + Statement statements[] = { Statement(this->insert_query_, 2), this->prepared_statement_.bind() }; // Iterate overall all the statements for (size_t i = 0; i < ARRAY_LEN(statements); ++i) { @@ -530,18 +508,16 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, Map) { // Initialize the table and assign the values for the map std::map map_values; const std::vector& values = CassandraTypesTest::values_; - for (typename std::vector::const_iterator it = values.begin(); - it != values.end(); ++it) { + for (typename std::vector::const_iterator it = values.begin(); it != values.end(); + ++it) { map_values[*it] = *it; } Map map(map_values); this->initialize("frozen<" + map.cql_type() + ">"); // Create both simple and prepared statements - Statement statements[] = { - Statement(this->insert_query_, 2), - this->prepared_statement_.bind() - }; + Statement statements[] = { Statement(this->insert_query_, 2), + this->prepared_statement_.bind() }; // Iterate over all the statements for (size_t i = 0; i < ARRAY_LEN(statements); ++i) { @@ -566,18 +542,16 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, Map) { std::map map_values; const std::vector& values = CassandraTypesTest::values_; cass_int32_t count = 1; - for (typename std::vector::const_iterator it = values.begin(); - it != values.end(); ++it) { + for (typename std::vector::const_iterator it = values.begin(); it != values.end(); + ++it) { map_values[Integer(count++)] = *it; } Map map(map_values); this->initialize("frozen<" + map.cql_type() + ">"); // Create both simple and prepared statements - Statement statements[] = { - Statement(this->insert_query_, 2), - this->prepared_statement_.bind() - }; + Statement statements[] = { Statement(this->insert_query_, 2), + this->prepared_statement_.bind() }; // Iterate over all the statements for (size_t i = 0; i < ARRAY_LEN(statements); ++i) { @@ -632,10 +606,7 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, Tuple) { this->initialize(cql_type); // Create both simple and prepared statements - Statement statements[] = { - Statement(this->insert_query_, 2), - this->prepared_statement_.bind() - }; + Statement statements[] = { Statement(this->insert_query_, 2), this->prepared_statement_.bind() }; // Iterate over all the statements for (size_t i = 0; i < ARRAY_LEN(statements); ++i) { @@ -703,7 +674,7 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, UDT) { this->session_.execute(create_type); // Initialize the table; NOTE: UDT must be frozen for older versions of Cassandra - this->initialize("frozen<" + cql_type + ">"); + this->initialize("frozen<" + cql_type + ">"); // Build our UDT values and UDT type std::map udt_values; @@ -712,21 +683,17 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, UDT) { field << "field" << i; udt_values[field.str()] = values[i]; } - UserType user_type(this->session_.schema() - .keyspace(this->keyspace_name_) - .user_type(cql_type).data_type()); + UserType user_type( + this->session_.schema().keyspace(this->keyspace_name_).user_type(cql_type).data_type()); // Assign/Set the values in the user type for (typename std::map::const_iterator it = udt_values.begin(); - it != udt_values.end(); ++it) { + it != udt_values.end(); ++it) { user_type.set(it->second, it->first); } // Use both simple and prepared statements - Statement statements[] = { - Statement(this->insert_query_, 2), - this->prepared_statement_.bind() - }; + Statement statements[] = { Statement(this->insert_query_, 2), this->prepared_statement_.bind() }; for (size_t i = 0; i < ARRAY_LEN(statements); ++i) { Statement& statement = statements[i]; @@ -756,16 +723,11 @@ CASSANDRA_INTEGRATION_TYPED_TEST_P(CassandraTypesTest, UDT) { // Register all parameterized test cases for primitives (excludes duration) REGISTER_TYPED_TEST_CASE_P(CassandraTypesTest, Integration_Cassandra_Basic, - Integration_Cassandra_BasicByName, - Integration_Cassandra_BasicNullValues, - Integration_Cassandra_BasicNullList, - Integration_Cassandra_BasicNullMap, - Integration_Cassandra_BasicNullSet, - Integration_Cassandra_List, - Integration_Cassandra_Set, - Integration_Cassandra_Map, - Integration_Cassandra_Tuple, - Integration_Cassandra_UDT); + Integration_Cassandra_BasicByName, Integration_Cassandra_BasicNullValues, + Integration_Cassandra_BasicNullList, Integration_Cassandra_BasicNullMap, + Integration_Cassandra_BasicNullSet, Integration_Cassandra_List, + Integration_Cassandra_Set, Integration_Cassandra_Map, + Integration_Cassandra_Tuple, Integration_Cassandra_UDT); /** * Attempt to utilize an invalid duration value on a statement @@ -800,115 +762,84 @@ CASSANDRA_INTEGRATION_TEST_F(CassandraTypesDurationTest, MixedValues) { } // Instantiate the test case for all the Cassandra data types -typedef testing::Types CassandraTypes; +typedef testing::Types + CassandraTypes; INSTANTIATE_TYPED_TEST_CASE_P(CassandraTypes, CassandraTypesTest, CassandraTypes); /** * Values for ASCII tests */ -const Ascii ASCII_VALUES[] = { - Ascii("DataStax"), - Ascii("C/C++"), - Ascii("Driver"), - Ascii("Cassandra") -}; -template<> const std::vector CassandraTypesTest::values_( - ASCII_VALUES, - ASCII_VALUES + ARRAY_LEN(ASCII_VALUES)); +const Ascii ASCII_VALUES[] = { Ascii("DataStax"), Ascii("C/C++"), Ascii("Driver"), + Ascii("Cassandra") }; +template <> +const std::vector CassandraTypesTest::values_(ASCII_VALUES, + ASCII_VALUES + ARRAY_LEN(ASCII_VALUES)); /** * Values for bigint tests */ -const BigInteger BIGINT_VALUES[] = { - BigInteger::max(), - BigInteger::min(), - BigInteger(static_cast(0)), - BigInteger(37) -}; -template<> const std::vector CassandraTypesTest::values_( - BIGINT_VALUES, - BIGINT_VALUES + ARRAY_LEN(BIGINT_VALUES)); +const BigInteger BIGINT_VALUES[] = { BigInteger::max(), BigInteger::min(), + BigInteger(static_cast(0)), BigInteger(37) }; +template <> +const std::vector CassandraTypesTest::values_(BIGINT_VALUES, + BIGINT_VALUES + + ARRAY_LEN(BIGINT_VALUES)); /** * Values for blob tests */ -const Blob BLOB_VALUES[] = { - Blob("DataStax C/C++ Driver"), - Blob("Cassandra"), - Blob("DataStax Enterprise") -}; -template<> const std::vector CassandraTypesTest::values_( - BLOB_VALUES, - BLOB_VALUES + ARRAY_LEN(BLOB_VALUES)); +const Blob BLOB_VALUES[] = { Blob("DataStax C/C++ Driver"), Blob("Cassandra"), + Blob("DataStax Enterprise") }; +template <> +const std::vector CassandraTypesTest::values_(BLOB_VALUES, + BLOB_VALUES + ARRAY_LEN(BLOB_VALUES)); /** * Values for boolean tests */ -const Boolean BOOLEAN_VALUES[] = { - Boolean(true), - Boolean(false) -}; -template<> const std::vector CassandraTypesTest::values_( - BOOLEAN_VALUES, - BOOLEAN_VALUES + ARRAY_LEN(BOOLEAN_VALUES)); +const Boolean BOOLEAN_VALUES[] = { Boolean(true), Boolean(false) }; +template <> +const std::vector CassandraTypesTest::values_(BOOLEAN_VALUES, + BOOLEAN_VALUES + + ARRAY_LEN(BOOLEAN_VALUES)); /** * Values for date tests */ -const Date DATE_VALUES[] = { - Date::max(), // maximum for strftime - Date::min(), // minimum for strftime - Date(static_cast(0)), - Date(12345u) -}; -template<> const std::vector CassandraTypesTest::values_( - DATE_VALUES, - DATE_VALUES + ARRAY_LEN(DATE_VALUES)); +const Date DATE_VALUES[] = { Date::max(), // maximum for strftime + Date::min(), // minimum for strftime + Date(static_cast(0)), Date(12345u) }; +template <> +const std::vector CassandraTypesTest::values_(DATE_VALUES, + DATE_VALUES + ARRAY_LEN(DATE_VALUES)); /** * Values for decimal tests */ -const Decimal DECIMAL_VALUES[] = { - Decimal("3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"), - Decimal("2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274"), - Decimal("1.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374") -}; -template<> const std::vector CassandraTypesTest::values_( - DECIMAL_VALUES, - DECIMAL_VALUES + ARRAY_LEN(DECIMAL_VALUES)); +const Decimal DECIMAL_VALUES[] = { Decimal("3." + "1415926535897932384626433832795028841971693993751058209" + "749445923078164062862089986280348253421170679"), + Decimal("2." + "7182818284590452353602874713526624977572470936999595749" + "669676277240766303535475945713821785251664274"), + Decimal("1." + "6180339887498948482045868343656381177203091798057628621" + "354486227052604628189024497072072041893911374") }; +template <> +const std::vector CassandraTypesTest::values_(DECIMAL_VALUES, + DECIMAL_VALUES + + ARRAY_LEN(DECIMAL_VALUES)); /** * Values for double tests */ -const Double DOUBLE_VALUES[] = { - Double::max(), - Double::min(), - Double(3.1415926535), - Double(2.7182818284), - Double(1.6180339887) -}; -template<> const std::vector CassandraTypesTest::values_( - DOUBLE_VALUES, - DOUBLE_VALUES + ARRAY_LEN(DOUBLE_VALUES)); +const Double DOUBLE_VALUES[] = { Double::max(), Double::min(), Double(3.1415926535), + Double(2.7182818284), Double(1.6180339887) }; +template <> +const std::vector + CassandraTypesTest::values_(DOUBLE_VALUES, DOUBLE_VALUES + ARRAY_LEN(DOUBLE_VALUES)); /** * Values for duration tests @@ -922,168 +853,127 @@ const Duration DURATION_VALUES[] = { Duration(CassDuration(0, std::numeric_limits::max(), 1)), Duration(CassDuration(0, std::numeric_limits::min(), -1)) }; -template<> const std::vector CassandraTypesTest::values_( - DURATION_VALUES, - DURATION_VALUES + ARRAY_LEN(DURATION_VALUES)); +template <> +const std::vector CassandraTypesTest::values_(DURATION_VALUES, + DURATION_VALUES + + ARRAY_LEN(DURATION_VALUES)); /** * Values for float tests */ -const Float FLOAT_VALUES[] = { - Float::max(), - Float::min(), - Float(3.14159f), - Float(2.71828f), - Float(1.61803f) -}; -template<> const std::vector CassandraTypesTest::values_( - FLOAT_VALUES, - FLOAT_VALUES + ARRAY_LEN(FLOAT_VALUES)); +const Float FLOAT_VALUES[] = { Float::max(), Float::min(), Float(3.14159f), Float(2.71828f), + Float(1.61803f) }; +template <> +const std::vector CassandraTypesTest::values_(FLOAT_VALUES, + FLOAT_VALUES + ARRAY_LEN(FLOAT_VALUES)); /** * Values for inet tests */ -const Inet INET_VALUES[] = { - Inet::max(), - Inet::min(), - Inet("127.0.0.1"), - Inet("0:0:0:0:0:0:0:1"), - Inet("2001:db8:85a3:0:0:8a2e:370:7334") -}; -template<> const std::vector CassandraTypesTest::values_( - INET_VALUES, - INET_VALUES + ARRAY_LEN(INET_VALUES)); +const Inet INET_VALUES[] = { Inet::max(), Inet::min(), Inet("127.0.0.1"), Inet("0:0:0:0:0:0:0:1"), + Inet("2001:db8:85a3:0:0:8a2e:370:7334") }; +template <> +const std::vector CassandraTypesTest::values_(INET_VALUES, + INET_VALUES + ARRAY_LEN(INET_VALUES)); /** * Values for int tests */ -const Integer INT_VALUES[] = { - Integer::max(), - Integer::min(), - Integer(0), - Integer(148) -}; -template<> const std::vector CassandraTypesTest::values_( - INT_VALUES, - INT_VALUES + ARRAY_LEN(INT_VALUES)); +const Integer INT_VALUES[] = { Integer::max(), Integer::min(), Integer(0), Integer(148) }; +template <> +const std::vector CassandraTypesTest::values_(INT_VALUES, + INT_VALUES + ARRAY_LEN(INT_VALUES)); /** * Values for smallint tests */ -const SmallInteger SMALLINT_VALUES[] = { - SmallInteger::max(), - SmallInteger::min(), - SmallInteger(static_cast(0)), - SmallInteger(148) -}; -template<> const std::vector CassandraTypesTest::values_( - SMALLINT_VALUES, - SMALLINT_VALUES + ARRAY_LEN(SMALLINT_VALUES)); +const SmallInteger SMALLINT_VALUES[] = { SmallInteger::max(), SmallInteger::min(), + SmallInteger(static_cast(0)), SmallInteger(148) }; +template <> +const std::vector + CassandraTypesTest::values_(SMALLINT_VALUES, + SMALLINT_VALUES + ARRAY_LEN(SMALLINT_VALUES)); /** * Values for text tests */ -const Text TEXT_VALUES[] = { - Text("The quick brown fox jumps over the lazy dog"), - Text("Hello World"), - Text("DataStax C/C++ Driver") -}; -template<> const std::vector CassandraTypesTest::values_( - TEXT_VALUES, - TEXT_VALUES + ARRAY_LEN(TEXT_VALUES)); +const Text TEXT_VALUES[] = { Text("The quick brown fox jumps over the lazy dog"), + Text("Hello World"), Text("DataStax C/C++ Driver") }; +template <> +const std::vector CassandraTypesTest::values_(TEXT_VALUES, + TEXT_VALUES + ARRAY_LEN(TEXT_VALUES)); /** * Values for time tests */ -const Time TIME_VALUES[] = { - Time::max(), - Time::min(), - Time(static_cast(0)), - Time(9876543210) -}; -template<> const std::vector