Skip to content

Commit c685b09

Browse files
authored
IGNITE-17424 Basic C++ client (#1085)
1 parent 3e689e8 commit c685b09

File tree

109 files changed

+11069
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+11069
-29
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ build/
1717
*.iml
1818
*.ipr
1919
out/
20+
21+
modules/platforms/cpp/cmake-build-*

modules/platforms/cpp/CMakeLists.txt

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,80 @@
1818
cmake_minimum_required(VERSION 3.10)
1919
project(Ignite.C++ VERSION 3 LANGUAGES CXX)
2020

21-
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
22-
2321
set(CMAKE_CXX_STANDARD 17)
2422
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2523

26-
include(GNUInstallDirs)
24+
set(CMAKE_PROJECT_VERSION ${PROJECT_VERSION})
25+
26+
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
27+
message(STATUS "Conan detected. Enabling...")
28+
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
29+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
30+
conan_basic_setup()
31+
endif()
32+
33+
if (MSVC)
34+
add_compile_options(/source-charset:utf-8 /execution-charset:utf-8)
35+
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
36+
endif()
37+
38+
if (WIN32)
39+
add_definitions(-DNOMINMAX)
40+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
41+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
42+
endif()
43+
2744
set(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/ignite)
2845

2946
option(ENABLE_ADDRESS_SANITIZER "If address sanitizer is enabled" OFF)
3047
option(ENABLE_UB_SANITIZER "If undefined behavior sanitizer is enabled" OFF)
48+
option(ENABLE_CLIENT "Build Ignite.C++ Client module" ON)
49+
option(ENABLE_TESTS "Build Ignite.C++ tests" OFF)
50+
option(WARNINGS_AS_ERRORS "Treat warning as errors" OFF)
3151

3252
# Turn on DLL export directives
3353
add_compile_definitions(IGNITE_IMPL)
3454

35-
if (ENABLE_ADDRESS_SANITIZER)
36-
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=address>)
37-
add_link_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=address>)
55+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
56+
include(GNUInstallDirs)
57+
if (ENABLE_ADDRESS_SANITIZER)
58+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=address>)
59+
add_link_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=address>)
60+
endif()
61+
62+
if (ENABLE_UB_SANITIZER)
63+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=undefined>)
64+
add_link_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=undefined>)
65+
endif()
66+
endif()
67+
68+
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
69+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstandalone-debug")
3870
endif()
3971

40-
if (ENABLE_UB_SANITIZER)
41-
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=undefined>)
42-
add_link_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=undefined>)
72+
if (${WARNINGS_AS_ERRORS})
73+
if (MSVC)
74+
add_compile_options(/WX)
75+
else()
76+
add_compile_options(-Wall -Wextra -Werror -Wno-variadic-macros)
77+
endif()
4378
endif()
4479

80+
enable_testing()
81+
4582
add_subdirectory(common)
4683
add_subdirectory(schema)
4784

48-
enable_testing()
85+
if (${ENABLE_CLIENT})
86+
add_subdirectory(protocol)
87+
add_subdirectory(network)
88+
add_subdirectory(client)
89+
endif()
4990

50-
add_subdirectory(tests)
91+
if (${ENABLE_TESTS})
92+
add_subdirectory(tests)
93+
if (${ENABLE_CLIENT})
94+
add_subdirectory(test-common)
95+
add_subdirectory(client-test)
96+
endif()
97+
endif()

modules/platforms/cpp/DEVNOTES.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
## Prerequisites
2+
* C++ compiler supporting C++17
3+
* Java 11 SDK
4+
* Maven 3.6.0+ (for building)
5+
* Conan C/C++ package manager
6+
* CMake 3.10+
7+
8+
## Build Java
9+
In repo root: `mvn clean install -DskipTests`
10+
11+
## Build C++
12+
13+
### For Windows Developers
14+
Building in debug mode with tests. In this dir:
15+
```shell
16+
mkdir cmake-build-debug
17+
cd cmake-build-debug
18+
conan install .. --build=missing -s build_type=Debug
19+
cmake .. -DENABLE_TESTS=ON
20+
cmake --build . -j8
21+
```
22+
23+
### For Linux Developers
24+
Building in debug mode with tests. In this dir:
25+
```shell
26+
mkdir cmake-build-debug
27+
cd cmake-build-debug
28+
conan install .. --build=missing -s build_type=Debug -s compiler.libcxx=libstdc++11 -o boost:shared=True
29+
cmake .. -DENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
30+
cmake --build . -j8
31+
```
32+
33+
### For Windows users
34+
Building in release mode without tests. In this dir:
35+
```shell
36+
mkdir cmake-build-release
37+
cd cmake-build-release
38+
conan install .. --build=missing -s build_type=Release
39+
cmake .. -DENABLE_TESTS=OFF
40+
cmake --build . -j8
41+
```
42+
43+
### For Linux users
44+
Building in release mode without tests. In this dir:
45+
```shell
46+
mkdir cmake-build-release
47+
cd cmake-build-release
48+
conan install .. --build=missing -s build_type=Release -s compiler.libcxx=libstdc++11 -o boost:shared=True
49+
cmake .. -DENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=Release
50+
cmake --build . -j8
51+
```
52+
53+
## Run Tests
54+
55+
### Windows
56+
In this dir: `./cmake-build-debug/bin/ignite-client-test.exe`
57+
Specific test: `./cmake-build-debug/bin/ignite-client-test.exe --gtest_filter=Test_Cases1*`
58+
59+
## Start a Test Node
60+
* cd `modules/runner`
61+
* `mvn exec:java@platform-test-node-runner`
62+
63+
To debug or profile Java side of the tests, run `org.apache.ignite.internal.runner.app.PlatformTestNodeRunner` class in IDEA with a debugger or profiler,
64+
then run C++ tests as always or with debugger.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
project(ignite-client-test)
19+
20+
set(TARGET ${PROJECT_NAME})
21+
22+
find_package(GTest REQUIRED)
23+
24+
include_directories(include src ${GTEST_INCLUDE_DIR})
25+
26+
enable_testing()
27+
28+
set(SOURCES
29+
src/ignite_client_test.cpp
30+
src/main.cpp
31+
)
32+
33+
add_executable(${TARGET} ${SOURCES})
34+
35+
target_link_libraries(${TARGET} ignite-test-common ignite-client GTest::gtest)
36+
37+
set(TEST_TARGET IgniteClientTest)
38+
add_test(NAME ${TEST_TARGET} COMMAND ${TARGET})
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include <memory>
21+
#include <string>
22+
#include <sstream>
23+
24+
#include <gtest/gtest.h>
25+
26+
namespace ignite
27+
{
28+
29+
/**
30+
* Test logger.
31+
*/
32+
class GtestLogger : public IgniteLogger
33+
{
34+
public:
35+
/**
36+
* Construct.
37+
*
38+
* @param includeTs Include timestamps.
39+
* @param debug Enable debug.
40+
*/
41+
GtestLogger(bool includeTs, bool debug) :
42+
m_includeTs(includeTs),
43+
m_debug(debug) { }
44+
45+
void logError(std::string_view message) override {
46+
std::cout << "[ ] [ ERROR ] " + std::string(message) + '\n' << std::flush;
47+
}
48+
49+
void logWarning(std::string_view message) override {
50+
std::cout << "[ ] [ WARNING ] " + std::string(message) + '\n' << std::flush;
51+
}
52+
53+
void logInfo(std::string_view message) override {
54+
std::cout << "[ ] [ INFO ] " + std::string(message) + '\n' << std::flush;
55+
}
56+
57+
void logDebug(std::string_view message) override {
58+
if (m_debug)
59+
std::cout << "[ ] [ DEBUG ] " + std::string(message) + '\n' << std::flush;
60+
}
61+
62+
private:
63+
/**
64+
* Get timestamp in string format.
65+
*
66+
* @return Timestamp string.
67+
*/
68+
[[nodiscard]]
69+
std::string getTimestamp() const
70+
{
71+
if (!m_includeTs)
72+
return {};
73+
74+
using clock = std::chrono::system_clock;
75+
76+
auto now = clock::now();
77+
auto cTime = clock::to_time_t(now);
78+
79+
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
80+
81+
std::stringstream ss;
82+
ss << std::put_time(std::localtime(&cTime), "%H:%M:%S.") << std::setw(3) << std::setfill('0') << (ms.count() % 1000) << " ";
83+
return ss.str();
84+
}
85+
86+
/** Include timestamps. */
87+
bool m_includeTs;
88+
89+
/** Include debug messages. */
90+
bool m_debug;
91+
};
92+
93+
} // namespace ignite

0 commit comments

Comments
 (0)