http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..bb40517 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,263 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +cmake_minimum_required(VERSION 3.4) +project(nativeclient) + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) + +if(CMAKE_GENERATOR MATCHES Win64*) + if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (CMAKE_GENERATOR_TOOLSET STREQUAL "")) + message(WARNING "GEODE expects that a user must provode -Thost=x64 if you are using a" + " 64-bit toolset, otherwise you may get a linker error when DLLs are larger" + " than 2GB saying \"Unable to open file apache-geode-static.dll.\" This is due" + " to the 32bit toolset being used by default.") + endif() +endif() + +set(BUILD_BITS 64 CACHE STRING "Build for 64 (default) or 32 bit.") + +set(PRODUCT_VENDOR "Apache" CACHE STRING "Product vendor") +set(PRODUCT_VENDOR_NAME "The Apache Software Foundation" CACHE STRING "Product vendor full legal name") +set(PRODUCT_NAME "Geode Native" CACHE STRING "Product name") +set(PRODUCT_VERSION "0.0.42-build.0" CACHE STRING "Product version") +set(PRODUCT_PACKAGE_NAME "apache-geode-native" CACHE STRING "Product package name") + +set(PRODUCT_BITS "${BUILD_BITS}bit") + +set(PRODUCT_LIB_NAME "apache-geode" CACHE STRING "Binary name") +set(PRODUCT_DLL_NAME "Apache.Geode" CACHE STRING ".Net Binary name") + +if(CMAKE_SYSTEM_NAME STREQUAL "SunOS") + if (CMAKE_SYSTEM_PROCESSOR STREQUAL "sparc") + set(PRODUCT_SYSTEM_NAME "solaris-sparc") + else() + set(PRODUCT_SYSTEM_NAME "solaris-x86") + endif() +else() + set(PRODUCT_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}" CACHE STRING "Product built for system name") +endif() + +string(REGEX REPLACE "-build" "" PRODUCT_VERSION_DOTTED ${PRODUCT_VERSION}) +string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" PRODUCT_VERSION_LONG ${PRODUCT_VERSION}) +string(REGEX MATCH "^[0-9]+\\.[0-9]+" PRODUCT_VERSION_SHORT ${PRODUCT_VERSION}) +string(REGEX REPLACE "\\." ";" PRODUCT_VERSION_LIST ${PRODUCT_VERSION_DOTTED}) +list(LENGTH PRODUCT_VERSION_LIST _length) +if (_length LESS 4) + foreach(_index RANGE ${_length} 3) + list(APPEND PRODUCT_VERSION_LIST 0) + endforeach() +endif() +list(GET PRODUCT_VERSION_LIST 0 PRODUCT_VERSION_MAJOR) +list(GET PRODUCT_VERSION_LIST 1 PRODUCT_VERSION_MINOR) +list(GET PRODUCT_VERSION_LIST 2 PRODUCT_VERSION_PATCH) +list(GET PRODUCT_VERSION_LIST 3 PRODUCT_VERSION_BUILD) + +# Please note that attempts to set CMAKE_INSTALL_PREFIX to a *ROOTED* +# path here will fail due to the design of CMake according to its +# development team. Setting it to a relative path appears to work. +# To override the install location, CMAKE_INSTALL_PREFIX must be +# specified at the time of generation, e.g.: +# $ cmake -G Xcode -DCMAKE_INSTALL_PREFIX=/my/favorite/location .. +set(CMAKE_INSTALL_PREFIX "nativeclient" CACHE STRING "Install prefix") + +set(CMAKE_CONFIGURATION_TYPES Debug Release) +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Debug) +endif() + +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +# TODO this doesn't seem to have effect +set(CMAKE_ECLIPSE_VERSION Mars) + +#TODO this check is failing to fail properly on solaris with sun CC 5.10 +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CPACK_PACKAGE_VERSION_MAJOR ${PRODUCT_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${PRODUCT_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${PRODUCT_VERSION_PATCH}) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PRODUCT_VENDOR} ${PRODUCT_NAME}") +set(CPACK_PACKAGE_VENDOR "${PRODUCT_VENDOR}") +set(CPACK_PACKAGE_NAME "${PRODUCT_PACKAGE_NAME}") +set(CPACK_SYSTEM_NAME "${PRODUCT_SYSTEM_NAME}-${PRODUCT_BITS}") +set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${PRODUCT_VERSION}-${CPACK_SYSTEM_NAME}) +set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0) +set(CPACK_PACKAGING_INSTALL_PREFIX "/${CPACK_PACKAGE_NAME}") +#set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/dist/LICENSE") +set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}") +set(CPACK_GENERATOR TGZ;ZIP) + +option(ENABLE_CLANG_TIDY "Enable clang-tidy checks." false) +if(ENABLE_CLANG_TIDY) + find_program(CLANG_TIDY "clang-tidy") + if(CLANG_TIDY) + set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY} -header-filter=${CMAKE_CURRENT_SOURCE_DIR}) + option(ENABLE_CLANG_TIDY_FIX "Enable clang-tidy fix." false) + if(ENABLE_CLANG_TIDY_FIX) + set(CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY} -fix -fix-errors) + endif() + message(STATUS "clang-tidy enabled.") + else() + message(SEND_ERROR "clang-tidy enabled but not found.") + endif() +endif() + +file(GLOB_RECURSE ALL_CXX_SOURCE_FILES *.[chi]pp *.[chi]xx *.cc *.hh *.ii *.[CHI]) +find_program(CLANG_FORMAT "clang-format") +if(CLANG_FORMAT) + add_custom_target(format) + set_target_properties(format PROPERTIES EXCLUDE_FROM_ALL TRUE EXCLUDE_FROM_DEFAULT_BUILD TRUE) + + foreach(_file ${ALL_CXX_SOURCE_FILES}) + add_custom_command(TARGET format PRE_BUILD COMMAND ${CLANG_FORMAT} -i -style=file -fallback-style=Google ${_file}) + endforeach() +endif() + +if(CMAKE_GENERATOR MATCHES Win64*) + set(CMAKE_GENERATOR_TOOLSET "host=x64") +else() + set(CMAKE_GENERATOR_TOOLSET ) +endif() + +include(CPack) +include(CheckCXXCompilerFlag) +include(CheckCCompilerFlag) + +set(CMAKE_REQUIRED_LIBRARIES -m64) +check_c_compiler_flag(-m64 CFLAGS_M64_ALLOWED) +check_cxx_compiler_flag(-m64 CXXFLAGS_M64_ALLOWED) +set(CMAKE_REQUIRED_LIBRARIES) + +check_c_compiler_flag(-mt CFLAGS_mt_ALLOWED) + +if (CFLAGS_M64_ALLOWED AND CXXFLAGS_M64_ALLOWED) + set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -m64) + add_compile_options(-m64) +#TODO cmake find better way to set linker flags + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m64") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -m64") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m64") +endif() + +if (CFLAGS_mt_ALLOWED) + set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -mt) + add_compile_options(-mt) +endif() + +#TODO remove this debugging for NMake +set(CMAKE_VERBOSE_MAKEFILE 0) + +add_library(c++11 INTERFACE) + + +if(CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") + # Force linker to error on undefined symbols in shared libraries + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z defs -xatomic=none") + # TODO cmake find a better way to set runtime libraries + # C++11 requires these libraries, treat -std=c++11 as library + #TODO look into CMAKE_CXX_STANDARD_LIBRARIES + target_link_libraries(c++11 INTERFACE -std=c++11 stdc++ gcc_s CrunG3 m c) +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs") +endif() +if(MSVC) + # TODO error on warnings + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") + set(BUILD_CLI 1) + set(STRONG_NAME_KEY "" CACHE FILEPATH "Strong Name Key File") + if(EXISTS "${STRONG_NAME_KEY}") + set(SHARED_LINKER_FLAGS_STRONG_KEY "/keyfile:${STRONG_NAME_KEY}") + execute_process(COMMAND sn -p ${STRONG_NAME_KEY} ${CMAKE_CURRENT_BINARY_DIR}/public.snk) + execute_process(COMMAND sn -tp ${CMAKE_CURRENT_BINARY_DIR}/public.snk OUTPUT_VARIABLE STRONG_NAME_PUBLIC_KEY) + string(REPLACE "\n" "" STRONG_NAME_PUBLIC_KEY ${STRONG_NAME_PUBLIC_KEY}) + string(REGEX REPLACE ".*sha1\\):([a-f0-9]+).*" "\\1" STRONG_NAME_PUBLIC_KEY ${STRONG_NAME_PUBLIC_KEY}) + endif() +endif() + +find_package(Java 1.8.0.60 REQUIRED COMPONENTS Development) + +if ("${CMAKE_AR}" STREQUAL "CMAKE_AR-NOTFOUND") + message(FATAL_ERROR "Utility ar not found.") +endif() + +if (WIN32 OR ${CMAKE_GENERATOR} STREQUAL "Xcode") + set(CMAKE_USES_BUILDTYPE TRUE) + set ( _DEBUG_OR_RELEASE $<$<CONFIG:Debug>:Debug>$<$<NOT:$<CONFIG:Debug>>:Release>) +else() + set(CMAKE_USES_BUILDTYPE FALSE) + set ( _DEBUG_OR_RELEASE ) +endif() + +# Since RPATH embeds path information into the executables that +# may not be valid in all execution contexts, do not use RPATH. +set(CMAKE_SKIP_RPATH TRUE) +set(CMAKE_MACOSX_RPATH FALSE) + +# Default to only showing output on failure for unit tests but allow +# overriding with the CTEST_UNITTEST_VERBOSITY environment variable. +set(CTEST_UNITTEST_VERBOSITY --output-on-failure) +if(DEFINED ENV{CTEST_UNITTEST_VERBOSITY}) + set(CTEST_UNITTEST_VERBOSITY $ENV{CTEST_UNITTEST_VERBOSITY}) +endif() + +find_package(Geode 1.0 REQUIRED) + +add_custom_target(client-libraries) + +add_custom_target(unit-tests) +add_custom_target(run-unit-tests) +add_dependencies(run-unit-tests unit-tests) +set_target_properties(run-unit-tests PROPERTIES + EXCLUDE_FROM_ALL TRUE + EXCLUDE_FROM_DEFAULT_BUILD TRUE +) + +add_custom_target(integration-tests) +add_custom_target(run-integration-tests) +add_dependencies(run-integration-tests integration-tests) +set_target_properties(run-integration-tests PROPERTIES + EXCLUDE_FROM_ALL TRUE + EXCLUDE_FROM_DEFAULT_BUILD TRUE +) + +add_subdirectory(dependencies) +add_subdirectory(cppcache) +add_subdirectory(cryptoimpl) +add_subdirectory(dhimpl) +add_subdirectory(sqliteimpl) +add_subdirectory(tests) +add_subdirectory(templates/security) +add_subdirectory(docs/api) +if (${BUILD_CLI}) + add_subdirectory(clicache) + add_subdirectory(plugins/SQLiteCLI) +endif() + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/quickstart/ DESTINATION SampleCode/quickstart USE_SOURCE_PERMISSIONS) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cppcache/integration-test/keystore/ DESTINATION SampleCode/quickstart/keystore) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/xsds/ DESTINATION xsds) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/defaultSystem/ DESTINATION defaultSystem) + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/ DESTINATION .) + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/templates/ DESTINATION templates + PATTERN "templates/security/CMakeLists.txt" EXCLUDE + PATTERN "templates/security/CMakeLists.txt.forInstall" EXCLUDE) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/templates/security/CMakeLists.txt.forInstall RENAME CMakeLists.txt DESTINATION templates/security) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tests/javaobject/javaobject.jar DESTINATION SampleCode/quickstart/lib)
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/FindNativeClient.cmake ---------------------------------------------------------------------- diff --git a/FindNativeClient.cmake b/FindNativeClient.cmake new file mode 100644 index 0000000..f180891 --- /dev/null +++ b/FindNativeClient.cmake @@ -0,0 +1,277 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +#.rst: +# FindJava +# -------- +# +# Find Java +# +# This module finds if Java is installed and determines where the +# include files and libraries are. The caller may set variable JAVA_HOME +# to specify a Java installation prefix explicitly. +# +# +# Specify one or more of the following components as you call this find module. See example below. +# +# :: +# +# Runtime = User just want to execute some Java byte-compiled +# Development = Development tools (java, javac, javah and javadoc), includes Runtime component +# IdlJ = idl compiler for Java +# JarSigner = signer tool for jar +# +# +# This module sets the following result variables: +# +# :: +# +# Java_JAVA_EXECUTABLE = the full path to the Java runtime +# Java_JAVAC_EXECUTABLE = the full path to the Java compiler +# Java_JAVAH_EXECUTABLE = the full path to the Java header generator +# Java_JAVADOC_EXECUTABLE = the full path to the Java documention generator +# Java_IDLJ_EXECUTABLE = the full path to the Java idl compiler +# Java_JAR_EXECUTABLE = the full path to the Java archiver +# Java_JARSIGNER_EXECUTABLE = the full path to the Java jar signer +# Java_VERSION_STRING = Version of java found, eg. 1.6.0_12 +# Java_VERSION_MAJOR = The major version of the package found. +# Java_VERSION_MINOR = The minor version of the package found. +# Java_VERSION_PATCH = The patch version of the package found. +# Java_VERSION_TWEAK = The tweak version of the package found (after '_') +# Java_VERSION = This is set to: $major.$minor.$patch(.$tweak) +# +# +# +# The minimum required version of Java can be specified using the +# standard CMake syntax, e.g. find_package(Java 1.5) +# +# NOTE: ${Java_VERSION} and ${Java_VERSION_STRING} are not guaranteed to +# be identical. For example some java version may return: +# Java_VERSION_STRING = 1.5.0_17 and Java_VERSION = 1.5.0.17 +# +# another example is the Java OEM, with: Java_VERSION_STRING = 1.6.0-oem +# and Java_VERSION = 1.6.0 +# +# For these components the following variables are set: +# +# :: +# +# Java_FOUND - TRUE if all components are found. +# Java_INCLUDE_DIRS - Full paths to all include dirs. +# Java_LIBRARIES - Full paths to all libraries. +# Java_<component>_FOUND - TRUE if <component> is found. +# +# +# +# Example Usages: +# +# :: +# +# find_package(Java) +# find_package(Java COMPONENTS Runtime) +# find_package(Java COMPONENTS Development) + +include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindJavaCommon.cmake) + +# The HINTS option should only be used for values computed from the system. +set(_JAVA_HINTS) +if(_JAVA_HOME) + list(APPEND _JAVA_HINTS ${_JAVA_HOME}/bin) +endif() +list(APPEND _JAVA_HINTS + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\2.0;JavaHome]/bin" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.9;JavaHome]/bin" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.8;JavaHome]/bin" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.7;JavaHome]/bin" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.6;JavaHome]/bin" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.5;JavaHome]/bin" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/bin" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/bin" + ) +# Hard-coded guesses should still go in PATHS. This ensures that the user +# environment can always override hard guesses. +set(_JAVA_PATHS + /usr/lib/java/bin + /usr/share/java/bin + /usr/local/java/bin + /usr/local/java/share/bin + /usr/java/j2sdk1.4.2_04 + /usr/lib/j2sdk1.4-sun/bin + /usr/java/j2sdk1.4.2_09/bin + /usr/lib/j2sdk1.5-sun/bin + /opt/sun-jdk-1.5.0.04/bin + /usr/local/jdk-1.7.0/bin + /usr/local/jdk-1.6.0/bin + ) +find_program(Java_JAVA_EXECUTABLE + NAMES java + HINTS ${_JAVA_HINTS} + PATHS ${_JAVA_PATHS} +) + +if(Java_JAVA_EXECUTABLE) + execute_process(COMMAND ${Java_JAVA_EXECUTABLE} -version + RESULT_VARIABLE res + OUTPUT_VARIABLE var + ERROR_VARIABLE var # sun-java output to stderr + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE) + if( res ) + if(var MATCHES "No Java runtime present, requesting install") + set_property(CACHE Java_JAVA_EXECUTABLE + PROPERTY VALUE "Java_JAVA_EXECUTABLE-NOTFOUND") + elseif(${Java_FIND_REQUIRED}) + message( FATAL_ERROR "Error executing java -version" ) + else() + message( STATUS "Warning, could not run java -version") + endif() + else() + # extract major/minor version and patch level from "java -version" output + # Tested on linux using + # 1. Sun / Sun OEM + # 2. OpenJDK 1.6 + # 3. GCJ 1.5 + # 4. Kaffe 1.4.2 + # 5. OpenJDK 1.7.x on OpenBSD + if(var MATCHES "java version \"([0-9]+\\.[0-9]+\\.[0-9_.]+.*)\"") + # This is most likely Sun / OpenJDK, or maybe GCJ-java compat layer + set(Java_VERSION_STRING "${CMAKE_MATCH_1}") + elseif(var MATCHES "java full version \"kaffe-([0-9]+\\.[0-9]+\\.[0-9_]+)\"") + # Kaffe style + set(Java_VERSION_STRING "${CMAKE_MATCH_1}") + elseif(var MATCHES "openjdk version \"([0-9]+\\.[0-9]+\\.[0-9_]+.*)\"") + # OpenJDK ver 1.7.x on OpenBSD + set(Java_VERSION_STRING "${CMAKE_MATCH_1}") + else() + if(NOT Java_FIND_QUIETLY) + message(WARNING "regex not supported: ${var}. Please report") + endif() + endif() + string( REGEX REPLACE "([0-9]+).*" "\\1" Java_VERSION_MAJOR "${Java_VERSION_STRING}" ) + string( REGEX REPLACE "[0-9]+\\.([0-9]+).*" "\\1" Java_VERSION_MINOR "${Java_VERSION_STRING}" ) + string( REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" Java_VERSION_PATCH "${Java_VERSION_STRING}" ) + # warning tweak version can be empty: + string( REGEX REPLACE "[0-9]+\\.[0-9]+\\.[0-9]+[_\\.]?([0-9]*).*$" "\\1" Java_VERSION_TWEAK "${Java_VERSION_STRING}" ) + if( Java_VERSION_TWEAK STREQUAL "" ) # check case where tweak is not defined + set(Java_VERSION ${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}.${Java_VERSION_PATCH}) + else() + set(Java_VERSION ${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}.${Java_VERSION_PATCH}.${Java_VERSION_TWEAK}) + endif() + endif() + +endif() + + +find_program(Java_JAR_EXECUTABLE + NAMES jar + HINTS ${_JAVA_HINTS} + PATHS ${_JAVA_PATHS} +) + +find_program(Java_JAVAC_EXECUTABLE + NAMES javac + HINTS ${_JAVA_HINTS} + PATHS ${_JAVA_PATHS} +) + +find_program(Java_JAVAH_EXECUTABLE + NAMES javah + HINTS ${_JAVA_HINTS} + PATHS ${_JAVA_PATHS} +) + +find_program(Java_JAVADOC_EXECUTABLE + NAMES javadoc + HINTS ${_JAVA_HINTS} + PATHS ${_JAVA_PATHS} +) + +find_program(Java_IDLJ_EXECUTABLE + NAMES idlj + HINTS ${_JAVA_HINTS} + PATHS ${_JAVA_PATHS} +) + +find_program(Java_JARSIGNER_EXECUTABLE + NAMES jarsigner + HINTS ${_JAVA_HINTS} + PATHS ${_JAVA_PATHS} +) + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +if(Java_FIND_COMPONENTS) + set(_JAVA_REQUIRED_VARS) + foreach(component ${Java_FIND_COMPONENTS}) + # User just want to execute some Java byte-compiled + If(component STREQUAL "Runtime") + list(APPEND _JAVA_REQUIRED_VARS Java_JAVA_EXECUTABLE) + if(Java_JAVA_EXECUTABLE) + set(Java_Runtime_FOUND TRUE) + endif() + elseif(component STREQUAL "Development") + list(APPEND _JAVA_REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAVAC_EXECUTABLE + Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE) + if(Java_JAVA_EXECUTABLE AND Java_JAVAC_EXECUTABLE + AND Java_JAVAH_EXECUTABLE AND Java_JAVADOC_EXECUTABLE) + set(Java_Development_FOUND TRUE) + endif() + elseif(component STREQUAL "IdlJ") + list(APPEND _JAVA_REQUIRED_VARS Java_IDLJ_EXECUTABLE) + if(Java_IdlJ_EXECUTABLE) + set(Java_Extra_FOUND TRUE) + endif() + elseif(component STREQUAL "JarSigner") + list(APPEND _JAVA_REQUIRED_VARS Java_JARSIGNER_EXECUTABLE) + if(Java_IDLJ_EXECUTABLE) + set(Java_JarSigner_FOUND TRUE) + endif() + else() + message(FATAL_ERROR "Comp: ${component} is not handled") + endif() + endforeach() + list (REMOVE_DUPLICATES _JAVA_REQUIRED_VARS) + find_package_handle_standard_args(Java + REQUIRED_VARS ${_JAVA_REQUIRED_VARS} HANDLE_COMPONENTS + VERSION_VAR Java_VERSION + ) + if(Java_FOUND) + foreach(component ${Java_FIND_COMPONENTS}) + set(Java_${component}_FOUND TRUE) + endforeach() + endif() +else() + # Check for Development + find_package_handle_standard_args(Java + REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE + Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE + VERSION_VAR Java_VERSION + ) +endif() + + +mark_as_advanced( + Java_JAVA_EXECUTABLE + Java_JAR_EXECUTABLE + Java_JAVAC_EXECUTABLE + Java_JAVAH_EXECUTABLE + Java_JAVADOC_EXECUTABLE + Java_IDLJ_EXECUTABLE + Java_JARSIGNER_EXECUTABLE + ) + +# LEGACY +set(JAVA_RUNTIME ${Java_JAVA_EXECUTABLE}) +set(JAVA_ARCHIVE ${Java_JAR_EXECUTABLE}) +set(JAVA_COMPILE ${Java_JAVAC_EXECUTABLE}) + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/FindNativeClientCPPCache.cmake ---------------------------------------------------------------------- diff --git a/FindNativeClientCPPCache.cmake b/FindNativeClientCPPCache.cmake new file mode 100644 index 0000000..6ea6143 --- /dev/null +++ b/FindNativeClientCPPCache.cmake @@ -0,0 +1,68 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +#.rst: +# FindNativeClientCPPCache +# ------------------------ +# +# Try to find the NativeClient cppcache library +# +# Once done this will define +# +# :: +# +# NATIVECLIENT_CPPCACHE_FOUND - true when cmake has found the NativeClient CPPCache library +# NATIVECLIENT_CPPCACHE_INCLUDE_DIR - The NativeClient include directory +# NATIVECLIENT_CPPCACHE_LIBRARIES - The libraries needed to use NativeClient CPPCache library +# NATIVECLIENT_CPPCACH_DEFINITIONS - Compiler switches required for using NativeClient CPPCache library +# NATIVECLIENT_CPPCACH_VERSION_STRING - the version of NativeClient CPPCache library found + +find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h + HINTS + ${PC_LIBXML_INCLUDEDIR} + ${PC_LIBXML_INCLUDE_DIRS} + PATH_SUFFIXES libxml2 + ) + +find_library(LIBXML2_LIBRARIES NAMES xml2 libxml2 + HINTS + ${PC_LIBXML_LIBDIR} + ${PC_LIBXML_LIBRARY_DIRS} + ) + +find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint) + +set( NATIVECLIENT_CPPCACHE_VERSION_STRING "9.0" ) +set( NATIVECLIENT_CPPCACHE_FOUND "YES" ) +set( NATIVECLIENT_CPPCACHE_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIRECTORY}/include ) # TODO: Replace with install directory +set( NATIVECLIENT_CPPCACHE_LIBRARIES ${GTK_gtk_LIBRARY} + ${GTK_gdk_LIBRARY} + ${GTK_glib_LIBRARY} ) +elseif(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h") + file(STRINGS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h" libxml2_version_str + REGEX "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\".*\"") + + string(REGEX REPLACE "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1" + LIBXML2_VERSION_STRING "${libxml2_version_str}") + unset(libxml2_version_str) +endif() + +# handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 + REQUIRED_VARS LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR + VERSION_VAR LIBXML2_VERSION_STRING) + +mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARIES LIBXML2_XMLLINT_EXECUTABLE) http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/.clang-format ---------------------------------------------------------------------- diff --git a/clicache/.clang-format b/clicache/.clang-format new file mode 100644 index 0000000..23a15d5 --- /dev/null +++ b/clicache/.clang-format @@ -0,0 +1,5 @@ +# C++/CLI sources not supported in clang-format +--- +Language: Cpp +DisableFormat: true +SortIncludes: false http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/clicache/CMakeLists.txt b/clicache/CMakeLists.txt new file mode 100644 index 0000000..9ea4f82 --- /dev/null +++ b/clicache/CMakeLists.txt @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +cmake_minimum_required(VERSION 3.4) +project(clicache_src) + +add_subdirectory(src) +add_subdirectory(test) +add_subdirectory(integration-test) http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/include/gfcli/Utils.hpp ---------------------------------------------------------------------- diff --git a/clicache/include/gfcli/Utils.hpp b/clicache/include/gfcli/Utils.hpp new file mode 100644 index 0000000..86808f7 --- /dev/null +++ b/clicache/include/gfcli/Utils.hpp @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + + + +#pragma once + +#include <geode/geode_base.hpp> +#include "geode_defs.hpp" +//#include "SystemProperties.hpp" +//#include "../../impl/NativeWrapper.hpp" +//#include "../../Log.hpp" + +using namespace System; +using namespace System::Reflection; + +namespace Apache +{ + namespace Geode + { + namespace Client + { + + /// <summary> + /// Some static utility methods. + /// </summary> + public ref class Utils STATICCLASS + { + public: + + /// <summary> + /// Load a method from the given assembly path using the default + /// constructor (if not a static method) of the given type. + /// </summary> + /// <param name="assemblyPath">The path of the assembly.</param> + /// <param name="typeName"> + /// The name of the class containing the method. + /// </param> + /// <param name="methodName">The name of the method.</param> + /// <returns> + /// The <c>System.Reflection.MethodInfo</c> for the given method, + /// or null if the method is not found. + /// </returns> + static MethodInfo^ LoadMethod( String^ assemblyPath, + String^ typeName, String^ methodName); + + /// <summary> + /// Load a method from the given assembly name using the default + /// constructor (if not a static method) of the given type. + /// </summary> + /// <param name="assemblyName">The name of the assembly.</param> + /// <param name="typeName"> + /// The name of the class containing the method. + /// </param> + /// <param name="methodName">The name of the method.</param> + /// <returns> + /// The <c>System.Reflection.MethodInfo</c> for the given method, + /// or null if the method is not found. + /// </returns> + static MethodInfo^ LoadMethodFrom( String^ assemblyName, + String^ typeName, String^ methodName); + + /// <summary> + /// Utility method to get the calling thread's last system error code. + /// </summary> + static property System::Int32 LastError + { + System::Int32 get( ); + } + }; + } // namespace Client + } // namespace Geode +} // namespace Apache + http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/AckMixTests.cs ---------------------------------------------------------------------- diff --git a/clicache/integration-test/AckMixTests.cs b/clicache/integration-test/AckMixTests.cs new file mode 100644 index 0000000..8cf394d --- /dev/null +++ b/clicache/integration-test/AckMixTests.cs @@ -0,0 +1,264 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +using System; +using System.Threading; + +namespace Apache.Geode.Client.UnitTests +{ + using NUnit.Framework; + using Apache.Geode.DUnitFramework; + + [TestFixture] + [Category("unicast_only")] + public class AckMixTests : UnitTests + { + private TallyListener m_listener = new TallyListener(); + private AckMixRegionWrapper m_regionw; + private const string RegionName = "ConfusedScope"; + + private UnitProcess m_client1, m_client2; + + protected override ClientBase[] GetClients() + { + m_client1 = new UnitProcess(); + m_client2 = new UnitProcess(); + return new ClientBase[] { m_client1, m_client2 }; + } + + #region Private functions + + private void Init() + { + Properties dsysConfig = new Properties(); + dsysConfig.Insert("ack-wait-threshold", "5"); + CacheHelper.InitConfig(dsysConfig); + } + + #endregion + + #region Functions called by the tests + + public void CreateRegionNOIL(int clientNum, bool ack) + { + Init(); + string ackStr; + if (ack) + { + ackStr = "with-ack"; + } + else + { + ackStr = "no-ack"; + } + Util.Log("Creating region in client {0}, " + ackStr + + ", no-mirror, cache, no-interestlist, with-listener", clientNum); + CacheHelper.CreateILRegion(RegionName, ack, true, m_listener); + m_regionw = new AckMixRegionWrapper(RegionName); + } + + //Verify no events received by the process + public void VerifyNoEvents() + { + Util.Log("Verifying TallyListener has received nothing."); + Assert.AreEqual(0, m_listener.Creates, "Should be no creates"); + Assert.AreEqual(0, m_listener.Updates, "Should be no updates"); + Assert.IsNull(m_listener.LastKey, "Should be no key"); + Assert.IsNull(m_listener.LastValue, "Should be no value"); + } + + public void SendCreate() + { + Util.Log("put(1,1) from Client 1 noack"); + m_regionw.Put(1, 1); + m_listener.ShowTallies(); + } + + //Test cache didn't stored update + public void TestCreateFromAck() + { + Util.Log("test(1, -1) in Client 2 ack"); + m_regionw.Test(1, -1); + + // now define something of our own to test create going the other way. + Util.Log("put(2,2) from Client 2"); + m_regionw.Put(2, 2); + Assert.AreEqual(1, m_listener.Creates, "Should be 1 create."); + // send update from ACK to NOACK + Util.Log("put(1,3) from Client 2"); + + Thread.Sleep(10000); // see if we can drop the incoming create before we define the key. + m_regionw.Test(1, -1); + + m_regionw.Put(1, 3); + Assert.AreEqual(2, m_listener.Creates, "Should be 2 creates."); + m_listener.ShowTallies(); + } + + public void TestCreateFromNoAck() + { + Util.Log("test( 2, -1 ) in Client 1"); + m_regionw.Test(2, -1); + Util.Log("test( 1, 3 ) in Client 1"); + m_regionw.Test(1, 3); + + // Now Updates from Client 1 to Client 2. + Util.Log("put( 1, 5) from Client 1"); + m_regionw.Put(1, 5); + m_listener.ShowTallies(); + } + + public void TestUpdateFromAck() + { + Util.Log("test( 1, 5 ) in Client 2"); + m_regionw.Test(1, 5, true); + } + + public void TestEventCount(int clientNum) + { + Util.Log("check Client {0} event count.", clientNum); + m_listener.ShowTallies(); + Assert.AreEqual(2, m_listener.ExpectCreates(2), "Should have been 2 creates."); + Assert.AreEqual(1, m_listener.ExpectUpdates(1), "Should have been 1 update."); + } + + public void TestTimeoutSetup() + { + Util.Log("creating after timeout key to verify."); + m_regionw.Put(40000, 1); + m_regionw.SetupTimeout(m_listener); + } + + public void TestPutTimeout(int newVal) + { + Util.Log("checking that timeout works."); + try + { + m_listener.IgnoreTimeout = true; + m_regionw.RequestTimeout(); + Assert.Fail("Should have thrown TimeoutException."); + } + catch (TimeoutException) + { + // good.. expected this... now sleep a bit and move on. + Util.Log("Expected: Received TimeoutException ( good news. )"); + m_listener.IgnoreTimeout = false; + Thread.Sleep(10000); // other process should be clear by now. + m_regionw.Put(40000, newVal); // Make sure we succeed with this next put. + Util.Log("Sent update to key 40000."); + } + catch (Exception ex) + { + Util.Log(ex.ToString()); + Assert.Fail(ex.Message); + } + } + + public void TestAfterPutTimeout(int newVal) + { + Util.Log("verifing values made it through from TestTimeout."); + m_regionw.CheckTimeout(); + m_regionw.Test(40000, newVal); + } + + #endregion + + [Test] + public void AckMix() + { + m_client1.Call(CreateRegionNOIL, 1, false); + m_client2.Call(CreateRegionNOIL, 2, true); + + m_client1.Call(VerifyNoEvents); + m_client2.Call(VerifyNoEvents); + + m_client1.Call(SendCreate); + m_client2.Call(TestCreateFromAck); + + m_client1.Call(TestCreateFromNoAck); + m_client2.Call(TestUpdateFromAck); + + m_client1.Call(TestEventCount, 1); + m_client2.Call(TestEventCount, 2); + + m_client1.Call(TestTimeoutSetup); + m_client2.Call(TestPutTimeout, 4000); + + m_client1.Call(TestAfterPutTimeout, 4000); + m_client2.Call(TestPutTimeout, 5000); + + m_client1.Call(TestAfterPutTimeout, 5000); + } + } + + class AckMixRegionWrapper : RegionWrapper + { + private bool m_timeoutUpdate; + + private static CacheableString timeoutKey = + new CacheableString("timeout"); + + public AckMixRegionWrapper(string name) + : base(name) + { + m_timeoutUpdate = false; + } + + public void RequestTimeout() + { + string timeoutValue = "timeout"; + if (m_timeoutUpdate) + { + timeoutValue = "timeoutUpdate"; + } + DateTime start = DateTime.Now; + TimeSpan span; + try + { + m_region.Put(timeoutKey, timeoutValue); + span = DateTime.Now - start; + Util.Log("put took {0} millis value({1})", span.TotalMilliseconds, timeoutValue); + } + catch + { + span = DateTime.Now - start; + Util.Log("put took {0} millis value({1})", span.TotalMilliseconds, timeoutValue); + m_timeoutUpdate = true; + throw; + } + } + + public void CheckTimeout() + { + string timeoutValue = "timeout"; + if (m_timeoutUpdate) + { + timeoutValue = "timeoutUpdate"; + } + CacheableString val = m_region.Get(timeoutKey) as CacheableString; + Assert.AreEqual(timeoutValue, val.ToString()); + m_timeoutUpdate = true; + } + + public void SetupTimeout(TallyListener listener) + { + listener.IgnoreTimeout = true; + m_region.Put(timeoutKey, timeoutKey); + listener.IgnoreTimeout = false; + } + } +} http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/clicache/integration-test/AssemblyInfo.cs b/clicache/integration-test/AssemblyInfo.cs new file mode 100644 index 0000000..e54a2f7 --- /dev/null +++ b/clicache/integration-test/AssemblyInfo.cs @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyProduct("UnitTests")] +[assembly: AssemblyCopyright("Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership.")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("182f654f-12a7-4355-b31c-bd54bea9eb29")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/AttributesFactoryTestsN.cs ---------------------------------------------------------------------- diff --git a/clicache/integration-test/AttributesFactoryTestsN.cs b/clicache/integration-test/AttributesFactoryTestsN.cs new file mode 100644 index 0000000..a570ac7 --- /dev/null +++ b/clicache/integration-test/AttributesFactoryTestsN.cs @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +//using System; +//using System.Reflection; + +//#pragma warning disable 618 + +//namespace Apache.Geode.Client.UnitTests +//{ +// using NUnit.Framework; +// using Apache.Geode.DUnitFramework; +// // using Apache.Geode.Client; +// using Apache.Geode.Client; +// //using Region = Apache.Geode.Client.IRegion<Object, Object>; + +// [TestFixture] +// [Category("group1")] +// [Category("unicast_only")] +// [Category("generics")] +// public class AttributesFactoryTests : UnitTests +// { +// protected override ClientBase[] GetClients() +// { +// return null; +// } + +// [Test] +// public void InvalidTCRegionAttributes() +// { +// Properties<string, string> config = new Properties<string, string>(); +// CacheHelper.InitConfig(config); +// IRegion<object, object> region; +// RegionAttributes<object, object> attrs; +// AttributesFactory<object, object> af = new AttributesFactory<object, object>(); +// af.SetScope(ScopeType.Local); +// af.SetEndpoints("bass:1234"); +// attrs = af.CreateRegionAttributes(); +// region = CacheHelper.CreateRegion<object, object>("region1", attrs); +// try +// { +// IRegion<Object, Object> localRegion = region.GetLocalView(); +// Assert.Fail( +// "LOCAL scope is incompatible with a native client region"); +// } +// catch (UnsupportedOperationException) +// { +// Util.Log("Got expected UnsupportedOperationException for " + +// "LOCAL scope for native client region"); +// } + +// af.SetScope(ScopeType.Local); +// af.SetClientNotificationEnabled(true); +// attrs = af.CreateRegionAttributes(); +// try +// { +// region = CacheHelper.CreateRegion<object, object>("region2", attrs); +// Assert.Fail( +// "LOCAL scope is incompatible with clientNotificationEnabled"); +// } +// catch (UnsupportedOperationException) +// { +// Util.Log("Got expected UnsupportedOperationException for " + +// "clientNotificationEnabled for non native client region"); +// } + +// // Checks for HA regions + +// CacheHelper.CloseCache(); +// af.SetScope(ScopeType.Local); +// af.SetEndpoints("bass:3434"); +// af.SetClientNotificationEnabled(false); +// attrs = af.CreateRegionAttributes(); +// try +// { +// region = CacheHelper.CreateRegion<object, object>("region2", attrs); +// Assert.Fail( +// "LOCAL scope is incompatible with a native client HA region"); +// } +// catch (UnsupportedOperationException) +// { +// Util.Log("Got expected UnsupportedOperationException for " + +// "LOCAL scope for native client region"); +// } + +// af.SetScope(ScopeType.Local); +// af.SetEndpoints("none"); +// af.SetClientNotificationEnabled(false); +// attrs = af.CreateRegionAttributes(); +// region = CacheHelper.CreateRegion<object, object>("region1", attrs); +// Util.Log("C++ local region created with HA cache specification."); +// } +// } +//} http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/AttributesMutatorTestsN.cs ---------------------------------------------------------------------- diff --git a/clicache/integration-test/AttributesMutatorTestsN.cs b/clicache/integration-test/AttributesMutatorTestsN.cs new file mode 100644 index 0000000..dbd2327 --- /dev/null +++ b/clicache/integration-test/AttributesMutatorTestsN.cs @@ -0,0 +1,329 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +using System; +using System.Threading; + +#pragma warning disable 618 + +namespace Apache.Geode.Client.UnitTests +{ + using NUnit.Framework; + using Apache.Geode.DUnitFramework; + using Apache.Geode.Client; + + using GIRegion = Apache.Geode.Client.IRegion<string, string>; + + class ThinClientTallyLoader : TallyLoader<string, string> + { + // Note this just returns default(TVal) hence null or empty string, use + // GetLoadCount() to get the load count int value. + public override string Load(GIRegion region, string key, object callbackArg) + { + base.Load(region, key, callbackArg); + int loadCount = GetLoadCount(); + if (key != null) + { + Util.Log(Util.LogLevel.Debug, + "Putting the value ({0}) for local region clients only.", + loadCount); + region[key] = loadCount.ToString(); + } + return loadCount.ToString(); + } + } + + [TestFixture] + [Category("group2")] + [Category("unicast_only")] + [Category("generics")] + public class AttributesMutatorTests : ThinClientRegionSteps + { + private UnitProcess m_client1, m_client2; + private const string Key = "one"; + private const int Val = 1; + private const int TimeToLive = 5; + private const string PeerRegionName = "PEER1"; + TallyListener<string, string> m_reg1Listener1, m_reg1Listener2; + TallyListener<string, string> m_reg2Listener1, m_reg2Listener2; + TallyListener<string, string> m_reg3Listener1, m_reg3Listener2; + TallyLoader<string, string> m_reg1Loader1, m_reg1Loader2; + TallyLoader<string, string> m_reg2Loader1, m_reg2Loader2; + TallyLoader<string, string> m_reg3Loader1, m_reg3Loader2; + TallyWriter<string, string> m_reg1Writer1, m_reg1Writer2; + TallyWriter<string, string> m_reg2Writer1, m_reg2Writer2; + TallyWriter<string, string> m_reg3Writer1, m_reg3Writer2; + + protected override ClientBase[] GetClients() + { + m_client1 = new UnitProcess(); + m_client2 = new UnitProcess(); + return new ClientBase[] { m_client1, m_client2 }; + } + + protected override string ExtraPropertiesFile + { + get + { + return null; + } + } + + #region Private methods + + private void SetCacheListener(string regionName, ICacheListener<string, string> listener) + { + GIRegion region = CacheHelper.GetVerifyRegion<string, string>(regionName); + AttributesMutator<string, string> attrMutator = region.AttributesMutator; + attrMutator.SetCacheListener(listener); + } + + private void SetCacheLoader(string regionName, ICacheLoader<string, string> loader) + { + GIRegion region = CacheHelper.GetVerifyRegion<string, string>(regionName); + AttributesMutator<string, string> attrMutator = region.AttributesMutator; + attrMutator.SetCacheLoader(loader); + } + + private void SetCacheWriter(string regionName, ICacheWriter<string, string> writer) + { + GIRegion region = CacheHelper.GetVerifyRegion<string, string>(regionName); + AttributesMutator<string, string> attrMutator = region.AttributesMutator; + attrMutator.SetCacheWriter(writer); + } + + private void RegisterKeys() + { + GIRegion region0 = CacheHelper.GetRegion<string, string>(m_regionNames[0]); + GIRegion region1 = CacheHelper.GetRegion<string, string>(m_regionNames[1]); + string cKey1 = m_keys[1]; + string cKey2 = m_keys[3]; + region0.GetSubscriptionService().RegisterKeys(new string[] { cKey1 }); + region1.GetSubscriptionService().RegisterKeys(new string[] { cKey2 }); + } + + #endregion + + #region Public methods invoked by the tests + + public void StepOneCallbacks() + { + m_reg1Listener1 = new TallyListener<string, string>(); + m_reg2Listener1 = new TallyListener<string, string>(); + m_reg1Loader1 = new ThinClientTallyLoader(); + m_reg2Loader1 = new ThinClientTallyLoader(); + m_reg1Writer1 = new TallyWriter<string, string>(); + m_reg2Writer1 = new TallyWriter<string, string>(); + + SetCacheListener(RegionNames[0], m_reg1Listener1); + SetCacheLoader(RegionNames[0], m_reg1Loader1); + SetCacheWriter(RegionNames[0], m_reg1Writer1); + + SetCacheListener(RegionNames[1], m_reg2Listener1); + SetCacheLoader(RegionNames[1], m_reg2Loader1); + SetCacheWriter(RegionNames[1], m_reg2Writer1); + + RegisterKeys(); + m_reg3Listener1 = new TallyListener<string, string>(); + //m_reg3Loader1 = new TallyLoader<string, string>(); + m_reg3Loader1 = new ThinClientTallyLoader(); + m_reg3Writer1 = new TallyWriter<string, string>(); + AttributesFactory<string, string> af = new AttributesFactory<string, string>(); + + GIRegion region = CacheHelper.CreateRegion<string, string>(PeerRegionName, + af.CreateRegionAttributes()); + + SetCacheListener(PeerRegionName, m_reg3Listener1); + SetCacheLoader(PeerRegionName, m_reg3Loader1); + SetCacheWriter(PeerRegionName, m_reg3Writer1); + + // Call the loader and writer + Assert.IsNotNull(GetEntry(RegionNames[0], m_keys[0]), + "Found null value."); + Assert.IsNotNull(GetEntry(RegionNames[1], m_keys[0]), + "Found null value."); + Assert.IsNotNull(GetEntry(PeerRegionName, m_keys[0]), + "Found null value."); + + CreateEntry(PeerRegionName, m_keys[1], m_vals[1]); + } + + public void StepTwoCallbacks() + { + AttributesFactory<string, string> af = new AttributesFactory<string, string>(); + + GIRegion region = CacheHelper.CreateRegion<string, string>(PeerRegionName, + af.CreateRegionAttributes()); + + CreateEntry(RegionNames[0], m_keys[1], m_vals[1]); + CreateEntry(RegionNames[1], m_keys[3], m_vals[3]); + + SetCacheLoader(RegionNames[0], new ThinClientTallyLoader()); + SetCacheLoader(RegionNames[1], new ThinClientTallyLoader()); + + Assert.IsNotNull(GetEntry(RegionNames[0], m_keys[0]), + "Found null value in region0."); + Assert.IsNotNull(GetEntry(RegionNames[1], m_keys[0]), + "Found null value in region1."); + + } + + public void StepThreeCallbacks() + { + Assert.AreEqual(2, m_reg1Listener1.ExpectCreates(2), + "Two creation events were expected for region1."); + Assert.AreEqual(2, m_reg2Listener1.ExpectCreates(2), + "Two creation events were expected for region2."); + + Assert.AreEqual(0, m_reg1Listener1.ExpectUpdates(0), + "No update event was expected for region1."); + Assert.AreEqual(0, m_reg2Listener1.ExpectUpdates(0), + "No update event was expected for region2."); + + Assert.AreEqual(1, m_reg1Loader1.ExpectLoads(1), + "One loader event was expected for region1."); + Assert.AreEqual(1, m_reg2Loader1.ExpectLoads(1), + "One loader event was expected for region2."); + + Assert.AreEqual(1, m_reg1Writer1.ExpectCreates(1), + "One writer create event was expected for region1."); + Assert.AreEqual(1, m_reg2Writer1.ExpectCreates(1), + "One writer create event was expected for region2."); + } + + public void StepFourCallbacks() + { + UpdateEntry(m_regionNames[0], m_keys[1], m_nvals[1], true); + UpdateEntry(m_regionNames[1], m_keys[3], m_nvals[3], true); + } + + public void StepFiveCallbacks() + { + Assert.AreEqual(1, m_reg1Listener1.Updates, + "One update event was expected for region."); + Assert.AreEqual(1, m_reg2Listener1.Updates, + "One update event was expected for region."); + + m_reg1Listener2 = new TallyListener<string, string>(); + m_reg2Listener2 = new TallyListener<string, string>(); + m_reg1Loader2 = new ThinClientTallyLoader(); + m_reg2Loader2 = new ThinClientTallyLoader(); + m_reg1Writer2 = new TallyWriter<string, string>(); + m_reg2Writer2 = new TallyWriter<string, string>(); + + SetCacheListener(RegionNames[0], m_reg1Listener2); + SetCacheLoader(RegionNames[0], m_reg1Loader2); + SetCacheWriter(RegionNames[0], m_reg1Writer2); + + SetCacheListener(RegionNames[1], m_reg2Listener2); + SetCacheLoader(RegionNames[1], m_reg2Loader2); + SetCacheWriter(RegionNames[1], m_reg2Writer2); + + m_reg3Listener2 = new TallyListener<string, string>(); + //m_reg3Loader2 = new TallyLoader<string, string>(); + m_reg3Loader2 = new ThinClientTallyLoader(); + m_reg3Writer2 = new TallyWriter<string, string>(); + + SetCacheListener(PeerRegionName, m_reg3Listener2); + SetCacheLoader(PeerRegionName, m_reg3Loader2); + SetCacheWriter(PeerRegionName, m_reg3Writer2); + + // Force a fresh key get to trigger the new loaders + Assert.IsNotNull(GetEntry(RegionNames[0], m_keys[2]), + "Found null value."); + Assert.IsNotNull(GetEntry(RegionNames[1], m_keys[2]), + "Found null value."); + } + + + + #endregion + + [TearDown] + public override void EndTest() + { + base.EndTest(); + } + + [Test] + public void CreateAndVerifyExpiry() + { + try + { + IRegion<string, int> region = CacheHelper.CreateLocalRegionWithETTL<string, int>(RegionName, + ExpirationAction.LocalInvalidate, TimeToLive); + + Apache.Geode.Client.RegionAttributes<string, int> newAttrs = region.Attributes; + int ttl = newAttrs.EntryTimeToLive; + Assert.AreEqual(TimeToLive, ttl); + + region[Key] = Val; + + // countdown begins... it is ttl so access should not play into it.. + Thread.Sleep(2000); // sleep for some time, expect value to still be there. + int res = region[Key]; + Assert.IsNotNull(res); + Assert.AreEqual(Val, res); + Thread.Sleep(6000); // sleep for 6 more seconds, expect value to be invalid. + bool containsKey = region.ContainsValueForKey(Key); + Assert.IsFalse(containsKey, "The region should not contain the key"); + } + finally + { + CacheHelper.Close(); + } + } + + [Test] + public void Callbacks() + { + CacheHelper.SetupJavaServers("cacheserver_notify_subscription.xml"); + CacheHelper.StartJavaLocator(1, "GFELOC"); + Util.Log("Locator 1 started."); + CacheHelper.StartJavaServerWithLocators(1, "GFECS1", 1); + Util.Log("Cacheserver 1 started."); + + try + { + m_client1.Call(CreateTCRegions, RegionNames, CacheHelper.Locators, true); + m_client1.Call(StepOneCallbacks); + Util.Log("StepOne complete."); + + m_client2.Call(CreateTCRegions, RegionNames, CacheHelper.Locators, true); + m_client2.Call(StepTwoCallbacks); + Util.Log("StepTwo complete."); + + m_client1.Call(StepThreeCallbacks); + Util.Log("StepThree complete."); + + m_client2.Call(StepFourCallbacks); + Util.Log("StepFour complete."); + + m_client1.Call(StepFiveCallbacks); + Util.Log("StepFive complete."); + } + finally + { + CacheHelper.StopJavaServer(1); + Util.Log("Cacheserver 1 stopped."); + m_client2.Call(DestroyRegions); + CacheHelper.StopJavaLocator(1); + CacheHelper.ClearEndpoints(); + } + } + } +}