diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..3464a34463 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "googletest"] + path = hazelcast/test/googletest + url = git@github.com:ihsandemir/googletest.git + branch = hazelcasttest diff --git a/CMakeLists.txt b/CMakeLists.txt index 923daf5377..d85adadcb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,6 @@ project (HazelcastClient) # -DHZ_BIT=[32 | 64] # -DHZ_CODE_COVERAGE=ON # -DHZ_VALGRIND=ON -# -DHZ_ADDRESS_SANITIZER=ON INCLUDE(TestBigEndian) @@ -29,7 +28,7 @@ SET(HZ_VERSION 3.6.1-SNAPSHOT) message(STATUS "Preparing hazelcast client ..... ") -include_directories( ${CMAKE_SOURCE_DIR}/external/include/) +include_directories(${CMAKE_SOURCE_DIR}/external/include/) #detect endianness TEST_BIG_ENDIAN(IS_BIG_ENDIAN) @@ -51,13 +50,6 @@ IF(NOT (${HZ_BIT} MATCHES "32") AND NOT (${HZ_BIT} MATCHES "64") ) set(HZ_BIT 64) ENDIF(NOT (${HZ_BIT} MATCHES "32") AND NOT (${HZ_BIT} MATCHES "64")) -SET(HZ_BIT_FLAG " ") -IF(${HZ_BIT} MATCHES "32") - SET(HZ_BIT_FLAG " -m32 ") -ENDIF(${HZ_BIT} MATCHES "32") - -message(STATUS "${HZ_BIT} Bit") - IF(NOT (${HZ_LIB_TYPE} MATCHES "STATIC") AND NOT (${HZ_LIB_TYPE} MATCHES "SHARED") ) message( STATUS "Build needs HZ_LIB_TYPE. Setting default as -DHZ_LIB_TYPE=STATIC (other option -DHZ_LIB_TYPE=SHARED)" ) set(HZ_LIB_TYPE STATIC) @@ -86,12 +78,18 @@ IF(${HZ_VALGRIND} MATCHES "ON") set(HZ_VALGRIND_LINK_FLAGS " -O0 ") ENDIF(${HZ_VALGRIND} MATCHES "ON") +set(HZ_C11_FLAGS "") +IF(${HZ_USE_C11} MATCHES "ON") + set(HZ_C11_FLAGS "-std=c++11") + message(STATUS "C++11 compiler is turned on.") +ENDIF(${HZ_USE_C11} MATCHES "ON") + message(STATUS "${CMAKE_SYSTEM}") IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") message(STATUS "APPLE ENVIRONMENT DETECTED") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -Wall -Werror") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wall") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -Wall -Werror ${HZ_C11_FLAGS}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wall ${HZ_C11_FLAGS}") link_libraries(${HZ_LIB_NAME} ) @@ -99,9 +97,16 @@ ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") message(STATUS "LINUX ENVIRONMENT DETECTED") - - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -Wall -Werror ${HZ_BIT_FLAG} ${HZ_CODE_COVERAGE_COMPILE_FLAGS} ${HZ_VALGRIND_COMPILE_FLAGS}") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wall ${HZ_BIT_FLAG} ${HZ_CODE_COVERAGE_COMPILE_FLAGS} ${HZ_VALGRIND_COMPILE_FLAGS}") + + SET(HZ_BIT_FLAG " ") + IF(${HZ_BIT} MATCHES "32") + SET(HZ_BIT_FLAG " -m32 ") + ENDIF(${HZ_BIT} MATCHES "32") + + message(STATUS "${HZ_BIT} Bit") + + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -Wall -Werror ${HZ_BIT_FLAG} ${HZ_CODE_COVERAGE_COMPILE_FLAGS} ${HZ_VALGRIND_COMPILE_FLAGS} ${HZ_C11_FLAGS}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wall ${HZ_BIT_FLAG} ${HZ_CODE_COVERAGE_COMPILE_FLAGS} ${HZ_VALGRIND_COMPILE_FLAGS} ${HZ_C11_FLAGS}") link_libraries(${HZ_LIB_NAME} pthread rt ) @@ -117,12 +122,18 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") add_definitions(-DHAZELCAST_EXPORTS=0) ENDIF(${HZ_LIB_TYPE} MATCHES "SHARED") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MP /EHsc") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MP /EHsc") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MP /EHsc ${HZ_C11_FLAGS}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MP /EHsc ${HZ_C11_FLAGS}") link_libraries(${HZ_LIB_NAME}) - ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") -ADD_SUBDIRECTORY(hazelcast/test) -ADD_SUBDIRECTORY(examples) +IF(${HZ_BUILD_TESTS} MATCHES "ON") + SET(BUILD_GTEST "ON") + SET(DBUILD_GMOCK "OFF") + ADD_SUBDIRECTORY(hazelcast/test) +ENDIF(${HZ_BUILD_TESTS} MATCHES "ON") + +IF(${HZ_BUILD_EXAMPLES} MATCHES "ON") + ADD_SUBDIRECTORY(examples) +ENDIF(${HZ_BUILD_EXAMPLES} MATCHES "ON") diff --git a/README.md b/README.md index 0ff520d2d6..fe4ecd1aaf 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,14 @@ API Documentation can be generated via doxygen from root with following command doxygen docsConfig ``` +## How to download + +Clone the project from github: + +git clone --recursive git@github.com:hazelcast/hazelcast-cpp-client.git + +We use --recursive flag for our dependency on googletest framework. + ## How to build First create a build directory from the root of the project and in the directory run the following commands depending on your environment. @@ -40,9 +48,6 @@ First create a build directory from the root of the project and in the directory cmake .. -G Xcode -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Debug cmake .. -G Xcode -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=archive -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=library -### For Linux Address Sanitizer - - cmake .. -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Debug -DHZ_ADDRESS_SANITIZER=ON ### valgrind sample run with suppresions @@ -56,6 +61,16 @@ First create a build directory from the root of the project and in the directory cmake .. -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release cmake .. -DHZ_LIB_TYPE=SHARED -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release +### For building the tests + + Add the -DHZ_BUILD_TESTS=ON flag to the cmake flags. e.g.: + cmake .. -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Debug -DHZ_BUILD_TESTS=ON + +### For building the examples + + Add the -DHZ_BUILD_EXAMPLES=ON flag to the cmake flags. e.g.: + cmake .. -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Debug -DHZ_BUILD_EXAMPLES=ON + ### For linux valgrind cmake .. -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Debug -DHZ_VALGRIND=ON diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index ed5171482f..91f358dd92 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,4 +1,4 @@ -# +# # Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +13,129 @@ # See the License for the specific language governing permissions and # limitations under the License. # +cmake_minimum_required (VERSION 3.1) +project (HazelcastExamples) + +INCLUDE(TestBigEndian) + +# if HAZELCAST_INSTALL_DIR option is provided, the examples shall compile with the released library +if (NOT("${HAZELCAST_INSTALL_DIR}x" STREQUAL "x")) + message (STATUS "Using hazelcast installation at ${HAZELCAST_INSTALL_DIR}.") + + if(NOT("${HZ_VERSION}x" MATCHES "x")) + message(FATAL_ERROR "Release verification require that this folder is NOT included from a parent CMakeLists.txt.") + endif (NOT("${HZ_VERSION}x" MATCHES "x")) + + if ("${HZ_BIT}x" STREQUAL "x") + message(FATAL_ERROR "You have to specify HZ_BIT variable!") + endif() + + IF(NOT (${HZ_LIB_TYPE} MATCHES "STATIC") AND NOT (${HZ_LIB_TYPE} MATCHES "SHARED") ) + message( STATUS "Build needs HZ_LIB_TYPE. Setting default as -DHZ_LIB_TYPE=STATIC (other option -DHZ_LIB_TYPE=SHARED)" ) + set(HZ_LIB_TYPE STATIC) + ENDIF(NOT (${HZ_LIB_TYPE} MATCHES "STATIC") AND NOT (${HZ_LIB_TYPE} MATCHES "SHARED") ) + + SET(HZ_VERSION 3.7-SNAPSHOT) + + IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + SET(HAZELCAST_PLATFORM_INSTALL_DIR ${HAZELCAST_INSTALL_DIR}\\${CMAKE_SYSTEM_NAME}_${HZ_BIT}) + ELSE() + SET(HAZELCAST_PLATFORM_INSTALL_DIR ${HAZELCAST_INSTALL_DIR}/${CMAKE_SYSTEM_NAME}_${HZ_BIT}) + ENDIF() + + message(STATUS "Shall try building the examples with installed Hazelcast client at ${HAZELCAST_PLATFORM_INSTALL_DIR}") + message(STATUS "Include directories: ${HAZELCAST_PLATFORM_INSTALL_DIR}/hazelcast/include ${HAZELCAST_PLATFORM_INSTALL_DIR}/external/include") + message(STATUS "Link directory: ${HAZELCAST_PLATFORM_INSTALL_DIR}/hazelcast/lib") + + #detect endianness + TEST_BIG_ENDIAN(IS_BIG_ENDIAN) + if (${IS_BIG_ENDIAN}) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DHZ_BIG_ENDIAN") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DHZ_BIG_ENDIAN") + ENDIF (${IS_BIG_ENDIAN}) + + include_directories(${HAZELCAST_PLATFORM_INSTALL_DIR}/hazelcast/include ${HAZELCAST_PLATFORM_INSTALL_DIR}/external/include) + + SET(HZ_LIB_NAME HazelcastClient${HZ_VERSION}_${HZ_BIT}) + + ADD_LIBRARY(${HZ_LIB_NAME} ${HZ_LIB_TYPE} IMPORTED) + + message(STATUS "${CMAKE_SYSTEM}") + + IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + message(STATUS "APPLE ENVIRONMENT DETECTED") + + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall") + + set(HZ_LIB_PATH "") + IF (${HZ_LIB_TYPE} MATCHES "STATIC") + set(HZ_LIB_PATH "${HAZELCAST_PLATFORM_INSTALL_DIR}/hazelcast/lib/lib${HZ_LIB_NAME}.a") + ELSE(${HZ_LIB_TYPE} MATCHES "STATIC") + set(HZ_LIB_PATH "${HAZELCAST_PLATFORM_INSTALL_DIR}/hazelcast/lib/lib${HZ_LIB_NAME}.dylib") + ENDIF(${HZ_LIB_TYPE} MATCHES "STATIC") + + message(STATUS "Using ${HZ_LIB_TYPE} library at ${HZ_LIB_PATH}") + + set_property(TARGET ${HZ_LIB_NAME} PROPERTY IMPORTED_LOCATION "${HZ_LIB_PATH}") + + link_libraries(${HZ_LIB_NAME} ) + + ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + + IF( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" ) + message(STATUS "LINUX ENVIRONMENT DETECTED") + + SET(HZ_BIT_FLAG " ") + IF(${HZ_BIT} MATCHES "32") + SET(HZ_BIT_FLAG " -m32 ") + ENDIF(${HZ_BIT} MATCHES "32") + + message(STATUS "${HZ_BIT} Bit") + + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall ${HZ_BIT_FLAG}") + + set(HZ_LIB_PATH "") + IF (${HZ_LIB_TYPE} MATCHES "STATIC") + set(HZ_LIB_PATH "${HAZELCAST_PLATFORM_INSTALL_DIR}/hazelcast/lib/lib${HZ_LIB_NAME}.a") + ELSE(${HZ_LIB_TYPE} MATCHES "STATIC") + set(HZ_LIB_PATH "${HAZELCAST_PLATFORM_INSTALL_DIR}/hazelcast/lib/lib${HZ_LIB_NAME}.so") + ENDIF(${HZ_LIB_TYPE} MATCHES "STATIC") + + message(STATUS "Using ${HZ_LIB_TYPE} library at ${HZ_LIB_PATH}") + + set_property(TARGET ${HZ_LIB_NAME} PROPERTY IMPORTED_LOCATION "${HZ_LIB_PATH}") + + link_libraries(${HZ_LIB_NAME} pthread rt ) + ENDIF( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" ) + + IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + message(STATUS "WINDOWS ENVIRONMENT DETECTED ${CMAKE_GENERATOR} ${CMAKE_BUILD_TYPE} ") + + add_definitions(-D__WIN${HZ_BIT}__ -DWIN${HZ_BIT} -D_WIN${HZ_BIT}) + + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /EHsc") + + add_definitions(-DHAZELCAST_EXPORTS=0) + + IF (${HZ_LIB_TYPE} MATCHES "STATIC") + set(HZ_LIB_PATH "${HAZELCAST_PLATFORM_INSTALL_DIR}\\hazelcast\\lib\\static\\${HZ_LIB_NAME}.lib") + set_property(TARGET ${HZ_LIB_NAME} PROPERTY IMPORTED_LOCATION ${HZ_LIB_PATH}) + + message(STATUS "Using ${HZ_LIB_TYPE} library at ${HZ_LIB_PATH}") + ELSE(${HZ_LIB_TYPE} MATCHES "STATIC") + set(HZ_LIB_PATH "${HAZELCAST_PLATFORM_INSTALL_DIR}\\hazelcast\\lib\\shared\\${HZ_LIB_NAME}.dll") + set(HZ_LIB_IMPLIB_PATH "${HAZELCAST_PLATFORM_INSTALL_DIR}\\hazelcast\\lib\\shared\\${HZ_LIB_NAME}.lib") + + set_property(TARGET ${HZ_LIB_NAME} PROPERTY IMPORTED_LOCATION ${HZ_LIB_PATH}) + set_property(TARGET ${HZ_LIB_NAME} PROPERTY IMPORTED_IMPLIB ${HZ_LIB_IMPLIB_PATH}) + + message(STATUS "Using ${HZ_LIB_TYPE} library at ${HZ_LIB_PATH}") + ENDIF(${HZ_LIB_TYPE} MATCHES "STATIC") + + link_libraries(${HZ_LIB_NAME}) + ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") +endif (NOT("${HAZELCAST_INSTALL_DIR}x" STREQUAL "x")) + add_subdirectory(CommandLineTool) add_subdirectory(transactions) add_subdirectory(spi) @@ -29,3 +152,4 @@ add_subdirectory(distributed-collections) + diff --git a/examples/distributed-map/locking/PessimisticUpdate.cpp b/examples/distributed-map/locking/PessimisticUpdate.cpp index 13f359266a..e01adaa6f9 100644 --- a/examples/distributed-map/locking/PessimisticUpdate.cpp +++ b/examples/distributed-map/locking/PessimisticUpdate.cpp @@ -76,7 +76,7 @@ int main() { map.unlock(key); } catch (hazelcast::client::exception::IException &e) { map.unlock(key); - throw; + throw e; } } std::cout << "Finished! Result = " << map.get(key)->amount << std::endl; diff --git a/examples/distributed-primitives/lock/RaceFree.cpp b/examples/distributed-primitives/lock/RaceFree.cpp index 020bdd2159..7bf9417af1 100644 --- a/examples/distributed-primitives/lock/RaceFree.cpp +++ b/examples/distributed-primitives/lock/RaceFree.cpp @@ -49,7 +49,7 @@ int main() { } } catch (hazelcast::client::exception::IException &e) { lock.unlock(); - throw; + throw e; } if (k % 2 == 0) { diff --git a/examples/distributed-primitives/semaphore/Semaphore.cpp b/examples/distributed-primitives/semaphore/Semaphore.cpp index f289e947d4..3749911d25 100644 --- a/examples/distributed-primitives/semaphore/Semaphore.cpp +++ b/examples/distributed-primitives/semaphore/Semaphore.cpp @@ -35,7 +35,7 @@ int main() { resource.decrementAndGet(); } catch (hazelcast::client::exception::IException &e) { semaphore.release(); - throw; + throw e; } } diff --git a/examples/serialization/custom/main.cpp b/examples/serialization/custom/main.cpp index be2b9e01ed..395d2f46e2 100644 --- a/examples/serialization/custom/main.cpp +++ b/examples/serialization/custom/main.cpp @@ -35,15 +35,13 @@ class Person { return name; } - int getTypeId() const{ - return 666; - } - private: std::string name; }; - +int getHazelcastTypeId(const Person* p){ + return 666; +} class CustomSerializer : public hazelcast::client::serialization::Serializer { public: @@ -62,7 +60,7 @@ class CustomSerializer : public hazelcast::client::serialization::Serializer #include #include @@ -201,7 +202,7 @@ namespace hazelcast { return boost::shared_ptr(static_cast(NULL)); } else { std::auto_ptr result(new T); - constants.checkClassType(result->getTypeId() , typeId); + constants.checkClassType(getHazelcastTypeId(result.get()) , typeId); if (constants.CONSTANT_TYPE_DATA == typeId) { readDataSerializable(reinterpret_cast(result.get())); } else if (constants.CONSTANT_TYPE_PORTABLE == typeId) { diff --git a/hazelcast/include/hazelcast/client/serialization/ObjectDataOutput.h b/hazelcast/include/hazelcast/client/serialization/ObjectDataOutput.h index da00c124a7..26ed50b2cb 100644 --- a/hazelcast/include/hazelcast/client/serialization/ObjectDataOutput.h +++ b/hazelcast/include/hazelcast/client/serialization/ObjectDataOutput.h @@ -25,6 +25,7 @@ #include "hazelcast/client/serialization/pimpl/PortableContext.h" #include "hazelcast/client/serialization/Serializer.h" #include "hazelcast/util/IOUtil.h" +#include "hazelcast/client/serialization/TypeIDS.h" #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) #pragma warning(push) @@ -209,7 +210,7 @@ namespace hazelcast { writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL); } else { const T *object = static_cast(serializable); - int type = object->getTypeId(); + int type = getHazelcastTypeId(object); writeInt(type); boost::shared_ptr serializer = context->getSerializerHolder().serializerFor(type); diff --git a/hazelcast/include/hazelcast/client/serialization/Portable.h b/hazelcast/include/hazelcast/client/serialization/Portable.h index 962a054a20..96adbef950 100644 --- a/hazelcast/include/hazelcast/client/serialization/Portable.h +++ b/hazelcast/include/hazelcast/client/serialization/Portable.h @@ -54,7 +54,9 @@ namespace hazelcast { /** * Destructor */ - virtual ~Portable(); + virtual ~Portable(){ + + } /** * @return factory id @@ -78,11 +80,6 @@ namespace hazelcast { */ virtual void readPortable(PortableReader& reader) = 0; - /** - * Not public api. Do not override this method. - * @return type id - */ - virtual int getTypeId() const; }; } } diff --git a/hazelcast/include/hazelcast/client/serialization/Serializer.h b/hazelcast/include/hazelcast/client/serialization/Serializer.h index 5da2eb469d..8c3841775c 100644 --- a/hazelcast/include/hazelcast/client/serialization/Serializer.h +++ b/hazelcast/include/hazelcast/client/serialization/Serializer.h @@ -16,9 +16,6 @@ // // Created by sancar koyunlu on 6/7/13. - - - #ifndef HAZELCAST_TYPE_SERIALIZER #define HAZELCAST_TYPE_SERIALIZER @@ -43,13 +40,14 @@ namespace hazelcast { /** * unique type id for this serializer. It will be used to decide which serializer needs to be used - * for your classes. Also not that your serialized classes needs to implement + * for your classes. Also not that for your serialized classes you need to implement as free function + * in same namespace with your class * - * int getTypeId(); + * int getHazelcastTypeId(const MyClass*); * * which should return same id with its serializer. */ - virtual int getTypeId() const = 0; + virtual int getHazelcastTypeId() const = 0; }; /** @@ -64,7 +62,7 @@ namespace hazelcast { void read(serialization::ObjectDataInput & in, ExampleBaseClass& object); - int getTypeId() const; + int getHazelcastTypeId() const; }; } @@ -86,11 +84,18 @@ namespace hazelcast { //..... } - int getTypeId() const { + int getHazelcastTypeId() const { //.. } }; + * + * Along with serializer following function should be provided with same namespace that ExampleBaseClass + * belongs to + * + * int getHazelcastTypeId(const MyClass*); + * + * which should return same id with its serializer. * * User than can register serializer via SerializationConfig as follows * diff --git a/hazelcast/src/hazelcast/client/serialization/Portable.cpp b/hazelcast/include/hazelcast/client/serialization/TypeIDS.h similarity index 65% rename from hazelcast/src/hazelcast/client/serialization/Portable.cpp rename to hazelcast/include/hazelcast/client/serialization/TypeIDS.h index ec74bacabc..1f9c784cf4 100644 --- a/hazelcast/src/hazelcast/client/serialization/Portable.cpp +++ b/hazelcast/include/hazelcast/client/serialization/TypeIDS.h @@ -13,24 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// -// Created by sancar koyunlu on 8/12/13. +#ifndef HAZELCAST_TypeIDS +#define HAZELCAST_TypeIDS - -#include "hazelcast/client/serialization/Portable.h" -#include "hazelcast/client/serialization/pimpl/SerializationConstants.h" +#include "hazelcast/util/HazelcastDll.h" namespace hazelcast { namespace client { namespace serialization { - Portable::~Portable() { + class Portable; + class IdentifiedDataSerializable; + + int HAZELCAST_API getHazelcastTypeId(const Portable* portable); - } + int HAZELCAST_API getHazelcastTypeId(const IdentifiedDataSerializable* identifiedDataSerializable); - int Portable::getTypeId() const { - return pimpl::SerializationConstants::CONSTANT_TYPE_PORTABLE; - } } } } + + +#endif //HAZELCAST_TypeIDS diff --git a/hazelcast/include/hazelcast/client/serialization/pimpl/SerializationConstants.h b/hazelcast/include/hazelcast/client/serialization/pimpl/SerializationConstants.h index 9eab923268..42e0e80122 100644 --- a/hazelcast/include/hazelcast/client/serialization/pimpl/SerializationConstants.h +++ b/hazelcast/include/hazelcast/client/serialization/pimpl/SerializationConstants.h @@ -41,28 +41,27 @@ namespace hazelcast { public: SerializationConstants(); - static int const CONSTANT_TYPE_NULL; - static int const CONSTANT_TYPE_PORTABLE; - static int const CONSTANT_TYPE_DATA; - static int const CONSTANT_TYPE_BYTE; - static int const CONSTANT_TYPE_BOOLEAN; - static int const CONSTANT_TYPE_CHAR; - static int const CONSTANT_TYPE_SHORT; - static int const CONSTANT_TYPE_INTEGER; - static int const CONSTANT_TYPE_LONG; - static int const CONSTANT_TYPE_FLOAT; - static int const CONSTANT_TYPE_DOUBLE; - static int const CONSTANT_TYPE_STRING; - static int const CONSTANT_TYPE_BYTE_ARRAY; - static int const CONSTANT_TYPE_BOOLEAN_ARRAY; - static int const CONSTANT_TYPE_CHAR_ARRAY; - static int const CONSTANT_TYPE_SHORT_ARRAY; - static int const CONSTANT_TYPE_INTEGER_ARRAY; - static int const CONSTANT_TYPE_LONG_ARRAY; - static int const CONSTANT_TYPE_FLOAT_ARRAY; - static int const CONSTANT_TYPE_DOUBLE_ARRAY; - static int const CONSTANT_TYPE_STRING_ARRAY; - + static int const CONSTANT_TYPE_NULL = 0; + static int const CONSTANT_TYPE_PORTABLE = -1; + static int const CONSTANT_TYPE_DATA = -2; + static int const CONSTANT_TYPE_BYTE = -3; + static int const CONSTANT_TYPE_BOOLEAN = -4; + static int const CONSTANT_TYPE_CHAR = -5; + static int const CONSTANT_TYPE_SHORT = -6; + static int const CONSTANT_TYPE_INTEGER = -7; + static int const CONSTANT_TYPE_LONG = -8; + static int const CONSTANT_TYPE_FLOAT = -9; + static int const CONSTANT_TYPE_DOUBLE = -10; + static int const CONSTANT_TYPE_STRING = -11; + static int const CONSTANT_TYPE_BYTE_ARRAY = -12; + static int const CONSTANT_TYPE_BOOLEAN_ARRAY = -13; + static int const CONSTANT_TYPE_CHAR_ARRAY = -14; + static int const CONSTANT_TYPE_SHORT_ARRAY = -15; + static int const CONSTANT_TYPE_INTEGER_ARRAY = -16; + static int const CONSTANT_TYPE_LONG_ARRAY = -17; + static int const CONSTANT_TYPE_FLOAT_ARRAY = -18; + static int const CONSTANT_TYPE_DOUBLE_ARRAY = -19; + static int const CONSTANT_TYPE_STRING_ARRAY = -20; // ------------------------------------------------------------ void checkClassType(int expectedType, int currentType) const; diff --git a/hazelcast/include/hazelcast/util/Bits.h b/hazelcast/include/hazelcast/util/Bits.h index 98309ed281..5fbbe00b6b 100644 --- a/hazelcast/include/hazelcast/util/Bits.h +++ b/hazelcast/include/hazelcast/util/Bits.h @@ -293,7 +293,7 @@ namespace hazelcast { } inline static void swapInplace4(void *orig) { - register uint32_t value = * reinterpret_cast (orig); + uint32_t value = * reinterpret_cast (orig); swap_4(&value, orig); } diff --git a/hazelcast/include/iTest/iTest.h b/hazelcast/include/iTest/iTest.h deleted file mode 100644 index 1adf888a52..0000000000 --- a/hazelcast/include/iTest/iTest.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 8/1/13. - - -#ifndef HAZELCAST_iTest -#define HAZELCAST_iTest - -#include "iTest/iTestFixture.h" -#include - -namespace iTest { - HAZELCAST_API void assertFalse(bool isFalse, const char *message); - - HAZELCAST_API void assertFalse(bool isFalse); - - HAZELCAST_API void assertTrue(bool isTrue, const char *message); - - HAZELCAST_API void assertTrue(bool isTrue); - - HAZELCAST_API void assertNull(const void *expected); - - HAZELCAST_API void assertNull(const void *expected, const char *message); - - HAZELCAST_API void assertNotNull(const void *expected); - - HAZELCAST_API void assertNotNull(const void *expected, const char *message); - -#define ASSERT_EQUAL(expected, actual) \ - if (expected != actual) { \ - iTest::iTestException e; \ - std::stringstream s; \ - s << "ASSERT_EQUAL(" #expected ", " #actual")" << " failed at line " << __LINE__ << " in file " << __FILE__<< std::endl; \ - s << "Expected value:" << expected << ", Actual value:" << actual << std::endl; \ - e.message = s.str(); \ - throw e; \ - } - -#define ASSERT_NOTEQUAL(expected, actual) \ - if (expected == actual) { \ - iTest::iTestException e; \ - std::stringstream s; \ - s << "ASSERT_EQUAL(" #expected ", " #actual")" << " failed at line " << __LINE__ << " in file " << __FILE__<< std::endl; \ - s << "Value should NOT be equal to :" << actual << std::endl; \ - e.message = s.str(); \ - throw e; \ - } - - template - void assertEqual(const Expected& expected, const Actual& actual, const char *message) { - assertNumber++; - if (expected != actual) { - iTestException e; - std::stringstream s; - s << "Assert[ " << assertNumber << " ] is failed. Message : " << message << std::endl; - e.message = s.str(); - throw e; - } - } - - template - void assertEqual(const Expected& expected, const Actual& actual) { - assertNumber++; - if (actual != expected) { - iTestException e; - std::stringstream s; - s << "Assert[ " << assertNumber << " ] is failed." << std::endl; - e.message = s.str(); - throw e; - } - } - - template - void assertEqualWithEpsilon(const Type& value1, const Type& value2, const Type& epsilon) { - assertNumber++; - if (std::abs(value1 - value2) > epsilon) { - iTestException e; - std::stringstream s; - s << "Assert[ " << assertNumber << " ] is failed." << std::endl; - s << "Message: " << value1 << " != " << value2 << " : epsilon " << epsilon << std::endl; - e.message = s.str(); - throw e; - } - } -} - - -#endif //HAZELCAST_iTest - diff --git a/hazelcast/include/iTest/iTestFixture.h b/hazelcast/include/iTest/iTestFixture.h deleted file mode 100644 index 94579625bd..0000000000 --- a/hazelcast/include/iTest/iTestFixture.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 8/1/13. - - -#ifndef HAZELCAST_iTestFixture -#define HAZELCAST_iTestFixture - -#include "hazelcast/util/HazelcastDll.h" -#include -#include -#include -#include -#include -#include "hazelcast/client/exception/IOException.h" - -#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) -#pragma warning(push) -#pragma warning(disable: 4251) //for dll export -#endif - -#define RUN_TEST(TEST, ...) do{ \ - TEST t( __VA_ARGS__ ); \ - if(!t.executeTests()){ \ - return 1; \ - } \ -}while(0) - -#define RUN_TEST_NO_ARGS(TEST) do{ \ - TEST t; \ - if(!t.executeTests()){ \ - return 1; \ - } \ -}while(0) - -namespace iTest { - static int assertNumber; - - struct HAZELCAST_API iTestException { - std::string message; - }; - - template - class iTestFixture { - typedef void (T::*TestFunction)(); - - public: - iTestFixture(const std::string& fixtureName) - : fixtureName(fixtureName), id(0) { - - } - - virtual ~iTestFixture() { - } - - virtual void addTests() = 0; - - virtual void beforeClass() = 0; - - virtual void afterClass() = 0; - - virtual void beforeTest() = 0; - - virtual void afterTest() = 0; - - void addTest(TestFunction test, const std::string& name) { - tests.push_back(test); - testNames[id++] = name; - } - - bool executeTests() { - addTests(); - (std::cout << "<<<<<<< " << fixtureName << " >>>>>>" << std::endl); - beforeClass(); - T *t = static_cast(this); - for (unsigned int i = 0; i < tests.size(); i++) { - TestFunction test = tests[i]; - (std::cout << "======= " << i << ". " << testNames[i] << " ======= " << std::endl); - beforeTest(); - bool isOk = true; - try { - assertNumber = 0; - ((*t).*(test))(); - } catch (iTestException& e) { - (std::cout << e.message << std::endl); - isOk = false; - } catch (hazelcast::client::exception::IException &e) { - (std::cout << e.what() << std::endl); - isOk = false; - } - catch (...) { - isOk = false; - std::cout << "========== EXCEPTION ======== " << std::endl; - throw; - } - afterTest(); - if (isOk) { - std::cout << "============OK============== " << std::endl; - } else { - std::cout << "============FAILED============== " << std::endl; - return false; - } - } - afterClass(); - return true; - } - - - private: - std::vector tests; - std::map testNames; - std::string fixtureName; - int id; - }; -} - -#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) -#pragma warning(pop) -#endif - -#endif //HAZELCAST_iTestFixture - diff --git a/hazelcast/src/hazelcast/client/serialization/IdentifiedDataSerializable.cpp b/hazelcast/src/hazelcast/client/serialization/TypeIDS.cpp similarity index 73% rename from hazelcast/src/hazelcast/client/serialization/IdentifiedDataSerializable.cpp rename to hazelcast/src/hazelcast/client/serialization/TypeIDS.cpp index 4d86540f6f..8590d0804b 100644 --- a/hazelcast/src/hazelcast/client/serialization/IdentifiedDataSerializable.cpp +++ b/hazelcast/src/hazelcast/client/serialization/TypeIDS.cpp @@ -14,23 +14,23 @@ * limitations under the License. */ // -// Created by sancar koyunlu on 8/12/13. - - -#include "hazelcast/client/serialization/IdentifiedDataSerializable.h" +#include "hazelcast/client/serialization/TypeIDS.h" #include "hazelcast/client/serialization/pimpl/SerializationConstants.h" +#include "hazelcast/client/serialization/IdentifiedDataSerializable.h" +#include "hazelcast/client/serialization/Portable.h" namespace hazelcast { namespace client { namespace serialization { - IdentifiedDataSerializable::~IdentifiedDataSerializable() { - + int getHazelcastTypeId(const Portable* portable) { + return pimpl::SerializationConstants::CONSTANT_TYPE_PORTABLE; } - int IdentifiedDataSerializable::getTypeId() const { + int getHazelcastTypeId(const IdentifiedDataSerializable* identifiedDataSerializable) { return pimpl::SerializationConstants::CONSTANT_TYPE_DATA; } } } } + diff --git a/hazelcast/src/hazelcast/client/serialization/pimpl/PortableContext.cpp b/hazelcast/src/hazelcast/client/serialization/pimpl/PortableContext.cpp index 454f27e128..d1d9fbd8f8 100644 --- a/hazelcast/src/hazelcast/client/serialization/pimpl/PortableContext.cpp +++ b/hazelcast/src/hazelcast/client/serialization/pimpl/PortableContext.cpp @@ -144,6 +144,7 @@ namespace hazelcast { return serializerHolder; } + SerializationConstants const& PortableContext::getConstants() const { return constants; } diff --git a/hazelcast/src/hazelcast/client/serialization/pimpl/SerializationConstants.cpp b/hazelcast/src/hazelcast/client/serialization/pimpl/SerializationConstants.cpp index 580da941e2..3b363d04ac 100644 --- a/hazelcast/src/hazelcast/client/serialization/pimpl/SerializationConstants.cpp +++ b/hazelcast/src/hazelcast/client/serialization/pimpl/SerializationConstants.cpp @@ -26,28 +26,6 @@ namespace hazelcast { namespace client { namespace serialization { namespace pimpl { - int const SerializationConstants::CONSTANT_TYPE_NULL = 0; - int const SerializationConstants::CONSTANT_TYPE_PORTABLE=-1; - int const SerializationConstants::CONSTANT_TYPE_DATA=-2; - int const SerializationConstants::CONSTANT_TYPE_BYTE=-3; - int const SerializationConstants::CONSTANT_TYPE_BOOLEAN=-4; - int const SerializationConstants::CONSTANT_TYPE_CHAR=-5; - int const SerializationConstants::CONSTANT_TYPE_SHORT=-6; - int const SerializationConstants::CONSTANT_TYPE_INTEGER=-7; - int const SerializationConstants::CONSTANT_TYPE_LONG=-8; - int const SerializationConstants::CONSTANT_TYPE_FLOAT=-9; - int const SerializationConstants::CONSTANT_TYPE_DOUBLE=-10; - int const SerializationConstants::CONSTANT_TYPE_STRING=-11; - int const SerializationConstants::CONSTANT_TYPE_BYTE_ARRAY=-12; - int const SerializationConstants::CONSTANT_TYPE_BOOLEAN_ARRAY=-13; - int const SerializationConstants::CONSTANT_TYPE_CHAR_ARRAY=-14; - int const SerializationConstants::CONSTANT_TYPE_SHORT_ARRAY=-15; - int const SerializationConstants::CONSTANT_TYPE_INTEGER_ARRAY=-16; - int const SerializationConstants::CONSTANT_TYPE_LONG_ARRAY=-17; - int const SerializationConstants::CONSTANT_TYPE_FLOAT_ARRAY=-18; - int const SerializationConstants::CONSTANT_TYPE_DOUBLE_ARRAY=-19; - int const SerializationConstants::CONSTANT_TYPE_STRING_ARRAY=-20; - SerializationConstants::SerializationConstants() : size(21) , typeIdNameVector(size){ diff --git a/hazelcast/src/hazelcast/client/serialization/pimpl/SerializerHolder.cpp b/hazelcast/src/hazelcast/client/serialization/pimpl/SerializerHolder.cpp index c55945f93b..ff445af3d1 100644 --- a/hazelcast/src/hazelcast/client/serialization/pimpl/SerializerHolder.cpp +++ b/hazelcast/src/hazelcast/client/serialization/pimpl/SerializerHolder.cpp @@ -31,7 +31,7 @@ namespace hazelcast { } bool SerializerHolder::registerSerializer(boost::shared_ptr serializer) { - boost::shared_ptr available = serializers.putIfAbsent(serializer->getTypeId(), serializer); + boost::shared_ptr available = serializers.putIfAbsent(serializer->getHazelcastTypeId(), serializer); return available.get() == NULL; } diff --git a/hazelcast/src/iTest/iTest.cpp b/hazelcast/src/iTest/iTest.cpp deleted file mode 100644 index f446ee7dd5..0000000000 --- a/hazelcast/src/iTest/iTest.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 8/1/13. - - - -#include "iTest/iTest.h" - -namespace iTest { - void assertFalse(bool isFalse, const char *message) { - assertNumber++; - if (isFalse) { - iTestException e; - std::stringstream s; - s << "Assert[ "<< assertNumber << " ] is failed. Message : " << message << std::endl; - e.message = s.str(); - throw e; - } - } - - void assertFalse(bool isFalse) { - assertNumber++; - if (isFalse) { - iTestException e; - std::stringstream s; - s << "Assert[ "<< assertNumber << " ] is failed." << std::endl; - e.message = s.str(); - throw e; - } - } - - void assertTrue(bool isTrue, const char *message) { - assertNumber++; - if (!isTrue) { - iTestException e; - std::stringstream s; - s << "Assert[ "<< assertNumber << " ] is failed. Message : " << message << std::endl; - e.message = s.str(); - throw e; - } - } - - void assertTrue(bool isTrue) { - assertNumber++; - if (!isTrue) { - iTestException e; - std::stringstream s; - s << "Assert[ "<< assertNumber << " ] is failed." << std::endl; - e.message = s.str(); - throw e; - } - } - - void assertNull(const void *expected) { - assertNumber++; - if (expected != NULL) { - iTestException e; - std::stringstream s; - s << "Assert[ "<< assertNumber << " ] is failed." << std::endl; - e.message = s.str(); - throw e; - } - } - - void assertNull(const void *expected, const char *message) { - assertNumber++; - if (expected != NULL) { - iTestException e; - std::stringstream s; - s << "Assert[ "<< assertNumber << " ] is failed. Message : " << message << std::endl; - e.message = s.str(); - throw e; - } - } - - void assertNotNull(const void *expected) { - assertNumber++; - if (expected == NULL) { - iTestException e; - std::stringstream s; - s << "Assert[ "<< assertNumber << " ] is failed." << std::endl; - e.message = s.str(); - throw e; - } - } - - void assertNotNull(const void *expected, const char *message) { - assertNumber++; - if (expected == NULL) { - iTestException e; - std::stringstream s; - s << "Assert[ "<< assertNumber << " ] is failed. Message : " << message << std::endl; - e.message = s.str(); - throw e; - } - } -} - diff --git a/hazelcast/test/CMakeLists.txt b/hazelcast/test/CMakeLists.txt index 48be17e5ba..aeb23cab21 100644 --- a/hazelcast/test/CMakeLists.txt +++ b/hazelcast/test/CMakeLists.txt @@ -1,41 +1,5 @@ -cmake_minimum_required (VERSION 3.1) -project (HazelcastClientTest) +SET(BUILD_GMOCK OFF) +SET(BUILD_TEST ON) -FILE(GLOB_RECURSE HZ_TEST_SOURCES "./*cpp") -FILE(GLOB_RECURSE HZ_TEST_HEADERS "./*h") - -include_directories(${CMAKE_SOURCE_DIR}/hazelcast/include ${CMAKE_SOURCE_DIR}/hazelcast/test) - -#set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/java/) - -SET(HZ_EXE_NAME clientTest_${HZ_LIB_TYPE}_${HZ_BIT}) - -add_executable(${HZ_EXE_NAME} ${HZ_TEST_SOURCES} ${HZ_TEST_HEADERS} ) - -IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - - target_link_libraries(${HZ_EXE_NAME} ${HZ_LIB_NAME} ) - -ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - -IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - - set_target_properties(${HZ_EXE_NAME} PROPERTIES COMPILE_FLAGS "${HZ_BIT_FLAG} ${HZ_CODE_COVERAGE_COMPILE_FLAGS} ${HZ_VALGRIND_COMPILE_FLAGS}" LINK_FLAGS "${HZ_BIT_FLAG} ${HZ_CODE_COVERAGE_LINK_FLAGS} ${HZ_VALGRIND_LINK_FLAGS}") - - target_link_libraries(${HZ_EXE_NAME} ${HZ_LIB_NAME} ) -ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - - -IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") - IF(${HZ_LIB_TYPE} MATCHES "STATIC") - message( STATUS "Shall use the STATIC Hazelcast library for the tests.") - add_definitions(-DHAZELCAST_USE_STATIC) - ELSE(${HZ_LIB_TYPE} MATCHES "SHARED") - message( STATUS "Shall use the SHARED Hazelcast library for the tests.") - add_definitions(-DHAZELCAST_USE_SHARED) - ENDIF(${HZ_LIB_TYPE} MATCHES "STATIC") - - set_target_properties(${HZ_EXE_NAME} PROPERTIES COMPILE_FLAGS " /EHsc ") - target_link_libraries(${HZ_EXE_NAME} ${HZ_LIB_NAME} ) - -ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") +add_subdirectory(src) +add_subdirectory(googletest) \ No newline at end of file diff --git a/hazelcast/test/ClientTestSupport.h b/hazelcast/test/ClientTestSupport.h deleted file mode 100644 index 52750823d9..0000000000 --- a/hazelcast/test/ClientTestSupport.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by İhsan Demir on 26/05/15. -// - -#ifndef HAZELCASTCLIENT_CLIENTTESTSUPPORT_H -#define HAZELCASTCLIENT_CLIENTTESTSUPPORT_H - -#include - -#include "iTest/iTestFixture.h" -#include "hazelcast/client/ClientConfig.h" -#include "hazelcast/client/HazelcastClient.h" -#include "HazelcastServerFactory.h" -#include "iTest/iTest.h" - -namespace hazelcast { - namespace client { - namespace test { - template - class ClientTestSupport : public iTest::iTestFixture { - public: - ClientTestSupport(const std::string &fixtureName, const HazelcastServerFactory *factory = NULL) : - iTest::iTestFixture(fixtureName), serverFactory(factory) { - } - - std::auto_ptr getConfig() { - std::auto_ptr clientConfig(new ClientConfig()); - if (NULL != serverFactory) { - clientConfig->addAddress(Address(serverFactory->getServerAddress(), 5701)); - } - return clientConfig; - } - - std::auto_ptr getNewClient() { - std::auto_ptr result(new HazelcastClient(*getConfig())); - return result; - } - - private: - const HazelcastServerFactory *serverFactory; - }; - - - } - } -} - -#endif //HAZELCASTCLIENT_CLIENTTESTSUPPORT_H diff --git a/hazelcast/test/TestHelperFunctions.h b/hazelcast/test/TestHelperFunctions.h deleted file mode 100644 index 9bb2198d7b..0000000000 --- a/hazelcast/test/TestHelperFunctions.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 15/05/14. -// - - -#ifndef HAZELCAST_TestHelperFunctions -#define HAZELCAST_TestHelperFunctions - -#define ASSERT_EVENTUALLY( CONDITION, ... ) do{ \ - for(int i = 0 ; i < 60 ; i++ ) { \ - util::sleep(2); \ - if(i == 59){ \ - CONDITION(__VA_ARGS__); \ - } \ - try{ \ - CONDITION(__VA_ARGS__); \ - break; \ - }catch(iTestException ignored){ \ - } \ - } \ - }while(0) \ - - -#endif //HAZELCAST_TestHelperFunctions diff --git a/hazelcast/test/atomiclong/IAtomicLongTest.cpp b/hazelcast/test/atomiclong/IAtomicLongTest.cpp deleted file mode 100644 index e6d0c54e91..0000000000 --- a/hazelcast/test/atomiclong/IAtomicLongTest.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// ClientAtomiclLong.h -// hazelcast -// -// Created by Sancar on 02.08.2013. -// Copyright (c) 2013 Sancar. All rights reserved. -// - -#include "IAtomicLongTest.h" -#include "HazelcastServerFactory.h" -#include "hazelcast/client/HazelcastClient.h" - -namespace hazelcast { - namespace client { - - class HazelcastClient; - - namespace test { - using namespace iTest; - - IAtomicLongTest::IAtomicLongTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("IAtomicLongTest" , &serverFactory) - , instance(serverFactory) - , client(getNewClient()) - , atom(new IAtomicLong(client->getIAtomicLong("clientAtomicLong"))) { - } - - - IAtomicLongTest::~IAtomicLongTest() { - } - - void IAtomicLongTest::addTests() { - addTest(&IAtomicLongTest::test, "ClientAtomicLongTest"); - } - - void IAtomicLongTest::beforeClass() { - - } - - void IAtomicLongTest::afterClass() { - client.reset(); - client.reset(); - client.reset(); - instance.shutdown(); - } - - void IAtomicLongTest::beforeTest() { - atom->set(0); - } - - void IAtomicLongTest::afterTest() { - atom->set(0); - } - - void IAtomicLongTest::test() { - assertEqual(0, atom->getAndAdd(2)); - assertEqual(2, atom->get()); - atom->set(5); - assertEqual(5, atom->get()); - assertEqual(8, atom->addAndGet(3)); - assertFalse(atom->compareAndSet(7, 4)); - assertEqual(8, atom->get()); - assertTrue(atom->compareAndSet(8, 4)); - assertEqual(4, atom->get()); - assertEqual(3, atom->decrementAndGet()); - assertEqual(3, atom->getAndIncrement()); - assertEqual(4, atom->getAndSet(9)); - assertEqual(10, atom->incrementAndGet()); - } - - } - } -} - - diff --git a/hazelcast/test/cluster/ClusterTest.h b/hazelcast/test/cluster/ClusterTest.h deleted file mode 100644 index 3160225379..0000000000 --- a/hazelcast/test/cluster/ClusterTest.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 26/02/14. -// - - -#ifndef HAZELCAST_ClusterTest -#define HAZELCAST_ClusterTest - - -#include "ClientTestSupport.h" - - -namespace hazelcast { - namespace client { - - class HazelcastClient; - - namespace test { - - class HazelcastServerFactory; - - class ClusterTest : public ClientTestSupport { - - public: - - ClusterTest(HazelcastServerFactory &); - - ~ClusterTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testClusterListeners(); - - void testClusterListenersFromConfig(); - - void testListenersWhenClusterDown(); - - void testBehaviourWhenClusterNotFound(); - - private: - HazelcastServerFactory & hazelcastInstanceFactory; - }; - } - } -} - - -#endif //HAZELCAST_ClusterTest - diff --git a/hazelcast/test/cluster/MemberAttributeTest.h b/hazelcast/test/cluster/MemberAttributeTest.h deleted file mode 100644 index 5f42507421..0000000000 --- a/hazelcast/test/cluster/MemberAttributeTest.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 27/02/14. -// - - -#ifndef HAZELCAST_MemberAttributeTest -#define HAZELCAST_MemberAttributeTest - -#include "ClientTestSupport.h" - -namespace hazelcast { - namespace client { - - class HazelcastClient; - - namespace test { - - class HazelcastServerFactory; - - class MemberAttributeTest : public ClientTestSupport { - - public: - - MemberAttributeTest(HazelcastServerFactory &); - - ~MemberAttributeTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testInitialValues(); - - void testChangeWithListeners(); - - private: - HazelcastServerFactory & hazelcastInstanceFactory; - }; - } -} -} - - - -#endif //HAZELCAST_MemberAttributeTest - diff --git a/hazelcast/test/common/containers/LitlleEndianBufferTest.h b/hazelcast/test/common/containers/LitlleEndianBufferTest.h deleted file mode 100644 index 0b52a4bad1..0000000000 --- a/hazelcast/test/common/containers/LitlleEndianBufferTest.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by İhsan Demir on 17/05/15. -// - -#ifndef HAZELCAST_CLIENT_COMMON_CONTAINERS_LITLLEENDIANBUFFERTEST_H -#define HAZELCAST_CLIENT_COMMON_CONTAINERS_LITLLEENDIANBUFFERTEST_H - -#include "HazelcastServerFactory.h" -#include -#include "hazelcast/util/LittleEndianBufferWrapper.h" - -namespace hazelcast { - namespace client { - namespace test { - class HazelcastServerFactory; - - namespace common { - namespace containers { - class LittleEndianBufferTest : public iTest::iTestFixture, - public util::LittleEndianBufferWrapper /* Need this in order to test*/ { - public: - LittleEndianBufferTest(); - - ~LittleEndianBufferTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testBinaryFormat(); - - }; - } - } - } - } -} - - -#endif //HAZELCAST_CLIENT_COMMON_CONTAINERS_LITLLEENDIANBUFFERTEST_H diff --git a/hazelcast/test/googletest b/hazelcast/test/googletest new file mode 160000 index 0000000000..96bf315160 --- /dev/null +++ b/hazelcast/test/googletest @@ -0,0 +1 @@ +Subproject commit 96bf315160298e124ac71f2b4ce3fc5d0e219265 diff --git a/hazelcast/test/list/ClientListTest.cpp b/hazelcast/test/list/ClientListTest.cpp deleted file mode 100644 index 72d22ae1a1..0000000000 --- a/hazelcast/test/list/ClientListTest.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 9/13/13. - - - -#include "list/ClientListTest.h" -#include "hazelcast/client/HazelcastClient.h" -#include "HazelcastServerFactory.h" - -namespace hazelcast { - namespace client { - namespace test { - using namespace iTest; - - ClientListTest::ClientListTest(HazelcastServerFactory& serverFactory) - : ClientTestSupport("ClientListTest", &serverFactory) - , instance(serverFactory) - , client(getNewClient()) - , list(new IList(client->getList("ClientListTest"))) { - } - - - ClientListTest::~ClientListTest() { - } - - void ClientListTest::addTests() { - addTest(&ClientListTest::testAddAll, "testAddAll"); - addTest(&ClientListTest::testAddSetRemove, "testAddSetRemove"); - addTest(&ClientListTest::testIndexOf, "testIndexOf"); - addTest(&ClientListTest::testToArray, "testToArray"); - addTest(&ClientListTest::testContains, "testContains"); - addTest(&ClientListTest::testRemoveRetainAll, "testRemoveRetainAll"); - addTest(&ClientListTest::testListener, "testListener"); - - } - - void ClientListTest::beforeClass() { - } - - void ClientListTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ClientListTest::beforeTest() { - - } - - void ClientListTest::afterTest() { - list->clear(); - } - - void ClientListTest::testAddAll() { - - std::vector l; - l.push_back("item1"); - l.push_back("item2"); - assertTrue(list->addAll(l)); - - assertTrue(list->addAll(1, l)); - assertEqual(4, list->size()); - - assertEqual("item1", *(list->get(0))); - assertEqual("item1", *(list->get(1))); - assertEqual("item2", *(list->get(2))); - assertEqual("item2", *(list->get(3))); - } - - void ClientListTest::testAddSetRemove() { - assertTrue(list->add("item1")); - assertTrue(list->add("item2")); - list->add(0, "item3"); - assertEqual(3, list->size()); - boost::shared_ptr temp = list->set(2, "item4"); - assertEqual("item2", *temp); - - assertEqual(3, list->size()); - assertEqual("item3", *(list->get(0))); - assertEqual("item1", *(list->get(1))); - assertEqual("item4", *(list->get(2))); - - assertFalse(list->remove("item2")); - assertTrue(list->remove("item3")); - - temp = list->remove(1); - assertEqual("item4", *temp); - - assertEqual(1, list->size()); - assertEqual("item1", *(list->get(0))); - } - - void ClientListTest::testIndexOf() { - assertTrue(list->add("item1")); - assertTrue(list->add("item2")); - assertTrue(list->add("item1")); - assertTrue(list->add("item4")); - - assertEqual(-1, list->indexOf("item5")); - assertEqual(0, list->indexOf("item1")); - - assertEqual(-1, list->lastIndexOf("item6")); - assertEqual(2, list->lastIndexOf("item1")); - } - - void ClientListTest::testToArray() { - assertTrue(list->add("item1")); - assertTrue(list->add("item2")); - assertTrue(list->add("item1")); - assertTrue(list->add("item4")); - - std::vector ar = list->toArray(); - - assertEqual("item1", ar[0]); - assertEqual("item2", ar[1]); - assertEqual("item1", ar[2]); - assertEqual("item4", ar[3]); - - std::vector arr2 = list->subList(1, 3); - - assertEqual(2, (int)arr2.size()); - assertEqual("item2", arr2[0]); - assertEqual("item1", arr2[1]); - } - - void ClientListTest::testContains() { - assertTrue(list->add("item1")); - assertTrue(list->add("item2")); - assertTrue(list->add("item1")); - assertTrue(list->add("item4")); - - assertFalse(list->contains("item3")); - assertTrue(list->contains("item2")); - - std::vector l; - l.push_back("item4"); - l.push_back("item3"); - - assertFalse(list->containsAll(l)); - assertTrue(list->add("item3")); - assertTrue(list->containsAll(l)); - } - - void ClientListTest::testRemoveRetainAll() { - assertTrue(list->add("item1")); - assertTrue(list->add("item2")); - assertTrue(list->add("item1")); - assertTrue(list->add("item4")); - - std::vector l; - l.push_back("item4"); - l.push_back("item3"); - - assertTrue(list->removeAll(l)); - assertEqual(3, (int)list->size()); - assertFalse(list->removeAll(l)); - assertEqual(3, (int)list->size()); - - l.clear(); - l.push_back("item1"); - l.push_back("item2"); - assertFalse(list->retainAll(l)); - assertEqual(3, (int)list->size()); - - l.clear(); - assertTrue(list->retainAll(l)); - assertEqual(0, (int)list->size()); - - } - - class MyListItemListener : public ItemListener { - public: - MyListItemListener(util::CountDownLatch& latch) - : latch(latch) { - - } - - void itemAdded(const ItemEvent& itemEvent) { - latch.countDown(); - } - - void itemRemoved(const ItemEvent& item) { - } - - private: - util::CountDownLatch& latch; - }; - - void ClientListTest::testListener() { - util::CountDownLatch latch(5); - - MyListItemListener listener(latch); - std::string registrationId = list->addItemListener(listener, true); - - for (int i = 0; i < 5; i++) { - list->add(std::string("item") + util::IOUtil::to_string(i)); - } - - assertTrue(latch.await(20)); - - assertTrue(list->removeItemListener(registrationId)); - } - - } - } -} - diff --git a/hazelcast/test/main.cpp b/hazelcast/test/main.cpp deleted file mode 100644 index 60597dc23b..0000000000 --- a/hazelcast/test/main.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "SimpleMapTest.h" -#include "HazelcastServerFactory.h" -#include "queue/ClientQueueTest.h" -#include "multimap/ClientMultiMapTest.h" -#include "map/ClientMapTest.h" -#include "map/ClientExpirationListenerTest.h" -#include "serialization/ClientSerializationTest.h" -#include "protocol/ClientMessageTest.h" -#include "list/ClientListTest.h" -#include "set/ClientSetTest.h" -#include "atomiclong/IAtomicLongTest.h" -#include "topic/ClientTopicTest.h" -#include "idgenerator/IdGeneratorTest.h" -#include "countdownlatch/ICountDownLatchTest.h" -#include "lock/ClientLockTest.h" -#include "semaphore/ClientSemaphoreTest.h" -#include "txn/ClientTxnTest.h" -#include "txn/ClientTxnSetTest.h" -#include "txn/ClientTxnQueueTest.h" -#include "txn/ClientTxnMapTest.h" -#include "txn/ClientTxnListTest.h" -#include "txn/ClientTxnMultiMapTest.h" -#include "cluster/ClusterTest.h" -#include "cluster/MemberAttributeTest.h" -#include "issues/IssueTest.h" -#include "util/ClientUtilTest.h" -#include "util/BitsTest.h" -#include -#include -#include - -using namespace hazelcast::client::test; - -void testSpeed(const char* address) { - SimpleMapTest s(address, 5701); - s.run(); -} - -int unitTests(const char* address) { - try { - RUN_TEST_NO_ARGS(ClientUtilTest); - RUN_TEST_NO_ARGS(ClientSerializationTest); - RUN_TEST_NO_ARGS(util::BitsTest); - RUN_TEST_NO_ARGS(test::protocol::ClientMessageTest); - HazelcastServerFactory factory(address); - RUN_TEST(ClientMapTest, factory); - RUN_TEST(ClientExpirationListenerTest, factory); - RUN_TEST(IssueTest, factory); - RUN_TEST(MemberAttributeTest, factory); - RUN_TEST(ClusterTest, factory); - RUN_TEST(ClientMultiMapTest, factory); - RUN_TEST(ClientQueueTest, factory); - RUN_TEST(ClientListTest, factory); - RUN_TEST(ClientSetTest, factory); - RUN_TEST(IAtomicLongTest, factory); - RUN_TEST(IdGeneratorTest, factory); - RUN_TEST(ICountDownLatchTest, factory); - RUN_TEST(ClientLockTest, factory); - RUN_TEST(ClientSemaphoreTest, factory); - RUN_TEST(ClientTopicTest, factory); - RUN_TEST(ClientTxnListTest, factory); - RUN_TEST(ClientTxnMapTest, factory); - RUN_TEST(ClientTxnMultiMapTest, factory); - RUN_TEST(ClientTxnQueueTest, factory); - RUN_TEST(ClientTxnSetTest, factory); - RUN_TEST(ClientTxnTest, factory); - return 0; - } catch (std::exception& e) { - std::cout << "unitTests " << e.what() << std::endl; - return 1; - } -} - -int main(int argc, char** argv) { - const char* address; - if(argc == 2){ - address = argv[1]; - } else { - address = "127.0.0.1"; - } - std::cout << "Server address : " << address << std::endl; - -// testSpeed(address); - return unitTests(address); -} - - diff --git a/hazelcast/test/map/ClientMapTest.h b/hazelcast/test/map/ClientMapTest.h deleted file mode 100644 index 609455f83a..0000000000 --- a/hazelcast/test/map/ClientMapTest.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 8/27/13. - - - - -#ifndef HAZELCAST_ClientMapTest -#define HAZELCAST_ClientMapTest - -#include "ClientTestSupport.h" -#include "hazelcast/client/ClientConfig.h" -#include "hazelcast/client/IMap.h" -#include "HazelcastServer.h" - -namespace hazelcast { - namespace client { - - class HazelcastClient; - - namespace test { - - class HazelcastServerFactory; - - class ClientMapTest : public ClientTestSupport { - public: - ClientMapTest(HazelcastServerFactory &); - - ~ClientMapTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void fillMap(); - - void testGet(); - - void testRemoveAndDelete(); - - void testRemoveIfSame(); - - void testContains(); - - void testReplace(); - - void testPutTtl(); - - void testTryPutRemove(); - - void testIssue537(); - - void testEvictAllEvent(); - - void testClearEvent(); - - void testPredicateListenerWithPortableKey(); - - void testListener(); - - void testTryLock(); - - void testForceUnlock(); - - void testLockTtl2(); - - void testLockTtl(); - - void testLock(); - - void testBasicPredicate(); - - void testKeySetAndValuesWithPredicates(); - - void testSet(); - - void testValues(); - - void testGetAllPutAll(); - - void testPutIfAbsent(); - - void testPutIfAbsentTtl(); - - void testMapWithPortable(); - - void testMapStoreRelatedRequests(); - - void testExecuteOnKey(); - - void testExecuteOnEntries(); - - private: - HazelcastServer instance; - HazelcastServer instance2; - ClientConfig clientConfig; - std::auto_ptr client; - std::auto_ptr > imap; - }; - } - } -} - -#endif //HAZELCAST_ClientMapTest - diff --git a/hazelcast/test/protocol/ClientMessageTest.cpp b/hazelcast/test/protocol/ClientMessageTest.cpp deleted file mode 100644 index c998434bbe..0000000000 --- a/hazelcast/test/protocol/ClientMessageTest.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by İhsan Demir on 19/05/15. -// - -#include "protocol/ClientMessageTest.h" - -#include "hazelcast/client/protocol/ClientMessage.h" - -namespace hazelcast { - namespace client { - namespace test { - namespace protocol { - using namespace iTest; - - ClientMessageTest::ClientMessageTest() - : iTestFixture("ClientMessageTest") { - - } - - void ClientMessageTest::addTests() { - addTest(&ClientMessageTest::testMessageFields, "Test Client Message Fields"); - } - - void ClientMessageTest::beforeClass() { - - } - - void ClientMessageTest::afterClass() { - - } - - void ClientMessageTest::beforeTest() { - - } - - void ClientMessageTest::afterTest() { - - } - - void ClientMessageTest::testMessageFields() { - std::auto_ptr msg = - hazelcast::client::protocol::ClientMessage::createForEncode( - hazelcast::client::protocol::ClientMessage::HEADER_SIZE); - - ASSERT_EQUAL(0, msg->getDataSize()); - - ASSERT_EQUAL(false, msg->isRetryable()); - - ASSERT_EQUAL(false, msg->isBindToSingleConnection()); - - ASSERT_EQUAL(hazelcast::client::protocol::ClientMessage::HEADER_SIZE, msg->getFrameLength()); - - msg->setIsBoundToSingleConnection(true); - msg->setRetryable(true); - msg->setCorrelationId(0xABCDEF12); - msg->setFlags(0x05); - msg->setMessageType(0xABCD); - msg->setPartitionId(0x8ABCDEF1); - msg->setVersion(4); - msg->updateFrameLength(); - - ASSERT_EQUAL(true, msg->isBindToSingleConnection()); - ASSERT_EQUAL(true, msg->isRetryable()); - ASSERT_EQUAL(0xABCDEF12, msg->getCorrelationId()); - ASSERT_EQUAL(false, msg->isFlagSet(2)); - ASSERT_EQUAL(true, msg->isFlagSet(4)); - ASSERT_EQUAL(true, msg->isFlagSet(0x05)); - ASSERT_EQUAL(0xABCD, msg->getMessageType()); - ASSERT_EQUAL((int32_t)0x8ABCDEF1, msg->getPartitionId()); - ASSERT_EQUAL(4, msg->getVersion()); - int32_t size = hazelcast::client::protocol::ClientMessage::HEADER_SIZE; - ASSERT_EQUAL(size, msg->getFrameLength()); - ASSERT_EQUAL(0, msg->getDataSize()); - - SocketStub sock; - ASSERT_EQUAL(size, msg->writeTo(sock, 0, size)); - } - - ClientMessageTest::SocketStub::SocketStub() : Socket(-1) { - } - - ClientMessageTest::SocketStub::~SocketStub() { - } - - - int ClientMessageTest::SocketStub::send(const void *buf, int size) const { - ASSERT_EQUAL(hazelcast::client::protocol::ClientMessage::HEADER_SIZE, size); - - byte expectedBytes[hazelcast::client::protocol::ClientMessage::HEADER_SIZE] = { - 0x16, 0x0, 0x0, 0x0, // Frame length - 0x04, // Version - 0x05, // Flags - 0xCD, 0xAB, // Message Type - 0x12, 0xEF, 0xCD, 0xAB, 0x00, 0x00, 0x00, 0x00, // Correlation Id - 0xF1, 0xDE, 0xBC, 0x8A, // Partition Id - 0x16, 0x0 // Data Offset - }; - - ASSERT_EQUAL(0, memcmp(expectedBytes, buf, hazelcast::client::protocol::ClientMessage::HEADER_SIZE)); - return size; - } - } - } - } -} diff --git a/hazelcast/test/queue/ClientQueueTest.cpp b/hazelcast/test/queue/ClientQueueTest.cpp deleted file mode 100644 index 79e1f51bf4..0000000000 --- a/hazelcast/test/queue/ClientQueueTest.cpp +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 9/4/13. - - - -#include "hazelcast/util/Util.h" -#include "queue/ClientQueueTest.h" -#include "hazelcast/client/HazelcastClient.h" -#include "hazelcast/client/ItemListener.h" -#include "HazelcastServerFactory.h" - -namespace hazelcast { - namespace client { - namespace test { - using namespace iTest; - - ClientQueueTest::ClientQueueTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("ClientQueueTest", &serverFactory) - , instance(serverFactory) - , client(getNewClient()) - , q(new IQueue< std::string>(client->getQueue< std::string >("clientQueueTest"))) { - - } - - ClientQueueTest::~ClientQueueTest() { - } - - void ClientQueueTest::addTests() { - addTest(&ClientQueueTest::testListener, "testListener"); - addTest(&ClientQueueTest::testOfferPoll, "testOfferPoll"); - addTest(&ClientQueueTest::testRemainingCapacity, "testRemainingCapacity"); - addTest(&ClientQueueTest::testRemove, "testRemove"); - addTest(&ClientQueueTest::testContains, "testContains"); - addTest(&ClientQueueTest::testDrain, "testDrain"); - addTest(&ClientQueueTest::testToArray, "testToArray"); - addTest(&ClientQueueTest::testAddAll, "testAddAll"); - addTest(&ClientQueueTest::testRemoveRetain, "testRemoveRetain"); - addTest(&ClientQueueTest::testClear, "testClear"); - } - - void ClientQueueTest::beforeClass() { - - } - - void ClientQueueTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ClientQueueTest::beforeTest() { - q->clear(); - } - - void ClientQueueTest::afterTest() { - q->clear(); - } - - class QueueTestItemListener : public ItemListener { - public: - QueueTestItemListener(util::CountDownLatch &latch) - :latch(latch) { - - } - - void itemAdded(const ItemEvent& itemEvent) { - latch.countDown(); - } - - void itemRemoved(const ItemEvent& item) { - } - - private: - util::CountDownLatch &latch; - }; - - void ClientQueueTest::testListener() { - assertEqual(0, q->size()); - - util::CountDownLatch latch(5); - - QueueTestItemListener listener(latch); - std::string id = q->addItemListener(listener, true); - - util::sleep(1); - - for (int i = 0; i < 5; i++) { - assertTrue(q->offer(std::string("event_item") + util::IOUtil::to_string(i))); - } - - assertTrue(latch.await(5)); - assertTrue(q->removeItemListener(id)); - } - - void testOfferPollThread2(util::ThreadArgs &args) { - IQueue *q = (IQueue *) args.arg0; - util::sleep(2); - q->offer("item1"); - std::cout << "item1 is offered" << std::endl; - } - - void ClientQueueTest::testOfferPoll() { - for (int i = 0; i < 10; i++) { - bool result = q->offer("item"); - assertTrue(result); - } - assertEqual(10, q->size()); - q->poll(); - bool result = q->offer("item", 5); - assertTrue(result); - - for (int i = 0; i < 10; i++) { - assertNotNull(q->poll().get()); - } - assertEqual(0, q->size()); - - util::Thread t2(testOfferPollThread2, q.get()); - - boost::shared_ptr item = q->poll(30 * 1000); - assertNotNull(item.get(), "item should not be null"); - assertEqual("item1", *item, "item1 is missing"); - t2.join(); - } - - void ClientQueueTest::testRemainingCapacity() { - int capacity = q->remainingCapacity(); - assertTrue(capacity > 10000); - q->offer("item"); - assertEqual(capacity - 1, q->remainingCapacity()); - } - - - void ClientQueueTest::testRemove() { - assertTrue(q->offer("item1")); - assertTrue(q->offer("item2")); - assertTrue(q->offer("item3")); - - assertFalse(q->remove("item4")); - assertEqual(3, q->size()); - - assertTrue(q->remove("item2")); - - assertEqual(2, q->size()); - - assertEqual("item1", *(q->poll())); - assertEqual("item3", *(q->poll())); - } - - - void ClientQueueTest::testContains() { - assertTrue(q->offer("item1")); - assertTrue(q->offer("item2")); - assertTrue(q->offer("item3")); - assertTrue(q->offer("item4")); - assertTrue(q->offer("item5")); - - - assertTrue(q->contains("item3")); - assertFalse(q->contains("item")); - - std::vector list; - list.push_back("item4"); - list.push_back("item2"); - - assertTrue(q->containsAll(list)); - - list.push_back("item"); - assertFalse(q->containsAll(list)); - - } - - void ClientQueueTest::testDrain() { - assertTrue(q->offer("item1")); - assertTrue(q->offer("item2")); - assertTrue(q->offer("item3")); - assertTrue(q->offer("item4")); - assertTrue(q->offer("item5")); - - std::vector list; - int result = q->drainTo(list, 2); - assertEqual(2, result); - assertEqual("item1", list[0]); - assertEqual("item2", list[1]); - - std::vector list2; - result = q->drainTo(list2); - assertEqual(3, result); - assertEqual("item3", list2[0]); - assertEqual("item4", list2[1]); - assertEqual("item5", list2[2]); - } - - void ClientQueueTest::testToArray() { - assertTrue(q->offer("item1")); - assertTrue(q->offer("item2")); - assertTrue(q->offer("item3")); - assertTrue(q->offer("item4")); - assertTrue(q->offer("item5")); - - std::vector array = q->toArray(); - int size = array.size(); - for (int i = 0; i < size; i++) { - assertEqual(std::string("item") + util::IOUtil::to_string(i + 1), array[i]); - } - - } - - void ClientQueueTest::testAddAll() { - std::vector coll; - coll.push_back("item1"); - coll.push_back("item2"); - coll.push_back("item3"); - coll.push_back("item4"); - - assertTrue(q->addAll(coll)); - int size = q->size(); - assertEqual(size, (int) coll.size()); - - } - - void ClientQueueTest::testRemoveRetain() { - assertTrue(q->offer("item1")); - assertTrue(q->offer("item2")); - assertTrue(q->offer("item3")); - assertTrue(q->offer("item4")); - assertTrue(q->offer("item5")); - - std::vector list; - list.push_back("item8"); - list.push_back("item9"); - assertFalse(q->removeAll(list)); - assertEqual(5, q->size()); - - list.push_back("item3"); - list.push_back("item4"); - list.push_back("item1"); - assertTrue(q->removeAll(list)); - assertEqual(2, q->size()); - - list.clear(); - list.push_back("item2"); - list.push_back("item5"); - assertFalse(q->retainAll(list)); - assertEqual(2, q->size()); - - list.clear(); - assertTrue(q->retainAll(list)); - assertEqual(0, q->size()); - } - - void ClientQueueTest::testClear() { - assertTrue(q->offer("item1")); - assertTrue(q->offer("item2")); - assertTrue(q->offer("item3")); - assertTrue(q->offer("item4")); - assertTrue(q->offer("item5")); - - q->clear(); - - assertEqual(0, q->size()); - assertNull(q->poll().get()); - - } - } - } -} - diff --git a/hazelcast/test/serialization/ClientSerializationTest.h b/hazelcast/test/serialization/ClientSerializationTest.h deleted file mode 100644 index 9fb948e0e2..0000000000 --- a/hazelcast/test/serialization/ClientSerializationTest.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 8/27/13. - - -#ifndef HAZELCAST_ClientSerializationTest -#define HAZELCAST_ClientSerializationTest - -#include "ClientTestSupport.h" - -namespace hazelcast { - namespace client { - namespace test { - - class ClientSerializationTest : public ClientTestSupport { - public: - ClientSerializationTest(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void addTests(); - - void testBasicFunctionality(); - - void testBasicFunctionalityWithLargeData(); - - void testBasicFunctionalityWithDifferentVersions(); - - void testCustomSerialization(); - - void testRawData(); - - void testIdentifiedDataSerializable(); - - void testRawDataWithoutRegistering(); - - void testInvalidWrite(); - - void testInvalidRead(); - - void testDifferentVersions(); - - void testTemplatedPortable_whenMultipleTypesAreUsed(); - - void testDataHash(); - - void testPrimitives(); - - void testPrimitiveArrays(); - - void testWriteObjectWithPortable(); - - void testWriteObjectWithIdentifiedDataSerializable(); - - void testWriteObjectWithCustomXSerializable(); - - void testWriteObjectWithCustomPersonSerializable(); - - void testNullData(); - - void testMorphingWithDifferentTypes_differentVersions(); - - template - T toDataAndBackToObject(serialization::pimpl::SerializationService& ss, T& value) { - serialization::pimpl::Data data = ss.toData(&value); - return *(ss.toObject(data)); - } - }; - } - } -} - - -#endif //HAZELCAST_ClientSerializationTest - diff --git a/hazelcast/test/set/ClientSetTest.cpp b/hazelcast/test/set/ClientSetTest.cpp deleted file mode 100644 index 517373518a..0000000000 --- a/hazelcast/test/set/ClientSetTest.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 9/13/13. - - - -#include "ClientSetTest.h" -#include "hazelcast/client/HazelcastClient.h" -#include "HazelcastServerFactory.h" - -namespace hazelcast { - namespace client { - namespace test { - using namespace iTest; - - ClientSetTest::ClientSetTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("ClientSetTest" , &serverFactory) - , instance(serverFactory) - , client(getNewClient()) - , set(new ISet(client->getSet< std::string >("ClientSetTest"))) { - } - - - ClientSetTest::~ClientSetTest() { - } - - void ClientSetTest::addTests() { - addTest(&ClientSetTest::testAddAll, "testAddAll"); - addTest(&ClientSetTest::testAddRemove, "testAddRemove"); - addTest(&ClientSetTest::testContains, "testContains"); - addTest(&ClientSetTest::testRemoveRetainAll, "testRemoveRetainAll"); - addTest(&ClientSetTest::testListener, "testListener"); - - } - - void ClientSetTest::beforeClass() { - } - - void ClientSetTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ClientSetTest::beforeTest() { - } - - void ClientSetTest::afterTest() { - set->clear(); - } - - void ClientSetTest::testAddAll() { - std::vector l; - l.push_back("item1"); - l.push_back("item2"); - - assertTrue(set->addAll(l)); - assertEqual(2, set->size()); - - assertFalse(set->addAll(l)); - assertEqual(2, set->size()); - - } - - void ClientSetTest::testAddRemove() { - assertTrue(set->add("item1")); - assertTrue(set->add("item2")); - assertTrue(set->add("item3")); - assertEqual(3, set->size()); - - assertFalse(set->add("item3")); - assertEqual(3, set->size()); - - - assertFalse(set->remove("item4")); - assertTrue(set->remove("item3")); - - } - - void ClientSetTest::testContains() { - assertTrue(set->add("item1")); - assertTrue(set->add("item2")); - assertTrue(set->add("item3")); - assertTrue(set->add("item4")); - - assertFalse(set->contains("item5")); - assertTrue(set->contains("item2")); - - std::vector l; - l.push_back("item6"); - l.push_back("item3"); - - assertFalse(set->containsAll(l)); - assertTrue(set->add("item6")); - assertTrue(set->containsAll(l)); - } - - - void ClientSetTest::testRemoveRetainAll() { - assertTrue(set->add("item1")); - assertTrue(set->add("item2")); - assertTrue(set->add("item3")); - assertTrue(set->add("item4")); - - std::vector l; - l.push_back("item4"); - l.push_back("item3"); - - assertTrue(set->removeAll(l)); - assertEqual(2, set->size()); - assertFalse(set->removeAll(l)); - assertEqual(2, set->size()); - - l.clear(); - l.push_back("item1"); - l.push_back("item2"); - assertFalse(set->retainAll(l)); - assertEqual(2, set->size()); - - l.clear(); - assertTrue(set->retainAll(l)); - assertEqual(0, set->size()); - - } - - class MySetItemListener : public ItemListener { - public: - MySetItemListener(util::CountDownLatch &latch) - :latch(latch) { - - } - - void itemAdded(const ItemEvent& itemEvent) { - latch.countDown(); - } - - void itemRemoved(const ItemEvent& item) { - } - - private: - util::CountDownLatch &latch; - }; - - - void ClientSetTest::testListener() { - util::CountDownLatch latch(6); - - MySetItemListener listener(latch); - std::string registrationId = set->addItemListener(listener, true); - - for (int i = 0; i < 5; i++) { - set->add(std::string("item") + util::IOUtil::to_string(i)); - } - set->add("done"); - - assertTrue(latch.await(20 )); - - assertTrue(set->removeItemListener(registrationId)); - } - - } - } -} - diff --git a/hazelcast/test/src/CMakeLists.txt b/hazelcast/test/src/CMakeLists.txt new file mode 100644 index 0000000000..c5367f5ea1 --- /dev/null +++ b/hazelcast/test/src/CMakeLists.txt @@ -0,0 +1,32 @@ +project(HazelcastClientTest) + +FILE(GLOB_RECURSE HZ_TEST_SOURCES "./*cpp") +FILE(GLOB_RECURSE HZ_TEST_HEADERS "./*h") + +set(GOOGLETEST_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/hazelcast/test/googletest/googletest/include) + +include_directories(${CMAKE_SOURCE_DIR}/hazelcast/include ${CMAKE_SOURCE_DIR}/hazelcast/test/src ${GOOGLETEST_INCLUDE_DIR}) + +SET(HZ_EXE_NAME clientTest_${HZ_LIB_TYPE}_${HZ_BIT}) + +add_executable(${HZ_EXE_NAME} ${HZ_TEST_SOURCES} ${HZ_TEST_HEADERS}) + +add_dependencies(${HZ_EXE_NAME} gtest) + +target_link_libraries(${HZ_EXE_NAME} ${HZ_LIB_NAME} gtest) + +IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set_target_properties(${HZ_EXE_NAME} PROPERTIES COMPILE_FLAGS "${HZ_BIT_FLAG} ${HZ_CODE_COVERAGE_COMPILE_FLAGS} ${HZ_VALGRIND_COMPILE_FLAGS}" LINK_FLAGS "${HZ_BIT_FLAG} ${HZ_CODE_COVERAGE_LINK_FLAGS} ${HZ_VALGRIND_LINK_FLAGS}") +ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + +IF (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + IF (${HZ_LIB_TYPE} MATCHES "STATIC") + message(STATUS "Shall use the STATIC Hazelcast library for the tests.") + add_definitions(-DHAZELCAST_USE_STATIC) + ELSE (${HZ_LIB_TYPE} MATCHES "SHARED") + message(STATUS "Shall use the SHARED Hazelcast library for the tests.") + add_definitions(-DHAZELCAST_USE_SHARED) + ENDIF (${HZ_LIB_TYPE} MATCHES "STATIC") + + set_target_properties(${HZ_EXE_NAME} PROPERTIES COMPILE_FLAGS " /EHsc ") +ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows") diff --git a/hazelcast/test/src/ClientTestSupport.cpp b/hazelcast/test/src/ClientTestSupport.cpp new file mode 100644 index 0000000000..b2a353f2e0 --- /dev/null +++ b/hazelcast/test/src/ClientTestSupport.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Created by İhsan Demir on 26/05/15. +// + +#include "ClientTestSupport.h" + +#include "hazelcast/client/ClientConfig.h" +#include "hazelcast/client/HazelcastClient.h" +#include "HazelcastServerFactory.h" + +namespace hazelcast { + namespace client { + namespace test { + + std::auto_ptr ClientTestSupport::getConfig() { + std::auto_ptr clientConfig(new ClientConfig()); + clientConfig->addAddress(Address(g_srvFactory->getServerAddress(), 5701)); + return clientConfig; + } + + std::auto_ptr ClientTestSupport::getNewClient() { + std::auto_ptr result(new HazelcastClient(*getConfig())); + return result; + } + } + } +} diff --git a/hazelcast/test/util/BitsTest.h b/hazelcast/test/src/ClientTestSupport.h similarity index 53% rename from hazelcast/test/util/BitsTest.h rename to hazelcast/test/src/ClientTestSupport.h index a654e6a67e..1617790c0c 100644 --- a/hazelcast/test/util/BitsTest.h +++ b/hazelcast/test/src/ClientTestSupport.h @@ -14,42 +14,33 @@ * limitations under the License. */ // -// Created by İhsan Demir on 18/05/15. +// Created by İhsan Demir on 26/05/15. // +#ifndef HAZELCASTCLIENT_CLIENTTESTSUPPORT_H +#define HAZELCASTCLIENT_CLIENTTESTSUPPORT_H -#ifndef HAZELCAST_CLIENT_TEST_UTIL_BITS_H -#define HAZELCAST_CLIENT_TEST_UTIL_BITS_H - - -#include "iTest/iTest.h" +#include +#include namespace hazelcast { namespace client { - namespace test { - namespace util { - class BitsTest : public iTest::iTestFixture { - public: - - BitsTest(); - - void addTests(); + class ClientConfig; + class HazelcastClient; - void beforeClass(); - - void afterClass(); + namespace test { + class HazelcastServerFactory; - void beforeTest(); + extern HazelcastServerFactory *g_srvFactory; - void afterTest(); + class ClientTestSupport : public ::testing::Test { + public: + std::auto_ptr getConfig(); - void testLittleEndian(); - }; - } + std::auto_ptr getNewClient(); + }; } } } - -#endif //HAZELCAST_CLIENT_TEST_UTIL_BITS_H - +#endif //HAZELCASTCLIENT_CLIENTTESTSUPPORT_H diff --git a/hazelcast/test/HazelcastServer.cpp b/hazelcast/test/src/HazelcastServer.cpp similarity index 100% rename from hazelcast/test/HazelcastServer.cpp rename to hazelcast/test/src/HazelcastServer.cpp diff --git a/hazelcast/test/HazelcastServer.h b/hazelcast/test/src/HazelcastServer.h similarity index 100% rename from hazelcast/test/HazelcastServer.h rename to hazelcast/test/src/HazelcastServer.h diff --git a/hazelcast/test/HazelcastServerFactory.cpp b/hazelcast/test/src/HazelcastServerFactory.cpp similarity index 100% rename from hazelcast/test/HazelcastServerFactory.cpp rename to hazelcast/test/src/HazelcastServerFactory.cpp diff --git a/hazelcast/test/HazelcastServerFactory.h b/hazelcast/test/src/HazelcastServerFactory.h similarity index 100% rename from hazelcast/test/HazelcastServerFactory.h rename to hazelcast/test/src/HazelcastServerFactory.h diff --git a/hazelcast/test/SimpleMapTest.h b/hazelcast/test/src/SimpleMapTest.h similarity index 100% rename from hazelcast/test/SimpleMapTest.h rename to hazelcast/test/src/SimpleMapTest.h diff --git a/hazelcast/test/src/TestHelperFunctions.h b/hazelcast/test/src/TestHelperFunctions.h new file mode 100644 index 0000000000..f45278fb4b --- /dev/null +++ b/hazelcast/test/src/TestHelperFunctions.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Created by sancar koyunlu on 15/05/14. +// + +#ifndef HAZELCAST_TestHelperFunctions +#define HAZELCAST_TestHelperFunctions + +#define ASSERT_EQ_EVENTUALLY(expected, actual) do{ \ + bool result = false; \ + for(int i = 0 ; i < 60 && !result ; i++ ) { \ + if (expected == actual) { \ + result = true; \ + } else { \ + util::sleep(2); \ + } \ + } \ + ASSERT_TRUE(result); \ + }while(0) \ + +#define ASSERT_NE_EVENTUALLY(expected, actual) do{ \ + bool result = false; \ + for(int i = 0 ; i < 60 && !result ; i++ ) { \ + if (expected != actual) { \ + result = true; \ + } else { \ + util::sleep(2); \ + } \ + } \ + ASSERT_TRUE(result); \ + }while(0) \ + +#define ASSERT_TRUE_EVENTUALLY(value) ASSERT_EQ_EVENTUALLY(value, true) +#define ASSERT_FALSE_EVENTUALLY(value) ASSERT_EQ_EVENTUALLY(value, false) +#define ASSERT_NULL_EVENTUALLY(value) ASSERT_EQ_EVENTUALLY(value, NULL) +#define ASSERT_NOTNULL_EVENTUALLY(value) ASSERT_NE_EVENTUALLY(value, NULL) + +#endif //HAZELCAST_TestHelperFunctions diff --git a/hazelcast/test/src/atomiclong/IAtomicLongTest.cpp b/hazelcast/test/src/atomiclong/IAtomicLongTest.cpp new file mode 100644 index 0000000000..61eb597205 --- /dev/null +++ b/hazelcast/test/src/atomiclong/IAtomicLongTest.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// ClientAtomiclLong.h +// hazelcast +// +// Created by Sancar on 02.08.2013. +// Copyright (c) 2013 Sancar. All rights reserved. +// + +#include "IAtomicLongTest.h" +#include "HazelcastServerFactory.h" +#include "hazelcast/client/HazelcastClient.h" + +namespace hazelcast { + namespace client { + namespace test { + IAtomicLongTest::IAtomicLongTest() : instance(*g_srvFactory), client(getNewClient()), + atom(new IAtomicLong(client->getIAtomicLong("clientAtomicLong"))) { + atom->set(0); + } + + IAtomicLongTest::~IAtomicLongTest() { + atom.reset(); + client.reset(); + instance.shutdown(); + } + + TEST_F(IAtomicLongTest, testAtomicLong) { + ASSERT_EQ(0, atom->getAndAdd(2)); + ASSERT_EQ(2, atom->get()); + atom->set(5); + ASSERT_EQ(5, atom->get()); + ASSERT_EQ(8, atom->addAndGet(3)); + ASSERT_FALSE(atom->compareAndSet(7, 4)); + ASSERT_EQ(8, atom->get()); + ASSERT_TRUE(atom->compareAndSet(8, 4)); + ASSERT_EQ(4, atom->get()); + ASSERT_EQ(3, atom->decrementAndGet()); + ASSERT_EQ(3, atom->getAndIncrement()); + ASSERT_EQ(4, atom->getAndSet(9)); + ASSERT_EQ(10, atom->incrementAndGet()); + } + + } + } +} diff --git a/hazelcast/test/atomiclong/IAtomicLongTest.h b/hazelcast/test/src/atomiclong/IAtomicLongTest.h similarity index 72% rename from hazelcast/test/atomiclong/IAtomicLongTest.h rename to hazelcast/test/src/atomiclong/IAtomicLongTest.h index 603ed38909..cf585c034d 100644 --- a/hazelcast/test/atomiclong/IAtomicLongTest.h +++ b/hazelcast/test/src/atomiclong/IAtomicLongTest.h @@ -26,45 +26,24 @@ #include "ClientTestSupport.h" #include "hazelcast/client/ClientConfig.h" -#include "hazelcast/client/IMap.h" -#include "HazelcastServer.h" #include "hazelcast/client/IAtomicLong.h" - +#include "HazelcastServer.h" namespace hazelcast { namespace client { - class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class IAtomicLongTest : public ClientTestSupport { - + class IAtomicLongTest : public ClientTestSupport { public: - - IAtomicLongTest(HazelcastServerFactory &); + IAtomicLongTest(); ~IAtomicLongTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void test(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; - std::auto_ptr atom; + std::auto_ptr atom; }; } } diff --git a/hazelcast/test/cluster/ClusterTest.cpp b/hazelcast/test/src/cluster/ClusterTest.cpp similarity index 54% rename from hazelcast/test/cluster/ClusterTest.cpp rename to hazelcast/test/src/cluster/ClusterTest.cpp index 4b1050ed23..19e57ed242 100644 --- a/hazelcast/test/cluster/ClusterTest.cpp +++ b/hazelcast/test/src/cluster/ClusterTest.cpp @@ -17,118 +17,87 @@ // Created by sancar koyunlu on 26/02/14. // - -#include "cluster/ClusterTest.h" -#include "hazelcast/client/HazelcastClient.h" +#include "ClientTestSupport.h" +#include +#include #include "hazelcast/client/InitialMembershipEvent.h" #include "hazelcast/client/InitialMembershipListener.h" #include "hazelcast/client/MemberAttributeEvent.h" #include "hazelcast/client/EntryAdapter.h" -#include "HazelcastServerFactory.h" +#include "hazelcast/client/HazelcastClient.h" #include "HazelcastServer.h" #include "hazelcast/client/LifecycleListener.h" namespace hazelcast { namespace client { - - class HazelcastClient; - namespace test { - using namespace iTest; - - ClusterTest::ClusterTest(HazelcastServerFactory& hazelcastInstanceFactory) - : ClientTestSupport("ClusterTest" , &hazelcastInstanceFactory), hazelcastInstanceFactory(hazelcastInstanceFactory) { - } - - - ClusterTest::~ClusterTest() { - } - - void ClusterTest::addTests() { - addTest(&ClusterTest::testClusterListeners, "testClusterListeners"); - addTest(&ClusterTest::testClusterListenersFromConfig, "testClusterListenersFromConfig"); - addTest(&ClusterTest::testListenersWhenClusterDown, "testListenersWhenClusterDown"); - addTest(&ClusterTest::testBehaviourWhenClusterNotFound, "testBehaviourWhenClusterNotFound"); - } - - void ClusterTest::beforeClass() { - - } - - void ClusterTest::afterClass() { - - } - - void ClusterTest::beforeTest() { - - } - - void ClusterTest::afterTest() { - - } + class ClusterTest : public ClientTestSupport { + }; class SampleInitialListener : public InitialMembershipListener { public: - SampleInitialListener(util::CountDownLatch& _memberAdded, util::CountDownLatch& _attributeLatch, util::CountDownLatch& _memberRemoved) - : _memberAdded(_memberAdded), _attributeLatch(_attributeLatch), _memberRemoved(_memberRemoved) { + SampleInitialListener(util::CountDownLatch &_memberAdded, util::CountDownLatch &_attributeLatch, + util::CountDownLatch &_memberRemoved) + : _memberAdded(_memberAdded), _attributeLatch(_attributeLatch), _memberRemoved(_memberRemoved) { } - void init(const InitialMembershipEvent& event) { - std::vector const& members = event.getMembers(); + void init(const InitialMembershipEvent &event) { + std::vector const &members = event.getMembers(); if (members.size() == 1) { _memberAdded.countDown(); } } - void memberAdded(const MembershipEvent& event) { + void memberAdded(const MembershipEvent &event) { _memberAdded.countDown(); } - void memberRemoved(const MembershipEvent& event) { + void memberRemoved(const MembershipEvent &event) { _memberRemoved.countDown(); } - void memberAttributeChanged(const MemberAttributeEvent& memberAttributeEvent) { + void memberAttributeChanged(const MemberAttributeEvent &memberAttributeEvent) { _attributeLatch.countDown(); } private: - util::CountDownLatch& _memberAdded; - util::CountDownLatch& _attributeLatch; - util::CountDownLatch& _memberRemoved; + util::CountDownLatch &_memberAdded; + util::CountDownLatch &_attributeLatch; + util::CountDownLatch &_memberRemoved; }; class SampleListenerInClusterTest : public MembershipListener { public: - SampleListenerInClusterTest(util::CountDownLatch& _memberAdded, util::CountDownLatch& _attributeLatch, util::CountDownLatch& _memberRemoved) - : _memberAdded(_memberAdded), _attributeLatch(_attributeLatch), _memberRemoved(_memberRemoved) { + SampleListenerInClusterTest(util::CountDownLatch &_memberAdded, util::CountDownLatch &_attributeLatch, + util::CountDownLatch &_memberRemoved) + : _memberAdded(_memberAdded), _attributeLatch(_attributeLatch), _memberRemoved(_memberRemoved) { } - void memberAdded(const MembershipEvent& event) { + void memberAdded(const MembershipEvent &event) { _memberAdded.countDown(); } - void memberRemoved(const MembershipEvent& event) { + void memberRemoved(const MembershipEvent &event) { _memberRemoved.countDown(); } - void memberAttributeChanged(const MemberAttributeEvent& memberAttributeEvent) { + void memberAttributeChanged(const MemberAttributeEvent &memberAttributeEvent) { memberAttributeEvent.getKey(); _attributeLatch.countDown(); } private: - util::CountDownLatch& _memberAdded; - util::CountDownLatch& _attributeLatch; - util::CountDownLatch& _memberRemoved; + util::CountDownLatch &_memberAdded; + util::CountDownLatch &_attributeLatch; + util::CountDownLatch &_memberRemoved; }; - void ClusterTest::testClusterListeners() { - HazelcastServer instance(hazelcastInstanceFactory); + TEST_F(ClusterTest, testClusterListeners) { + HazelcastServer instance(*g_srvFactory); std::auto_ptr hazelcastClient(getNewClient()); Cluster cluster = hazelcastClient->getCluster(); util::CountDownLatch memberAdded(1); @@ -144,17 +113,17 @@ namespace hazelcast { cluster.addMembershipListener(&sampleInitialListener); cluster.addMembershipListener(&sampleListener); - HazelcastServer instance2(hazelcastInstanceFactory); + HazelcastServer instance2(*g_srvFactory); - assertTrue(attributeLatchInit.await(30), "attributeLatchInit"); - assertTrue(attributeLatch.await(30), "attributeLatch"); - assertTrue(memberAdded.await(30), "memberAdded"); - assertTrue(memberAddedInit.await(30), "memberAddedInit"); + ASSERT_TRUE(attributeLatchInit.await(30)); + ASSERT_TRUE(attributeLatch.await(30)); + ASSERT_TRUE(memberAdded.await(30)); + ASSERT_TRUE(memberAddedInit.await(30)); instance2.shutdown(); - assertTrue(memberRemoved.await(30), "memberRemoved"); - assertTrue(memberRemovedInit.await(30), "memberRemovedInit"); + ASSERT_TRUE(memberRemoved.await(30)); + ASSERT_TRUE(memberRemovedInit.await(30)); instance.shutdown(); @@ -162,7 +131,7 @@ namespace hazelcast { cluster.removeMembershipListener(&sampleListener); } - void ClusterTest::testClusterListenersFromConfig() { + TEST_F(ClusterTest, testClusterListenersFromConfig) { util::CountDownLatch memberAdded(2); util::CountDownLatch memberAddedInit(3); util::CountDownLatch memberRemoved(1); @@ -176,57 +145,57 @@ namespace hazelcast { clientConfig->addListener(&sampleListener); clientConfig->addListener(&sampleInitialListener); - HazelcastServer instance(hazelcastInstanceFactory); + HazelcastServer instance(*g_srvFactory); HazelcastClient hazelcastClient(*clientConfig); - HazelcastServer instance2(hazelcastInstanceFactory); + HazelcastServer instance2(*g_srvFactory); - assertTrue(attributeLatchInit.await(30), "attributeLatchInit"); - assertTrue(attributeLatch.await(30), "attributeLatch"); - assertTrue(memberAdded.await(30), "memberAdded"); - assertTrue(memberAddedInit.await(30), "memberAddedInit"); + ASSERT_TRUE(attributeLatchInit.await(30)); + ASSERT_TRUE(attributeLatch.await(30)); + ASSERT_TRUE(memberAdded.await(30)); + ASSERT_TRUE(memberAddedInit.await(30)); instance2.shutdown(); - assertTrue(memberRemoved.await(30), "memberRemoved"); - assertTrue(memberRemovedInit.await(30), "memberRemovedInit"); + ASSERT_TRUE(memberRemoved.await(30)); + ASSERT_TRUE(memberRemovedInit.await(30)); instance.shutdown(); } class DummyListenerClusterTest : public EntryAdapter { public: - DummyListenerClusterTest(util::CountDownLatch& addLatch) - : addLatch(addLatch) { + DummyListenerClusterTest(util::CountDownLatch &addLatch) + : addLatch(addLatch) { } - void entryAdded(const EntryEvent& event) { + void entryAdded(const EntryEvent &event) { addLatch.countDown(); } private: - util::CountDownLatch& addLatch; + util::CountDownLatch &addLatch; }; class LclForClusterTest : public LifecycleListener { public: - LclForClusterTest(util::CountDownLatch& latch) - : latch(latch) { + LclForClusterTest(util::CountDownLatch &latch) + : latch(latch) { } - void stateChanged(const LifecycleEvent& event) { + void stateChanged(const LifecycleEvent &event) { if (event.getState() == LifecycleEvent::CLIENT_CONNECTED) { latch.countDown(); } } private: - util::CountDownLatch& latch; + util::CountDownLatch &latch; }; - void ClusterTest::testListenersWhenClusterDown() { - HazelcastServer instance(hazelcastInstanceFactory); + TEST_F(ClusterTest, testListenersWhenClusterDown) { + HazelcastServer instance(*g_srvFactory); std::auto_ptr clientConfig(getConfig()); clientConfig->setAttemptPeriod(1000 * 10).setConnectionAttemptLimit(100).setLogLevel(FINEST); @@ -234,7 +203,8 @@ namespace hazelcast { util::CountDownLatch countDownLatch(1); DummyListenerClusterTest listener(countDownLatch); - IMap m = hazelcastClient.getMap("testListenersWhenClusterDown"); + IMap m = hazelcastClient.getMap( + "testListenersWhenClusterDown"); m.addEntryListener(listener, true); instance.shutdown(); @@ -242,23 +212,18 @@ namespace hazelcast { LclForClusterTest lifecycleListener(lifecycleLatch); hazelcastClient.addLifecycleListener(&lifecycleListener); - HazelcastServer instance2(hazelcastInstanceFactory); - assertTrue(lifecycleLatch.await(120), "Lifecycle latch await timed out!"); + HazelcastServer instance2(*g_srvFactory); + ASSERT_TRUE(lifecycleLatch.await(120)); // Let enough time for the client to re-register the failed listeners util::sleep(1); m.put("sample", "entry"); - assertTrue(countDownLatch.await(60), "Await timed out !"); - assertTrue(hazelcastClient.removeLifecycleListener(&lifecycleListener), "Listener could not be removed"); + ASSERT_TRUE(countDownLatch.await(60)); + ASSERT_TRUE(hazelcastClient.removeLifecycleListener(&lifecycleListener)); } - void ClusterTest::testBehaviourWhenClusterNotFound() { + TEST_F(ClusterTest, testBehaviourWhenClusterNotFound) { ClientConfig clientConfig; - try { - HazelcastClient hazelcastClient(clientConfig); - assertTrue(false); - } catch (exception::IllegalStateException&) { - - } + ASSERT_THROW(HazelcastClient client(clientConfig), exception::IllegalStateException); } } } diff --git a/hazelcast/test/cluster/MemberAttributeTest.cpp b/hazelcast/test/src/cluster/MemberAttributeTest.cpp similarity index 66% rename from hazelcast/test/cluster/MemberAttributeTest.cpp rename to hazelcast/test/src/cluster/MemberAttributeTest.cpp index 5df6fd8f4b..35eea8ea66 100644 --- a/hazelcast/test/cluster/MemberAttributeTest.cpp +++ b/hazelcast/test/src/cluster/MemberAttributeTest.cpp @@ -17,8 +17,6 @@ // Created by sancar koyunlu on 27/02/14. // -#include "MemberAttributeTest.h" - #include "HazelcastServerFactory.h" #include "hazelcast/client/HazelcastClient.h" #include "hazelcast/client/Cluster.h" @@ -30,6 +28,7 @@ #include "hazelcast/client/MemberAttributeEvent.h" #include +#include namespace hazelcast { namespace client { @@ -37,70 +36,40 @@ namespace hazelcast { class HazelcastClient; namespace test { - using namespace iTest; - - MemberAttributeTest::MemberAttributeTest(HazelcastServerFactory &hazelcastInstanceFactory) - :ClientTestSupport("MemberAttributeTest" , &hazelcastInstanceFactory) - ,hazelcastInstanceFactory(hazelcastInstanceFactory){ - } - - - MemberAttributeTest::~MemberAttributeTest() { - } - - void MemberAttributeTest::addTests() { - addTest(&MemberAttributeTest::testInitialValues, "testInitialValues"); - addTest(&MemberAttributeTest::testChangeWithListeners, "testChangeWithListeners"); - } - - void MemberAttributeTest::beforeClass() { - - } + class MemberAttributeTest : public ClientTestSupport + {}; - void MemberAttributeTest::afterClass() { - - } - - void MemberAttributeTest::beforeTest() { - - } - - void MemberAttributeTest::afterTest() { - - } - - void MemberAttributeTest::testInitialValues() { - HazelcastServer instance(hazelcastInstanceFactory); + TEST_F(MemberAttributeTest, testInitialValues) { + HazelcastServer instance(*g_srvFactory); std::auto_ptr hazelcastClient(getNewClient()); Cluster cluster = hazelcastClient->getCluster(); std::vector members = cluster.getMembers(); - assertEqual(1U,members.size()); + ASSERT_EQ(1U,members.size()); Member &member = members[0]; - assertTrue(member.lookupAttribute("intAttr")); - assertEqual("211", *member.getAttribute("intAttr")); + ASSERT_TRUE(member.lookupAttribute("intAttr")); + ASSERT_EQ("211", *member.getAttribute("intAttr")); - assertTrue(member.lookupAttribute("boolAttr")); - assertEqual("true", *member.getAttribute("boolAttr")); + ASSERT_TRUE(member.lookupAttribute("boolAttr")); + ASSERT_EQ("true", *member.getAttribute("boolAttr")); - assertTrue(member.lookupAttribute("byteAttr")); - assertEqual("7", *member.getAttribute("byteAttr")); + ASSERT_TRUE(member.lookupAttribute("byteAttr")); + ASSERT_EQ("7", *member.getAttribute("byteAttr")); - assertTrue(member.lookupAttribute("doubleAttr")); - assertEqual("2.0", *member.getAttribute("doubleAttr")); + ASSERT_TRUE(member.lookupAttribute("doubleAttr")); + ASSERT_EQ("2.0", *member.getAttribute("doubleAttr")); - assertTrue(member.lookupAttribute("floatAttr")); - assertEqual("1.2", *member.getAttribute("floatAttr")); + ASSERT_TRUE(member.lookupAttribute("floatAttr")); + ASSERT_EQ("1.2", *member.getAttribute("floatAttr")); - assertTrue(member.lookupAttribute("shortAttr")); - assertEqual("3", *member.getAttribute("shortAttr")); + ASSERT_TRUE(member.lookupAttribute("shortAttr")); + ASSERT_EQ("3", *member.getAttribute("shortAttr")); - assertTrue(member.lookupAttribute("strAttr")); - assertEqual(std::string("strAttr"), *member.getAttribute("strAttr")); + ASSERT_TRUE(member.lookupAttribute("strAttr")); + ASSERT_EQ(std::string("strAttr"), *member.getAttribute("strAttr")); instance.shutdown(); } - class AttributeListener : public MembershipListener { public: AttributeListener(util::CountDownLatch &_attributeLatch) @@ -161,20 +130,19 @@ namespace hazelcast { util::CountDownLatch &_attributeLatch; }; - void MemberAttributeTest::testChangeWithListeners(){ + TEST_F(MemberAttributeTest, testChangeWithListeners){ util::CountDownLatch attributeLatch(7); AttributeListener sampleListener(attributeLatch); std::auto_ptr clientConfig(getConfig()); clientConfig->addListener(&sampleListener); - HazelcastServer instance(hazelcastInstanceFactory); + HazelcastServer instance(*g_srvFactory); HazelcastClient hazelcastClient(*clientConfig); - HazelcastServer instance2(hazelcastInstanceFactory); + HazelcastServer instance2(*g_srvFactory); - bool a = attributeLatch.await(30); - assertTrue(a, "attributeLatch"); + ASSERT_TRUE(attributeLatch.await(30)); instance2.shutdown(); diff --git a/hazelcast/test/common/containers/LitlleEndianBufferTest.cpp b/hazelcast/test/src/common/containers/LitlleEndianBufferTest.cpp similarity index 76% rename from hazelcast/test/common/containers/LitlleEndianBufferTest.cpp rename to hazelcast/test/src/common/containers/LitlleEndianBufferTest.cpp index d3294f66cd..3d90eed14d 100644 --- a/hazelcast/test/common/containers/LitlleEndianBufferTest.cpp +++ b/hazelcast/test/src/common/containers/LitlleEndianBufferTest.cpp @@ -17,44 +17,21 @@ // Created by İhsan Demir on 17/05/15. // -#include "common/containers/LitlleEndianBufferTest.h" -#include "iTest/iTest.h" #include +#include + +#include "hazelcast/util/LittleEndianBufferWrapper.h" namespace hazelcast { namespace client { namespace test { namespace common { namespace containers { - using namespace iTest; - - LittleEndianBufferTest::LittleEndianBufferTest() - : iTestFixture("LittleEndianBufferTest") { - } - - - LittleEndianBufferTest::~LittleEndianBufferTest() { - } - - void LittleEndianBufferTest::addTests() { - addTest(&LittleEndianBufferTest::testBinaryFormat, "Test Binary Format"); - - } - - void LittleEndianBufferTest::beforeClass() { - } - - void LittleEndianBufferTest::afterClass() { - } - - void LittleEndianBufferTest::beforeTest() { - - } - - void LittleEndianBufferTest::afterTest() { - } + class LittleEndianBufferTest : public ::testing::Test, + public util::LittleEndianBufferWrapper /* Need this in order to test*/ + {}; - void LittleEndianBufferTest::testBinaryFormat() { + TEST_F (LittleEndianBufferTest, testBinaryFormat) { #define TEST_DATA_SIZE 8 #define LARGE_BUFFER_SIZE 20 #define START_BYTE_NUMBER 5 @@ -78,20 +55,20 @@ namespace hazelcast { { wrapForRead(largeBuffer, LARGE_BUFFER_SIZE, START_BYTE_NUMBER); uint8_t result = getUint8(); - ASSERT_EQUAL(0x8A, result); + ASSERT_EQ(0x8A, result); } { wrapForRead(largeBuffer, LARGE_BUFFER_SIZE, START_BYTE_NUMBER); uint16_t result = getUint16(); - ASSERT_EQUAL(0x8A + + ASSERT_EQ(0x8A + 0x9A * oneByteFactor, result); } { wrapForRead(largeBuffer, LARGE_BUFFER_SIZE, START_BYTE_NUMBER); uint32_t result = getUint32(); - ASSERT_EQUAL(0x8A + + ASSERT_EQ(0x8A + 0x9A * oneByteFactor + 0xAA * twoBytesFactor + 0xBA * threeBytesFactor , result); @@ -100,7 +77,7 @@ namespace hazelcast { { wrapForRead(largeBuffer, LARGE_BUFFER_SIZE, START_BYTE_NUMBER); uint64_t result = getUint64(); - ASSERT_EQUAL(0x8A + + ASSERT_EQ(0x8A + 0x9A * oneByteFactor + 0xAA * twoBytesFactor + 0xBA * threeBytesFactor + @@ -116,14 +93,14 @@ namespace hazelcast { { wrapForRead(largeBuffer, LARGE_BUFFER_SIZE, START_BYTE_NUMBER); int16_t result = getInt16(); - ASSERT_EQUAL(-1 * (~((int16_t)(0x8A + + ASSERT_EQ(-1 * (~((int16_t)(0x8A + 0x9A * oneByteFactor)) + 1), result); } { wrapForRead(largeBuffer, LARGE_BUFFER_SIZE, START_BYTE_NUMBER); int32_t result = getInt32(); - ASSERT_EQUAL(-1 * (~((int32_t)( + ASSERT_EQ(-1 * (~((int32_t)( 0x8A + 0x9A * oneByteFactor + 0xAA * twoBytesFactor + @@ -133,7 +110,7 @@ namespace hazelcast { { wrapForRead(largeBuffer, LARGE_BUFFER_SIZE, START_BYTE_NUMBER); int64_t result = getInt64(); - ASSERT_EQUAL(-1 * (~((int64_t)( + ASSERT_EQ(-1 * (~((int64_t)( 0x8A + 0x9A * oneByteFactor + 0xAA * twoBytesFactor + @@ -145,13 +122,13 @@ namespace hazelcast { } // ----- Test signed get ends --------------------------------- - byte firstChar = 'B'; + const byte firstChar = 'B'; byte strBytes[8] = {4, 0, 0, 0, /* This part is the len field which is 4 bytes */ firstChar, firstChar + 1, firstChar + 2, firstChar + 3}; // This is string BCDE { wrapForRead(strBytes, 8, 0); - ASSERT_EQUAL("BCDE", getStringUtf8()); + ASSERT_EQ("BCDE", getStringUtf8()); } // ---- Test consecutive gets starts --------------------------- @@ -168,18 +145,18 @@ namespace hazelcast { { uint8_t result = getUint8(); - ASSERT_EQUAL(0x8A, result); + ASSERT_EQ(0x8A, result); } { uint16_t result = getUint16(); - ASSERT_EQUAL(0x9A + + ASSERT_EQ(0x9A + 0xAA * oneByteFactor, result); } { uint32_t result = getUint32(); - ASSERT_EQUAL(0xBA + + ASSERT_EQ(0xBA + 0xCA * oneByteFactor + 0xDA * twoBytesFactor + 0xEA * threeBytesFactor , result); @@ -187,7 +164,7 @@ namespace hazelcast { { uint64_t result = getUint64(); - ASSERT_EQUAL(0x8B + + ASSERT_EQ(0x8B + 0x8A * oneByteFactor + 0x9A * twoBytesFactor + 0xAA * threeBytesFactor + @@ -202,13 +179,13 @@ namespace hazelcast { { int16_t result = getInt16(); - ASSERT_EQUAL(-1 * (~((int16_t)(0x8B + + ASSERT_EQ(-1 * (~((int16_t)(0x8B + 0x8A * oneByteFactor)) + 1), result); } { int32_t result = getInt32(); - ASSERT_EQUAL(-1 * (~((int32_t)( + ASSERT_EQ(-1 * (~((int32_t)( 0x9A + 0xAA * oneByteFactor + 0xBA * twoBytesFactor + @@ -217,7 +194,7 @@ namespace hazelcast { { int64_t result = getInt64(); - ASSERT_EQUAL(-1 * (~((int64_t)( + ASSERT_EQ(-1 * (~((int64_t)( 0xDA + 0xEA * oneByteFactor + 0x8B * twoBytesFactor + @@ -230,18 +207,18 @@ namespace hazelcast { // ----- Test signed get ends --------------------------------- { - ASSERT_EQUAL("BCDE", getStringUtf8()); + ASSERT_EQ("BCDE", getStringUtf8()); } { bool result = getBoolean(); - ASSERT_EQUAL(true, result); + ASSERT_EQ(true, result); result = getBoolean(); - ASSERT_EQUAL(true, result); + ASSERT_EQ(true, result); result = getBoolean(); - ASSERT_EQUAL(false, result); + ASSERT_EQ(false, result); } } @@ -252,43 +229,43 @@ namespace hazelcast { wrapForWrite(writeBuffer, 30, 0); set((uint8_t) 0x8A); - ASSERT_EQUAL(0x8A, writeBuffer[0]); + ASSERT_EQ(0x8A, writeBuffer[0]); set(true); - ASSERT_EQUAL(0x01, writeBuffer[1]); + ASSERT_EQ(0x01, writeBuffer[1]); set(false); - ASSERT_EQUAL(0x00, writeBuffer[2]); + ASSERT_EQ(0x00, writeBuffer[2]); set('C'); - ASSERT_EQUAL('C', writeBuffer[3]); + ASSERT_EQ('C', writeBuffer[3]); int16_t int16Val = 0x7BCD; set(int16Val); - ASSERT_EQUAL(0xCD, writeBuffer[4]); - ASSERT_EQUAL(0x7B, writeBuffer[5]); + ASSERT_EQ(0xCD, writeBuffer[4]); + ASSERT_EQ(0x7B, writeBuffer[5]); uint16_t uInt16Val = 0xABCD; set(uInt16Val); - ASSERT_EQUAL(0xCD, writeBuffer[6]); - ASSERT_EQUAL(0xAB, writeBuffer[7]); + ASSERT_EQ(0xCD, writeBuffer[6]); + ASSERT_EQ(0xAB, writeBuffer[7]); int32_t int32Val = 0xAEBCEEFF; set(int32Val); - ASSERT_EQUAL(0xFF, writeBuffer[8]); - ASSERT_EQUAL(0xEE, writeBuffer[9]); - ASSERT_EQUAL(0xBC, writeBuffer[10]); - ASSERT_EQUAL(0xAE, writeBuffer[11]); + ASSERT_EQ(0xFF, writeBuffer[8]); + ASSERT_EQ(0xEE, writeBuffer[9]); + ASSERT_EQ(0xBC, writeBuffer[10]); + ASSERT_EQ(0xAE, writeBuffer[11]); set(std::string("Test Data")); - ASSERT_EQUAL(0x09, (int)writeBuffer[12]); - ASSERT_EQUAL(0x0, writeBuffer[13]); - ASSERT_EQUAL(0x0, writeBuffer[14]); - ASSERT_EQUAL(0x0, writeBuffer[15]); - ASSERT_EQUAL('T', writeBuffer[16]); - ASSERT_EQUAL('e', writeBuffer[17]); - ASSERT_EQUAL('a', writeBuffer[24]); + ASSERT_EQ(0x09, (int)writeBuffer[12]); + ASSERT_EQ(0x0, writeBuffer[13]); + ASSERT_EQ(0x0, writeBuffer[14]); + ASSERT_EQ(0x0, writeBuffer[15]); + ASSERT_EQ('T', writeBuffer[16]); + ASSERT_EQ('e', writeBuffer[17]); + ASSERT_EQ('a', writeBuffer[24]); } } } diff --git a/hazelcast/test/countdownlatch/ICountDownLatchTest.cpp b/hazelcast/test/src/countdownlatch/ICountDownLatchTest.cpp similarity index 54% rename from hazelcast/test/countdownlatch/ICountDownLatchTest.cpp rename to hazelcast/test/src/countdownlatch/ICountDownLatchTest.cpp index 43f1e97fe0..a1fba87ebb 100644 --- a/hazelcast/test/countdownlatch/ICountDownLatchTest.cpp +++ b/hazelcast/test/src/countdownlatch/ICountDownLatchTest.cpp @@ -18,49 +18,21 @@ -#include "countdownlatch/ICountDownLatchTest.h" -#include "HazelcastServerFactory.h" +#include "ICountDownLatchTest.h" #include "hazelcast/client/HazelcastClient.h" namespace hazelcast { namespace client { - - class HazelcastClient; - namespace test { - using namespace iTest; - - ICountDownLatchTest::ICountDownLatchTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("ICountDownLatchTest" , &serverFactory) - , instance(serverFactory) + ICountDownLatchTest::ICountDownLatchTest() + : instance(*g_srvFactory) , client(getNewClient()) , l(new ICountDownLatch(client->getICountDownLatch("ICountDownLatchTest"))) { } - ICountDownLatchTest::~ICountDownLatchTest() { } - void ICountDownLatchTest::addTests() { - addTest(&ICountDownLatchTest::testLatch, "ICountDownLatchTest"); - } - - void ICountDownLatchTest::beforeClass() { - - } - - void ICountDownLatchTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ICountDownLatchTest::beforeTest() { - - } - - void ICountDownLatchTest::afterTest() { - } - void testLatchThread(util::ThreadArgs &args) { ICountDownLatch *l = (ICountDownLatch *) args.arg0; for (int i = 0; i < 20; i++) { @@ -68,14 +40,14 @@ namespace hazelcast { } } - void ICountDownLatchTest::testLatch() { - assertTrue(l->trySetCount(20)); - assertFalse(l->trySetCount(10)); - assertEqual(20, l->getCount()); + TEST_F(ICountDownLatchTest, testLatch) { + ASSERT_TRUE(l->trySetCount(20)); + ASSERT_FALSE(l->trySetCount(10)); + ASSERT_EQ(20, l->getCount()); util::Thread t(testLatchThread, l.get()); - assertTrue(l->await(10 * 1000)); + ASSERT_TRUE(l->await(10 * 1000)); } } diff --git a/hazelcast/test/countdownlatch/ICountDownLatchTest.h b/hazelcast/test/src/countdownlatch/ICountDownLatchTest.h similarity index 78% rename from hazelcast/test/countdownlatch/ICountDownLatchTest.h rename to hazelcast/test/src/countdownlatch/ICountDownLatchTest.h index c68b70fac4..92135c2310 100644 --- a/hazelcast/test/countdownlatch/ICountDownLatchTest.h +++ b/hazelcast/test/src/countdownlatch/ICountDownLatchTest.h @@ -29,37 +29,22 @@ namespace hazelcast { namespace client { - class HazelcastClient; namespace test { class HazelcastServerFactory; - class ICountDownLatchTest : public ClientTestSupport { + class ICountDownLatchTest : public ClientTestSupport { public: - - ICountDownLatchTest(HazelcastServerFactory &); + ICountDownLatchTest(); ~ICountDownLatchTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testLatch(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; - std::auto_ptr l; + std::auto_ptr l; }; } } diff --git a/hazelcast/test/customSerialization/TestCustomPersonSerializer.cpp b/hazelcast/test/src/customSerialization/TestCustomPersonSerializer.cpp similarity index 95% rename from hazelcast/test/customSerialization/TestCustomPersonSerializer.cpp rename to hazelcast/test/src/customSerialization/TestCustomPersonSerializer.cpp index 8dcb67fec6..f73b37a6e8 100644 --- a/hazelcast/test/customSerialization/TestCustomPersonSerializer.cpp +++ b/hazelcast/test/src/customSerialization/TestCustomPersonSerializer.cpp @@ -37,7 +37,7 @@ namespace hazelcast { assert(i == 999); } - int TestCustomPersonSerializer::getTypeId() const { + int TestCustomPersonSerializer::getHazelcastTypeId() const { return 999; } diff --git a/hazelcast/test/customSerialization/TestCustomPersonSerializer.h b/hazelcast/test/src/customSerialization/TestCustomPersonSerializer.h similarity index 96% rename from hazelcast/test/customSerialization/TestCustomPersonSerializer.h rename to hazelcast/test/src/customSerialization/TestCustomPersonSerializer.h index f9b44b54c2..5638bfc029 100644 --- a/hazelcast/test/customSerialization/TestCustomPersonSerializer.h +++ b/hazelcast/test/src/customSerialization/TestCustomPersonSerializer.h @@ -35,7 +35,7 @@ namespace hazelcast { void read(serialization::ObjectDataInput & in, TestCustomPerson& object); - int getTypeId() const; + int getHazelcastTypeId() const; }; } } diff --git a/hazelcast/test/customSerialization/TestCustomSerializerX.h b/hazelcast/test/src/customSerialization/TestCustomSerializerX.h similarity index 97% rename from hazelcast/test/customSerialization/TestCustomSerializerX.h rename to hazelcast/test/src/customSerialization/TestCustomSerializerX.h index 50495c3bfd..17560dab6d 100644 --- a/hazelcast/test/customSerialization/TestCustomSerializerX.h +++ b/hazelcast/test/src/customSerialization/TestCustomSerializerX.h @@ -48,7 +48,7 @@ namespace hazelcast { assert(i == 666); } - int getTypeId() const { + int getHazelcastTypeId() const { return 666; }; }; diff --git a/hazelcast/test/customSerialization/TestCustomXSerializable.cpp b/hazelcast/test/src/customSerialization/TestCustomXSerializable.cpp similarity index 94% rename from hazelcast/test/customSerialization/TestCustomXSerializable.cpp rename to hazelcast/test/src/customSerialization/TestCustomXSerializable.cpp index ed02fcad7c..ba64705c30 100644 --- a/hazelcast/test/customSerialization/TestCustomXSerializable.cpp +++ b/hazelcast/test/src/customSerialization/TestCustomXSerializable.cpp @@ -39,7 +39,7 @@ namespace hazelcast { return !(*this == rhs); } - int TestCustomXSerializable::getTypeId() const { + int getHazelcastTypeId(TestCustomXSerializable const* param) { return 666; } @@ -71,7 +71,7 @@ namespace hazelcast { return name; } - int TestCustomPerson::getTypeId() const { + int getHazelcastTypeId(TestCustomPerson const* param) { return 999; } diff --git a/hazelcast/test/customSerialization/TestCustomXSerializable.h b/hazelcast/test/src/customSerialization/TestCustomXSerializable.h similarity index 87% rename from hazelcast/test/customSerialization/TestCustomXSerializable.h rename to hazelcast/test/src/customSerialization/TestCustomXSerializable.h index 82a06d75a7..b474f79e2a 100644 --- a/hazelcast/test/customSerialization/TestCustomXSerializable.h +++ b/hazelcast/test/src/customSerialization/TestCustomXSerializable.h @@ -27,14 +27,12 @@ namespace hazelcast { namespace client { namespace test { - class TestCustomXSerializable : public serialization::SerializerBase { + class TestCustomXSerializable{ public: TestCustomXSerializable(); TestCustomXSerializable(int id); - int getTypeId() const; - bool operator ==(const TestCustomXSerializable & rhs) const; bool operator !=(const TestCustomXSerializable& m) const; @@ -42,7 +40,9 @@ namespace hazelcast { int id; }; - class TestCustomPerson : public serialization::SerializerBase { + int getHazelcastTypeId(const TestCustomXSerializable* ); + + class TestCustomPerson { public: TestCustomPerson(); @@ -52,8 +52,6 @@ namespace hazelcast { void setName(const std::string & name); - int getTypeId() const; - bool operator ==(const TestCustomPerson & rhs) const; bool operator !=(const TestCustomPerson& m) const; @@ -62,6 +60,8 @@ namespace hazelcast { private: std::string name; }; + + int getHazelcastTypeId(const TestCustomPerson* ); } } } diff --git a/hazelcast/test/idgenerator/IdGeneratorTest.cpp b/hazelcast/test/src/idgenerator/IdGeneratorTest.cpp similarity index 55% rename from hazelcast/test/idgenerator/IdGeneratorTest.cpp rename to hazelcast/test/src/idgenerator/IdGeneratorTest.cpp index 664ce499b7..f23715aa56 100644 --- a/hazelcast/test/idgenerator/IdGeneratorTest.cpp +++ b/hazelcast/test/src/idgenerator/IdGeneratorTest.cpp @@ -28,44 +28,18 @@ namespace hazelcast { namespace client { namespace test { - using namespace iTest; - - IdGeneratorTest::IdGeneratorTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("IdGeneratorTest" , &serverFactory) - , instance(serverFactory) + IdGeneratorTest::IdGeneratorTest() + : instance(*g_srvFactory) , client(getNewClient()) , generator(new IdGenerator(client->getIdGenerator("clientIdGenerator"))) { } - - IdGeneratorTest::~IdGeneratorTest() { - } - - void IdGeneratorTest::addTests() { - addTest(&IdGeneratorTest::testGenerator, "clientIdGenerator"); - } - - void IdGeneratorTest::beforeClass() { - - } - - void IdGeneratorTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void IdGeneratorTest::beforeTest() { - } - - void IdGeneratorTest::afterTest() { - } - - void IdGeneratorTest::testGenerator() { + TEST_F (IdGeneratorTest, testGenerator) { int initValue = 3569; - assertTrue(generator->init(initValue)); - assertFalse(generator->init(4569)); + ASSERT_TRUE(generator->init(initValue)); + ASSERT_FALSE(generator->init(4569)); for(int i = 0 ; i < 2000 ; i++){ - assertEqual(++initValue, generator->newId()); + ASSERT_EQ(++initValue, generator->newId()); } } diff --git a/hazelcast/test/idgenerator/IdGeneratorTest.h b/hazelcast/test/src/idgenerator/IdGeneratorTest.h similarity index 74% rename from hazelcast/test/idgenerator/IdGeneratorTest.h rename to hazelcast/test/src/idgenerator/IdGeneratorTest.h index 49a97c4032..b7f8a76230 100644 --- a/hazelcast/test/idgenerator/IdGeneratorTest.h +++ b/hazelcast/test/src/idgenerator/IdGeneratorTest.h @@ -32,33 +32,14 @@ namespace hazelcast { namespace client { - class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class IdGeneratorTest : public ClientTestSupport { - + class IdGeneratorTest : public ClientTestSupport { public: - IdGeneratorTest(HazelcastServerFactory &); - - ~IdGeneratorTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testGenerator(); + IdGeneratorTest(); - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; diff --git a/hazelcast/test/issues/IssueTest.cpp b/hazelcast/test/src/issues/IssueTest.cpp similarity index 68% rename from hazelcast/test/issues/IssueTest.cpp rename to hazelcast/test/src/issues/IssueTest.cpp index f776c1fade..a72385b7f4 100644 --- a/hazelcast/test/issues/IssueTest.cpp +++ b/hazelcast/test/src/issues/IssueTest.cpp @@ -28,38 +28,13 @@ namespace hazelcast { namespace client { namespace test { - IssueTest::IssueTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("IssueTest", &serverFactory) - , serverFactory(serverFactory), latch(2), listener(latch) { - + IssueTest::IssueTest() + : latch(2), listener(latch) { } IssueTest::~IssueTest() { - } - - void IssueTest::addTests() { - addTest(&IssueTest::testOperationRedo_smartRoutingDisabled, "testOperationRedo_smartRoutingDisabled"); - addTest(&IssueTest::testListenerSubscriptionOnSingleServerRestart, - "testListenerSubscriptionOnSingleServerRestart"); - } - - void IssueTest::beforeClass() { - - } - - void IssueTest::afterClass() { - - } - - void IssueTest::beforeTest() { - - } - - void IssueTest::afterTest() { - - } - + void threadTerminateNode(util::ThreadArgs &args) { HazelcastServer *node = (HazelcastServer *) args.arg0; node->shutdown(); @@ -82,9 +57,9 @@ namespace hazelcast { } - void IssueTest::testOperationRedo_smartRoutingDisabled() { - HazelcastServer hz1(serverFactory); - HazelcastServer hz2(serverFactory); + TEST_F(IssueTest, testOperationRedo_smartRoutingDisabled) { + HazelcastServer hz1(*g_srvFactory); + HazelcastServer hz2(*g_srvFactory); std::auto_ptr clientConfig(getConfig()); clientConfig->setRedoOperation(true); @@ -103,11 +78,11 @@ namespace hazelcast { } thread->join(); delete thread; - ASSERT_EQUAL(expected, map.size()); + ASSERT_EQ(expected, map.size()); } - void IssueTest::testListenerSubscriptionOnSingleServerRestart() { - HazelcastServer server(serverFactory); + TEST_F(IssueTest, testListenerSubscriptionOnSingleServerRestart) { + HazelcastServer server(*g_srvFactory); // 2. Start a client std::auto_ptr clientConfig(getConfig()); @@ -122,48 +97,48 @@ namespace hazelcast { map.addEntryListener(listener, true); // Put a key, value to the map - ASSERT_EQUAL((int *)NULL, map.put(1, 10).get()); + ASSERT_EQ((int *)NULL, map.put(1, 10).get()); - ASSERT_EQUAL(true, latch.await(20, 1)); // timeout of 20 seconds + ASSERT_EQ(true, latch.await(20, 1)); // timeout of 20 seconds // 5. Verify that the listener got the entry added event - ASSERT_EQUAL(1, latch.get()); + ASSERT_EQ(1, latch.get()); // 6. Restart the server - ASSERT_EQUAL(true, server.shutdown()); - ASSERT_EQUAL(true, server.start()); + ASSERT_EQ(true, server.shutdown()); + ASSERT_EQ(true, server.start()); std::string putThreadName("Map Put Thread"); util::Thread t(putThreadName, putMapMessage, &map, &latch); // 8. Verify that the 2nd entry is received by the listener - ASSERT_EQUAL(true, latch.await(20, 0)); // timeout of 20 seconds + ASSERT_EQ(true, latch.await(20, 0)); // timeout of 20 seconds t.interrupt(); t.join(); // 9. Shut down the server - ASSERT_EQUAL(true, server.shutdown()); + ASSERT_EQ(true, server.shutdown()); } void IssueTest::Issue864MapListener::entryAdded(const EntryEvent &event) { int count = latch.get(); if (2 == count) { // The received event should be the addition of key value: 1, 10 - ASSERT_EQUAL(1, event.getKey()); - ASSERT_EQUAL(10, event.getValue()); + ASSERT_EQ(1, event.getKey()); + ASSERT_EQ(10, event.getValue()); } else if (1 == count) { // The received event should be the addition of key value: 2, 20 - ASSERT_EQUAL(2, event.getKey()); - ASSERT_EQUAL(20, event.getValue()); + ASSERT_EQ(2, event.getKey()); + ASSERT_EQ(20, event.getValue()); } latch.countDown(); } void IssueTest::Issue864MapListener::entryUpdated(const EntryEvent &event) { - ASSERT_EQUAL(2, event.getKey()); - ASSERT_EQUAL(20, event.getValue()); + ASSERT_EQ(2, event.getKey()); + ASSERT_EQ(20, event.getValue()); latch.countDown(); } diff --git a/hazelcast/test/issues/IssueTest.h b/hazelcast/test/src/issues/IssueTest.h similarity index 69% rename from hazelcast/test/issues/IssueTest.h rename to hazelcast/test/src/issues/IssueTest.h index e12b0eabb0..f179333469 100644 --- a/hazelcast/test/issues/IssueTest.h +++ b/hazelcast/test/src/issues/IssueTest.h @@ -26,42 +26,18 @@ namespace hazelcast { namespace client { - class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class IssueTest : public ClientTestSupport { + class IssueTest : public ClientTestSupport { public: - IssueTest(HazelcastServerFactory &); + IssueTest(); ~IssueTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testOperationRedo_smartRoutingDisabled(); - - /** - * This test tests the changes for customer reported zendesk issue 864. - */ - void testListenerSubscriptionOnSingleServerRestart(); - - private: + protected: class Issue864MapListener : public hazelcast::client::EntryAdapter { - public: - Issue864MapListener(util::CountDownLatch &l); virtual void entryAdded(const EntryEvent &event); @@ -72,7 +48,6 @@ namespace hazelcast { util::CountDownLatch &latch; }; - HazelcastServerFactory& serverFactory; util::CountDownLatch latch; Issue864MapListener listener; }; diff --git a/hazelcast/test/src/list/ClientListTest.cpp b/hazelcast/test/src/list/ClientListTest.cpp new file mode 100644 index 0000000000..43d5599492 --- /dev/null +++ b/hazelcast/test/src/list/ClientListTest.cpp @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Created by sancar koyunlu on 9/13/13. + +#include "list/ClientListTest.h" +#include "hazelcast/client/HazelcastClient.h" +#include "HazelcastServerFactory.h" + +namespace hazelcast { + namespace client { + namespace test { + ClientListTest::ClientListTest() + : instance(*g_srvFactory) + , client(getNewClient()) + , list(new IList(client->getList("ClientListTest"))) { + } + + ClientListTest::~ClientListTest() { + } + + TEST_F(ClientListTest, testAddAll) { + + std::vector l; + l.push_back("item1"); + l.push_back("item2"); + ASSERT_TRUE(list->addAll(l)); + + ASSERT_TRUE(list->addAll(1, l)); + ASSERT_EQ(4, list->size()); + + ASSERT_EQ("item1", *(list->get(0))); + ASSERT_EQ("item1", *(list->get(1))); + ASSERT_EQ("item2", *(list->get(2))); + ASSERT_EQ("item2", *(list->get(3))); + } + + TEST_F(ClientListTest, testAddSetRemove) { + ASSERT_TRUE(list->add("item1")); + ASSERT_TRUE(list->add("item2")); + list->add(0, "item3"); + ASSERT_EQ(3, list->size()); + boost::shared_ptr temp = list->set(2, "item4"); + ASSERT_EQ("item2", *temp); + + ASSERT_EQ(3, list->size()); + ASSERT_EQ("item3", *(list->get(0))); + ASSERT_EQ("item1", *(list->get(1))); + ASSERT_EQ("item4", *(list->get(2))); + + ASSERT_FALSE(list->remove("item2")); + ASSERT_TRUE(list->remove("item3")); + + temp = list->remove(1); + ASSERT_EQ("item4", *temp); + + ASSERT_EQ(1, list->size()); + ASSERT_EQ("item1", *(list->get(0))); + } + + TEST_F(ClientListTest, testIndexOf) { + ASSERT_TRUE(list->add("item1")); + ASSERT_TRUE(list->add("item2")); + ASSERT_TRUE(list->add("item1")); + ASSERT_TRUE(list->add("item4")); + + ASSERT_EQ(-1, list->indexOf("item5")); + ASSERT_EQ(0, list->indexOf("item1")); + + ASSERT_EQ(-1, list->lastIndexOf("item6")); + ASSERT_EQ(2, list->lastIndexOf("item1")); + } + + TEST_F(ClientListTest, testToArray) { + ASSERT_TRUE(list->add("item1")); + ASSERT_TRUE(list->add("item2")); + ASSERT_TRUE(list->add("item1")); + ASSERT_TRUE(list->add("item4")); + + std::vector ar = list->toArray(); + + ASSERT_EQ("item1", ar[0]); + ASSERT_EQ("item2", ar[1]); + ASSERT_EQ("item1", ar[2]); + ASSERT_EQ("item4", ar[3]); + + std::vector arr2 = list->subList(1, 3); + + ASSERT_EQ(2, (int)arr2.size()); + ASSERT_EQ("item2", arr2[0]); + ASSERT_EQ("item1", arr2[1]); + } + + TEST_F(ClientListTest, testContains) { + ASSERT_TRUE(list->add("item1")); + ASSERT_TRUE(list->add("item2")); + ASSERT_TRUE(list->add("item1")); + ASSERT_TRUE(list->add("item4")); + + ASSERT_FALSE(list->contains("item3")); + ASSERT_TRUE(list->contains("item2")); + + std::vector l; + l.push_back("item4"); + l.push_back("item3"); + + ASSERT_FALSE(list->containsAll(l)); + ASSERT_TRUE(list->add("item3")); + ASSERT_TRUE(list->containsAll(l)); + } + + TEST_F(ClientListTest, testRemoveRetainAll) { + ASSERT_TRUE(list->add("item1")); + ASSERT_TRUE(list->add("item2")); + ASSERT_TRUE(list->add("item1")); + ASSERT_TRUE(list->add("item4")); + + std::vector l; + l.push_back("item4"); + l.push_back("item3"); + + ASSERT_TRUE(list->removeAll(l)); + ASSERT_EQ(3, (int)list->size()); + ASSERT_FALSE(list->removeAll(l)); + ASSERT_EQ(3, (int)list->size()); + + l.clear(); + l.push_back("item1"); + l.push_back("item2"); + ASSERT_FALSE(list->retainAll(l)); + ASSERT_EQ(3, (int)list->size()); + + l.clear(); + ASSERT_TRUE(list->retainAll(l)); + ASSERT_EQ(0, (int)list->size()); + + } + + class MyListItemListener : public ItemListener { + public: + MyListItemListener(util::CountDownLatch& latch) + : latch(latch) { + + } + + void itemAdded(const ItemEvent& itemEvent) { + latch.countDown(); + } + + void itemRemoved(const ItemEvent& item) { + } + + private: + util::CountDownLatch& latch; + }; + + TEST_F(ClientListTest, testListener) { + util::CountDownLatch latch(5); + + MyListItemListener listener(latch); + std::string registrationId = list->addItemListener(listener, true); + + for (int i = 0; i < 5; i++) { + list->add(std::string("item") + util::IOUtil::to_string(i)); + } + + ASSERT_TRUE(latch.await(20)); + + ASSERT_TRUE(list->removeItemListener(registrationId)); + } + } + } +} + diff --git a/hazelcast/test/list/ClientListTest.h b/hazelcast/test/src/list/ClientListTest.h similarity index 66% rename from hazelcast/test/list/ClientListTest.h rename to hazelcast/test/src/list/ClientListTest.h index bbcba0d222..885e5cdb2f 100644 --- a/hazelcast/test/list/ClientListTest.h +++ b/hazelcast/test/src/list/ClientListTest.h @@ -16,9 +16,6 @@ // // Created by sancar koyunlu on 9/13/13. - - - #ifndef HAZELCAST_ClientListTest #define HAZELCAST_ClientListTest @@ -29,44 +26,15 @@ namespace hazelcast { namespace client { - class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class ClientListTest : public ClientTestSupport { + class ClientListTest : public ClientTestSupport { public: - ClientListTest(HazelcastServerFactory &); + ClientListTest(); ~ClientListTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testAddAll(); - - void testAddSetRemove(); - - void testIndexOf(); - - void testToArray(); - - void testContains(); - - void testRemoveRetainAll(); - - void testListener(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; diff --git a/hazelcast/test/lock/ClientLockTest.cpp b/hazelcast/test/src/lock/ClientLockTest.cpp similarity index 59% rename from hazelcast/test/lock/ClientLockTest.cpp rename to hazelcast/test/src/lock/ClientLockTest.cpp index b38375497b..7d7d26ed7f 100644 --- a/hazelcast/test/lock/ClientLockTest.cpp +++ b/hazelcast/test/src/lock/ClientLockTest.cpp @@ -24,42 +24,15 @@ namespace hazelcast { class HazelcastClient; namespace test { - using namespace iTest; - - ClientLockTest::ClientLockTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("ClientLockTest", &serverFactory) - , instance(serverFactory) + ClientLockTest::ClientLockTest() + : instance(*g_srvFactory) , client(getNewClient()) , l(new ILock(client->getILock("ClientLockTest"))) { } - ClientLockTest::~ClientLockTest() { } - void ClientLockTest::addTests() { - addTest(&ClientLockTest::testLock, "testLock"); - addTest(&ClientLockTest::testLockTtl, "testLockTtl"); - addTest(&ClientLockTest::testTryLock, "testTryLock"); - addTest(&ClientLockTest::testForceUnlock, "testForceUnlock"); - addTest(&ClientLockTest::testStats, "testStats"); - } - - void ClientLockTest::beforeClass() { - } - - void ClientLockTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ClientLockTest::beforeTest() { - } - - void ClientLockTest::afterTest() { - l->forceUnlock(); - } - void testLockLockThread(util::ThreadArgs &args) { ILock *l = (ILock *) args.arg0; util::CountDownLatch *latch = (util::CountDownLatch *) args.arg1; @@ -67,12 +40,12 @@ namespace hazelcast { latch->countDown(); } - void ClientLockTest::testLock() { + TEST_F(ClientLockTest, testLock) { l->lock(); util::CountDownLatch latch(1); util::Thread t(testLockLockThread, l.get(), &latch); - assertTrue(latch.await(5)); + ASSERT_TRUE(latch.await(5)); l->forceUnlock(); } @@ -87,11 +60,11 @@ namespace hazelcast { } } - void ClientLockTest::testLockTtl() { + TEST_F(ClientLockTest, testLockTtl) { l->lock(3 * 1000); util::CountDownLatch latch(2); util::Thread t(testLockTtlThread, l.get(), &latch); - assertTrue(latch.await(10)); + ASSERT_TRUE(latch.await(10)); l->forceUnlock(); } @@ -111,21 +84,21 @@ namespace hazelcast { } } - void ClientLockTest::testTryLock() { + TEST_F(ClientLockTest, testTryLock) { - assertTrue(l->tryLock(2 * 1000)); + ASSERT_TRUE(l->tryLock(2 * 1000)); util::CountDownLatch latch(1); util::Thread t1(testLockTryLockThread1, l.get(), &latch); - assertTrue(latch.await(100)); + ASSERT_TRUE(latch.await(100)); - assertTrue(l->isLocked()); + ASSERT_TRUE(l->isLocked()); util::CountDownLatch latch2(1); util::Thread t2(testLockTryLockThread2, l.get(), &latch2); util::sleep(1); l->unlock(); - assertTrue(latch2.await(100)); - assertTrue(l->isLocked()); + ASSERT_TRUE(latch2.await(100)); + ASSERT_TRUE(l->isLocked()); l->forceUnlock(); } @@ -136,49 +109,44 @@ namespace hazelcast { latch->countDown(); } - void ClientLockTest::testForceUnlock() { + TEST_F(ClientLockTest, testForceUnlock) { l->lock(); util::CountDownLatch latch(1); util::Thread t(testLockForceUnlockThread, l.get(), &latch); - assertTrue(latch.await(100)); - assertFalse(l->isLocked()); + ASSERT_TRUE(latch.await(100)); + ASSERT_FALSE(l->isLocked()); } - void testStatsThread(util::ThreadArgs &args) { ILock *l = (ILock *) args.arg0; util::CountDownLatch *latch = (util::CountDownLatch *) args.arg1; - try { - assertTrue(l->isLocked(), "l->isLocked()"); - assertFalse(l->isLockedByCurrentThread(), "isLockedByCurrentThread"); - assertEqual(1, l->getLockCount(), "getLockCount"); - assertTrue(l->getRemainingLeaseTime() > 1000 * 30, "getRemainingLeaseTime"); - latch->countDown(); - } catch(iTest::iTestException &e) { - (std::cout << e.message << std::endl); - } + ASSERT_TRUE(l->isLocked()); + ASSERT_FALSE(l->isLockedByCurrentThread()); + ASSERT_EQ(1, l->getLockCount()); + ASSERT_TRUE(l->getRemainingLeaseTime() > 1000 * 30); + latch->countDown(); } - void ClientLockTest::testStats() { + TEST_F(ClientLockTest, testStats) { l->lock(); - assertTrue(l->isLocked()); - assertTrue(l->isLockedByCurrentThread()); - assertEqual(1, l->getLockCount()); + ASSERT_TRUE(l->isLocked()); + ASSERT_TRUE(l->isLockedByCurrentThread()); + ASSERT_EQ(1, l->getLockCount()); l->unlock(); - assertFalse(l->isLocked()); - assertEqual(0, l->getLockCount()); - assertEqual(-1L, l->getRemainingLeaseTime()); + ASSERT_FALSE(l->isLocked()); + ASSERT_EQ(0, l->getLockCount()); + ASSERT_EQ(-1L, l->getRemainingLeaseTime()); l->lock(1 * 1000 * 60); - assertTrue(l->isLocked()); - assertTrue(l->isLockedByCurrentThread()); - assertEqual(1, l->getLockCount()); - assertTrue(l->getRemainingLeaseTime() > 1000 * 30); + ASSERT_TRUE(l->isLocked()); + ASSERT_TRUE(l->isLockedByCurrentThread()); + ASSERT_EQ(1, l->getLockCount()); + ASSERT_TRUE(l->getRemainingLeaseTime() > 1000 * 30); util::CountDownLatch latch(1); util::Thread t(testStatsThread, l.get(), &latch); - assertTrue(latch.await(60)); + ASSERT_TRUE(latch.await(60)); } } } diff --git a/hazelcast/test/lock/ClientLockTest.h b/hazelcast/test/src/lock/ClientLockTest.h similarity index 70% rename from hazelcast/test/lock/ClientLockTest.h rename to hazelcast/test/src/lock/ClientLockTest.h index 9e250d780b..0652d0fd71 100644 --- a/hazelcast/test/lock/ClientLockTest.h +++ b/hazelcast/test/src/lock/ClientLockTest.h @@ -31,48 +31,20 @@ namespace hazelcast { namespace client { - class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class ClientLockTest : public ClientTestSupport { - + class ClientLockTest : public ClientTestSupport { public: - - ClientLockTest(HazelcastServerFactory &); + ClientLockTest(); ~ClientLockTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testLock(); - - void testLockTtl(); - - void testTryLock(); - - void testForceUnlock(); - - void testStats(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; std::auto_ptr l; }; - } } } diff --git a/hazelcast/test/src/main.cpp b/hazelcast/test/src/main.cpp new file mode 100644 index 0000000000..e31d2c7a28 --- /dev/null +++ b/hazelcast/test/src/main.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "HazelcastServerFactory.h" +#include "SimpleMapTest.h" +#include +#include +#include +#include + +using namespace hazelcast::client::test; + +void testSpeed(const char* address) { + SimpleMapTest s(address, 5701); + s.run(); +} + +namespace hazelcast { + namespace client { + namespace test { + HazelcastServerFactory *g_srvFactory = NULL; + } + } +} + +class ServerFactoryEnvironment : public ::testing::Environment { +public: + ServerFactoryEnvironment(const char *srvAddress) : serverAddress(srvAddress) { + } + + void SetUp() { + hazelcast::client::test::g_srvFactory = new HazelcastServerFactory(serverAddress); + } + + void TearDown() { + delete hazelcast::client::test::g_srvFactory; + } + +private : + const char *serverAddress; +}; + +int main(int argc, char** argv) { + const char* address; + + testing::InitGoogleTest(&argc, argv); + + if(argc == 2){ + address = argv[1]; + } else { + address = "127.0.0.1"; + } + std::cout << "Server address : " << address << std::endl; + + ::testing::AddGlobalTestEnvironment(new ServerFactoryEnvironment(address)); + + return RUN_ALL_TESTS(); + + //SimpleMapTest(address, 5701).run(); +} + diff --git a/hazelcast/test/map/ClientExpirationListenerTest.cpp b/hazelcast/test/src/map/ClientExpirationListenerTest.cpp similarity index 73% rename from hazelcast/test/map/ClientExpirationListenerTest.cpp rename to hazelcast/test/src/map/ClientExpirationListenerTest.cpp index 87c515d9a3..6732eeb11a 100644 --- a/hazelcast/test/map/ClientExpirationListenerTest.cpp +++ b/hazelcast/test/src/map/ClientExpirationListenerTest.cpp @@ -20,45 +20,19 @@ #include "hazelcast/util/Util.h" #include "map/ClientExpirationListenerTest.h" #include "hazelcast/client/EntryAdapter.h" +#include "hazelcast/client/HazelcastClient.h" namespace hazelcast { namespace client { namespace test { - using namespace iTest; - - - ClientExpirationListenerTest::ClientExpirationListenerTest(HazelcastServerFactory& serverFactory) - : ClientTestSupport("ClientExpirationListenerTest", &serverFactory) - , instance(serverFactory) - , instance2(serverFactory) + ClientExpirationListenerTest::ClientExpirationListenerTest() + : instance(*g_srvFactory) + , instance2(*g_srvFactory) , client(getNewClient()) , imap(new IMap(client->getMap("clientExpirationListenerTest"))) { - } ClientExpirationListenerTest::~ClientExpirationListenerTest() { - - } - - void ClientExpirationListenerTest::addTests() { - addTest(&ClientExpirationListenerTest::notified_afterExpirationOfEntries, "notified_afterExpirationOfEntries"); - addTest(&ClientExpirationListenerTest::bothNotified_afterExpirationOfEntries, "bothNotified_afterExpirationOfEntries"); - } - - void ClientExpirationListenerTest::beforeClass() { - - } - - void ClientExpirationListenerTest::afterClass() { - - } - - void ClientExpirationListenerTest::beforeTest() { - - } - - void ClientExpirationListenerTest::afterTest() { - } class ExpirationListener : public EntryAdapter { @@ -76,7 +50,7 @@ namespace hazelcast { util::CountDownLatch& latch; }; - void ClientExpirationListenerTest::notified_afterExpirationOfEntries() { + TEST_F(ClientExpirationListenerTest, notified_afterExpirationOfEntries) { int numberOfPutOperations = 1000; util::CountDownLatch expirationEventArrivalCount(numberOfPutOperations); @@ -95,8 +69,8 @@ namespace hazelcast { imap->get(i); } - assertTrue(expirationEventArrivalCount.await(120)); - assertTrue(imap->removeEntryListener(registrationId)); + ASSERT_TRUE(expirationEventArrivalCount.await(120)); + ASSERT_TRUE(imap->removeEntryListener(registrationId)); } @@ -121,7 +95,7 @@ namespace hazelcast { util::CountDownLatch& expiredLatch; }; - void ClientExpirationListenerTest::bothNotified_afterExpirationOfEntries() { + TEST_F(ClientExpirationListenerTest, bothNotified_afterExpirationOfEntries) { int numberOfPutOperations = 1000; util::CountDownLatch expirationEventArrivalCount(numberOfPutOperations); util::CountDownLatch evictedEventArrivalCount(numberOfPutOperations); @@ -141,12 +115,10 @@ namespace hazelcast { imap->get(i); } - assertTrue(expirationEventArrivalCount.await(120)); - assertTrue(evictedEventArrivalCount.await(120)); - assertTrue(imap->removeEntryListener(registrationId)); + ASSERT_TRUE(expirationEventArrivalCount.await(120)); + ASSERT_TRUE(evictedEventArrivalCount.await(120)); + ASSERT_TRUE(imap->removeEntryListener(registrationId)); } - - } } } diff --git a/hazelcast/test/map/ClientExpirationListenerTest.h b/hazelcast/test/src/map/ClientExpirationListenerTest.h similarity index 74% rename from hazelcast/test/map/ClientExpirationListenerTest.h rename to hazelcast/test/src/map/ClientExpirationListenerTest.h index 0491bfc410..f2822277af 100644 --- a/hazelcast/test/map/ClientExpirationListenerTest.h +++ b/hazelcast/test/src/map/ClientExpirationListenerTest.h @@ -28,39 +28,23 @@ namespace hazelcast { namespace client { - class HazelcastClient; namespace test { class HazelcastServerFactory; - class ClientExpirationListenerTest : public ClientTestSupport { + class ClientExpirationListenerTest : public ClientTestSupport { public: - ClientExpirationListenerTest(HazelcastServerFactory &); + ClientExpirationListenerTest(); ~ClientExpirationListenerTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void notified_afterExpirationOfEntries(); - - void bothNotified_afterExpirationOfEntries(); - - private: + protected: HazelcastServer instance; HazelcastServer instance2; ClientConfig clientConfig; std::auto_ptr client; - std::auto_ptr > imap; + std::auto_ptr > imap; }; } } diff --git a/hazelcast/test/map/ClientMapTest.cpp b/hazelcast/test/src/map/ClientMapTest.cpp similarity index 65% rename from hazelcast/test/map/ClientMapTest.cpp rename to hazelcast/test/src/map/ClientMapTest.cpp index c7071da199..a43175e477 100644 --- a/hazelcast/test/map/ClientMapTest.cpp +++ b/hazelcast/test/src/map/ClientMapTest.cpp @@ -16,10 +16,9 @@ // // Created by sancar koyunlu on 8/27/13. - - #include "hazelcast/client/query/SqlPredicate.h" #include "hazelcast/util/Util.h" +#include "hazelcast/client/HazelcastClient.h" #include "map/ClientMapTest.h" #include "hazelcast/client/EntryAdapter.h" #include "hazelcast/client/serialization/IdentifiedDataSerializable.h" @@ -30,12 +29,9 @@ namespace hazelcast { namespace client { namespace test { - using namespace iTest; - - ClientMapTest::ClientMapTest(HazelcastServerFactory& serverFactory) - : ClientTestSupport("ClientMapTest", &serverFactory) - , instance(serverFactory) - , instance2(serverFactory) + ClientMapTest::ClientMapTest() + : instance(*g_srvFactory) + , instance2(*g_srvFactory) , client(getNewClient()) , imap(new IMap(client->getMap("clientMapTest"))) { } @@ -44,54 +40,6 @@ namespace hazelcast { ClientMapTest::~ClientMapTest() { } - void ClientMapTest::addTests() { - addTest(&ClientMapTest::testContains, "testContains"); - addTest(&ClientMapTest::testGet, "testGet"); - addTest(&ClientMapTest::testRemoveAndDelete, "testRemoveAndDelete"); - addTest(&ClientMapTest::testRemoveIfSame, "testRemoveIfSame"); - addTest(&ClientMapTest::testGetAllPutAll, "testGetAllPutAll"); - addTest(&ClientMapTest::testTryPutRemove, "testTryPutRemove"); - addTest(&ClientMapTest::testPutTtl, "testPutTtl"); - addTest(&ClientMapTest::testPutIfAbsent, "testPutIfAbsent"); - addTest(&ClientMapTest::testPutIfAbsentTtl, "testPutIfAbsentTtl"); - addTest(&ClientMapTest::testSet, "testSet"); - addTest(&ClientMapTest::testLock, "testLock"); - addTest(&ClientMapTest::testLockTtl, "testLockTtl"); - addTest(&ClientMapTest::testLockTtl2, "testLockTtl2"); - addTest(&ClientMapTest::testTryLock, "testTryLock"); - addTest(&ClientMapTest::testForceUnlock, "testForceUnlock"); - addTest(&ClientMapTest::testValues, "testValues"); - addTest(&ClientMapTest::testReplace, "testReplace"); - addTest(&ClientMapTest::testPredicateListenerWithPortableKey, "testPredicateListenerWithPortableKey"); - addTest(&ClientMapTest::testListener, "testListener"); - addTest(&ClientMapTest::testBasicPredicate, "testBasicPredicate"); - addTest(&ClientMapTest::testIssue537, "testIssue537"); - addTest(&ClientMapTest::testEvictAllEvent, "testEvictAllEvent"); - addTest(&ClientMapTest::testClearEvent, "testClearEvent"); - addTest(&ClientMapTest::testMapWithPortable, "testMapWithPortable"); - addTest(&ClientMapTest::testMapStoreRelatedRequests, "testMapStoreRelatedRequests"); - addTest(&ClientMapTest::testKeySetAndValuesWithPredicates, "testKeySetAndValuesWithPredicates"); - addTest(&ClientMapTest::testExecuteOnKey, "testExecuteOnKey"); - addTest(&ClientMapTest::testExecuteOnEntries, "testExecuteOnEntries"); - } - - void ClientMapTest::beforeClass() { - } - - void ClientMapTest::afterClass() { - client.reset(); - instance.shutdown(); - instance2.shutdown(); - } - - void ClientMapTest::beforeTest() { - imap->clear(); - } - - void ClientMapTest::afterTest() { - imap->clear(); - } - void ClientMapTest::fillMap() { for (int i = 0; i < 10; i++) { std::string key = "key"; @@ -168,7 +116,7 @@ namespace hazelcast { util::CountDownLatch& latch; }; - void ClientMapTest::testIssue537() { + TEST_F(ClientMapTest, testIssue537) { util::CountDownLatch latch(2); util::CountDownLatch nullLatch(1); MyListener myListener(latch, nullLatch); @@ -176,27 +124,27 @@ namespace hazelcast { imap->put("key1", "value1", 2 * 1000); - assertTrue(latch.await(10)); - assertTrue(nullLatch.await(1)); + ASSERT_TRUE(latch.await(10)); + ASSERT_TRUE(nullLatch.await(1)); - assertTrue(imap->removeEntryListener(id)); + ASSERT_TRUE(imap->removeEntryListener(id)); imap->put("key2", "value2"); - assertEqual(1, imap->size()); + ASSERT_EQ(1, imap->size()); } - void ClientMapTest::testContains() { + TEST_F(ClientMapTest, testContains) { fillMap(); - assertFalse(imap->containsKey("key10")); - assertTrue(imap->containsKey("key1")); + ASSERT_FALSE(imap->containsKey("key10")); + ASSERT_TRUE(imap->containsKey("key1")); - assertFalse(imap->containsValue("value10")); - assertTrue(imap->containsValue("value1")); + ASSERT_FALSE(imap->containsValue("value10")); + ASSERT_TRUE(imap->containsValue("value1")); } - void ClientMapTest::testGet() { + TEST_F(ClientMapTest, testGet) { fillMap(); for (int i = 0; i < 10; i++) { std::string key = "key"; @@ -205,39 +153,39 @@ namespace hazelcast { std::string value = "value"; value += util::IOUtil::to_string(i); - assertEqual(*temp, value); + ASSERT_EQ(*temp, value); } } - void ClientMapTest::testRemoveAndDelete() { + TEST_F(ClientMapTest, testRemoveAndDelete) { fillMap(); boost::shared_ptr temp = imap->remove("key10"); - assertNull(temp.get()); + ASSERT_EQ(temp.get(), (std::string *)NULL); imap->deleteEntry("key9"); - assertEqual(imap->size(), 9); + ASSERT_EQ(imap->size(), 9); for (int i = 0; i < 9; i++) { std::string key = "key"; key += util::IOUtil::to_string(i); boost::shared_ptr temp2 = imap->remove(key); std::string value = "value"; value += util::IOUtil::to_string(i); - assertEqual(*temp2, value); + ASSERT_EQ(*temp2, value); } - assertEqual(imap->size(), 0); + ASSERT_EQ(imap->size(), 0); } - void ClientMapTest::testRemoveIfSame() { + TEST_F(ClientMapTest, testRemoveIfSame) { fillMap(); - assertFalse(imap->remove("key2", "value")); - assertEqual(10, imap->size()); + ASSERT_FALSE(imap->remove("key2", "value")); + ASSERT_EQ(10, imap->size()); - assertTrue((imap->remove("key2", "value2"))); - assertEqual(9, imap->size()); + ASSERT_TRUE((imap->remove("key2", "value2"))); + ASSERT_EQ(9, imap->size()); } - void ClientMapTest::testGetAllPutAll() { + TEST_F(ClientMapTest, testGetAllPutAll) { std::map mapTemp; @@ -245,12 +193,12 @@ namespace hazelcast { mapTemp[util::IOUtil::to_string(i)] = util::IOUtil::to_string(i); } imap->putAll(mapTemp); - assertEqual(imap->size(), 100); + ASSERT_EQ(imap->size(), 100); for (int i = 0; i < 100; i++) { std::string expected = util::IOUtil::to_string(i); boost::shared_ptr actual = imap->get(util::IOUtil::to_string(i)); - assertEqual(expected, *actual); + ASSERT_EQ(expected, *actual); } std::set tempSet; @@ -259,9 +207,9 @@ namespace hazelcast { std::map m2 = imap->getAll(tempSet); - assertEqual(2U, m2.size()); - assertEqual(m2[util::IOUtil::to_string(1)], "1"); - assertEqual(m2[util::IOUtil::to_string(3)], "3"); + ASSERT_EQ(2U, m2.size()); + ASSERT_EQ(m2[util::IOUtil::to_string(1)], "1"); + ASSERT_EQ(m2[util::IOUtil::to_string(3)], "3"); } @@ -283,10 +231,10 @@ namespace hazelcast { } } - void ClientMapTest::testTryPutRemove() { + TEST_F(ClientMapTest, testTryPutRemove) { - assertTrue(imap->tryPut("key1", "value1", 1 * 1000)); - assertTrue(imap->tryPut("key2", "value2", 1 * 1000)); + ASSERT_TRUE(imap->tryPut("key1", "value1", 1 * 1000)); + ASSERT_TRUE(imap->tryPut("key2", "value2", 1 * 1000)); imap->lock("key1"); imap->lock("key2"); @@ -295,14 +243,14 @@ namespace hazelcast { util::Thread t1(tryPutThread, &latch, imap.get()); util::Thread t2(tryRemoveThread, &latch, imap.get()); - assertTrue(latch.await(20)); - assertEqual("value1", *(imap->get("key1"))); - assertEqual("value2", *(imap->get("key2"))); + ASSERT_TRUE(latch.await(20)); + ASSERT_EQ("value1", *(imap->get("key1"))); + ASSERT_EQ("value2", *(imap->get("key2"))); imap->forceUnlock("key1"); imap->forceUnlock("key2"); } - void ClientMapTest::testPutTtl() { + TEST_F(ClientMapTest, testPutTtl) { util::CountDownLatch dummy(10); util::CountDownLatch evict(1); SampleEntryListener sampleEntryListener(dummy, dummy, dummy, evict); @@ -310,38 +258,39 @@ namespace hazelcast { imap->put("key1", "value1", 2000); boost::shared_ptr temp = imap->get("key1"); - assertEqual(*temp, "value1"); - assertTrue(evict.await(20 * 1000)); + ASSERT_EQ(*temp, "value1"); + ASSERT_TRUE(evict.await(20 * 1000)); boost::shared_ptr temp2 = imap->get("key1"); - assertNull(temp2.get()); + ASSERT_EQ(temp2.get(), (std::string *)NULL); - assertTrue(imap->removeEntryListener(id)); + ASSERT_TRUE(imap->removeEntryListener(id)); } - void ClientMapTest::testPutIfAbsent() { + TEST_F(ClientMapTest, testPutIfAbsent) { boost::shared_ptr o = imap->putIfAbsent("key1", "value1"); - assertNull(o.get()); - assertEqual("value1", *(imap->putIfAbsent("key1", "value3"))); + ASSERT_EQ(o.get(), (std::string *)NULL); + ASSERT_EQ("value1", *(imap->putIfAbsent("key1", "value3"))); } - void ClientMapTest::testPutIfAbsentTtl() { - assertNull(imap->putIfAbsent("key1", "value1", 1000).get()); - assertEqual("value1", *(imap->putIfAbsent("key1", "value3", 1000))); - ASSERT_EVENTUALLY(assertNull, imap->putIfAbsent("key1", "value3", 1000).get()); - assertEqual("value3", *(imap->putIfAbsent("key1", "value4", 1000))); + TEST_F(ClientMapTest, testPutIfAbsentTtl) { + ASSERT_EQ(imap->putIfAbsent("key1", "value1", 1000).get(), (std::string *)NULL); + ASSERT_EQ("value1", *(imap->putIfAbsent("key1", "value3", 1000))); + + ASSERT_NULL_EVENTUALLY(imap->putIfAbsent("key1", "value3", 1000).get()); + ASSERT_EQ("value3", *(imap->putIfAbsent("key1", "value4", 1000))); } - void ClientMapTest::testSet() { + TEST_F(ClientMapTest, testSet) { imap->set("key1", "value1"); - assertEqual("value1", *(imap->get("key1"))); + ASSERT_EQ("value1", *(imap->get("key1"))); imap->set("key1", "value2"); - assertEqual("value2", *(imap->get("key1"))); + ASSERT_EQ("value2", *(imap->get("key1"))); imap->set("key1", "value3", 1000); - assertEqual("value3", *(imap->get("key1"))); + ASSERT_EQ("value3", *(imap->get("key1"))); - ASSERT_EVENTUALLY(assertNull, imap->get("key1").get()); + ASSERT_NULL_EVENTUALLY(imap->get("key1").get()); } void testLockThread(util::ThreadArgs& args) { @@ -351,14 +300,14 @@ namespace hazelcast { latch->countDown(); } - void ClientMapTest::testLock() { + TEST_F(ClientMapTest, testLock) { imap->put("key1", "value1"); - assertEqual("value1", *(imap->get("key1"))); + ASSERT_EQ("value1", *(imap->get("key1"))); imap->lock("key1"); util::CountDownLatch latch(1); util::Thread t1(testLockThread, &latch, imap.get()); - assertTrue(latch.await(5)); - assertEqual("value1", *(imap->get("key1"))); + ASSERT_TRUE(latch.await(5)); + ASSERT_EQ("value1", *(imap->get("key1"))); imap->forceUnlock("key1"); } @@ -370,15 +319,15 @@ namespace hazelcast { latch->countDown(); } - void ClientMapTest::testLockTtl() { + TEST_F(ClientMapTest, testLockTtl) { imap->put("key1", "value1"); - assertEqual("value1", *(imap->get("key1"))); + ASSERT_EQ("value1", *(imap->get("key1"))); imap->lock("key1", 2 * 1000); util::CountDownLatch latch(1); util::Thread t1(testLockTTLThread, &latch, imap.get()); - assertTrue(latch.await(10)); - assertFalse(imap->isLocked("key1")); - assertEqual("value2", *(imap->get("key1"))); + ASSERT_TRUE(latch.await(10)); + ASSERT_FALSE(imap->isLocked("key1")); + ASSERT_EQ("value2", *(imap->get("key1"))); imap->forceUnlock("key1"); } @@ -394,11 +343,11 @@ namespace hazelcast { } } - void ClientMapTest::testLockTtl2() { + TEST_F(ClientMapTest, testLockTtl2) { imap->lock("key1", 3 * 1000); util::CountDownLatch latch(2); util::Thread t1(testLockTTL2Thread, &latch, imap.get()); - assertTrue(latch.await(10)); + ASSERT_TRUE(latch.await(10)); imap->forceUnlock("key1"); } @@ -419,23 +368,23 @@ namespace hazelcast { } } - void ClientMapTest::testTryLock() { + TEST_F(ClientMapTest, testTryLock) { - assertTrue(imap->tryLock("key1", 2 * 1000), "1"); + ASSERT_TRUE(imap->tryLock("key1", 2 * 1000)); util::CountDownLatch latch(1); util::Thread t1(testMapTryLockThread1, &latch, imap.get()); - assertTrue(latch.await(100), "2"); + ASSERT_TRUE(latch.await(100)); - assertTrue(imap->isLocked("key1"), "3"); + ASSERT_TRUE(imap->isLocked("key1")); util::CountDownLatch latch2(1); util::Thread t2(testMapTryLockThread2, &latch2, imap.get()); util::sleep(1); imap->unlock("key1"); - assertTrue(latch2.await(100), "4"); - assertTrue(imap->isLocked("key1"), "5"); + ASSERT_TRUE(latch2.await(100)); + ASSERT_TRUE(imap->isLocked("key1")); imap->forceUnlock("key1"); } @@ -447,44 +396,44 @@ namespace hazelcast { latch->countDown(); } - void ClientMapTest::testForceUnlock() { + TEST_F(ClientMapTest, testForceUnlock) { imap->lock("key1"); util::CountDownLatch latch(1); util::Thread t2(testMapForceUnlockThread, &latch, imap.get()); - assertTrue(latch.await(100)); + ASSERT_TRUE(latch.await(100)); t2.join(); - assertFalse(imap->isLocked("key1")); + ASSERT_FALSE(imap->isLocked("key1")); } - void ClientMapTest::testValues() { + TEST_F(ClientMapTest, testValues) { fillMap(); std::vector tempVector; query::SqlPredicate predicate("this == value1"); tempVector = imap->values(predicate); - assertEqual(1U, tempVector.size()); + ASSERT_EQ(1U, tempVector.size()); std::vector::iterator it = tempVector.begin(); - assertEqual("value1", *it); + ASSERT_EQ("value1", *it); } - void ClientMapTest::testReplace() { + TEST_F(ClientMapTest, testReplace) { boost::shared_ptr temp = imap->replace("key1", "value"); - assertNull(temp.get()); + ASSERT_EQ(temp.get(), (std::string *)NULL); std::string tempKey = "key1"; std::string tempValue = "value1"; imap->put(tempKey, tempValue); - assertEqual("value1", *(imap->replace("key1", "value2"))); - assertEqual("value2", *(imap->get("key1"))); + ASSERT_EQ("value1", *(imap->replace("key1", "value2"))); + ASSERT_EQ("value2", *(imap->get("key1"))); - assertEqual(false, imap->replace("key1", "value1", "value3")); - assertEqual("value2", *(imap->get("key1"))); + ASSERT_EQ(false, imap->replace("key1", "value1", "value3")); + ASSERT_EQ("value2", *(imap->get("key1"))); - assertEqual(true, imap->replace("key1", "value2", "value3")); - assertEqual("value3", *(imap->get("key1"))); + ASSERT_EQ(true, imap->replace("key1", "value2", "value3")); + ASSERT_EQ("value3", *(imap->get("key1"))); } class SampleEntryListenerForPortableKey : public EntryAdapter{ @@ -505,7 +454,7 @@ namespace hazelcast { }; - void ClientMapTest::testPredicateListenerWithPortableKey() { + TEST_F(ClientMapTest, testPredicateListenerWithPortableKey) { IMap tradeMap = client->getMap("tradeMap"); util::CountDownLatch countDownLatch(1); util::AtomicInt atomicInteger(0); @@ -515,13 +464,13 @@ namespace hazelcast { Employee key2("a", 2); tradeMap.put(key2, 1); tradeMap.put(key, 3); - assertTrue(countDownLatch.await(5)); - assertEqual(1, (int)atomicInteger); + ASSERT_TRUE(countDownLatch.await(5)); + ASSERT_EQ(1, (int)atomicInteger); - assertTrue(tradeMap.removeEntryListener(id)); + ASSERT_TRUE(tradeMap.removeEntryListener(id)); } - void ClientMapTest::testListener() { + TEST_F(ClientMapTest, testListener) { util::CountDownLatch latch1Add(5); util::CountDownLatch latch1Remove(2); util::CountDownLatch dummy(10); @@ -545,64 +494,61 @@ namespace hazelcast { imap->remove("key1"); imap->remove("key3"); - assertTrue(latch1Add.await(10)); - assertTrue(latch1Remove.await(10)); - assertTrue(latch2Add.await(5)); - assertTrue(latch2Remove.await(5)); + ASSERT_TRUE(latch1Add.await(10)); + ASSERT_TRUE(latch1Remove.await(10)); + ASSERT_TRUE(latch2Add.await(5)); + ASSERT_TRUE(latch2Remove.await(5)); - assertTrue(imap->removeEntryListener(listener1ID)); - assertTrue(imap->removeEntryListener(listener2ID)); + ASSERT_TRUE(imap->removeEntryListener(listener1ID)); + ASSERT_TRUE(imap->removeEntryListener(listener2ID)); } - void ClientMapTest::testClearEvent() { + TEST_F(ClientMapTest, testClearEvent) { util::CountDownLatch latch(1); ClearListener clearListener(latch); std::string listenerId = imap->addEntryListener(clearListener, false); imap->put("key1", "value1"); imap->clear(); - assertTrue(latch.await(120)); + ASSERT_TRUE(latch.await(120)); imap->removeEntryListener(listenerId); } - void ClientMapTest::testEvictAllEvent() { + TEST_F(ClientMapTest, testEvictAllEvent) { util::CountDownLatch latch(1); EvictListener evictListener(latch); std::string listenerId = imap->addEntryListener(evictListener, false); imap->put("key1", "value1"); imap->evictAll(); - assertTrue(latch.await(120)); + ASSERT_TRUE(latch.await(120)); imap->removeEntryListener(listenerId); } - - void ClientMapTest::testBasicPredicate() { - + TEST_F(ClientMapTest, testBasicPredicate) { fillMap(); query::SqlPredicate predicate("this = 'value1'"); std::vector tempVector; tempVector = imap->values(predicate); - assertEqual("value1", tempVector[0]); + ASSERT_EQ("value1", tempVector[0]); std::vector tempVector2; tempVector2 = imap->keySet(predicate); std::vector::iterator it2 = tempVector2.begin(); - assertEqual("key1", *it2); + ASSERT_EQ("key1", *it2); std::vector > tempVector3; tempVector3 = imap->entrySet(predicate); std::vector >::iterator it3 = tempVector3.begin(); - assertEqual("key1", (*it3).first); - assertEqual("value1", (*it3).second); - + ASSERT_EQ("key1", (*it3).first); + ASSERT_EQ("value1", (*it3).second); } - void ClientMapTest::testKeySetAndValuesWithPredicates() { + TEST_F(ClientMapTest, testKeySetAndValuesWithPredicates) { std::string name = "testKeysetAndValuesWithPredicates"; IMap map = client->getMap(name); @@ -610,44 +556,44 @@ namespace hazelcast { Employee emp2("abc-123-xvz", 20); map.put(emp1, emp1); - assertNull(map.put(emp2, emp2).get()); - assertEqual(2, (int)map.size()); - assertEqual(2, (int)map.keySet().size()); + ASSERT_EQ(map.put(emp2, emp2).get(), (Employee *)NULL); + ASSERT_EQ(2, (int)map.size()); + ASSERT_EQ(2, (int)map.keySet().size()); query::SqlPredicate predicate("a = 10"); - assertEqual(0, (int)map.keySet(predicate).size()); + ASSERT_EQ(0, (int)map.keySet(predicate).size()); predicate.setSql("a = 10"); - assertEqual(0, (int)map.values(predicate).size()); + ASSERT_EQ(0, (int)map.values(predicate).size()); predicate.setSql("a >= 10"); - assertEqual(2, (int)map.keySet(predicate).size()); - assertEqual(2, (int)map.values(predicate).size()); - assertEqual(2, (int)map.size()); - assertEqual(2, (int)map.values().size()); + ASSERT_EQ(2, (int)map.keySet(predicate).size()); + ASSERT_EQ(2, (int)map.values(predicate).size()); + ASSERT_EQ(2, (int)map.size()); + ASSERT_EQ(2, (int)map.values().size()); } - void ClientMapTest::testMapWithPortable() { + TEST_F(ClientMapTest, testMapWithPortable) { IMap employees = client->getMap("employees"); boost::shared_ptr n1 = employees.get(1); - assertNull(n1.get()); + ASSERT_EQ(n1.get(), (Employee *)NULL); Employee employee("sancar", 24); boost::shared_ptr ptr = employees.put(1, employee); - assertNull(ptr.get()); - assertFalse(employees.isEmpty()); + ASSERT_EQ(ptr.get(), (Employee *)NULL); + ASSERT_FALSE(employees.isEmpty()); EntryView view = employees.getEntryView(1); - assertEqual(view.value, employee); - assertEqual(view.key, 1); + ASSERT_EQ(view.value, employee); + ASSERT_EQ(view.key, 1); employees.addIndex("a", true); employees.addIndex("n", false); } - void ClientMapTest::testMapStoreRelatedRequests() { + TEST_F(ClientMapTest, testMapStoreRelatedRequests) { imap->putTransient("ali", "veli", 1100); imap->flush(); - assertEqual(1, imap->size()); - assertFalse(imap->evict("deli")); - assertTrue(imap->evict("ali")); - assertNull(imap->get("ali").get()); + ASSERT_EQ(1, imap->size()); + ASSERT_FALSE(imap->evict("deli")); + ASSERT_TRUE(imap->evict("ali")); + ASSERT_EQ(imap->get("ali").get(), (std::string *)NULL); } class EntryMultiplier : public serialization::IdentifiedDataSerializable { @@ -692,7 +638,7 @@ namespace hazelcast { int multiplier; }; - void ClientMapTest::testExecuteOnKey() { + TEST_F(ClientMapTest, testExecuteOnKey) { IMap employees = client->getMap("executeOnKey"); Employee empl1("ahmet", 35); @@ -705,11 +651,11 @@ namespace hazelcast { boost::shared_ptr result = employees.executeOnKey(4, processor); - ASSERT_NOTEQUAL(NULL, result.get()); - ASSERT_EQUAL(4 * processor.getMultiplier(), *result); + ASSERT_NE((int *)NULL, result.get()); + ASSERT_EQ(4 * processor.getMultiplier(), *result); } - void ClientMapTest::testExecuteOnEntries() { + TEST_F(ClientMapTest, testExecuteOnEntries) { IMap employees = client->getMap("testExecuteOnEntries"); Employee empl1("ahmet", 35); @@ -722,17 +668,15 @@ namespace hazelcast { EntryMultiplier processor(4); - std::map > result = employees.executeOnEntries(processor); - ASSERT_EQUAL(3, result.size()); - ASSERT_EQUAL(true, (result.end() != result.find(3))); - ASSERT_EQUAL(true, (result.end() != result.find(4))); - ASSERT_EQUAL(true, (result.end() != result.find(5))); - ASSERT_EQUAL(3 * processor.getMultiplier(), *result[3]); - ASSERT_EQUAL(4 * processor.getMultiplier(), *result[4]); - ASSERT_EQUAL(5 * processor.getMultiplier(), *result[5]); - + ASSERT_EQ(3, (int)result.size()); + ASSERT_EQ(true, (result.end() != result.find(3))); + ASSERT_EQ(true, (result.end() != result.find(4))); + ASSERT_EQ(true, (result.end() != result.find(5))); + ASSERT_EQ(3 * processor.getMultiplier(), *result[3]); + ASSERT_EQ(4 * processor.getMultiplier(), *result[4]); + ASSERT_EQ(5 * processor.getMultiplier(), *result[5]); } } } diff --git a/hazelcast/test/src/map/ClientMapTest.h b/hazelcast/test/src/map/ClientMapTest.h new file mode 100644 index 0000000000..4c3be147c9 --- /dev/null +++ b/hazelcast/test/src/map/ClientMapTest.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Created by sancar koyunlu on 8/27/13. + +#ifndef HAZELCAST_ClientMapTest +#define HAZELCAST_ClientMapTest + +#include "ClientTestSupport.h" +#include "hazelcast/client/ClientConfig.h" +#include "hazelcast/client/IMap.h" +#include "HazelcastServer.h" + +namespace hazelcast { + namespace client { + class HazelcastClient; + + namespace test { + class ClientMapTest : public ClientTestSupport { + public: + ClientMapTest(); + + ~ClientMapTest(); + + void fillMap(); + protected: + HazelcastServer instance; + HazelcastServer instance2; + ClientConfig clientConfig; + std::auto_ptr client; + std::auto_ptr > imap; + }; + } + } +} + +#endif //HAZELCAST_ClientMapTest + diff --git a/hazelcast/test/multimap/ClientMultiMapTest.cpp b/hazelcast/test/src/multimap/ClientMultiMapTest.cpp similarity index 55% rename from hazelcast/test/multimap/ClientMultiMapTest.cpp rename to hazelcast/test/src/multimap/ClientMultiMapTest.cpp index 856f93892f..c321d27435 100644 --- a/hazelcast/test/multimap/ClientMultiMapTest.cpp +++ b/hazelcast/test/src/multimap/ClientMultiMapTest.cpp @@ -27,118 +27,86 @@ namespace hazelcast { namespace client { namespace test { - using namespace iTest; - - ClientMultiMapTest::ClientMultiMapTest(HazelcastServerFactory& serverFactory) - : ClientTestSupport("ClientMultiMapTest", &serverFactory) - , instance(serverFactory) - , client(getNewClient()) - , mm(new MultiMap(client->getMultiMap("ClientMultiMapTest"))) { + ClientMultiMapTest::ClientMultiMapTest() + : instance(*g_srvFactory) + , client(getNewClient()) + , mm(new MultiMap(client->getMultiMap("ClientMultiMapTest"))) { } - ClientMultiMapTest::~ClientMultiMapTest() { } - void ClientMultiMapTest::addTests() { - addTest(&ClientMultiMapTest::testPutGetRemove, "testPutGetRemove"); - addTest(&ClientMultiMapTest::testKeySetEntrySetAndValues, "testKeySetEntrySetAndValues"); - addTest(&ClientMultiMapTest::testContains, "testContains"); - addTest(&ClientMultiMapTest::testListener, "testListener"); - addTest(&ClientMultiMapTest::testLock, "testLock"); - addTest(&ClientMultiMapTest::testLockTtl, "testLockTtl"); - addTest(&ClientMultiMapTest::testTryLock, "testTryLock"); - addTest(&ClientMultiMapTest::testForceUnlock, "testForceUnlock"); - - } - - void ClientMultiMapTest::beforeClass() { - } - - void ClientMultiMapTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ClientMultiMapTest::beforeTest() { - mm->clear(); - } - - void ClientMultiMapTest::afterTest() { - mm->clear(); - } - - void ClientMultiMapTest::testPutGetRemove() { - assertTrue(mm->put("key1", "value1")); - assertTrue(mm->put("key1", "value2")); - assertTrue(mm->put("key1", "value3")); + TEST_F(ClientMultiMapTest, testPutGetRemove) { + ASSERT_TRUE(mm->put("key1", "value1")); + ASSERT_TRUE(mm->put("key1", "value2")); + ASSERT_TRUE(mm->put("key1", "value3")); - assertTrue(mm->put("key2", "value4")); - assertTrue(mm->put("key2", "value5")); + ASSERT_TRUE(mm->put("key2", "value4")); + ASSERT_TRUE(mm->put("key2", "value5")); - assertEqual(3, mm->valueCount("key1")); - assertEqual(2, mm->valueCount("key2")); - assertEqual(5, mm->size()); + ASSERT_EQ(3, mm->valueCount("key1")); + ASSERT_EQ(2, mm->valueCount("key2")); + ASSERT_EQ(5, mm->size()); std::vector coll = mm->get("key1"); - assertEqual(3, (int)coll.size()); + ASSERT_EQ(3, (int)coll.size()); coll = mm->remove("key2"); - assertEqual(2, (int)coll.size()); - assertEqual(0, mm->valueCount("key2")); - assertEqual(0, (int)mm->get("key2").size()); + ASSERT_EQ(2, (int)coll.size()); + ASSERT_EQ(0, mm->valueCount("key2")); + ASSERT_EQ(0, (int)mm->get("key2").size()); - assertFalse(mm->remove("key1", "value4")); - assertEqual(3, mm->size()); + ASSERT_FALSE(mm->remove("key1", "value4")); + ASSERT_EQ(3, mm->size()); - assertTrue(mm->remove("key1", "value2")); - assertEqual(2, mm->size()); + ASSERT_TRUE(mm->remove("key1", "value2")); + ASSERT_EQ(2, mm->size()); - assertTrue(mm->remove("key1", "value1")); - assertEqual(1, mm->size()); - assertEqual("value3", mm->get("key1")[0]); + ASSERT_TRUE(mm->remove("key1", "value1")); + ASSERT_EQ(1, mm->size()); + ASSERT_EQ("value3", mm->get("key1")[0]); } - void ClientMultiMapTest::testKeySetEntrySetAndValues() { - assertTrue(mm->put("key1", "value1")); - assertTrue(mm->put("key1", "value2")); - assertTrue(mm->put("key1", "value3")); + TEST_F(ClientMultiMapTest, testKeySetEntrySetAndValues) { + ASSERT_TRUE(mm->put("key1", "value1")); + ASSERT_TRUE(mm->put("key1", "value2")); + ASSERT_TRUE(mm->put("key1", "value3")); - assertTrue(mm->put("key2", "value4")); - assertTrue(mm->put("key2", "value5")); + ASSERT_TRUE(mm->put("key2", "value4")); + ASSERT_TRUE(mm->put("key2", "value5")); - assertEqual(2, (int)mm->keySet().size()); - assertEqual(5, (int)mm->values().size()); - assertEqual(5, (int)mm->entrySet().size()); + ASSERT_EQ(2, (int)mm->keySet().size()); + ASSERT_EQ(5, (int)mm->values().size()); + ASSERT_EQ(5, (int)mm->entrySet().size()); } - void ClientMultiMapTest::testContains() { - assertTrue(mm->put("key1", "value1")); - assertTrue(mm->put("key1", "value2")); - assertTrue(mm->put("key1", "value3")); + TEST_F(ClientMultiMapTest, testContains) { + ASSERT_TRUE(mm->put("key1", "value1")); + ASSERT_TRUE(mm->put("key1", "value2")); + ASSERT_TRUE(mm->put("key1", "value3")); - assertTrue(mm->put("key2", "value4")); - assertTrue(mm->put("key2", "value5")); + ASSERT_TRUE(mm->put("key2", "value4")); + ASSERT_TRUE(mm->put("key2", "value5")); - assertFalse(mm->containsKey("key3")); - assertTrue(mm->containsKey("key1")); + ASSERT_FALSE(mm->containsKey("key3")); + ASSERT_TRUE(mm->containsKey("key1")); - assertFalse(mm->containsValue("value6")); - assertTrue(mm->containsValue("value4")); + ASSERT_FALSE(mm->containsValue("value6")); + ASSERT_TRUE(mm->containsValue("value4")); - assertFalse(mm->containsEntry("key1", "value4")); - assertFalse(mm->containsEntry("key2", "value3")); - assertTrue(mm->containsEntry("key1", "value1")); - assertTrue(mm->containsEntry("key2", "value5")); + ASSERT_FALSE(mm->containsEntry("key1", "value4")); + ASSERT_FALSE(mm->containsEntry("key2", "value3")); + ASSERT_TRUE(mm->containsEntry("key1", "value1")); + ASSERT_TRUE(mm->containsEntry("key2", "value5")); } class MyMultiMapListener : public EntryAdapter{ public: MyMultiMapListener(util::CountDownLatch& addedLatch, util::CountDownLatch& removedLatch) - : addedLatch(addedLatch), removedLatch(removedLatch) { + : addedLatch(addedLatch), removedLatch(removedLatch) { } void entryAdded(const EntryEvent& event) { @@ -154,7 +122,7 @@ namespace hazelcast { util::CountDownLatch& removedLatch; }; - void ClientMultiMapTest::testListener() { + TEST_F(ClientMultiMapTest, testListener) { util::CountDownLatch latch1Add(8); util::CountDownLatch latch1Remove(4); @@ -181,14 +149,14 @@ namespace hazelcast { mm->remove("key3"); - assertTrue(latch1Add.await(20), "a"); - assertTrue(latch1Remove.await(20), "b"); + ASSERT_TRUE(latch1Add.await(20)); + ASSERT_TRUE(latch1Remove.await(20)); - assertTrue(latch2Add.await(20), "c"); - assertTrue(latch2Remove.await(20), "d"); + ASSERT_TRUE(latch2Add.await(20)); + ASSERT_TRUE(latch2Remove.await(20)); - assertTrue(mm->removeEntryListener(id1)); - assertTrue(mm->removeEntryListener(id2)); + ASSERT_TRUE(mm->removeEntryListener(id1)); + ASSERT_TRUE(mm->removeEntryListener(id2)); } @@ -200,11 +168,11 @@ namespace hazelcast { } } - void ClientMultiMapTest::testLock() { + TEST_F(ClientMultiMapTest, testLock) { mm->lock("key1"); util::CountDownLatch latch(1); util::Thread t(lockThread, mm.get(), &latch); - assertTrue(latch.await(5)); + ASSERT_TRUE(latch.await(5)); mm->forceUnlock("key1"); } @@ -221,11 +189,11 @@ namespace hazelcast { } } - void ClientMultiMapTest::testLockTtl() { + TEST_F(ClientMultiMapTest, testLockTtl) { mm->lock("key1", 3 * 1000); util::CountDownLatch latch(2); util::Thread t(lockTtlThread, mm.get(), &latch); - assertTrue(latch.await(10)); + ASSERT_TRUE(latch.await(10)); mm->forceUnlock("key1"); } @@ -254,20 +222,20 @@ namespace hazelcast { } } - void ClientMultiMapTest::testTryLock() { - assertTrue(mm->tryLock("key1", 2 * 1000)); + TEST_F(ClientMultiMapTest, testTryLock) { + ASSERT_TRUE(mm->tryLock("key1", 2 * 1000)); util::CountDownLatch latch(1); util::Thread t(tryLockThread, mm.get(), &latch); - assertTrue(latch.await(100)); - assertTrue(mm->isLocked("key1")); + ASSERT_TRUE(latch.await(100)); + ASSERT_TRUE(mm->isLocked("key1")); util::CountDownLatch latch2(1); util::Thread t2(tryLockThread2, mm.get(), &latch2); util::sleep(1); mm->unlock("key1"); - assertTrue(latch2.await(100)); - assertTrue(mm->isLocked("key1")); + ASSERT_TRUE(latch2.await(100)); + ASSERT_TRUE(mm->isLocked("key1")); mm->forceUnlock("key1"); } @@ -278,12 +246,12 @@ namespace hazelcast { latch->countDown(); } - void ClientMultiMapTest::testForceUnlock() { + TEST_F(ClientMultiMapTest, testForceUnlock) { mm->lock("key1"); util::CountDownLatch latch(1); util::Thread t(forceUnlockThread, mm.get(), &latch); - assertTrue(latch.await(100)); - assertFalse(mm->isLocked("key1")); + ASSERT_TRUE(latch.await(100)); + ASSERT_FALSE(mm->isLocked("key1")); } } } diff --git a/hazelcast/test/multimap/ClientMultiMapTest.h b/hazelcast/test/src/multimap/ClientMultiMapTest.h similarity index 66% rename from hazelcast/test/multimap/ClientMultiMapTest.h rename to hazelcast/test/src/multimap/ClientMultiMapTest.h index 27860f84a7..2091c09d4d 100644 --- a/hazelcast/test/multimap/ClientMultiMapTest.h +++ b/hazelcast/test/src/multimap/ClientMultiMapTest.h @@ -31,46 +31,16 @@ namespace hazelcast { namespace client { - class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class ClientMultiMapTest : public ClientTestSupport { + class ClientMultiMapTest : public ClientTestSupport { public: - ClientMultiMapTest(HazelcastServerFactory &); + ClientMultiMapTest(); ~ClientMultiMapTest(); - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testPutGetRemove(); - - void testKeySetEntrySetAndValues(); - - void testContains(); - - void testListener(); - - void testLock(); - - void testLockTtl(); - - void testTryLock(); - - void testForceUnlock(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; diff --git a/hazelcast/test/src/protocol/ClientMessageTest.cpp b/hazelcast/test/src/protocol/ClientMessageTest.cpp new file mode 100644 index 0000000000..448b82a012 --- /dev/null +++ b/hazelcast/test/src/protocol/ClientMessageTest.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Created by İhsan Demir on 19/05/15. +// + +#include "protocol/ClientMessageTest.h" + +#include "hazelcast/client/protocol/ClientMessage.h" + +namespace hazelcast { + namespace client { + namespace test { + namespace protocol { + TEST_F(ClientMessageTest, testMessageFields) { + std::auto_ptr msg = + hazelcast::client::protocol::ClientMessage::createForEncode(22); + ASSERT_EQ(0, msg->getDataSize()); + + ASSERT_EQ(false, msg->isRetryable()); + + ASSERT_EQ(false, msg->isBindToSingleConnection()); + + ASSERT_EQ(22, msg->getFrameLength()); + + msg->setIsBoundToSingleConnection(true); + msg->setRetryable(true); + msg->setCorrelationId(0xABCDEF12); + msg->setFlags(0x05); + msg->setMessageType(0xABCD); + msg->setPartitionId(0x8ABCDEF1); + msg->setVersion(4); + msg->updateFrameLength(); + + ASSERT_EQ(true, msg->isBindToSingleConnection()); + ASSERT_EQ(true, msg->isRetryable()); + ASSERT_EQ(0xABCDEF12, msg->getCorrelationId()); + ASSERT_EQ(false, msg->isFlagSet(2)); + ASSERT_EQ(true, msg->isFlagSet(4)); + ASSERT_EQ(true, msg->isFlagSet(0x05)); + ASSERT_EQ(0xABCD, msg->getMessageType()); + ASSERT_EQ((int32_t)0x8ABCDEF1, msg->getPartitionId()); + ASSERT_EQ(4, msg->getVersion()); + ASSERT_EQ(22, msg->getFrameLength()); + ASSERT_EQ(0, msg->getDataSize()); + + SocketStub sock; + ASSERT_EQ(22, msg->writeTo(sock, 0, 22)); + + ASSERT_EQ(22, numBytes); + + byte expectedBytes[22] = { + 0x16, 0x0, 0x0, 0x0, // Frame length + 0x04, // Version + 0x05, // Flags + 0xCD, 0xAB, // Message Type + 0x12, 0xEF, 0xCD, 0xAB, 0x00, 0x00, 0x00, 0x00, // Correlation Id + 0xF1, 0xDE, 0xBC, 0x8A, // Partition Id + 0x16, 0x0 // Data Offset + }; + + ASSERT_EQ(0, memcmp(expectedBytes, buffer, 22)); + + } + + ClientMessageTest::SocketStub::SocketStub() : Socket(-1) { + } + + ClientMessageTest::SocketStub::~SocketStub() { + } + + int ClientMessageTest::SocketStub::send(const void *buf, int size) const { + if (size <= 100) { + numBytes = size; + memcpy(buffer, buf, (size_t)numBytes); + } else { + numBytes = 0; + } + return numBytes; + } + } + } + } +} diff --git a/hazelcast/test/protocol/ClientMessageTest.h b/hazelcast/test/src/protocol/ClientMessageTest.h similarity index 64% rename from hazelcast/test/protocol/ClientMessageTest.h rename to hazelcast/test/src/protocol/ClientMessageTest.h index 9160d5a5f5..5bec7b221a 100644 --- a/hazelcast/test/protocol/ClientMessageTest.h +++ b/hazelcast/test/src/protocol/ClientMessageTest.h @@ -17,36 +17,22 @@ // Created by İhsan Demir on 19/05/15. // -#ifndef HAZELCAST_CLIENT_TEST_PROTOCOL_CLIENTMESSAGE_H -#define HAZELCAST_CLIENT_TEST_PROTOCOL_CLIENTMESSAGE_H +#ifndef HAZELCAST_CLIENT_TEST_PROTOCOL_CLIENTMESSAGETEST_H +#define HAZELCAST_CLIENT_TEST_PROTOCOL_CLIENTMESSAGETEST_H +#include #include "hazelcast/client/Socket.h" -#include "iTest/iTest.h" namespace hazelcast { namespace client { namespace test { namespace protocol { - class ClientMessageTest : public iTest::iTestFixture { - public: + static int numBytes; + static byte buffer[100]; - ClientMessageTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testMessageFields(); - - private: + class ClientMessageTest : public ::testing::Test { + protected: class SocketStub : public Socket { - public: virtual int send(const void *buf, int size) const; @@ -60,4 +46,4 @@ namespace hazelcast { } } -#endif //HAZELCAST_CLIENT_TEST_PROTOCOL_CLIENTMESSAGE_H +#endif //HAZELCAST_CLIENT_TEST_PROTOCOL_CLIENTMESSAGETEST_H diff --git a/hazelcast/test/src/queue/ClientQueueTest.cpp b/hazelcast/test/src/queue/ClientQueueTest.cpp new file mode 100644 index 0000000000..7417790dbc --- /dev/null +++ b/hazelcast/test/src/queue/ClientQueueTest.cpp @@ -0,0 +1,243 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Created by sancar koyunlu on 9/4/13. + +#include "hazelcast/util/Util.h" +#include "queue/ClientQueueTest.h" +#include "hazelcast/client/HazelcastClient.h" +#include "hazelcast/client/ItemListener.h" +#include "HazelcastServerFactory.h" + +namespace hazelcast { + namespace client { + namespace test { + ClientQueueTest::ClientQueueTest() + : instance(*g_srvFactory) + , client(getNewClient()) + , q(new IQueue< std::string>(client->getQueue< std::string >("clientQueueTest"))) { + + } + + ClientQueueTest::~ClientQueueTest() { + } + + class QueueTestItemListener : public ItemListener { + public: + QueueTestItemListener(util::CountDownLatch &latch) + :latch(latch) { + + } + + void itemAdded(const ItemEvent& itemEvent) { + latch.countDown(); + } + + void itemRemoved(const ItemEvent& item) { + } + + private: + util::CountDownLatch &latch; + }; + + TEST_F(ClientQueueTest, testListener) { + ASSERT_EQ(0, q->size()); + + util::CountDownLatch latch(5); + + QueueTestItemListener listener(latch); + std::string id = q->addItemListener(listener, true); + + util::sleep(1); + + for (int i = 0; i < 5; i++) { + ASSERT_TRUE(q->offer(std::string("event_item") + util::IOUtil::to_string(i))); + } + + ASSERT_TRUE(latch.await(5)); + ASSERT_TRUE(q->removeItemListener(id)); + } + + void testOfferPollThread2(util::ThreadArgs &args) { + IQueue *q = (IQueue *) args.arg0; + util::sleep(2); + q->offer("item1"); + std::cout << "item1 is offered" << std::endl; + } + + TEST_F(ClientQueueTest, testOfferPoll) { + for (int i = 0; i < 10; i++) { + bool result = q->offer("item"); + ASSERT_TRUE(result); + } + ASSERT_EQ(10, q->size()); + q->poll(); + bool result = q->offer("item", 5); + ASSERT_TRUE(result); + + for (int i = 0; i < 10; i++) { + ASSERT_NE(q->poll().get(), (std::string *)NULL); + } + ASSERT_EQ(0, q->size()); + + util::Thread t2(testOfferPollThread2, q.get()); + + boost::shared_ptr item = q->poll(30 * 1000); + ASSERT_NE(item.get(), (std::string *)NULL); + ASSERT_EQ("item1", *item); + t2.join(); + } + + TEST_F(ClientQueueTest, testRemainingCapacity) { + int capacity = q->remainingCapacity(); + ASSERT_TRUE(capacity > 10000); + q->offer("item"); + ASSERT_EQ(capacity - 1, q->remainingCapacity()); + } + + + TEST_F(ClientQueueTest, testRemove) { + ASSERT_TRUE(q->offer("item1")); + ASSERT_TRUE(q->offer("item2")); + ASSERT_TRUE(q->offer("item3")); + + ASSERT_FALSE(q->remove("item4")); + ASSERT_EQ(3, q->size()); + + ASSERT_TRUE(q->remove("item2")); + + ASSERT_EQ(2, q->size()); + + ASSERT_EQ("item1", *(q->poll())); + ASSERT_EQ("item3", *(q->poll())); + } + + + TEST_F(ClientQueueTest, testContains) { + ASSERT_TRUE(q->offer("item1")); + ASSERT_TRUE(q->offer("item2")); + ASSERT_TRUE(q->offer("item3")); + ASSERT_TRUE(q->offer("item4")); + ASSERT_TRUE(q->offer("item5")); + + + ASSERT_TRUE(q->contains("item3")); + ASSERT_FALSE(q->contains("item")); + + std::vector list; + list.push_back("item4"); + list.push_back("item2"); + + ASSERT_TRUE(q->containsAll(list)); + + list.push_back("item"); + ASSERT_FALSE(q->containsAll(list)); + } + + TEST_F(ClientQueueTest, testDrain) { + ASSERT_TRUE(q->offer("item1")); + ASSERT_TRUE(q->offer("item2")); + ASSERT_TRUE(q->offer("item3")); + ASSERT_TRUE(q->offer("item4")); + ASSERT_TRUE(q->offer("item5")); + + std::vector list; + int result = q->drainTo(list, 2); + ASSERT_EQ(2, result); + ASSERT_EQ("item1", list[0]); + ASSERT_EQ("item2", list[1]); + + std::vector list2; + result = q->drainTo(list2); + ASSERT_EQ(3, result); + ASSERT_EQ("item3", list2[0]); + ASSERT_EQ("item4", list2[1]); + ASSERT_EQ("item5", list2[2]); + } + + TEST_F(ClientQueueTest, testToArray) { + ASSERT_TRUE(q->offer("item1")); + ASSERT_TRUE(q->offer("item2")); + ASSERT_TRUE(q->offer("item3")); + ASSERT_TRUE(q->offer("item4")); + ASSERT_TRUE(q->offer("item5")); + + std::vector array = q->toArray(); + int size = array.size(); + for (int i = 0; i < size; i++) { + ASSERT_EQ(std::string("item") + util::IOUtil::to_string(i + 1), array[i]); + } + + } + + TEST_F(ClientQueueTest, testAddAll) { + std::vector coll; + coll.push_back("item1"); + coll.push_back("item2"); + coll.push_back("item3"); + coll.push_back("item4"); + + ASSERT_TRUE(q->addAll(coll)); + int size = q->size(); + ASSERT_EQ(size, (int) coll.size()); + } + + TEST_F(ClientQueueTest, testRemoveRetain) { + ASSERT_TRUE(q->offer("item1")); + ASSERT_TRUE(q->offer("item2")); + ASSERT_TRUE(q->offer("item3")); + ASSERT_TRUE(q->offer("item4")); + ASSERT_TRUE(q->offer("item5")); + + std::vector list; + list.push_back("item8"); + list.push_back("item9"); + ASSERT_FALSE(q->removeAll(list)); + ASSERT_EQ(5, q->size()); + + list.push_back("item3"); + list.push_back("item4"); + list.push_back("item1"); + ASSERT_TRUE(q->removeAll(list)); + ASSERT_EQ(2, q->size()); + + list.clear(); + list.push_back("item2"); + list.push_back("item5"); + ASSERT_FALSE(q->retainAll(list)); + ASSERT_EQ(2, q->size()); + + list.clear(); + ASSERT_TRUE(q->retainAll(list)); + ASSERT_EQ(0, q->size()); + } + + TEST_F(ClientQueueTest, testClear) { + ASSERT_TRUE(q->offer("item1")); + ASSERT_TRUE(q->offer("item2")); + ASSERT_TRUE(q->offer("item3")); + ASSERT_TRUE(q->offer("item4")); + ASSERT_TRUE(q->offer("item5")); + + q->clear(); + + ASSERT_EQ(0, q->size()); + ASSERT_EQ(q->poll().get(), (std::string *)NULL); + } + } + } +} + diff --git a/hazelcast/test/queue/ClientQueueTest.h b/hazelcast/test/src/queue/ClientQueueTest.h similarity index 63% rename from hazelcast/test/queue/ClientQueueTest.h rename to hazelcast/test/src/queue/ClientQueueTest.h index 61ee3ecf2d..e5ff300750 100644 --- a/hazelcast/test/queue/ClientQueueTest.h +++ b/hazelcast/test/src/queue/ClientQueueTest.h @@ -32,46 +32,13 @@ namespace hazelcast { class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class ClientQueueTest : public ClientTestSupport { + class ClientQueueTest : public ClientTestSupport { public: - ClientQueueTest(HazelcastServerFactory&); + ClientQueueTest(); ~ClientQueueTest(); - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testListener(); - - void testOfferPoll(); - - void testRemainingCapacity(); - - void testRemove(); - - void testContains(); - - void testDrain(); - - void testToArray(); - - void testAddAll(); - - void testRemoveRetain(); - - void testClear(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; diff --git a/hazelcast/test/semaphore/ClientSemaphoreTest.cpp b/hazelcast/test/src/semaphore/ClientSemaphoreTest.cpp similarity index 59% rename from hazelcast/test/semaphore/ClientSemaphoreTest.cpp rename to hazelcast/test/src/semaphore/ClientSemaphoreTest.cpp index e07b261cb9..679635e3fd 100644 --- a/hazelcast/test/semaphore/ClientSemaphoreTest.cpp +++ b/hazelcast/test/src/semaphore/ClientSemaphoreTest.cpp @@ -16,8 +16,6 @@ // // Created by sancar koyunlu on 9/5/13. - - #include "hazelcast/util/Util.h" #include "ClientSemaphoreTest.h" #include "HazelcastServerFactory.h" @@ -26,44 +24,18 @@ namespace hazelcast { namespace client { - - class HazelcastClient; - namespace test { - using namespace iTest; - - ClientSemaphoreTest::ClientSemaphoreTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("ClientSemaphoreTest", &serverFactory) - , instance(serverFactory) + ClientSemaphoreTest::ClientSemaphoreTest() + : instance(*g_srvFactory) , client(getNewClient()) , s(new ISemaphore(client->getISemaphore("ClientSemaphoreTest"))) { - } - - - ClientSemaphoreTest::~ClientSemaphoreTest() { - } - - void ClientSemaphoreTest::addTests() { - addTest(&ClientSemaphoreTest::testAcquire, "testAcquire"); - addTest(&ClientSemaphoreTest::testTryAcquire, "testTryAcquire"); - } - - void ClientSemaphoreTest::beforeClass() { - } - - void ClientSemaphoreTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ClientSemaphoreTest::beforeTest() { s->reducePermits(100); s->release(10); } - void ClientSemaphoreTest::afterTest() { + ClientSemaphoreTest::~ClientSemaphoreTest() { s->reducePermits(100); - s->release(10); + s->release(10); } void testAcquireThread(util::ThreadArgs& args) { @@ -73,8 +45,8 @@ namespace hazelcast { latch->countDown(); } - void ClientSemaphoreTest::testAcquire() { - assertEqual(10, s->drainPermits()); + TEST_F(ClientSemaphoreTest, testAcquire) { + ASSERT_EQ(10, s->drainPermits()); util::CountDownLatch latch(1); util::Thread t(testAcquireThread, s.get(), &latch); @@ -82,8 +54,8 @@ namespace hazelcast { util::sleep(1); s->release(2); - assertTrue(latch.await(10 )); - assertEqual(1, s->availablePermits()); + ASSERT_TRUE(latch.await(10 )); + ASSERT_EQ(1, s->availablePermits()); } @@ -95,21 +67,20 @@ namespace hazelcast { } } - void ClientSemaphoreTest::testTryAcquire() { - assertTrue(s->tryAcquire()); - assertTrue(s->tryAcquire(9)); - assertEqual(0, s->availablePermits()); - assertFalse(s->tryAcquire(1 * 1000)); - assertFalse(s->tryAcquire(2, 1 * 1000)); + TEST_F(ClientSemaphoreTest, testTryAcquire) { + ASSERT_TRUE(s->tryAcquire()); + ASSERT_TRUE(s->tryAcquire(9)); + ASSERT_EQ(0, s->availablePermits()); + ASSERT_FALSE(s->tryAcquire(1 * 1000)); + ASSERT_FALSE(s->tryAcquire(2, 1 * 1000)); util::CountDownLatch latch(1); util::Thread t(testTryAcquireThread, s.get(), &latch); s->release(2); - assertTrue(latch.await(10 )); - assertEqual(0, s->availablePermits()); - + ASSERT_TRUE(latch.await(10)); + ASSERT_EQ(0, s->availablePermits()); } } } diff --git a/hazelcast/test/semaphore/ClientSemaphoreTest.h b/hazelcast/test/src/semaphore/ClientSemaphoreTest.h similarity index 77% rename from hazelcast/test/semaphore/ClientSemaphoreTest.h rename to hazelcast/test/src/semaphore/ClientSemaphoreTest.h index 8d126a97f5..c274d938e6 100644 --- a/hazelcast/test/semaphore/ClientSemaphoreTest.h +++ b/hazelcast/test/src/semaphore/ClientSemaphoreTest.h @@ -29,35 +29,17 @@ namespace hazelcast { namespace client { - class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class ClientSemaphoreTest : public ClientTestSupport { + class ClientSemaphoreTest : public ClientTestSupport { public: - ClientSemaphoreTest(HazelcastServerFactory &); + ClientSemaphoreTest(); ~ClientSemaphoreTest(); - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testAcquire(); - - void testTryAcquire(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; diff --git a/hazelcast/test/serialization/ChildTemplatedPortable1.h b/hazelcast/test/src/serialization/ChildTemplatedPortable1.h similarity index 100% rename from hazelcast/test/serialization/ChildTemplatedPortable1.h rename to hazelcast/test/src/serialization/ChildTemplatedPortable1.h diff --git a/hazelcast/test/serialization/ChildTemplatedPortable2.h b/hazelcast/test/src/serialization/ChildTemplatedPortable2.h similarity index 100% rename from hazelcast/test/serialization/ChildTemplatedPortable2.h rename to hazelcast/test/src/serialization/ChildTemplatedPortable2.h diff --git a/hazelcast/test/serialization/ClientSerializationTest.cpp b/hazelcast/test/src/serialization/ClientSerializationTest.cpp similarity index 67% rename from hazelcast/test/serialization/ClientSerializationTest.cpp rename to hazelcast/test/src/serialization/ClientSerializationTest.cpp index 7ce58d1997..57124f0990 100644 --- a/hazelcast/test/serialization/ClientSerializationTest.cpp +++ b/hazelcast/test/src/serialization/ClientSerializationTest.cpp @@ -40,57 +40,18 @@ namespace hazelcast { namespace client { namespace test { - static const unsigned int LARGE_ARRAY_SIZE = 5 * 1024 * 1024; // 5 MB. Previously it was 10 MB but then the - // test fails when using Windows 32-bit DLL - // library with std::bad_alloc with 10 MB + static const unsigned int LARGE_ARRAY_SIZE = + 5 * 1024 * 1024; // 5 MB. Previously it was 10 MB but then the + // test fails when using Windows 32-bit DLL + // library with std::bad_alloc with 10 MB - ClientSerializationTest::ClientSerializationTest() - : ClientTestSupport("ClientSerializationTest") { - - } - - void ClientSerializationTest::beforeClass() { - } - - void ClientSerializationTest::afterClass() { - } - - void ClientSerializationTest::beforeTest() { - } - - void ClientSerializationTest::afterTest() { - } - - void ClientSerializationTest::addTests() { - addTest(&ClientSerializationTest::testBasicFunctionality, "testBasicFunctionality"); - addTest(&ClientSerializationTest::testBasicFunctionalityWithLargeData, "testBasicFunctionalityWithLargeData"); - addTest(&ClientSerializationTest::testBasicFunctionalityWithDifferentVersions, "testBasicFunctionalityWithDifferentVersions"); - addTest(&ClientSerializationTest::testCustomSerialization, "testCustomSerialization"); - addTest(&ClientSerializationTest::testRawData, "testRawData"); - addTest(&ClientSerializationTest::testIdentifiedDataSerializable, "testIdentifiedDataSerializable"); - addTest(&ClientSerializationTest::testRawDataWithoutRegistering, "testRawDataWithoutRegistering"); - addTest(&ClientSerializationTest::testInvalidWrite, "testInvalidWrite"); - addTest(&ClientSerializationTest::testInvalidRead, "testInvalidRead"); - addTest(&ClientSerializationTest::testDifferentVersions, "testDifferentVersions"); - addTest(&ClientSerializationTest::testBasicFunctionality, "testBasicFunctionality"); - addTest(&ClientSerializationTest::testTemplatedPortable_whenMultipleTypesAreUsed, "testTemplatedPortable_whenMultipleTypesAreUsed"); - addTest(&ClientSerializationTest::testDataHash, "testDataHash"); - addTest(&ClientSerializationTest::testPrimitives, "testPrimitives"); - addTest(&ClientSerializationTest::testPrimitiveArrays, "testPrimitiveArrays"); - addTest(&ClientSerializationTest::testWriteObjectWithPortable, "testWriteObjectWithPortable"); - addTest(&ClientSerializationTest::testWriteObjectWithIdentifiedDataSerializable, "testWriteObjectWithIdentifiedDataSerilizable"); - addTest(&ClientSerializationTest::testWriteObjectWithCustomXSerializable, "testWriteObjectWithCustomXSerializable"); - addTest(&ClientSerializationTest::testWriteObjectWithCustomPersonSerializable, "testWriteObjectWithCustomPersonSerializable"); - addTest(&ClientSerializationTest::testNullData, "testNullData"); - addTest(&ClientSerializationTest::testMorphingWithDifferentTypes_differentVersions, "testMorphingWithDifferentTypes_differentVersions"); - } - - void ClientSerializationTest::testCustomSerialization() { + TEST_F(ClientSerializationTest, testCustomSerialization) { SerializationConfig serializationConfig; serializationConfig.setPortableVersion(1); serialization::pimpl::SerializationService serializationService(serializationConfig); - boost::shared_ptr serializer1(new TestCustomSerializerX()); + boost::shared_ptr serializer1( + new TestCustomSerializerX()); boost::shared_ptr serializer2(new TestCustomPersonSerializer()); serializationService.registerSerializer(serializer1); @@ -98,17 +59,18 @@ namespace hazelcast { TestCustomXSerializable a(131321); serialization::pimpl::Data data = serializationService.toData(&a); - boost::shared_ptr a2 = serializationService.toObject(data); - iTest::assertEqual(a, *a2); + boost::shared_ptr a2 = serializationService.toObject( + data); + ASSERT_EQ(a, *a2); TestCustomPerson b("TestCustomPerson"); serialization::pimpl::Data data1 = serializationService.toData(&b); boost::shared_ptr b2 = serializationService.toObject(data1); - iTest::assertEqual(b, *b2); + ASSERT_EQ(b, *b2); } - void ClientSerializationTest::testRawData() { + TEST_F(ClientSerializationTest, testRawData) { SerializationConfig serializationConfig; serializationConfig.setPortableVersion(1); serialization::pimpl::SerializationService serializationService(serializationConfig); @@ -122,11 +84,10 @@ namespace hazelcast { serialization::pimpl::Data data = serializationService.toData(&p); boost::shared_ptr x = serializationService.toObject(data); - iTest::assertEqual(p, *x); + ASSERT_EQ(p, *x); } - - void ClientSerializationTest::testIdentifiedDataSerializable() { + TEST_F(ClientSerializationTest, testIdentifiedDataSerializable) { SerializationConfig serializationConfig; serializationConfig.setPortableVersion(1); serialization::pimpl::SerializationService serializationService(serializationConfig); @@ -137,15 +98,15 @@ namespace hazelcast { boost::shared_ptr tnp1; tnp1 = serializationService.toObject(data); - iTest::assertEqual(np, *tnp1); + ASSERT_EQ(np, *tnp1); int x = 4; data = serializationService.toData(&x); boost::shared_ptr ptr = serializationService.toObject(data); int y = *ptr; - iTest::assertEqual(x, y); + ASSERT_EQ(x, y); } - void ClientSerializationTest::testRawDataWithoutRegistering() { + TEST_F(ClientSerializationTest, testRawDataWithoutRegistering) { SerializationConfig serializationConfig; serializationConfig.setPortableVersion(1); serialization::pimpl::SerializationService serializationService(serializationConfig); @@ -159,39 +120,31 @@ namespace hazelcast { serialization::pimpl::Data data = serializationService.toData(&p); boost::shared_ptr x = serializationService.toObject(data); - iTest::assertEqual(p, *x); + ASSERT_EQ(p, *x); } - void ClientSerializationTest::testInvalidWrite() { + TEST_F(ClientSerializationTest, testInvalidWrite) { SerializationConfig serializationConfig; serializationConfig.setPortableVersion(1); serialization::pimpl::SerializationService serializationService(serializationConfig); TestInvalidWritePortable p(2131, 123, "q4edfd"); - try { - serializationService.toData(&p); - iTest::assertTrue(false, "toData should trow exception"); - } catch (exception::HazelcastSerializationException&) { - - } + ASSERT_THROW(serializationService.toData(&p), + exception::HazelcastSerializationException); } - void ClientSerializationTest::testInvalidRead() { + TEST_F(ClientSerializationTest, testInvalidRead) { SerializationConfig serializationConfig; serializationConfig.setPortableVersion(1); serialization::pimpl::SerializationService serializationService(serializationConfig); TestInvalidReadPortable p(2131, 123, "q4edfd"); serialization::pimpl::Data data = serializationService.toData(&p); - try { - serializationService.toObject(data); - iTest::assertTrue(false, "toObject should trow exception"); - } catch (exception::HazelcastSerializationException&) { - - } + ASSERT_THROW(serializationService.toObject(data), + exception::HazelcastSerializationException); } - void ClientSerializationTest::testDifferentVersions() { + TEST_F(ClientSerializationTest, testDifferentVersions) { SerializationConfig serializationConfig; serializationConfig.setPortableVersion(1); serialization::pimpl::SerializationService serializationService(serializationConfig); @@ -206,21 +159,18 @@ namespace hazelcast { TestNamedPortableV2 p2("portable-v2", 123); serialization::pimpl::Data data2 = serializationService2.toData(&p2); - - boost::shared_ptr t2 = serializationService2.toObject(data); - iTest::assertEqual(std::string("portable-v1"), t2->name); - iTest::assertEqual(111, t2->k); - iTest::assertEqual(0, t2->v); - + ASSERT_EQ(std::string("portable-v1"), t2->name); + ASSERT_EQ(111, t2->k); + ASSERT_EQ(0, t2->v); boost::shared_ptr t1 = serializationService.toObject(data2); - iTest::assertEqual(std::string("portable-v2"), t1->name); - iTest::assertEqual(123 * 10, t1->k); + ASSERT_EQ(std::string("portable-v2"), t1->name); + ASSERT_EQ(123 * 10, t1->k); } - void ClientSerializationTest::testBasicFunctionality() { + TEST_F(ClientSerializationTest, testBasicFunctionality) { SerializationConfig serializationConfig; serializationConfig.setPortableVersion(1); serialization::pimpl::SerializationService serializationService(serializationConfig); @@ -230,13 +180,13 @@ namespace hazelcast { data = serializationService.toData(&x); boost::shared_ptr returnedInt = serializationService.toObject(data); - iTest::assertEqual(x, *returnedInt); + ASSERT_EQ(x, *returnedInt); short f = 2; data = serializationService.toData(&f); boost::shared_ptr temp = serializationService.toObject(data); - iTest::assertEqual(f, *temp); + ASSERT_EQ(f, *temp); TestNamedPortable np("name", 5); data = serializationService.toData(&np); @@ -246,8 +196,8 @@ namespace hazelcast { tnp2 = serializationService.toObject(data); - iTest::assertEqual(np, *tnp1); - iTest::assertEqual(np, *tnp2); + ASSERT_EQ(np, *tnp1); + ASSERT_EQ(np, *tnp2); byte byteArray[] = {0, 1, 2}; std::vector bb(byteArray, byteArray + 3); @@ -279,21 +229,22 @@ namespace hazelcast { tip2 = serializationService.toObject(data); - iTest::assertEqual(inner, *tip1); - iTest::assertEqual(inner, *tip2); + ASSERT_EQ(inner, *tip1); + ASSERT_EQ(inner, *tip2); - TestMainPortable main((byte)113, true, 'x', -500, 56789, -50992225, 900.5678f, -897543.3678909, "this is main portable object created for testing!", inner); + TestMainPortable main((byte) 113, true, 'x', -500, 56789, -50992225, 900.5678f, -897543.3678909, + "this is main portable object created for testing!", inner); data = serializationService.toData(&main); boost::shared_ptr tmp1, tmp2; tmp1 = serializationService.toObject(data); tmp2 = serializationService.toObject(data); - iTest::assertEqual(main, *tmp1); - iTest::assertEqual(main, *tmp2); + ASSERT_EQ(main, *tmp1); + ASSERT_EQ(main, *tmp2); } - void ClientSerializationTest::testBasicFunctionalityWithLargeData() { + TEST_F(ClientSerializationTest, testBasicFunctionalityWithLargeData) { SerializationConfig serializationConfig; serializationConfig.setPortableVersion(1); serialization::pimpl::SerializationService serializationService(serializationConfig); @@ -337,12 +288,12 @@ namespace hazelcast { tip2 = serializationService.toObject(data); - iTest::assertEqual(inner, *tip1); - iTest::assertEqual(inner, *tip2); + ASSERT_EQ(inner, *tip1); + ASSERT_EQ(inner, *tip2); } - void ClientSerializationTest::testBasicFunctionalityWithDifferentVersions() { + TEST_F(ClientSerializationTest, testBasicFunctionalityWithDifferentVersions) { SerializationConfig serializationConfig; serializationConfig.setPortableVersion(1); serialization::pimpl::SerializationService serializationService(serializationConfig); @@ -356,13 +307,13 @@ namespace hazelcast { data = serializationService.toData(&x); boost::shared_ptr returnedInt = serializationService.toObject(data); - iTest::assertEqual(x, *returnedInt); + ASSERT_EQ(x, *returnedInt); short f = 2; data = serializationService.toData(&f); boost::shared_ptr temp = serializationService.toObject(data); - iTest::assertEqual(f, *temp); + ASSERT_EQ(f, *temp); TestNamedPortable np("name", 5); data = serializationService.toData(&np); @@ -372,8 +323,8 @@ namespace hazelcast { tnp2 = serializationService2.toObject(data); - iTest::assertEqual(np, *tnp1); - iTest::assertEqual(np, *tnp2); + ASSERT_EQ(np, *tnp1); + ASSERT_EQ(np, *tnp2); byte byteArray[] = {0, 1, 2}; std::vector bb(byteArray, byteArray + 3); @@ -405,22 +356,23 @@ namespace hazelcast { tip2 = serializationService2.toObject(data); - iTest::assertEqual(inner, *tip1); - iTest::assertEqual(inner, *tip2); + ASSERT_EQ(inner, *tip1); + ASSERT_EQ(inner, *tip2); - TestMainPortable main((byte)113, true, 'x', -500, 56789, -50992225, 900.5678f, -897543.3678909, "this is main portable object created for testing!", inner); + TestMainPortable main((byte) 113, true, 'x', -500, 56789, -50992225, 900.5678f, -897543.3678909, + "this is main portable object created for testing!", inner); data = serializationService.toData(&main); boost::shared_ptr tmp1, tmp2; tmp1 = serializationService.toObject(data); tmp2 = serializationService2.toObject(data); - iTest::assertEqual(main, *tmp1); - iTest::assertEqual(main, *tmp2); + ASSERT_EQ(main, *tmp1); + ASSERT_EQ(main, *tmp2); } - void ClientSerializationTest::testTemplatedPortable_whenMultipleTypesAreUsed() { + TEST_F(ClientSerializationTest, testTemplatedPortable_whenMultipleTypesAreUsed) { SerializationConfig serializationConfig; serialization::pimpl::SerializationService ss(serializationConfig); @@ -428,27 +380,21 @@ namespace hazelcast { ss.toData >(&portable); ParentTemplatedPortable portable2(new ChildTemplatedPortable2("ccc")); - bool expectedException = false; - try { - ss.toData >(&portable2); - } catch (exception::HazelcastSerializationException&) { - expectedException = true; - } - iTest::assertTrue(expectedException); - + ASSERT_THROW(ss.toData >(&portable2), + exception::HazelcastSerializationException); } - void ClientSerializationTest::testDataHash() { + TEST_F(ClientSerializationTest, testDataHash) { SerializationConfig serializationConfig; serialization::pimpl::SerializationService serializationService(serializationConfig); std::string serializable = "key1"; serialization::pimpl::Data data = serializationService.toData(&serializable); serialization::pimpl::Data data2 = serializationService.toData(&serializable); - iTest::assertEqual(data.getPartitionHash(), data2.getPartitionHash()); + ASSERT_EQ(data.getPartitionHash(), data2.getPartitionHash()); } - void ClientSerializationTest::testPrimitives() { + TEST_F(ClientSerializationTest, testPrimitives) { SerializationConfig serializationConfig; serialization::pimpl::SerializationService serializationService(serializationConfig); byte by = 2; @@ -457,24 +403,24 @@ namespace hazelcast { short s = 4; int i = 2000; long l = 321324141; - float f = 3.14f; + float f = 3.14f; double d = 3.14334; std::string str = "Hello world"; std::string utfStr = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム"; - iTest::assertEqual(by,toDataAndBackToObject(serializationService, by)); - iTest::assertEqual(boolean,toDataAndBackToObject(serializationService, boolean)); - iTest::assertEqual(c,toDataAndBackToObject(serializationService, c)); - iTest::assertEqual(s,toDataAndBackToObject(serializationService, s)); - iTest::assertEqual(i,toDataAndBackToObject(serializationService, i)); - iTest::assertEqual(l,toDataAndBackToObject(serializationService, l)); - iTest::assertEqual(f,toDataAndBackToObject(serializationService, f)); - iTest::assertEqual(d,toDataAndBackToObject(serializationService, d)); - iTest::assertEqual(str,toDataAndBackToObject(serializationService, str)); - iTest::assertEqual(utfStr,toDataAndBackToObject(serializationService, utfStr)); + ASSERT_EQ(by, toDataAndBackToObject(serializationService, by)); + ASSERT_EQ(boolean, toDataAndBackToObject(serializationService, boolean)); + ASSERT_EQ(c, toDataAndBackToObject(serializationService, c)); + ASSERT_EQ(s, toDataAndBackToObject(serializationService, s)); + ASSERT_EQ(i, toDataAndBackToObject(serializationService, i)); + ASSERT_EQ(l, toDataAndBackToObject(serializationService, l)); + ASSERT_EQ(f, toDataAndBackToObject(serializationService, f)); + ASSERT_EQ(d, toDataAndBackToObject(serializationService, d)); + ASSERT_EQ(str, toDataAndBackToObject(serializationService, str)); + ASSERT_EQ(utfStr, toDataAndBackToObject(serializationService, utfStr)); } - void ClientSerializationTest::testPrimitiveArrays() { + TEST_F(ClientSerializationTest, testPrimitiveArrays) { SerializationConfig serializationConfig; serialization::pimpl::SerializationService serializationService(serializationConfig); @@ -494,82 +440,91 @@ namespace hazelcast { std::vector dd(doubleArray, doubleArray + 3); const std::string stringArray[] = {"ali", "veli", "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム"}; std::vector stringVector; - for (int i = 0;i < 3; ++i) { + for (int i = 0; i < 3; ++i) { stringVector.push_back(stringArray[i]); } - iTest::assertEqual(cc, toDataAndBackToObject >(serializationService, cc)); - iTest::assertEqual(ba, toDataAndBackToObject > (serializationService, ba)); - iTest::assertEqual(ss, toDataAndBackToObject >(serializationService, ss)); - iTest::assertEqual(ii, toDataAndBackToObject >(serializationService, ii)); - iTest::assertEqual(ll, toDataAndBackToObject >(serializationService, ll)); - iTest::assertEqual(ff, toDataAndBackToObject >(serializationService, ff)); - iTest::assertEqual(dd, toDataAndBackToObject >(serializationService, dd)); - iTest::assertEqual(stringVector, toDataAndBackToObject >(serializationService, - stringVector)); + ASSERT_EQ(cc, toDataAndBackToObject >(serializationService, cc)); + ASSERT_EQ(ba, toDataAndBackToObject >(serializationService, ba)); + ASSERT_EQ(ss, toDataAndBackToObject >(serializationService, ss)); + ASSERT_EQ(ii, toDataAndBackToObject >(serializationService, ii)); + ASSERT_EQ(ll, toDataAndBackToObject >(serializationService, ll)); + ASSERT_EQ(ff, toDataAndBackToObject >(serializationService, ff)); + ASSERT_EQ(dd, toDataAndBackToObject >(serializationService, dd)); + ASSERT_EQ(stringVector, toDataAndBackToObject >(serializationService, + stringVector)); } - void ClientSerializationTest::testWriteObjectWithPortable() { + TEST_F(ClientSerializationTest, testWriteObjectWithPortable) { SerializationConfig serializationConfig; serialization::pimpl::SerializationService ss(serializationConfig); TestNamedPortable *namedPortable = new TestNamedPortable("name", 2); ObjectCarryingPortable objectCarryingPortable(namedPortable); - serialization::pimpl::Data data = ss.toData >(&objectCarryingPortable); - boost::shared_ptr > ptr = ss.toObject >(data); - iTest::assertEqual(objectCarryingPortable, *ptr); + serialization::pimpl::Data data = ss.toData >( + &objectCarryingPortable); + boost::shared_ptr > ptr = ss.toObject >( + data); + ASSERT_EQ(objectCarryingPortable, *ptr); } - void ClientSerializationTest::testWriteObjectWithIdentifiedDataSerializable() { + TEST_F(ClientSerializationTest, testWriteObjectWithIdentifiedDataSerializable) { SerializationConfig serializationConfig; serialization::pimpl::SerializationService ss(serializationConfig); TestDataSerializable *testDataSerializable = new TestDataSerializable(2, 'c'); ObjectCarryingPortable objectCarryingPortable(testDataSerializable); - serialization::pimpl::Data data = ss.toData >(&objectCarryingPortable); - boost::shared_ptr > ptr = ss.toObject >(data); - iTest::assertEqual(objectCarryingPortable, *ptr); + serialization::pimpl::Data data = ss.toData >( + &objectCarryingPortable); + boost::shared_ptr > ptr = ss.toObject >( + data); + ASSERT_EQ(objectCarryingPortable, *ptr); } - void ClientSerializationTest::testWriteObjectWithCustomXSerializable() { + TEST_F(ClientSerializationTest, testWriteObjectWithCustomXSerializable) { SerializationConfig serializationConfig; serialization::pimpl::SerializationService ss(serializationConfig); - boost::shared_ptr serializer(new TestCustomSerializerX()); + boost::shared_ptr serializer( + new TestCustomSerializerX()); ss.registerSerializer(serializer); - TestCustomXSerializable* customXSerializable = new TestCustomXSerializable(131321); + TestCustomXSerializable *customXSerializable = new TestCustomXSerializable(131321); ObjectCarryingPortable objectCarryingPortable(customXSerializable); - serialization::pimpl::Data data = ss.toData >(&objectCarryingPortable); - boost::shared_ptr > ptr = ss.toObject >(data); - iTest::assertEqual(objectCarryingPortable, *ptr); + serialization::pimpl::Data data = ss.toData >( + &objectCarryingPortable); + boost::shared_ptr > ptr = ss.toObject >( + data); + ASSERT_EQ(objectCarryingPortable, *ptr); } - void ClientSerializationTest::testWriteObjectWithCustomPersonSerializable() { + TEST_F(ClientSerializationTest, testWriteObjectWithCustomPersonSerializable) { SerializationConfig serializationConfig; serialization::pimpl::SerializationService ss(serializationConfig); boost::shared_ptr serializer(new TestCustomPersonSerializer()); ss.registerSerializer(serializer); - TestCustomPerson* testCustomPerson = new TestCustomPerson("TestCustomPerson"); + TestCustomPerson *testCustomPerson = new TestCustomPerson("TestCustomPerson"); ObjectCarryingPortable objectCarryingPortable(testCustomPerson); - serialization::pimpl::Data data = ss.toData >(&objectCarryingPortable); - boost::shared_ptr > ptr = ss.toObject >(data); - iTest::assertEqual(objectCarryingPortable, *ptr); + serialization::pimpl::Data data = ss.toData >( + &objectCarryingPortable); + boost::shared_ptr > ptr = ss.toObject >( + data); + ASSERT_EQ(objectCarryingPortable, *ptr); } - void ClientSerializationTest::testNullData() { + TEST_F(ClientSerializationTest, testNullData) { serialization::pimpl::Data data; SerializationConfig serializationConfig; serialization::pimpl::SerializationService ss(serializationConfig); boost::shared_ptr ptr = ss.toObject(data); - iTest::assertNull(ptr.get()); + ASSERT_EQ(ptr.get(), (int *)NULL); } - void ClientSerializationTest::testMorphingWithDifferentTypes_differentVersions() { + TEST_F(ClientSerializationTest, testMorphingWithDifferentTypes_differentVersions) { SerializationConfig serializationConfig; serializationConfig.setPortableVersion(1); serialization::pimpl::SerializationService serializationService(serializationConfig); @@ -582,10 +537,8 @@ namespace hazelcast { serialization::pimpl::Data data2 = serializationService2.toData(&p2); boost::shared_ptr t1 = serializationService.toObject(data2); - iTest::assertEqual(std::string("portable-v2"), t1->name); - iTest::assertEqual(123, t1->k); - - + ASSERT_EQ(std::string("portable-v2"), t1->name); + ASSERT_EQ(123, t1->k); } } } diff --git a/hazelcast/test/src/serialization/ClientSerializationTest.h b/hazelcast/test/src/serialization/ClientSerializationTest.h new file mode 100644 index 0000000000..7ab1e4bbf9 --- /dev/null +++ b/hazelcast/test/src/serialization/ClientSerializationTest.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Created by sancar koyunlu on 8/27/13. + + +#ifndef HAZELCAST_ClientSerializationTest +#define HAZELCAST_ClientSerializationTest + +#include + +namespace hazelcast { + namespace client { + namespace test { + class ClientSerializationTest : public ::testing::Test { + public: + template + T toDataAndBackToObject(serialization::pimpl::SerializationService& ss, T& value) { + serialization::pimpl::Data data = ss.toData(&value); + return *(ss.toObject(data)); + } + }; + } + } +} + +#endif //HAZELCAST_ClientSerializationTest + diff --git a/hazelcast/test/serialization/Employee.cpp b/hazelcast/test/src/serialization/Employee.cpp similarity index 100% rename from hazelcast/test/serialization/Employee.cpp rename to hazelcast/test/src/serialization/Employee.cpp diff --git a/hazelcast/test/serialization/Employee.h b/hazelcast/test/src/serialization/Employee.h similarity index 100% rename from hazelcast/test/serialization/Employee.h rename to hazelcast/test/src/serialization/Employee.h diff --git a/hazelcast/test/serialization/ObjectCarryingPortable.h b/hazelcast/test/src/serialization/ObjectCarryingPortable.h similarity index 100% rename from hazelcast/test/serialization/ObjectCarryingPortable.h rename to hazelcast/test/src/serialization/ObjectCarryingPortable.h diff --git a/hazelcast/test/serialization/ParentTemplatedPortable.h b/hazelcast/test/src/serialization/ParentTemplatedPortable.h similarity index 100% rename from hazelcast/test/serialization/ParentTemplatedPortable.h rename to hazelcast/test/src/serialization/ParentTemplatedPortable.h diff --git a/hazelcast/test/serialization/TestDataSerializable.cpp b/hazelcast/test/src/serialization/TestDataSerializable.cpp similarity index 100% rename from hazelcast/test/serialization/TestDataSerializable.cpp rename to hazelcast/test/src/serialization/TestDataSerializable.cpp diff --git a/hazelcast/test/serialization/TestDataSerializable.h b/hazelcast/test/src/serialization/TestDataSerializable.h similarity index 100% rename from hazelcast/test/serialization/TestDataSerializable.h rename to hazelcast/test/src/serialization/TestDataSerializable.h diff --git a/hazelcast/test/serialization/TestInnerPortable.cpp b/hazelcast/test/src/serialization/TestInnerPortable.cpp similarity index 100% rename from hazelcast/test/serialization/TestInnerPortable.cpp rename to hazelcast/test/src/serialization/TestInnerPortable.cpp diff --git a/hazelcast/test/serialization/TestInnerPortable.h b/hazelcast/test/src/serialization/TestInnerPortable.h similarity index 100% rename from hazelcast/test/serialization/TestInnerPortable.h rename to hazelcast/test/src/serialization/TestInnerPortable.h diff --git a/hazelcast/test/serialization/TestInvalidReadPortable.cpp b/hazelcast/test/src/serialization/TestInvalidReadPortable.cpp similarity index 100% rename from hazelcast/test/serialization/TestInvalidReadPortable.cpp rename to hazelcast/test/src/serialization/TestInvalidReadPortable.cpp diff --git a/hazelcast/test/serialization/TestInvalidReadPortable.h b/hazelcast/test/src/serialization/TestInvalidReadPortable.h similarity index 100% rename from hazelcast/test/serialization/TestInvalidReadPortable.h rename to hazelcast/test/src/serialization/TestInvalidReadPortable.h diff --git a/hazelcast/test/serialization/TestInvalidWritePortable.cpp b/hazelcast/test/src/serialization/TestInvalidWritePortable.cpp similarity index 100% rename from hazelcast/test/serialization/TestInvalidWritePortable.cpp rename to hazelcast/test/src/serialization/TestInvalidWritePortable.cpp diff --git a/hazelcast/test/serialization/TestInvalidWritePortable.h b/hazelcast/test/src/serialization/TestInvalidWritePortable.h similarity index 100% rename from hazelcast/test/serialization/TestInvalidWritePortable.h rename to hazelcast/test/src/serialization/TestInvalidWritePortable.h diff --git a/hazelcast/test/serialization/TestMainPortable.cpp b/hazelcast/test/src/serialization/TestMainPortable.cpp similarity index 100% rename from hazelcast/test/serialization/TestMainPortable.cpp rename to hazelcast/test/src/serialization/TestMainPortable.cpp diff --git a/hazelcast/test/serialization/TestMainPortable.h b/hazelcast/test/src/serialization/TestMainPortable.h similarity index 100% rename from hazelcast/test/serialization/TestMainPortable.h rename to hazelcast/test/src/serialization/TestMainPortable.h diff --git a/hazelcast/test/serialization/TestNamedPortable.cpp b/hazelcast/test/src/serialization/TestNamedPortable.cpp similarity index 100% rename from hazelcast/test/serialization/TestNamedPortable.cpp rename to hazelcast/test/src/serialization/TestNamedPortable.cpp diff --git a/hazelcast/test/serialization/TestNamedPortable.h b/hazelcast/test/src/serialization/TestNamedPortable.h similarity index 100% rename from hazelcast/test/serialization/TestNamedPortable.h rename to hazelcast/test/src/serialization/TestNamedPortable.h diff --git a/hazelcast/test/serialization/TestNamedPortableV2.cpp b/hazelcast/test/src/serialization/TestNamedPortableV2.cpp similarity index 100% rename from hazelcast/test/serialization/TestNamedPortableV2.cpp rename to hazelcast/test/src/serialization/TestNamedPortableV2.cpp diff --git a/hazelcast/test/serialization/TestNamedPortableV2.h b/hazelcast/test/src/serialization/TestNamedPortableV2.h similarity index 100% rename from hazelcast/test/serialization/TestNamedPortableV2.h rename to hazelcast/test/src/serialization/TestNamedPortableV2.h diff --git a/hazelcast/test/serialization/TestNamedPortableV3.cpp b/hazelcast/test/src/serialization/TestNamedPortableV3.cpp similarity index 100% rename from hazelcast/test/serialization/TestNamedPortableV3.cpp rename to hazelcast/test/src/serialization/TestNamedPortableV3.cpp diff --git a/hazelcast/test/serialization/TestNamedPortableV3.h b/hazelcast/test/src/serialization/TestNamedPortableV3.h similarity index 100% rename from hazelcast/test/serialization/TestNamedPortableV3.h rename to hazelcast/test/src/serialization/TestNamedPortableV3.h diff --git a/hazelcast/test/serialization/TestRawDataPortable.cpp b/hazelcast/test/src/serialization/TestRawDataPortable.cpp similarity index 100% rename from hazelcast/test/serialization/TestRawDataPortable.cpp rename to hazelcast/test/src/serialization/TestRawDataPortable.cpp diff --git a/hazelcast/test/serialization/TestRawDataPortable.h b/hazelcast/test/src/serialization/TestRawDataPortable.h similarity index 100% rename from hazelcast/test/serialization/TestRawDataPortable.h rename to hazelcast/test/src/serialization/TestRawDataPortable.h diff --git a/hazelcast/test/serialization/TestSerializationConstants.h b/hazelcast/test/src/serialization/TestSerializationConstants.h similarity index 100% rename from hazelcast/test/serialization/TestSerializationConstants.h rename to hazelcast/test/src/serialization/TestSerializationConstants.h diff --git a/hazelcast/test/src/set/ClientSetTest.cpp b/hazelcast/test/src/set/ClientSetTest.cpp new file mode 100644 index 0000000000..d8e15fce59 --- /dev/null +++ b/hazelcast/test/src/set/ClientSetTest.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Created by sancar koyunlu on 9/13/13. + +#include "ClientSetTest.h" +#include "hazelcast/client/HazelcastClient.h" +#include "HazelcastServerFactory.h" + +namespace hazelcast { + namespace client { + namespace test { + ClientSetTest::ClientSetTest() + : instance(*g_srvFactory) + , client(getNewClient()) + , set(new ISet(client->getSet< std::string >("ClientSetTest"))) { + } + + + ClientSetTest::~ClientSetTest() { + } + + TEST_F(ClientSetTest, testAddAll) { + std::vector l; + l.push_back("item1"); + l.push_back("item2"); + + ASSERT_TRUE(set->addAll(l)); + ASSERT_EQ(2, set->size()); + + ASSERT_FALSE(set->addAll(l)); + ASSERT_EQ(2, set->size()); + + } + + TEST_F(ClientSetTest, testAddRemove) { + ASSERT_TRUE(set->add("item1")); + ASSERT_TRUE(set->add("item2")); + ASSERT_TRUE(set->add("item3")); + ASSERT_EQ(3, set->size()); + + ASSERT_FALSE(set->add("item3")); + ASSERT_EQ(3, set->size()); + + + ASSERT_FALSE(set->remove("item4")); + ASSERT_TRUE(set->remove("item3")); + + } + + TEST_F(ClientSetTest, testContains) { + ASSERT_TRUE(set->add("item1")); + ASSERT_TRUE(set->add("item2")); + ASSERT_TRUE(set->add("item3")); + ASSERT_TRUE(set->add("item4")); + + ASSERT_FALSE(set->contains("item5")); + ASSERT_TRUE(set->contains("item2")); + + std::vector l; + l.push_back("item6"); + l.push_back("item3"); + + ASSERT_FALSE(set->containsAll(l)); + ASSERT_TRUE(set->add("item6")); + ASSERT_TRUE(set->containsAll(l)); + } + + + TEST_F(ClientSetTest, testRemoveRetainAll) { + ASSERT_TRUE(set->add("item1")); + ASSERT_TRUE(set->add("item2")); + ASSERT_TRUE(set->add("item3")); + ASSERT_TRUE(set->add("item4")); + + std::vector l; + l.push_back("item4"); + l.push_back("item3"); + + ASSERT_TRUE(set->removeAll(l)); + ASSERT_EQ(2, set->size()); + ASSERT_FALSE(set->removeAll(l)); + ASSERT_EQ(2, set->size()); + + l.clear(); + l.push_back("item1"); + l.push_back("item2"); + ASSERT_FALSE(set->retainAll(l)); + ASSERT_EQ(2, set->size()); + + l.clear(); + ASSERT_TRUE(set->retainAll(l)); + ASSERT_EQ(0, set->size()); + + } + + class MySetItemListener : public ItemListener { + public: + MySetItemListener(util::CountDownLatch &latch) + :latch(latch) { + + } + + void itemAdded(const ItemEvent& itemEvent) { + latch.countDown(); + } + + void itemRemoved(const ItemEvent& item) { + } + + private: + util::CountDownLatch &latch; + }; + + + TEST_F(ClientSetTest, testListener) { + util::CountDownLatch latch(6); + + MySetItemListener listener(latch); + std::string registrationId = set->addItemListener(listener, true); + + for (int i = 0; i < 5; i++) { + set->add(std::string("item") + util::IOUtil::to_string(i)); + } + set->add("done"); + + ASSERT_TRUE(latch.await(20 )); + + ASSERT_TRUE(set->removeItemListener(registrationId)); + } + + } + } +} + diff --git a/hazelcast/test/set/ClientSetTest.h b/hazelcast/test/src/set/ClientSetTest.h similarity index 69% rename from hazelcast/test/set/ClientSetTest.h rename to hazelcast/test/src/set/ClientSetTest.h index 12988ad777..54326c0a1d 100644 --- a/hazelcast/test/set/ClientSetTest.h +++ b/hazelcast/test/src/set/ClientSetTest.h @@ -29,40 +29,15 @@ namespace hazelcast { namespace client { - class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class ClientSetTest : public ClientTestSupport { + class ClientSetTest : public ClientTestSupport { public: - ClientSetTest(HazelcastServerFactory &); + ClientSetTest(); ~ClientSetTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testAddAll(); - - void testAddRemove(); - - void testContains(); - - void testRemoveRetainAll(); - - void testListener(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; diff --git a/hazelcast/test/topic/ClientTopicTest.cpp b/hazelcast/test/src/topic/ClientTopicTest.cpp similarity index 68% rename from hazelcast/test/topic/ClientTopicTest.cpp rename to hazelcast/test/src/topic/ClientTopicTest.cpp index e3ebd3daf4..c745779a98 100644 --- a/hazelcast/test/topic/ClientTopicTest.cpp +++ b/hazelcast/test/src/topic/ClientTopicTest.cpp @@ -23,34 +23,12 @@ namespace hazelcast { class HazelcastClient; namespace test { - using namespace iTest; - - ClientTopicTest::ClientTopicTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("ClientTopicTest" , &serverFactory) - , instance(serverFactory) + ClientTopicTest::ClientTopicTest() + : instance(*g_srvFactory) , client(getNewClient()) , topic(new ITopic(client->getTopic("ClientTopicTest"))) { } - - void ClientTopicTest::addTests() { - addTest(&ClientTopicTest::testTopicListeners, "testTopicListeners"); - } - - void ClientTopicTest::beforeClass() { - } - - void ClientTopicTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ClientTopicTest::beforeTest() { - } - - void ClientTopicTest::afterTest() { - } - class MyMessageListener { public: MyMessageListener(util::CountDownLatch &latch) @@ -66,7 +44,7 @@ namespace hazelcast { util::CountDownLatch &latch; }; - void ClientTopicTest::testTopicListeners() { + TEST_F(ClientTopicTest, testTopicListeners) { util::CountDownLatch latch(10); MyMessageListener listener(latch); @@ -75,9 +53,8 @@ namespace hazelcast { for (int i = 0; i < 10; i++) { topic->publish(std::string("naber") + util::IOUtil::to_string(i)); } - assertTrue(latch.await(20 )); + ASSERT_TRUE(latch.await(20 )); topic->removeMessageListener(id); - } } } diff --git a/hazelcast/test/topic/ClientTopicTest.h b/hazelcast/test/src/topic/ClientTopicTest.h similarity index 75% rename from hazelcast/test/topic/ClientTopicTest.h rename to hazelcast/test/src/topic/ClientTopicTest.h index dd60b004e7..b8b7bca2fe 100644 --- a/hazelcast/test/topic/ClientTopicTest.h +++ b/hazelcast/test/src/topic/ClientTopicTest.h @@ -31,32 +31,14 @@ namespace hazelcast { namespace client { - class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class ClientTopicTest : public ClientTestSupport { - + class ClientTopicTest : public ClientTestSupport { public: + ClientTopicTest(); - ClientTopicTest(HazelcastServerFactory &); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testTopicListeners(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; diff --git a/hazelcast/test/txn/ClientTxnListTest.cpp b/hazelcast/test/src/txn/ClientTxnListTest.cpp similarity index 57% rename from hazelcast/test/txn/ClientTxnListTest.cpp rename to hazelcast/test/src/txn/ClientTxnListTest.cpp index f092c48ff2..bac424e3dd 100644 --- a/hazelcast/test/txn/ClientTxnListTest.cpp +++ b/hazelcast/test/src/txn/ClientTxnListTest.cpp @@ -16,67 +16,40 @@ // // Created by sancar koyunlu on 9/18/13. - - #include "ClientTxnListTest.h" #include "HazelcastServerFactory.h" #include "hazelcast/client/HazelcastClient.h" namespace hazelcast { namespace client { - class HazelcastClient; namespace test { - using namespace iTest; - - ClientTxnListTest::ClientTxnListTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("ClientTxnListTest" , &serverFactory) - , instance(serverFactory) + ClientTxnListTest::ClientTxnListTest() + : instance(*g_srvFactory) , client(getNewClient()) { } - ClientTxnListTest::~ClientTxnListTest() { } - void ClientTxnListTest::addTests() { - addTest(&ClientTxnListTest::testAddRemove, "testAddRemove"); - } - - void ClientTxnListTest::beforeClass() { - } - - void ClientTxnListTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ClientTxnListTest::beforeTest() { - } - - void ClientTxnListTest::afterTest() { - } - - void ClientTxnListTest::testAddRemove() { + TEST_F(ClientTxnListTest, testAddRemove) { IList l = client->getList("testAddRemove"); l.add("item1"); TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalList list = context.getList("testAddRemove"); - assertTrue(list.add("item2")); - assertEqual(2, list.size()); - assertEqual(1, l.size()); - assertFalse(list.remove("item3")); - assertTrue(list.remove("item1")); + ASSERT_TRUE(list.add("item2")); + ASSERT_EQ(2, list.size()); + ASSERT_EQ(1, l.size()); + ASSERT_FALSE(list.remove("item3")); + ASSERT_TRUE(list.remove("item1")); context.commitTransaction(); - assertEqual(1, l.size()); + ASSERT_EQ(1, l.size()); } - - } } } diff --git a/hazelcast/test/txn/ClientTxnListTest.h b/hazelcast/test/src/txn/ClientTxnListTest.h similarity index 73% rename from hazelcast/test/txn/ClientTxnListTest.h rename to hazelcast/test/src/txn/ClientTxnListTest.h index 0d7ea7e3da..5938791308 100644 --- a/hazelcast/test/txn/ClientTxnListTest.h +++ b/hazelcast/test/src/txn/ClientTxnListTest.h @@ -16,47 +16,25 @@ // // Created by sancar koyunlu on 9/18/13. - - - #ifndef HAZELCAST_ClientTxnListTest #define HAZELCAST_ClientTxnListTest - #include "ClientTestSupport.h" #include "hazelcast/client/ClientConfig.h" #include "HazelcastServer.h" namespace hazelcast { namespace client { - class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class ClientTxnListTest : public ClientTestSupport { + class ClientTxnListTest : public ClientTestSupport { public: - - ClientTxnListTest(HazelcastServerFactory &); + ClientTxnListTest(); ~ClientTxnListTest(); - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testAddRemove(); - - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; diff --git a/hazelcast/test/txn/ClientTxnMapTest.cpp b/hazelcast/test/src/txn/ClientTxnMapTest.cpp similarity index 64% rename from hazelcast/test/txn/ClientTxnMapTest.cpp rename to hazelcast/test/src/txn/ClientTxnMapTest.cpp index 8d56a532a0..ac4a1334f0 100644 --- a/hazelcast/test/txn/ClientTxnMapTest.cpp +++ b/hazelcast/test/src/txn/ClientTxnMapTest.cpp @@ -30,39 +30,15 @@ namespace hazelcast { class HazelcastClient; namespace test { - using namespace iTest; - - ClientTxnMapTest::ClientTxnMapTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("ClientTxnMapTest" , &serverFactory) - , instance(serverFactory) + ClientTxnMapTest::ClientTxnMapTest() + : instance(*g_srvFactory) , client(getNewClient()) { } - - + ClientTxnMapTest::~ClientTxnMapTest() { } - void ClientTxnMapTest::addTests() { - addTest(&ClientTxnMapTest::testPutGet, "testPutGet"); - addTest(&ClientTxnMapTest::testKeySetValues, "testKeySetValues"); - addTest(&ClientTxnMapTest::testKeySetAndValuesWithPredicates, "testKeysetAndValuesWithPredicates"); - } - - void ClientTxnMapTest::beforeClass() { - } - - void ClientTxnMapTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ClientTxnMapTest::beforeTest() { - } - - void ClientTxnMapTest::afterTest() { - } - - void ClientTxnMapTest::testPutGet() { + TEST_F(ClientTxnMapTest, testPutGet) { std::string name = "defMap"; TransactionContext context = client->newTransactionContext(); @@ -70,13 +46,14 @@ namespace hazelcast { TransactionalMap map = context.getMap(name); - assertNull(map.put("key1", "value1").get()); - assertEqual("value1", *(map.get("key1"))); - assertNull(client->getMap(name).get("key1").get()); + ASSERT_EQ(map.put("key1", "value1").get(), (std::string *)NULL); + ASSERT_EQ("value1", *(map.get("key1"))); + boost::shared_ptr val = client->getMap(name).get("key1"); + ASSERT_EQ(val.get(), (std::string *)NULL); context.commitTransaction(); - assertEqual("value1", *(client->getMap(name).get("key1"))); + ASSERT_EQ("value1", *(client->getMap(name).get("key1"))); } @@ -117,7 +94,7 @@ namespace hazelcast { // assertTrue(map.tryPut("var", 1, 0, TimeUnit.SECONDS)); // } - void ClientTxnMapTest::testKeySetValues() { + TEST_F(ClientTxnMapTest, testKeySetValues) { std::string name = "testKeySetValues"; IMap map = client->getMap(name); map.put("key1", "value1"); @@ -126,21 +103,21 @@ namespace hazelcast { TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalMap txMap = context.getMap(name); - assertNull(txMap.put("key3", "value3").get()); + ASSERT_EQ(txMap.put("key3", "value3").get(), (std::string *)NULL); - assertEqual(3, (int)txMap.size()); - assertEqual(3, (int)txMap.keySet().size()); - assertEqual(3, (int)txMap.values().size()); + ASSERT_EQ(3, (int)txMap.size()); + ASSERT_EQ(3, (int)txMap.keySet().size()); + ASSERT_EQ(3, (int)txMap.values().size()); context.commitTransaction(); - assertEqual(3, (int)map.size()); - assertEqual(3, (int)map.keySet().size()); - assertEqual(3, (int)map.values().size()); + ASSERT_EQ(3, (int)map.size()); + ASSERT_EQ(3, (int)map.keySet().size()); + ASSERT_EQ(3, (int)map.values().size()); } - void ClientTxnMapTest::testKeySetAndValuesWithPredicates() { + TEST_F(ClientTxnMapTest, testKeySetAndValuesWithPredicates) { std::string name = "testKeysetAndValuesWithPredicates"; IMap map = client->getMap(name); @@ -153,23 +130,21 @@ namespace hazelcast { context.beginTransaction(); TransactionalMap txMap = context.getMap(name); - assertNull(txMap.put(emp2, emp2).get()); + ASSERT_EQ(txMap.put(emp2, emp2).get(), (Employee *)NULL); - assertEqual(2, (int)txMap.size()); - assertEqual(2, (int)txMap.keySet().size()); + ASSERT_EQ(2, (int)txMap.size()); + ASSERT_EQ(2, (int)txMap.keySet().size()); query::SqlPredicate predicate("a = 10"); - assertEqual(0, (int)txMap.keySet(&predicate).size()); - assertEqual(0, (int)txMap.values(&predicate).size()); + ASSERT_EQ(0, (int)txMap.keySet(&predicate).size()); + ASSERT_EQ(0, (int)txMap.values(&predicate).size()); predicate.setSql("a >= 10"); - assertEqual(2, (int)txMap.keySet(&predicate).size()); - assertEqual(2, (int)txMap.values(&predicate).size()); + ASSERT_EQ(2, (int)txMap.keySet(&predicate).size()); + ASSERT_EQ(2, (int)txMap.values(&predicate).size()); context.commitTransaction(); - assertEqual(2, (int)map.size()); - assertEqual(2, (int)map.values().size()); - - + ASSERT_EQ(2, (int)map.size()); + ASSERT_EQ(2, (int)map.values().size()); } } diff --git a/hazelcast/test/txn/ClientTxnMapTest.h b/hazelcast/test/src/txn/ClientTxnMapTest.h similarity index 69% rename from hazelcast/test/txn/ClientTxnMapTest.h rename to hazelcast/test/src/txn/ClientTxnMapTest.h index 3a5d53a03f..12d93d1d0e 100644 --- a/hazelcast/test/txn/ClientTxnMapTest.h +++ b/hazelcast/test/src/txn/ClientTxnMapTest.h @@ -28,37 +28,16 @@ namespace hazelcast { namespace client { - class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class ClientTxnMapTest : public ClientTestSupport { + class ClientTxnMapTest : public ClientTestSupport { public: - - ClientTxnMapTest(HazelcastServerFactory &); + ClientTxnMapTest(); ~ClientTxnMapTest(); - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testPutGet(); - - void testKeySetAndValuesWithPredicates(); - - void testKeySetValues(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; diff --git a/hazelcast/test/txn/ClientTxnMultiMapTest.cpp b/hazelcast/test/src/txn/ClientTxnMultiMapTest.cpp similarity index 52% rename from hazelcast/test/txn/ClientTxnMultiMapTest.cpp rename to hazelcast/test/src/txn/ClientTxnMultiMapTest.cpp index 1d581569e1..c9829bed0b 100644 --- a/hazelcast/test/txn/ClientTxnMultiMapTest.cpp +++ b/hazelcast/test/src/txn/ClientTxnMultiMapTest.cpp @@ -29,83 +29,47 @@ namespace hazelcast { class HazelcastClient; namespace test { - using namespace iTest; - - ClientTxnMultiMapTest::ClientTxnMultiMapTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("ClientTxnMultiMapTest" , &serverFactory) - , instance(serverFactory) + ClientTxnMultiMapTest::ClientTxnMultiMapTest() + : instance(*g_srvFactory) , client(getNewClient()) { } - - + ClientTxnMultiMapTest::~ClientTxnMultiMapTest() { } - void ClientTxnMultiMapTest::addTests() { - addTest(&ClientTxnMultiMapTest::testPutGetRemove, "testPutGetRemove"); - } - - void ClientTxnMultiMapTest::beforeClass() { - } - - void ClientTxnMultiMapTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ClientTxnMultiMapTest::beforeTest() { - } - - void ClientTxnMultiMapTest::afterTest() { - } - void putGetRemoveTestThread(util::ThreadArgs& args) { MultiMap *mm = (MultiMap *)args.arg0; HazelcastClient *client = (HazelcastClient *)args.arg1; util::CountDownLatch *latch = (util::CountDownLatch *)args.arg2; - util::AtomicInt *error = (util::AtomicInt *)args.arg3; std::string key = util::IOUtil::to_string(util::Thread::getThreadID()); client->getMultiMap("testPutGetRemove").put(key, "value"); TransactionContext context = client->newTransactionContext(); - try { - context.beginTransaction(); - TransactionalMultiMap multiMap = context.getMultiMap("testPutGetRemove"); - assertFalse(multiMap.put(key, "value")); - assertTrue(multiMap.put(key, "value1")); - assertTrue(multiMap.put(key, "value2")); - assertEqual(3, (int)multiMap.get(key).size()); - context.commitTransaction(); + context.beginTransaction(); + TransactionalMultiMap multiMap = context.getMultiMap("testPutGetRemove"); + ASSERT_FALSE(multiMap.put(key, "value")); + ASSERT_TRUE(multiMap.put(key, "value1")); + ASSERT_TRUE(multiMap.put(key, "value2")); + ASSERT_EQ(3, (int)multiMap.get(key).size()); + context.commitTransaction(); - assertEqual(3, (int)mm->get(key).size()); + ASSERT_EQ(3, (int)mm->get(key).size()); - latch->countDown(); - } catch (std::exception &) { - ++(*error); - latch->countDown(); - } catch(iTest::iTestException&){ - ++(*error); - latch->countDown(); - } + latch->countDown(); } - void ClientTxnMultiMapTest::testPutGetRemove() { - + TEST_F(ClientTxnMultiMapTest, testPutGetRemove) { MultiMap mm = client->getMultiMap("testPutGetRemove"); int n = 10; util::CountDownLatch latch(n); - util::AtomicInt error(0); std::vector threads(n); for (int i = 0; i < n; i++) { - threads[i] = new util::Thread(putGetRemoveTestThread, &mm, client.get(), &latch, &error); + threads[i] = new util::Thread(putGetRemoveTestThread, &mm, client.get(), &latch); } - assertTrue(latch.await(1)); - assertEqual(0, (int)error); + ASSERT_TRUE(latch.await(1)); for (int i = 0; i < n; i++) { delete threads[i] ; } } - - } } } diff --git a/hazelcast/test/txn/ClientTxnMultiMapTest.h b/hazelcast/test/src/txn/ClientTxnMultiMapTest.h similarity index 77% rename from hazelcast/test/txn/ClientTxnMultiMapTest.h rename to hazelcast/test/src/txn/ClientTxnMultiMapTest.h index 021a71d1bf..a9b3a35b65 100644 --- a/hazelcast/test/txn/ClientTxnMultiMapTest.h +++ b/hazelcast/test/src/txn/ClientTxnMultiMapTest.h @@ -32,30 +32,13 @@ namespace hazelcast { class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class ClientTxnMultiMapTest : public ClientTestSupport { - + class ClientTxnMultiMapTest : public ClientTestSupport { public: - - ClientTxnMultiMapTest(HazelcastServerFactory &); + ClientTxnMultiMapTest(); ~ClientTxnMultiMapTest(); - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testPutGetRemove(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; diff --git a/hazelcast/test/txn/ClientTxnQueueTest.cpp b/hazelcast/test/src/txn/ClientTxnQueueTest.cpp similarity index 59% rename from hazelcast/test/txn/ClientTxnQueueTest.cpp rename to hazelcast/test/src/txn/ClientTxnQueueTest.cpp index 4af2f21dfc..bd30eff614 100644 --- a/hazelcast/test/txn/ClientTxnQueueTest.cpp +++ b/hazelcast/test/src/txn/ClientTxnQueueTest.cpp @@ -16,8 +16,6 @@ // // Created by sancar koyunlu on 9/18/13. - - #include "ClientTxnQueueTest.h" #include "HazelcastServerFactory.h" #include "hazelcast/client/HazelcastClient.h" @@ -26,51 +24,25 @@ namespace hazelcast { namespace client { - - class HazelcastClient; - namespace test { - using namespace iTest; - - ClientTxnQueueTest::ClientTxnQueueTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("ClientTxnQueueTest" , &serverFactory) - , instance(serverFactory) + ClientTxnQueueTest::ClientTxnQueueTest() + : instance(*g_srvFactory) , client(getNewClient()) { } - - + ClientTxnQueueTest::~ClientTxnQueueTest() { } - void ClientTxnQueueTest::addTests() { - addTest(&ClientTxnQueueTest::testTransactionalOfferPoll1, "testTransactionalOfferPoll1"); - addTest(&ClientTxnQueueTest::testTransactionalOfferPoll2, "testTransactionalOfferPoll2"); - } - - void ClientTxnQueueTest::beforeClass() { - } - - void ClientTxnQueueTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ClientTxnQueueTest::beforeTest() { - } - - void ClientTxnQueueTest::afterTest() { - } - - void ClientTxnQueueTest::testTransactionalOfferPoll1() { + TEST_F(ClientTxnQueueTest, testTransactionalOfferPoll1) { std::string name = "defQueue"; TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalQueue q = context.getQueue(name); - assertTrue(q.offer("ali")); - assertEqual("ali", *(q.poll())); + ASSERT_TRUE(q.offer("ali")); + ASSERT_EQ("ali", *(q.poll())); context.commitTransaction(); - assertEqual(0, client->getQueue(name).size()); + ASSERT_EQ(0, client->getQueue(name).size()); } void testTransactionalOfferPoll2Thread(util::ThreadArgs& args) { @@ -80,8 +52,7 @@ namespace hazelcast { client->getQueue("defQueue0").offer("item0"); } - void ClientTxnQueueTest::testTransactionalOfferPoll2() { - + TEST_F(ClientTxnQueueTest, testTransactionalOfferPoll2) { util::CountDownLatch latch(1); util::Thread t(testTransactionalOfferPoll2Thread, &latch, client.get()); TransactionContext context = client->newTransactionContext(); @@ -91,20 +62,14 @@ namespace hazelcast { boost::shared_ptr s; latch.countDown(); s = q0.poll(10 * 1000); - assertEqual("item0", *s); + ASSERT_EQ("item0", *s); q1.offer(*s); - try { - context.commitTransaction(); - } catch (exception::IException &e) { - assertTrue(false, e.what()); - } + ASSERT_NO_THROW(context.commitTransaction()); - assertEqual(0, client->getQueue("defQueue0").size()); - assertEqual("item0", *(client->getQueue("defQueue1").poll())); + ASSERT_EQ(0, client->getQueue("defQueue0").size()); + ASSERT_EQ("item0", *(client->getQueue("defQueue1").poll())); } - - } } } diff --git a/hazelcast/test/txn/ClientTxnQueueTest.h b/hazelcast/test/src/txn/ClientTxnQueueTest.h similarity index 70% rename from hazelcast/test/txn/ClientTxnQueueTest.h rename to hazelcast/test/src/txn/ClientTxnQueueTest.h index 345aaf1c05..4978e64192 100644 --- a/hazelcast/test/txn/ClientTxnQueueTest.h +++ b/hazelcast/test/src/txn/ClientTxnQueueTest.h @@ -16,9 +16,6 @@ // // Created by sancar koyunlu on 9/18/13. - - - #ifndef HAZELCAST_ClientTxnQueueTest #define HAZELCAST_ClientTxnQueueTest @@ -32,37 +29,16 @@ namespace hazelcast { class HazelcastClient; namespace test { - - class HazelcastServerFactory; - - class ClientTxnQueueTest : public ClientTestSupport { - + class ClientTxnQueueTest : public ClientTestSupport { public: - - ClientTxnQueueTest(HazelcastServerFactory &); + ClientTxnQueueTest(); ~ClientTxnQueueTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testTransactionalOfferPoll1(); - - void testTransactionalOfferPoll2(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; }; - } } } diff --git a/hazelcast/test/txn/ClientTxnSetTest.cpp b/hazelcast/test/src/txn/ClientTxnSetTest.cpp similarity index 57% rename from hazelcast/test/txn/ClientTxnSetTest.cpp rename to hazelcast/test/src/txn/ClientTxnSetTest.cpp index a9ad190a9a..16e63810fc 100644 --- a/hazelcast/test/txn/ClientTxnSetTest.cpp +++ b/hazelcast/test/src/txn/ClientTxnSetTest.cpp @@ -16,8 +16,6 @@ // // Created by sancar koyunlu on 9/18/13. - - #include "ClientTxnSetTest.h" #include "HazelcastServerFactory.h" #include "hazelcast/client/HazelcastClient.h" @@ -28,55 +26,31 @@ namespace hazelcast { class HazelcastClient; namespace test { - using namespace iTest; - - ClientTxnSetTest::ClientTxnSetTest(HazelcastServerFactory &serverFactory) - : ClientTestSupport("ClientTxnSetTest" , &serverFactory) - , instance(serverFactory) + ClientTxnSetTest::ClientTxnSetTest() + : instance(*g_srvFactory) , client(getNewClient()) { } - - + ClientTxnSetTest::~ClientTxnSetTest() { } - void ClientTxnSetTest::addTests() { - addTest(&ClientTxnSetTest::testAddRemove, "testAddRemove"); - } - - void ClientTxnSetTest::beforeClass() { - } - - void ClientTxnSetTest::afterClass() { - client.reset(); - instance.shutdown(); - } - - void ClientTxnSetTest::beforeTest() { - } - - void ClientTxnSetTest::afterTest() { - } - - void ClientTxnSetTest::testAddRemove() { + TEST_F(ClientTxnSetTest, testAddRemove) { ISet s = client->getSet("testAddRemove"); s.add("item1"); TransactionContext context = client->newTransactionContext(); context.beginTransaction(); TransactionalSet set = context.getSet("testAddRemove"); - assertTrue(set.add("item2")); - assertEqual(2, set.size()); - assertEqual(1, s.size()); - assertFalse(set.remove("item3")); - assertTrue(set.remove("item1")); + ASSERT_TRUE(set.add("item2")); + ASSERT_EQ(2, set.size()); + ASSERT_EQ(1, s.size()); + ASSERT_FALSE(set.remove("item3")); + ASSERT_TRUE(set.remove("item1")); context.commitTransaction(); - assertEqual(1, s.size()); + ASSERT_EQ(1, s.size()); } - - } } } diff --git a/hazelcast/test/txn/ClientTxnSetTest.h b/hazelcast/test/src/txn/ClientTxnSetTest.h similarity index 71% rename from hazelcast/test/txn/ClientTxnSetTest.h rename to hazelcast/test/src/txn/ClientTxnSetTest.h index daba7b4748..9ac90bc3f1 100644 --- a/hazelcast/test/txn/ClientTxnSetTest.h +++ b/hazelcast/test/src/txn/ClientTxnSetTest.h @@ -16,9 +16,6 @@ // // Created by sancar koyunlu on 9/18/13. - - - #ifndef HAZELCAST_ClientTxnSetTest #define HAZELCAST_ClientTxnSetTest @@ -28,38 +25,18 @@ namespace hazelcast { namespace client { - - class HazelcastClient; - namespace test { - - class HazelcastServerFactory; - - class ClientTxnSetTest : public ClientTestSupport { + class ClientTxnSetTest : public ClientTestSupport { public: - - ClientTxnSetTest(HazelcastServerFactory &); + ClientTxnSetTest(); ~ClientTxnSetTest(); - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testAddRemove(); - - private: + protected: HazelcastServer instance; ClientConfig clientConfig; std::auto_ptr client; }; - } } } diff --git a/hazelcast/test/txn/ClientTxnTest.cpp b/hazelcast/test/src/txn/ClientTxnTest.cpp similarity index 63% rename from hazelcast/test/txn/ClientTxnTest.cpp rename to hazelcast/test/src/txn/ClientTxnTest.cpp index c06259ec34..7efb6c8f50 100644 --- a/hazelcast/test/txn/ClientTxnTest.cpp +++ b/hazelcast/test/src/txn/ClientTxnTest.cpp @@ -16,8 +16,6 @@ // // Created by sancar koyunlu on 9/18/13. - - #include "ClientTxnTest.h" #include "HazelcastServerFactory.h" #include "hazelcast/client/HazelcastClient.h" @@ -25,12 +23,7 @@ namespace hazelcast { namespace client { - - class HazelcastClient; - namespace test { - using namespace iTest; - class MyLoadBalancer : public impl::AbstractLoadBalancer { public: const Member next() { @@ -72,27 +65,8 @@ namespace hazelcast { util::CountDownLatch& countDownLatch; }; - ClientTxnTest::ClientTxnTest(HazelcastServerFactory& hazelcastInstanceFactory) - : ClientTestSupport("ClientTxnTest" , &hazelcastInstanceFactory) - , hazelcastInstanceFactory(hazelcastInstanceFactory) { - } - - - ClientTxnTest::~ClientTxnTest() { - } - - void ClientTxnTest::addTests() { - addTest(&ClientTxnTest::testTxnRollback, "testTxnRollback"); - addTest(&ClientTxnTest::testTxnRollbackOnServerCrash, "testTxnRollbackOnServerCrash"); - } - - void ClientTxnTest::beforeClass() { - } - - void ClientTxnTest::afterClass() { - } - - void ClientTxnTest::beforeTest() { + ClientTxnTest::ClientTxnTest() + : hazelcastInstanceFactory(*g_srvFactory) { server.reset(new HazelcastServer(hazelcastInstanceFactory)); second.reset(new HazelcastServer(hazelcastInstanceFactory)); std::auto_ptr clientConfig = getConfig(); @@ -103,50 +77,42 @@ namespace hazelcast { client.reset(new HazelcastClient(*clientConfig)); } - void ClientTxnTest::afterTest() { - hazelcastInstanceFactory.shutdownAll(); + ClientTxnTest::~ClientTxnTest() { + g_srvFactory->shutdownAll(); client->shutdown(); - client.reset(); + client.reset(); } - - void ClientTxnTest::testTxnRollback() { + TEST_F(ClientTxnTest, testTxnRollback) { util::CountDownLatch memberRemovedLatch(1); std::string queueName = "testTxnRollback"; MyLifecycleListener myLifecycleListener(memberRemovedLatch); client->getCluster().addMembershipListener(&myLifecycleListener); TransactionContext context = client->newTransactionContext(); - bool rollbackSuccessful = false; - try { - context.beginTransaction(); - TransactionalQueue queue = context.getQueue(queueName); - queue.offer("item"); - server->shutdown(); - context.commitTransaction(); - assertTrue(false, "commit should throw exception!!!"); - } catch (exception::IException&) { - context.rollbackTransaction(); - rollbackSuccessful = true; - } + context.beginTransaction(); + TransactionalQueue queue = context.getQueue(queueName); + queue.offer("item"); + server->shutdown(); - assertTrue(rollbackSuccessful); - assertTrue(memberRemovedLatch.await(10), "Member removed is not signalled"); + ASSERT_THROW(context.commitTransaction(), exception::IException); + + context.rollbackTransaction(); + + ASSERT_TRUE(memberRemovedLatch.await(10)); IQueue q = client->getQueue(queueName); try { - assertEqual(0, q.size()); - assertNull(q.poll().get()); + ASSERT_EQ(0, q.size()); + ASSERT_EQ(q.poll().get(), (std::string *)NULL); } catch (exception::IException& e) { std::cout << e.what() << std::endl; } - } - void ClientTxnTest::testTxnRollbackOnServerCrash() { + TEST_F(ClientTxnTest, testTxnRollbackOnServerCrash) { std::string queueName = "testTxnRollbackOnServerCrash"; TransactionContext context = client->newTransactionContext(); - bool rollbackSuccessful = false; util::CountDownLatch memberRemovedLatch(1); context.beginTransaction(); TransactionalQueue queue = context.getQueue(queueName); @@ -154,22 +120,17 @@ namespace hazelcast { MyLifecycleListener myLifecycleListener(memberRemovedLatch); client->getCluster().addMembershipListener(&myLifecycleListener); server->shutdown(); - try { - context.commitTransaction(); - assertTrue(false, "commit should throw exception!!!"); - } catch (exception::IException&) { - context.rollbackTransaction(); - rollbackSuccessful = true; - } - assertTrue(rollbackSuccessful); - assertTrue(memberRemovedLatch.await(10)); + ASSERT_THROW(context.commitTransaction(), exception::IException); + + context.rollbackTransaction(); + + ASSERT_TRUE(memberRemovedLatch.await(10)); IQueue q = client->getQueue(queueName); - assertNull(q.poll().get()); - assertEqual(0, q.size()); + ASSERT_EQ(q.poll().get(), (std::string *)NULL); + ASSERT_EQ(0, q.size()); } - } } } diff --git a/hazelcast/test/txn/ClientTxnTest.h b/hazelcast/test/src/txn/ClientTxnTest.h similarity index 72% rename from hazelcast/test/txn/ClientTxnTest.h rename to hazelcast/test/src/txn/ClientTxnTest.h index f86692d3df..04dbfdf67b 100644 --- a/hazelcast/test/txn/ClientTxnTest.h +++ b/hazelcast/test/src/txn/ClientTxnTest.h @@ -16,9 +16,6 @@ // // Created by sancar koyunlu on 9/18/13. - - - #ifndef HAZELCAST_ClientTxnTest #define HAZELCAST_ClientTxnTest @@ -28,43 +25,20 @@ namespace hazelcast { namespace client { - - class HazelcastClient; - namespace test { - - class HazelcastServerFactory; - - class ClientTxnTest : public ClientTestSupport { - + class ClientTxnTest : public ClientTestSupport { public: - - ClientTxnTest(HazelcastServerFactory &); + ClientTxnTest(); ~ClientTxnTest(); - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testTxnRollback(); - - void testTxnRollbackOnServerCrash(); - - private: + protected: HazelcastServerFactory & hazelcastInstanceFactory; std::auto_ptr server; std::auto_ptr second; std::auto_ptr client; std::auto_ptr loadBalancer; }; - } } } diff --git a/hazelcast/test/util/BitsTest.cpp b/hazelcast/test/src/util/BitsTest.cpp similarity index 71% rename from hazelcast/test/util/BitsTest.cpp rename to hazelcast/test/src/util/BitsTest.cpp index d34c5b1a19..727c2207ea 100644 --- a/hazelcast/test/util/BitsTest.cpp +++ b/hazelcast/test/src/util/BitsTest.cpp @@ -17,8 +17,7 @@ // Created by İhsan Demir on 18/05/15. // -#include "util/BitsTest.h" - +#include #include "hazelcast/util/Bits.h" namespace hazelcast { @@ -28,34 +27,10 @@ namespace hazelcast { namespace test { namespace util { - using namespace iTest; - - BitsTest::BitsTest() - : iTestFixture("BitsTest") { - - } - - void BitsTest::addTests() { - addTest(&BitsTest::testLittleEndian, "Test Little Endian Conversions"); - } - - void BitsTest::beforeClass() { - - } - - void BitsTest::afterClass() { - - } - - void BitsTest::beforeTest() { - - } - - void BitsTest::afterTest() { - - } + class BitsTest : public ::testing::Test + {}; - void BitsTest::testLittleEndian() { + TEST_F(BitsTest, testLittleEndian) { uint64_t ONE = 1; uint64_t oneByteFactor = ONE << 8; uint64_t twoBytesFactor = ONE << 16; @@ -70,8 +45,8 @@ namespace hazelcast { int16_t actual; byte *resBytes = (byte *)&actual; hazelcast::util::Bits::nativeToLittleEndian2(&expected, &actual); - ASSERT_EQUAL(0xBC, resBytes[0]); - ASSERT_EQUAL(0x7A, resBytes[1]); + ASSERT_EQ(0xBC, resBytes[0]); + ASSERT_EQ(0x7A, resBytes[1]); } { @@ -80,10 +55,10 @@ namespace hazelcast { int32_t actual; byte *resBytes = (byte *)&actual; hazelcast::util::Bits::nativeToLittleEndian4(&expected, &actual); - ASSERT_EQUAL(0xBA, resBytes[0]); - ASSERT_EQUAL(0xAA, resBytes[1]); - ASSERT_EQUAL(0x9A, resBytes[2]); - ASSERT_EQUAL(0x1A, resBytes[3]); + ASSERT_EQ(0xBA, resBytes[0]); + ASSERT_EQ(0xAA, resBytes[1]); + ASSERT_EQ(0x9A, resBytes[2]); + ASSERT_EQ(0x1A, resBytes[3]); } { @@ -100,14 +75,14 @@ namespace hazelcast { int64_t actual; byte *resBytes = (byte *)&actual; hazelcast::util::Bits::nativeToLittleEndian8(&expected, &actual); - ASSERT_EQUAL(0x8A, resBytes[0]); - ASSERT_EQUAL(0x7A, resBytes[1]); - ASSERT_EQUAL(0x6A, resBytes[2]); - ASSERT_EQUAL(0x5A, resBytes[3]); - ASSERT_EQUAL(0x4A, resBytes[4]); - ASSERT_EQUAL(0x3A, resBytes[5]); - ASSERT_EQUAL(0x2A, resBytes[6]); - ASSERT_EQUAL(0x1A, resBytes[7]); + ASSERT_EQ(0x8A, resBytes[0]); + ASSERT_EQ(0x7A, resBytes[1]); + ASSERT_EQ(0x6A, resBytes[2]); + ASSERT_EQ(0x5A, resBytes[3]); + ASSERT_EQ(0x4A, resBytes[4]); + ASSERT_EQ(0x3A, resBytes[5]); + ASSERT_EQ(0x2A, resBytes[6]); + ASSERT_EQ(0x1A, resBytes[7]); } // Little to Native tests @@ -115,14 +90,14 @@ namespace hazelcast { byte source[2] = {0xAB, 0xBC}; uint16_t actual; hazelcast::util::Bits::littleEndianToNative2(&source, &actual); - ASSERT_EQUAL(0xBC * oneByteFactor + 0xAB, actual); + ASSERT_EQ(0xBC * oneByteFactor + 0xAB, actual); } { byte source[4] = {0xAB, 0xBC, 0xDE, 0xA1}; uint32_t actual; hazelcast::util::Bits::littleEndianToNative4(&source, &actual); - ASSERT_EQUAL(0xA1 * threeBytesFactor + + ASSERT_EQ(0xA1 * threeBytesFactor + 0xDE * twoBytesFactor + 0xBC * oneByteFactor + 0xAB, actual); @@ -132,7 +107,7 @@ namespace hazelcast { byte source[8] = {0xAB, 0x9B, 0x8B, 0x7B, 0x6B, 0x5B, 0x4B, 0xA1}; uint64_t actual; hazelcast::util::Bits::littleEndianToNative8(&source, &actual); - ASSERT_EQUAL(0xA1 * sevenBytesFactor + + ASSERT_EQ(0xA1 * sevenBytesFactor + 0x4B * sixBytesFactor + 0x5B * fiveBytesFactor + 0x6B * fourBytesFactor + diff --git a/hazelcast/test/src/util/ClientUtilTest.cpp b/hazelcast/test/src/util/ClientUtilTest.cpp new file mode 100644 index 0000000000..40e0c19d26 --- /dev/null +++ b/hazelcast/test/src/util/ClientUtilTest.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// Created by sancar koyunlu on 22/08/14. +// + +#include "hazelcast/util/Util.h" +#include "hazelcast/util/Future.h" +#include "hazelcast/util/Thread.h" + +#include +#include + +namespace hazelcast { + namespace client { + namespace test { + class ClientUtilTest : public ::testing::Test { + public: + static void wakeTheConditionUp(util::ThreadArgs& args) { + util::Mutex *mutex = (util::Mutex *)args.arg0; + util::ConditionVariable *cv = (util::ConditionVariable *)args.arg1; + int wakeUpTime = *(int *)args.arg2; + util::sleep(wakeUpTime); + + util::LockGuard lockGuard(*mutex); + cv->notify(); + } + + static void setValueToFuture(util::ThreadArgs& args) { + util::Future *future = (util::Future *)args.arg0; + int value = *(int *)args.arg1; + int wakeUpTime = *(int *)args.arg2; + util::sleep(wakeUpTime); + future->set_value(value); + } + + static void setExceptionToFuture(util::ThreadArgs& args) { + util::Future *future = (util::Future *)args.arg0; + int wakeUpTime = *(int *)args.arg1; + util::sleep(wakeUpTime); + future->set_exception("exceptionName", "details"); + } + }; + + TEST_F(ClientUtilTest, testConditionWaitTimeout) { + util::Mutex mutex; + util::ConditionVariable conditionVariable; + int wakeUpTime = 3; + util::Thread thread(wakeTheConditionUp, &mutex, &conditionVariable, &wakeUpTime); + int waitSeconds = 30; + { + util::LockGuard lockGuard(mutex); + time_t beg = time(NULL); + time_t end = 0; + bool wokenUpByInterruption = conditionVariable.waitFor(mutex, waitSeconds); + if (wokenUpByInterruption) { + end = time(NULL); + } + ASSERT_NEAR(end-beg, wakeUpTime, 1); + } + + } + + TEST_F (ClientUtilTest, testFutureWaitTimeout) { + util::Future future; + int waitSeconds = 3; + time_t beg = time(NULL); + time_t end = 0; + try { + future.get(waitSeconds); + } catch (exception::TimeoutException&) { + end = time(NULL); + } + ASSERT_NEAR(end-beg, waitSeconds, 1); + } + + TEST_F (ClientUtilTest, testFutureSetValue) { + util::Future future; + int waitSeconds = 3; + int expectedValue = 2; + future.set_value(expectedValue); + int value = future.get(waitSeconds); + ASSERT_EQ(expectedValue, value); + } + + TEST_F (ClientUtilTest, testFutureSetException) { + util::Future future; + int waitSeconds = 3; + + future.set_exception("exceptionName", "details"); + + ASSERT_THROW(future.get(waitSeconds), exception::IException); + } + + + TEST_F (ClientUtilTest, testFutureSetValue_afterSomeTime) { + util::Future future; + int waitSeconds = 30; + int wakeUpTime = 3; + int expectedValue = 2; + util::Thread thread(ClientUtilTest::setValueToFuture, &future, &expectedValue, &wakeUpTime); + int value = future.get(waitSeconds); + ASSERT_EQ(expectedValue, value); + + } + + TEST_F (ClientUtilTest, testFutureSetException_afterSomeTime) { + util::Future future; + int waitSeconds = 30; + int wakeUpTime = 3; + bool gotException = false; + util::Thread thread(ClientUtilTest::setExceptionToFuture, &future, &wakeUpTime); + try { + future.get(waitSeconds); + } catch (exception::IException&) { + gotException = true; + } + ASSERT_EQ(true, gotException); + } + + void dummyThread(util::ThreadArgs& args) { + + } + + TEST_F (ClientUtilTest, testThreadName) { + std::string threadName = "myThreadName"; + util::Thread thread(threadName, dummyThread); + ASSERT_EQ(threadName, thread.getThreadName()); + } + + void sleepyThread(util::ThreadArgs& args) { + int sleepTime = *(int *)args.arg0; + args.currentThread->interruptibleSleep(sleepTime); + } + + TEST_F (ClientUtilTest, testThreadInterruptibleSleep) { + int sleepTime = 30; + int wakeUpTime = 3; + time_t beg = time(NULL); + util::Thread thread(sleepyThread, &sleepTime); + util::sleep(wakeUpTime); + thread.interrupt(); + thread.join(); + time_t end = time(NULL); + ASSERT_NEAR((int)(end - beg), wakeUpTime , 1); + } + } + } +} + diff --git a/hazelcast/test/util/ClientUtilTest.cpp b/hazelcast/test/util/ClientUtilTest.cpp deleted file mode 100644 index 70718f88cf..0000000000 --- a/hazelcast/test/util/ClientUtilTest.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 22/08/14. -// - -#include "ClientUtilTest.h" -#include "hazelcast/util/Util.h" -#include "hazelcast/util/Future.h" -#include "hazelcast/util/Thread.h" -#include - -namespace hazelcast { - namespace client { - namespace test { - using namespace iTest; - - - ClientUtilTest::ClientUtilTest() - : ClientTestSupport("ClientUtilTest") { - - } - - void ClientUtilTest::addTests() { - addTest(&ClientUtilTest::testConditionWaitTimeout, "testConditionWaitTimeout"); - addTest(&ClientUtilTest::testConditionWakeUpTime, "testConditionWakeUpTime"); - addTest(&ClientUtilTest::testFutureWaitTimeout, "testFutureWaitTimeout"); - addTest(&ClientUtilTest::testFutureSetValue, "testFutureSetValue"); - addTest(&ClientUtilTest::testFutureSetException, "testFutureSetException"); - addTest(&ClientUtilTest::testFutureSetValue_afterSomeTime, "testFutureSetValue_afterSomeTime"); - addTest(&ClientUtilTest::testFutureSetException_afterSomeTime, "testFutureSetException_afterSomeTime"); - addTest(&ClientUtilTest::testThreadName, "testThreadName"); - addTest(&ClientUtilTest::testThreadInterruptibleSleep, "testThreadInterruptibleSleep"); - } - - void ClientUtilTest::beforeClass() { - - } - - void ClientUtilTest::afterClass() { - - } - - void ClientUtilTest::beforeTest() { - - } - - void ClientUtilTest::afterTest() { - - } - - void ClientUtilTest::testConditionWaitTimeout() { - util::Mutex mutex; - util::ConditionVariable conditionVariable; - int waitSeconds = 3; - { - util::LockGuard lockGuard(mutex); - time_t beg = time(NULL); - time_t end = 0; - bool wokenUpByInterruption = conditionVariable.waitFor(mutex, waitSeconds); - if (!wokenUpByInterruption) { - end = time(NULL); - } - assertEqualWithEpsilon((int)(end - beg), waitSeconds , 1); - } - } - - - void wakeTheConditionUp(util::ThreadArgs& args) { - util::Mutex *mutex = (util::Mutex *)args.arg0; - util::ConditionVariable *cv = (util::ConditionVariable *)args.arg1; - int wakeUpTime = *(int *)args.arg2; - util::sleep(wakeUpTime); - - util::LockGuard lockGuard(*mutex); - cv->notify(); - } - - void ClientUtilTest::testConditionWakeUpTime() { - util::Mutex mutex; - util::ConditionVariable conditionVariable; - int wakeUpTime = 3; - util::Thread thread(wakeTheConditionUp, &mutex, &conditionVariable, &wakeUpTime); - int waitSeconds = 30; - { - util::LockGuard lockGuard(mutex); - time_t beg = time(NULL); - time_t end = 0; - bool wokenUpByInterruption = conditionVariable.waitFor(mutex, waitSeconds); - if (wokenUpByInterruption) { - end = time(NULL); - } - assertEqualWithEpsilon((int)(end - beg), wakeUpTime , 1); - } - - } - - void ClientUtilTest::testFutureWaitTimeout() { - util::Future future; - int waitSeconds = 3; - time_t beg = time(NULL); - time_t end = 0; - try { - future.get(waitSeconds); - } catch (exception::TimeoutException&) { - end = time(NULL); - } - assertEqualWithEpsilon((int)(end - beg), waitSeconds , 1); - } - - - void ClientUtilTest::testFutureSetValue() { - util::Future future; - int waitSeconds = 3; - int expectedValue = 2; - future.set_value(expectedValue); - int value = future.get(waitSeconds); - assertEqual(expectedValue, value); - } - - void ClientUtilTest::testFutureSetException() { - util::Future future; - int waitSeconds = 3; - bool gotException = false; - future.set_exception("exceptionName", "details"); - try { - future.get(waitSeconds); - } catch (exception::IException&) { - gotException = true; - } - assertEqual(true, gotException); - } - - void setValueToFuture(util::ThreadArgs& args) { - util::Future *future = (util::Future *)args.arg0; - int value = *(int *)args.arg1; - int wakeUpTime = *(int *)args.arg2; - util::sleep(wakeUpTime); - future->set_value(value); - } - - void setExceptionToFuture(util::ThreadArgs& args) { - util::Future *future = (util::Future *)args.arg0; - int wakeUpTime = *(int *)args.arg1; - util::sleep(wakeUpTime); - future->set_exception("exceptionName", "details"); - } - - void ClientUtilTest::testFutureSetValue_afterSomeTime() { - util::Future future; - int waitSeconds = 30; - int wakeUpTime = 3; - int expectedValue = 2; - util::Thread thread(setValueToFuture, &future, &expectedValue, &wakeUpTime); - int value = future.get(waitSeconds); - assertEqual(expectedValue, value); - - } - - void ClientUtilTest::testFutureSetException_afterSomeTime() { - util::Future future; - int waitSeconds = 30; - int wakeUpTime = 3; - bool gotException = false; - util::Thread thread(setExceptionToFuture, &future, &wakeUpTime); - try { - future.get(waitSeconds); - } catch (exception::IException&) { - gotException = true; - } - assertEqual(true, gotException); - } - - void dummyThread(util::ThreadArgs& args) { - - } - - void ClientUtilTest::testThreadName() { - std::string threadName = "myThreadName"; - util::Thread thread(threadName, dummyThread); - assertEqual(threadName, thread.getThreadName()); - } - - void sleepyThread(util::ThreadArgs& args) { - int sleepTime = *(int *)args.arg0; - args.currentThread->interruptibleSleep(sleepTime); - } - - void ClientUtilTest::testThreadInterruptibleSleep() { - int sleepTime = 30; - int wakeUpTime = 3; - time_t beg = time(NULL); - util::Thread thread(sleepyThread, &sleepTime); - util::sleep(wakeUpTime); - thread.interrupt(); - thread.join(); - time_t end = time(NULL); - assertEqualWithEpsilon((int)(end - beg), wakeUpTime , 1); - } - - } - } -} - diff --git a/hazelcast/test/util/ClientUtilTest.h b/hazelcast/test/util/ClientUtilTest.h deleted file mode 100644 index 3ffbb09294..0000000000 --- a/hazelcast/test/util/ClientUtilTest.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// -// Created by sancar koyunlu on 22/08/14. -// - - -#ifndef HAZELCAST_CLientUtilTest -#define HAZELCAST_CLientUtilTest - - -#include "ClientTestSupport.h" - -namespace hazelcast { - namespace client { - - class HazelcastClient; - - namespace test { - - class HazelcastServerFactory; - - class ClientUtilTest : public ClientTestSupport { - public: - - ClientUtilTest(); - - void addTests(); - - void beforeClass(); - - void afterClass(); - - void beforeTest(); - - void afterTest(); - - void testConditionWaitTimeout(); - - void testConditionWakeUpTime(); - - void testFutureWaitTimeout(); - - void testFutureSetValue(); - - void testFutureSetException(); - - void testFutureSetValue_afterSomeTime(); - - void testFutureSetException_afterSomeTime(); - - void testThreadName(); - - void testThreadInterruptibleSleep(); - - }; - - } - } -} - - -#endif //HAZELCAST_CLientUtilTest diff --git a/releaseLinux.sh b/releaseLinux.sh index 0390aaee80..7e44e4d5a5 100755 --- a/releaseLinux.sh +++ b/releaseLinux.sh @@ -1,4 +1,4 @@ -set -e #abort the script at first faiure +set -e #abort the script at first failure echo "Cleanup release directories" rm -rf ./Release* @@ -7,15 +7,15 @@ rm -rf ./cpp echo "Compiling Static 32bit library" mkdir ReleaseStatic32; cd ./ReleaseStatic32; -cmake .. -DHZ_LIB_TYPE=STATIC -DHZ_BIT=32 -DCMAKE_BUILD_TYPE=Release -make -j; +cmake .. -DHZ_LIB_TYPE=STATIC -DHZ_BIT=32 -DCMAKE_BUILD_TYPE=Release -DHZ_BUILD_TESTS=ON -DHZ_BUILD_EXAMPLES=ON +make -j 4; cd ..; echo "Compiling Shared 32bit library" mkdir ReleaseShared32; cd ./ReleaseShared32; -cmake .. -DHZ_LIB_TYPE=SHARED -DHZ_BIT=32 -DCMAKE_BUILD_TYPE=Release -make -j; +cmake .. -DHZ_LIB_TYPE=SHARED -DHZ_BIT=32 -DCMAKE_BUILD_TYPE=Release -DHZ_BUILD_TESTS=ON -DHZ_BUILD_EXAMPLES=ON +make -j 4; cd ..; @@ -44,15 +44,15 @@ rm -rf ./ReleaseStatic32 echo "Compiling Static 64bit library" mkdir ReleaseStatic64; cd ./ReleaseStatic64; -cmake .. -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release -make -j; +cmake .. -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release -DHZ_BUILD_TESTS=ON -DHZ_BUILD_EXAMPLES=ON +make -j 4; cd ..; echo "Compiling Shared 64bit library" mkdir ReleaseShared64; cd ./ReleaseShared64; -cmake .. -DHZ_LIB_TYPE=SHARED -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release -make -j; +cmake .. -DHZ_LIB_TYPE=SHARED -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release -DHZ_BUILD_TESTS=ON -DHZ_BUILD_EXAMPLES=ON +make -j 4; cd ..; @@ -77,3 +77,7 @@ find ReleaseStatic64/examples -perm +111 -type f -exec cp {} cpp/Linux_64/exampl echo "Clearing temporary 64bit libraries" rm -rf ./ReleaseShared64 rm -rf ./ReleaseStatic64 + +# Verify release +scripts/verifyReleaseLinux.sh + diff --git a/releaseWindows.bat b/releaseWindows.bat index 626c77b90f..b2d74026b9 100644 --- a/releaseWindows.bat +++ b/releaseWindows.bat @@ -6,7 +6,7 @@ echo "Compiling Static 32bit library" mkdir ReleaseStatic32 cd .\ReleaseStatic32 cd -cmake .. -G "Visual Studio 12" -DHZ_LIB_TYPE=STATIC -DHZ_BIT=32 -DCMAKE_BUILD_TYPE=Release +cmake .. -G "Visual Studio 12" -DHZ_LIB_TYPE=STATIC -DHZ_BIT=32 -DCMAKE_BUILD_TYPE=Release -DHZ_BUILD_TESTS=ON -DHZ_BUILD_EXAMPLES=ON MSBuild.exe HazelcastClient.sln /m /property:Configuration=Release /p:VisualStudioVersion=12.0;Flavor=32;Platform=win32;PlatformTarget=win32 cd .. @@ -14,7 +14,7 @@ echo "Compiling Shared 32bit library" mkdir ReleaseShared32 cd .\ReleaseShared32 cd; -cmake .. -G "Visual Studio 12" -DHZ_LIB_TYPE=SHARED -DHZ_BIT=32 -DCMAKE_BUILD_TYPE=Release +cmake .. -G "Visual Studio 12" -DHZ_LIB_TYPE=SHARED -DHZ_BIT=32 -DCMAKE_BUILD_TYPE=Release -DHZ_BUILD_TESTS=ON -DHZ_BUILD_EXAMPLES=ON MSBuild.exe HazelcastClient.sln /m /property:Configuration=Release /p:VisualStudioVersion=12.0;Flavor=32;Platform=win32;PlatformTarget=win32 cd .. @@ -46,7 +46,7 @@ echo "Compiling Static 64bit library" mkdir ReleaseStatic64 cd .\ReleaseStatic64 cd; -cmake .. -G "Visual Studio 12 Win64" -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release +cmake .. -G "Visual Studio 12 Win64" -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release -DHZ_BUILD_TESTS=ON -DHZ_BUILD_EXAMPLES=ON MSBuild.exe HazelcastClient.sln /m /property:Configuration=Release /p:VisualStudioVersion=12.0;Flavor=64;Platform=x64;PlatformTarget=x64 cd .. @@ -54,7 +54,7 @@ echo "Compiling Shared 64bit library" mkdir ReleaseShared64 cd .\ReleaseShared64 cd; -cmake .. -G "Visual Studio 12 Win64" -DHZ_LIB_TYPE=SHARED -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release +cmake .. -G "Visual Studio 12 Win64" -DHZ_LIB_TYPE=SHARED -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release -DHZ_BUILD_TESTS=ON -DHZ_BUILD_EXAMPLES=ON MSBuild.exe HazelcastClient.sln /m /property:Configuration=Release /p:VisualStudioVersion=12.0;Flavor=64;Platform=x64;PlatformTarget=x64 cd .. @@ -82,3 +82,5 @@ echo "Clearing tempraroy 64bit librares" rm -rf ./ReleaseShared64 rm -rf ./ReleaseStatic64 +@REM Verify release +call scripts/verifyReleaseWindows.bat || exit /b 1 diff --git a/releaseWindowsDev.bat b/releaseWindowsDev.bat index 3ffd49d94c..0e516c278d 100644 --- a/releaseWindowsDev.bat +++ b/releaseWindowsDev.bat @@ -2,7 +2,7 @@ echo "Compiling Static 64bit library" mkdir ReleaseStatic64 cd .\ReleaseStatic64 cd; -cmake .. -G "Visual Studio 10 Win64" -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release +cmake .. -G "Visual Studio 10 Win64" -DHZ_LIB_TYPE=STATIC -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release -DHZ_BUILD_TESTS=ON -DHZ_BUILD_EXAMPLES=ON MSBuild.exe HazelcastClient.sln /property:Configuration=Release cd .. @@ -10,7 +10,7 @@ echo "Compiling Shared 64bit library" mkdir ReleaseShared64 cd .\ReleaseShared64 cd; -cmake .. -G "Visual Studio 10 Win64" -DHZ_LIB_TYPE=SHARED -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release +cmake .. -G "Visual Studio 10 Win64" -DHZ_LIB_TYPE=SHARED -DHZ_BIT=64 -DCMAKE_BUILD_TYPE=Release -DHZ_BUILD_TESTS=ON -DHZ_BUILD_EXAMPLES=ON MSBuild.exe HazelcastClient.sln /property:Configuration=Release cd .. @@ -37,3 +37,12 @@ echo "Clearing tempraroy 64bit librares" rm -rf ./ReleaseShared64 rm -rf ./ReleaseStatic64 +cd examples +rm -rf build +mkdir build +cd build +cmake .. -DHAZELCAST_INSTALL_DIR=../cpp -DHZ_BIT=32 +MSBuild.exe HazelcastClient.sln /m +cd .. +rm -rf build +cd .. diff --git a/scripts/verifyReleaseLinux.sh b/scripts/verifyReleaseLinux.sh new file mode 100755 index 0000000000..d0ea6926d6 --- /dev/null +++ b/scripts/verifyReleaseLinux.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e #abort the script at first failure + +# Verify release +CURRENT_DIRECTORY=`pwd` + +${CURRENT_DIRECTORY}/scripts/verifyReleaseLinuxSingleCase.sh ${CURRENT_DIRECTORY}/cpp 32 STATIC + +${CURRENT_DIRECTORY}/scripts/verifyReleaseLinuxSingleCase.sh ${CURRENT_DIRECTORY}/cpp 32 SHARED + +${CURRENT_DIRECTORY}/scripts/verifyReleaseLinuxSingleCase.sh ${CURRENT_DIRECTORY}/cpp 64 STATIC + +${CURRENT_DIRECTORY}/scripts/verifyReleaseLinuxSingleCase.sh ${CURRENT_DIRECTORY}/cpp 64 SHARED + +exit 0 + + diff --git a/scripts/verifyReleaseLinuxSingleCase.sh b/scripts/verifyReleaseLinuxSingleCase.sh new file mode 100755 index 0000000000..bd90b18afe --- /dev/null +++ b/scripts/verifyReleaseLinuxSingleCase.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -e #abort the script at first failure + +HZ_INSTALL_DIR=$1 +HZ_BIT_VERSION=$2 +HZ_LIB_TYPE=$3 + +echo "Verifying the release located at ${HZ_INSTALL_DIR} for ${HZ_LIB_TYPE} ${HZ_BIT_VERSION} bit library." + +cd examples +rm -rf build +mkdir build +cd build + +cmake .. -DHAZELCAST_INSTALL_DIR=${HZ_INSTALL_DIR} -DHZ_BIT=${HZ_BIT_VERSION} -DHZ_LIB_TYPE=${HZ_LIB_TYPE} + +make -j 4 + +echo "Verification of the release located at ${HZ_INSTALL_DIR} for ${HZ_LIB_TYPE} ${HZ_BIT_VERSION} bit library is finished." + +exit 0 + + diff --git a/scripts/verifyReleaseWindows.bat b/scripts/verifyReleaseWindows.bat new file mode 100755 index 0000000000..a628f28e2b --- /dev/null +++ b/scripts/verifyReleaseWindows.bat @@ -0,0 +1,14 @@ +# Verify release +SET CURRENT_DIRECTORY=%cd% + +call scripts\verifyReleaseWindowsSingleCase.bat %CURRENT_DIRECTORY%\cpp 32 STATIC || exit /b 1 + +call scripts\verifyReleaseWindowsSingleCase.bat %CURRENT_DIRECTORY%\cpp 32 SHARED || exit /b 1 + +call scripts\verifyReleaseWindowsSingleCase.bat %CURRENT_DIRECTORY%\cpp 64 STATIC || exit /b 1 + +call scripts\verifyReleaseWindowsSingleCase.bat %CURRENT_DIRECTORY%\cpp 64 SHARED || exit /b 1 + +exit 0 + + diff --git a/scripts/verifyReleaseWindowsSingleCase.bat b/scripts/verifyReleaseWindowsSingleCase.bat new file mode 100755 index 0000000000..a8c883f724 --- /dev/null +++ b/scripts/verifyReleaseWindowsSingleCase.bat @@ -0,0 +1,33 @@ +SET HZ_INSTALL_DIR=%1 +SET HZ_BIT_VERSION=%2 +SET HZ_LIB_TYPE=%3 + +echo "Verifying the release located at %HZ_INSTALL_DIR% for %HZ_LIB_TYPE% %HZ_BIT_VERSION% bit library." + +cd examples +rm -rf build +mkdir build +cd build + +SET HZ_BUILD_TYPE=Release + +if %HZ_BIT_VERSION% == 32 ( + set BUILDFORPLATFORM="win32" + set SOLUTIONTYPE="Visual Studio 12" +) else ( + set BUILDFORPLATFORM="x64" + set SOLUTIONTYPE="Visual Studio 12 Win64" +) + +echo "Generating the solution files for compilation" +cmake .. -G %SOLUTIONTYPE% -DHAZELCAST_INSTALL_DIR=%HZ_INSTALL_DIR% -DHZ_LIB_TYPE=%HZ_LIB_TYPE% -DHZ_BIT=%HZ_BIT_VERSION% -DCMAKE_BUILD_TYPE=%HZ_BUILD_TYPE% || exit /b 1 + +echo "Building for platform %BUILDFORPLATFORM%" + +MSBuild.exe HazelcastExamples.sln /m /p:Flavor=%HZ_BUILD_TYPE%;Configuration=%HZ_BUILD_TYPE%;VisualStudioVersion=12.0;Platform=%BUILDFORPLATFORM%;PlatformTarget=%BUILDFORPLATFORM% || exit /b 1 + +echo "Verification of the release located at %HZ_INSTALL_DIR% for %HZ_LIB_TYPE% %HZ_BIT_VERSION% bit library is finished." + +exit 0 + + diff --git a/testLinuxSingleCase.sh b/testLinuxSingleCase.sh index ee68dbc178..e2f8490bf3 100755 --- a/testLinuxSingleCase.sh +++ b/testLinuxSingleCase.sh @@ -16,6 +16,14 @@ HZ_BIT_VERSION=$1 HZ_LIB_TYPE=$2 HZ_BUILD_TYPE=$3 +if [ "$4" == "WITH_COVERAGE" ]; then + if [ ${HZ_BUILD_TYPE} != Debug ]; then + echo "WITH_COVERAGE is requested. The build type should be Debug but it is provided as ${HZ_BUILD_TYPE}." + exit 1 + fi + HZ_COVERAGE_STRING="-DHZ_CODE_COVERAGE=ON" +fi + BUILD_DIR=build${HZ_LIB_TYPE}${HZ_BIT_VERSION}${HZ_BUILD_TYPE} EXECUTABLE_NAME=clientTest_${HZ_LIB_TYPE}_${HZ_BIT_VERSION} @@ -26,12 +34,19 @@ echo HZ_BUILD_TYPE=${HZ_BUILD_TYPE} echo BUILD_DIR=${BUILD_DIR} echo EXECUTABLE_NAME=${EXECUTABLE_NAME} +if [ "$4" == "WITH_COVERAGE" ]; then +echo "Code coverage is ON. Cmake flag: ${HZ_COVERAGE_STRING}" +fi + +# Let the submodule code be downloaded +git submodule update --init + rm -rf ${BUILD_DIR} mkdir ${BUILD_DIR} cd ${BUILD_DIR} echo "Running cmake to compose Makefiles for compilation." -cmake .. -DHZ_LIB_TYPE=${HZ_LIB_TYPE} -DHZ_BIT=${HZ_BIT_VERSION} -DCMAKE_BUILD_TYPE=${HZ_BUILD_TYPE} +cmake .. -DHZ_LIB_TYPE=${HZ_LIB_TYPE} -DHZ_BIT=${HZ_BIT_VERSION} -DCMAKE_BUILD_TYPE=${HZ_BUILD_TYPE} ${HZ_COVERAGE_STRING} -DHZ_BUILD_TESTS=ON -DHZ_BUILD_EXAMPLES=ON echo "Running make. Building the project." make -j 8 -l 4 # run 8 jobs in parallel and a maximum load of 4 @@ -88,7 +103,7 @@ fi cd .. echo "Starting the client test now." -${BUILD_DIR}/hazelcast/test/${EXECUTABLE_NAME} +${BUILD_DIR}/hazelcast/test/src/${EXECUTABLE_NAME} --gtest_output="xml:CPP_Client_Test_Report.xml" result=$? diff --git a/testWindowsSingleCase.bat b/testWindowsSingleCase.bat index 756486b77c..3b79449ae0 100644 --- a/testWindowsSingleCase.bat +++ b/testWindowsSingleCase.bat @@ -12,6 +12,9 @@ @echo BUILD_DIR=%BUILD_DIR% @echo EXECUTABLE_NAME=%EXECUTABLE_NAME% +@REM Let the submodule code be downloaded +git submodule update --init + RD /S /Q %BUILD_DIR% mkdir %BUILD_DIR% @@ -26,7 +29,7 @@ if %HZ_BIT_VERSION% == 32 ( ) echo "Generating the solution files for ompilation" -cmake .. -G %SOLUTIONTYPE% -DHZ_LIB_TYPE=%HZ_LIB_TYPE% -DHZ_BIT=%HZ_BIT_VERSION% -DCMAKE_BUILD_TYPE=%HZ_BUILD_TYPE% +cmake .. -G %SOLUTIONTYPE% -DHZ_LIB_TYPE=%HZ_LIB_TYPE% -DHZ_BIT=%HZ_BIT_VERSION% -DCMAKE_BUILD_TYPE=%HZ_BUILD_TYPE% -DHZ_BUILD_TESTS=ON -DHZ_BUILD_EXAMPLES=ON echo "Building for platform %BUILDFORPLATFORM%" @@ -81,6 +84,6 @@ echo "Starting the client test now." SET PATH=%BUILD_DIR%\%HZ_BUILD_TYPE%;%PATH% -%BUILD_DIR%\hazelcast\test\%HZ_BUILD_TYPE%\%EXECUTABLE_NAME% || exit /b 1 +%BUILD_DIR%\hazelcast\test\src\%HZ_BUILD_TYPE%\%EXECUTABLE_NAME% --gtest_output="xml:CPP_Client_Test_Report.xml" || exit /b 1 taskkill /F /FI "WINDOWTITLE eq cpp-java"