diff options
-rw-r--r-- | contrib/native/client/CMakeLists.txt | 44 | ||||
-rw-r--r-- | contrib/native/client/cmakeModules/FindCppUnit.cmake | 67 | ||||
-rw-r--r-- | contrib/native/client/cmakeModules/FindZookeeper.cmake | 4 | ||||
-rw-r--r-- | contrib/native/client/readme.win.txt | 21 | ||||
-rw-r--r-- | contrib/native/client/src/clientlib/utils.hpp | 2 | ||||
-rw-r--r-- | contrib/native/client/src/test/CMakeLists.txt | 40 | ||||
-rw-r--r-- | contrib/native/client/src/test/UtilsTest.cpp | 51 | ||||
-rw-r--r-- | contrib/native/client/src/test/main.cpp | 39 |
8 files changed, 259 insertions, 9 deletions
diff --git a/contrib/native/client/CMakeLists.txt b/contrib/native/client/CMakeLists.txt index b53cb0a62..e61eb9c9b 100644 --- a/contrib/native/client/CMakeLists.txt +++ b/contrib/native/client/CMakeLists.txt @@ -17,9 +17,47 @@ # cmake_minimum_required(VERSION 2.6) -project(drillclient) +cmake_policy(SET CMP0043 NEW) +cmake_policy(SET CMP0048 NEW) +enable_testing() + +set (DRILL_ROOT ${CMAKE_SOURCE_DIR}/../../..) +if (NOT DEFINED DRILL_VERSION) + message("Detecting Drill version:") + if (WIN32) + find_program(POWERSHELL Powershell) + file(TO_NATIVE_PATH "${DRILL_ROOT}/pom.xml" DRILL_POM_FILE) + execute_process( + COMMAND ${POWERSHELL} "Select-Xml -Namespace @{'m'='http://maven.apache.org/POM/4.0.0'} -XPath '//m:project/m:version/text()' -Path ${DRILL_POM_FILE} | foreach {$_.Node.Value}" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE DRILL_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + else () + find_program(MVN mvn) + execute_process( + COMMAND ${MVN} -q -f ${DRILL_ROOT}/pom.xml -Dexec.executable=echo -Dexec.args=\${project.version} --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE DRILL_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + endif () + if ("${DRILL_VERSION}" STREQUAL "") + message(FATAL_ERROR "Cannot detect Drill version") + endif() +endif() + +string(REGEX REPLACE "^([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" + DRILL_VERSION + ${DRILL_VERSION} + ) + +project(drillclient + VERSION ${DRILL_VERSION} + ) message("Project Dir = ${PROJECT_SOURCE_DIR}") +message("Project version = ${PROJECT_VERSION} ") message("Source Dir = ${CMAKE_SOURCE_DIR} ") cmake_policy(SET CMP0043 NEW) @@ -76,7 +114,7 @@ find_package(Protobuf REQUIRED ) include_directories(${PROTOBUF_INCLUDE_DIR}) #Find Zookeeper -find_package(Zookeeper REQUIRED ) +find_package(Zookeeper REQUIRED ) # Generated sources @@ -105,6 +143,8 @@ add_subdirectory("${CMAKE_SOURCE_DIR}/src/clientlib/y2038") add_subdirectory("${CMAKE_SOURCE_DIR}/src/clientlib") include_directories(${CMAKE_SOURCE_DIR}/src/include ${Zookeeper_INCLUDE_DIRS}) +add_subdirectory("${CMAKE_SOURCE_DIR}/src/test") + # add a DEBUG preprocessor macro set_property( DIRECTORY diff --git a/contrib/native/client/cmakeModules/FindCppUnit.cmake b/contrib/native/client/cmakeModules/FindCppUnit.cmake new file mode 100644 index 000000000..c7d68550f --- /dev/null +++ b/contrib/native/client/cmakeModules/FindCppUnit.cmake @@ -0,0 +1,67 @@ +# +# 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. +# + +# A simple cmake module to find CppUnit (inspired by +# http://root.cern.ch/viewvc/trunk/cint/reflex/cmake/modules/FindCppUnit.cmake) + +# +# - Find CppUnit +# This module finds an installed CppUnit package. +# +# It sets the following variables: +# CPPUNIT_FOUND - Set to false if CppUnit isn't found. +# CPPUNIT_INCLUDE_DIR - The CppUnit include directory. +# CPPUNIT_LIBRARY - The CppUnit library to link against. + +if (MSVC) + if (${CMAKE_BUILD_TYPE} MATCHES "Debug") + set(CPPUNIT_BuildOutputDir "Debug") + set(CPPUNIT_LibName "cppunitd") + else() + set(CPPUNIT_BuildOutputDir "Release") + set(CPPUNIT_LibName "cppunit") + endif() + if ("${CPPUNIT_HOME}_" MATCHES "^_$") + message(" ") + message("- Please set the cache variable CPPUNIT_HOME to point to the directory with the cppunit source.") + message("- CMAKE will look for cppunit include files in $CPPUNIT_HOME/include.") + message("- CMAKE will look for cppunit library files in $CPPUNIT_HOME/src/Debug or $CPPUNIT_HOME/src/Release.") + else() + file(TO_CMAKE_PATH ${CPPUNIT_HOME} CPPUNIT_HomePath) + set(CPPUNIT_LIB_PATHS ${CPPUNIT_HomePath}/src/cppunit/${CPPUNIT_BuildOutputDir}) + + find_path(CPPUNIT_INCLUDE_DIR cppunit/Test.h ${CPPUNIT_HomePath}/include) + find_library(CPPUNIT_LIBRARY NAMES ${CPPUNIT_LibName} PATHS ${CPPUNIT_LIB_PATHS}) + endif() +else() + set(CPPUNIT_LIB_PATHS /usr/local/lib /opt/local/lib) + find_path(CPPUNIT_INCLUDE_DIR cppunit/Test.h /usr/local/include /opt/local/include) + find_library(CPPUNIT_LIBRARY NAMES cppunit PATHS ${CPPUNIT_LIB_PATHS}) +endif() + +if (CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARY) + set(CPPUNIT_FOUND TRUE) +else (CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARY) + set(CPPUNIT_FOUND FALSE) +endif (CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARY) + +if (CPPUNIT_FOUND) + message(STATUS "Found CppUnit: ${CPPUNIT_LIBRARY}") +else (CPPUNIT_FOUND) + message(WARNING "Could not find CppUnit: tests won't compile") +endif (CPPUNIT_FOUND) diff --git a/contrib/native/client/cmakeModules/FindZookeeper.cmake b/contrib/native/client/cmakeModules/FindZookeeper.cmake index 151c05cda..628bbcc82 100644 --- a/contrib/native/client/cmakeModules/FindZookeeper.cmake +++ b/contrib/native/client/cmakeModules/FindZookeeper.cmake @@ -30,8 +30,10 @@ if (MSVC) if(${CMAKE_BUILD_TYPE} MATCHES "Debug") set(ZK_BuildOutputDir "Debug") + set(ZK_LibName "zookeeper_d") else() set(ZK_BuildOutputDir "Release") + set(ZK_LibName "zookeeper") endif() if("${ZOOKEEPER_HOME}_" MATCHES "^_$") message(" ") @@ -45,7 +47,7 @@ if (MSVC) find_path(ZK_INCLUDE_DIR zookeeper.h ${Zookeeper_HomePath}/src/c/include) find_path(ZK_INCLUDE_DIR_GEN zookeeper.jute.h ${Zookeeper_HomePath}/src/c/generated) set(Zookeeper_INCLUDE_DIR zookeeper.h ${ZK_INCLUDE_DIR} ${ZK_INCLUDE_DIR_GEN} ) - find_library(Zookeeper_LIBRARY NAMES zookeeper PATHS ${Zookeeper_LIB_PATHS}) + find_library(Zookeeper_LIBRARY NAMES ${ZK_LibName} PATHS ${Zookeeper_LIB_PATHS}) endif() else() set(Zookeeper_LIB_PATHS /usr/local/lib /opt/local/lib) diff --git a/contrib/native/client/readme.win.txt b/contrib/native/client/readme.win.txt index 35dbb1d4c..93910381b 100644 --- a/contrib/native/client/readme.win.txt +++ b/contrib/native/client/readme.win.txt @@ -59,6 +59,7 @@ Windows platforms should be more or less similar. boost zookeeper C API protobufs + cppunit The Drill client is linked with STATIC versions of these libraries. The libraries are themselves linked with the DYNAMIC C Runtime DLLs. It is important that the libraries all have the same linkage model, otherwise the @@ -74,6 +75,8 @@ Windows platforms should be more or less similar. this is the directory for the full Zookeeper source not just the source for the C library. PROTOBUF_HOME - Directory where Protobuf source is installed. + CPPUNIT_HOME - Directory where CPPUnit source is installed + d) The build assumes that Powershell is installed 2.1 Boost (version 1.55) a) Download Boost from: @@ -133,13 +136,21 @@ Windows platforms should be more or less similar. fix that for the 64 bit build, apply patch zookeeper-3.4.6-x64.patch For example in Msysgit $ cd <ZOOKEEPER_HOME> && git apply <DRILL_HOME>/contrib/native/client/patches/zookeeper-3.4.6-x64.patch - c) InVisual Studio 2010 Express open <ZOOKEEPER_HOME>/src/c/zookeeper.sln + c) In Visual Studio 2010 Express open <ZOOKEEPER_HOME>/src/c/zookeeper.sln i) Add a 64 bit project configuration for each project. (Make sure the platform toolset is set to Windows7.1SDK) ii) Change the output type for the zookeeper project to a static lib Properties->Configuration Properties->General->Configuration Type = Static Library iii) In the cli project add the preprocessor define USE_STATIC_LIB - iv) Build. Build zookeeper lib first, then build cli + iv) Build. Build zookeeper lib first, then build cli + +2.4 CppUnit (3.4.6) + a) Download cppunit and unzip/untar it. + Latest version is available at: http://dev-www.libreoffice.org/src/cppunit-1.13.2.tar.gz + More informations: https://www.freedesktop.org/wiki/Software/cppunit/ + b) Set the CPPUNIT_HOME environment variable + c) InVisual Studio 2010 Express open <CPPUNIT_HOME>/src/CppUnitLibraries2010.sln + i) Build cppunit project 3 Building Drill Clientlib 3.1 SET the following environment variables @@ -152,10 +163,10 @@ Windows platforms should be more or less similar. C:> cd build a) For the 32 bit build : - C:> cmake -G "Visual Studio 10" -D ZOOKEEPER_HOME=<ZOOKEPER_HOME> -D PROTOBUF_SRC_ROOT_FOLDER=<PROTOBUF_HOME> -D CMAKE_BUILD_TYPE=Debug .. + C:> cmake -G "Visual Studio 10" -D ZOOKEEPER_HOME=<ZOOKEPER_HOME> -D PROTOBUF_SRC_ROOT_FOLDER=<PROTOBUF_HOME> -D CPPUNIT_HOME=<CPPUNIT_HOME> -D CMAKE_BUILD_TYPE=Debug .. b) For the 64 bit build : - C:> cmake -G "Visual Studio 10 Win64 " -D ZOOKEEPER_HOME=<ZOOKEPER_HOME> -D PROTOBUF_SRC_ROOT_FOLDER=<PROTOBUF_HOME> -D CMAKE_BUILD_TYPE=Debug .. + C:> cmake -G "Visual Studio 10 Win64 " -D ZOOKEEPER_HOME=<ZOOKEPER_HOME> -D PROTOBUF_SRC_ROOT_FOLDER=<PROTOBUF_HOME> -D CPPUNIT_HOME=<CPPUNIT_HOME> -D CMAKE_BUILD_TYPE=Debug .. 3.3 Open the generated <DRILL_HOME>/contrib/native/client/build/drillclient.sln file in Visual Studio. @@ -185,4 +196,4 @@ Windows platforms should be more or less similar. In particular, for debug builds, check the path of the protobuf library. 5 Testing with querySubmitter -querySubmitter query="select * from INFORMAITON_SCHEMA.SCHEMATA" type=sql connectStr=local=192.168.39.43:31010 api=sync logLevel=trace user=yourUserName password=yourPassWord
\ No newline at end of file +querySubmitter query="select * from INFORMAITON_SCHEMA.SCHEMATA" type=sql connectStr=local=192.168.39.43:31010 api=sync logLevel=trace user=yourUserName password=yourPassWord diff --git a/contrib/native/client/src/clientlib/utils.hpp b/contrib/native/client/src/clientlib/utils.hpp index 36fb91f81..3237aa333 100644 --- a/contrib/native/client/src/clientlib/utils.hpp +++ b/contrib/native/client/src/clientlib/utils.hpp @@ -62,7 +62,7 @@ class AllocatedBuffer{ }; -class Utils{ +class DECLSPEC_DRILL_CLIENT Utils{ public: static boost::random::random_device s_RNG; //Truly random (expensive and device dependent) static boost::random::mt19937 s_URNG; //Pseudo random with a period of ( 2^19937 - 1 ) diff --git a/contrib/native/client/src/test/CMakeLists.txt b/contrib/native/client/src/test/CMakeLists.txt new file mode 100644 index 000000000..892b58c46 --- /dev/null +++ b/contrib/native/client/src/test/CMakeLists.txt @@ -0,0 +1,40 @@ +# +# 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. +# + +# Drill Client unit tests +set (TESTS_SRC_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/UtilsTest.cpp + ) + +find_package(CppUnit REQUIRED) +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include ) +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../clientlib ) +include_directories(${CPPUNIT_INCLUDE_DIR}) +include_directories(${Boost_INCLUDE_DIRS}) +include_directories(${PROTOBUF_INCLUDE_DIR}) +include_directories(${Zookeeper_INCLUDE_DIRS}) + +link_directories(/usr/local/lib) +add_executable(unit-tests ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp ${TESTS_SRC_FILES} ) +target_link_libraries(unit-tests drillClient protomsgs y2038 ${CPPUNIT_LIBRARY} ${Boost_LIBRARIES} ${PROTOBUF_LIBRARY} ${Zookeeper_LIBRARIES}) + +foreach(testfile ${TESTS_SRC_FILES}) +get_filename_component(testname ${testfile} NAME_WE) +add_test(NAME ${testname} + COMMAND unit-tests ${testname}) +endforeach(testfile) diff --git a/contrib/native/client/src/test/UtilsTest.cpp b/contrib/native/client/src/test/UtilsTest.cpp new file mode 100644 index 000000000..0fba45e20 --- /dev/null +++ b/contrib/native/client/src/test/UtilsTest.cpp @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#include <string> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +#include "utils.hpp" + +class UtilsTest: public CppUnit::TestFixture { +public: + UtilsTest() {} + + CPPUNIT_TEST_SUITE( UtilsTest ); + CPPUNIT_TEST(testParseConnectStr); + CPPUNIT_TEST_SUITE_END(); + + + void testParseConnectStr() { + std::string protocol; + std::string hostAndPort; + std::string path; + + Drill::Utils::parseConnectStr("local=localhost:12345/path/to/drill", + path, + protocol, + hostAndPort); + + CPPUNIT_ASSERT(protocol == "local"); + CPPUNIT_ASSERT(hostAndPort == "localhost:12345"); + CPPUNIT_ASSERT(path == "/path/to/drill"); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest ); diff --git a/contrib/native/client/src/test/main.cpp b/contrib/native/client/src/test/main.cpp new file mode 100644 index 000000000..e5e17101d --- /dev/null +++ b/contrib/native/client/src/test/main.cpp @@ -0,0 +1,39 @@ +/* + * 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. + */ + +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <cppunit/ui/text/TestRunner.h> + +int main( int argc, char **argv) +{ + CppUnit::TextUi::TestRunner runner; + CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry(); + + CppUnit::Test* testSuite = registry.makeTest(); + CppUnit::Test* test; + if (argc > 1) { + test = testSuite->findTest(argv[1]); + } + else { + test = testSuite; + } + + runner.addTest( testSuite ); + bool wasSuccessful = runner.run("", false ); + return !wasSuccessful; +} |