Skip to content

Commit 5e6a5e8

Browse files
authored
IGNITE-26843 C++ Client: Add compatibility test suite (#6856)
1 parent 32f0661 commit 5e6a5e8

File tree

13 files changed

+638
-10
lines changed

13 files changed

+638
-10
lines changed

modules/platforms/cpp/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ option(ENABLE_CLIENT "Build Ignite.C++ Client module" ON)
3535
option(ENABLE_ODBC "Build Ignite ODBC driver module" OFF)
3636
option(ENABLE_PROTOCOL "Build Ignite Protocol library" ON)
3737
option(ENABLE_TESTS "Build Ignite.C++ tests" OFF)
38+
option(ENABLE_COMPATIBILITY_TESTS "Build Ignite.C++ compatibility tests" OFF)
3839
option(ENABLE_ADDRESS_SANITIZER "If address sanitizer is enabled" OFF)
3940
option(ENABLE_UB_SANITIZER "If undefined behavior sanitizer is enabled" OFF)
4041
option(WARNINGS_AS_ERRORS "Treat warning as errors" OFF)
@@ -144,7 +145,7 @@ endif()
144145

145146
# Add integration tests.
146147
if (${ENABLE_TESTS})
147-
if (${ENABLE_CLIENT} OR ${ENABLE_ODBC})
148+
if (${ENABLE_CLIENT} OR ${ENABLE_ODBC} OR ${ENABLE_COMPATIBILITY_TESTS})
148149
add_subdirectory(tests/test-common)
149150
endif()
150151

@@ -155,6 +156,10 @@ if (${ENABLE_TESTS})
155156
if (${ENABLE_ODBC})
156157
add_subdirectory(tests/odbc-test)
157158
endif()
159+
160+
if (${ENABLE_COMPATIBILITY_TESTS})
161+
add_subdirectory(tests/compatibility-tests)
162+
endif()
158163
endif()
159164

160165
# Source code formatting with clang-format.

modules/platforms/cpp/DEVNOTES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,11 @@ To run a specific test:
186186

187187
To debug or profile the Java side of the tests, run the `org.apache.ignite.internal.runner.app.PlatformTestNodeRunner`
188188
class in IDEA with a debugger or profiler, then run C++ tests as usual, optionally with debugger.
189+
190+
191+
### Running compatibility Tests
192+
193+
To enable compatibility test pass `-DENABLE_COMPATIBILITY_TESTS=ON` to cmake build.
194+
If you are debugging then it is recommended to run one version at once by providing environment variable e.g `IGNITE_CPP_TESTS_COMPATIBILITY_VERSIONS_OVERRIDE=3.0.0`
195+
To start tests run in modules/platforms/cpp/tests/compatibility-tests
196+
`./cmake-build-debug/bin/ignite-client-compatibility-test`
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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-compatibility-test)
19+
20+
set(TARGET ${PROJECT_NAME})
21+
22+
set(SOURCES
23+
main.cpp
24+
ignite_xml_unit_test_result_printer.cpp
25+
basic_test.cpp
26+
)
27+
28+
ignite_test(${TARGET} SOURCES ${SOURCES} LIBS ignite-test-common ignite3-client)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one or more
2+
// contributor license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright ownership.
4+
// The ASF licenses this file to You under the Apache License, Version 2.0
5+
// (the "License"); you may not use this file except in compliance with
6+
// the License. You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#include "tests/client-test/ignite_runner_suite.h"
18+
19+
using namespace ignite;
20+
21+
class basic_test_ign_version : public ignite::ignite_runner_suite {
22+
private:
23+
static ignite_client ConnectToCluster() {
24+
ignite_client_configuration cfg{get_node_addrs()};
25+
cfg.set_logger(get_logger());
26+
return ignite_client::start(cfg, std::chrono::seconds(30));
27+
}
28+
29+
protected:
30+
void SetUp() override {
31+
m_client = ConnectToCluster();
32+
33+
std::cout << "CompatibilityServer version" << ignite_runner::COMPATIBILITY_VERSION << "\n";
34+
}
35+
36+
ignite_client m_client;
37+
};
38+
39+
40+
TEST_F(basic_test_ign_version, get_cluster_nodes_successful) {
41+
auto cluster_nodes = m_client.get_cluster_nodes();
42+
43+
ASSERT_GE(cluster_nodes.size(), 1);
44+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one or more
2+
// contributor license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright ownership.
4+
// The ASF licenses this file to You under the Apache License, Version 2.0
5+
// (the "License"); you may not use this file except in compliance with
6+
// the License. You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#include "ignite_xml_unit_test_result_printer.h"
18+
19+
namespace ignite::detail {
20+
21+
ignite_xml_unit_test_result_printer::ignite_xml_unit_test_result_printer(
22+
testing::TestEventListener *delegate, std::string version)
23+
: m_delegate(delegate)
24+
, m_version(std::move(version)){}
25+
26+
void ignite_xml_unit_test_result_printer::OnTestProgramStart(const ::testing::UnitTest &unit_test) {
27+
m_delegate->OnTestProgramStart(unit_test);
28+
}
29+
30+
void ignite_xml_unit_test_result_printer::OnTestIterationStart(const ::testing::UnitTest &unit_test, int iteration) {
31+
m_delegate->OnTestIterationStart(unit_test, iteration);
32+
}
33+
34+
void ignite_xml_unit_test_result_printer::OnEnvironmentsSetUpStart(const ::testing::UnitTest &unit_test) {
35+
m_delegate->OnEnvironmentsSetUpStart(unit_test);
36+
}
37+
38+
void ignite_xml_unit_test_result_printer::OnEnvironmentsSetUpEnd(const ::testing::UnitTest &unit_test) {
39+
m_delegate->OnEnvironmentsSetUpEnd(unit_test);
40+
}
41+
42+
void ignite_xml_unit_test_result_printer::OnTestSuiteStart(const ::testing::TestSuite &test_suite) {
43+
m_delegate->OnTestSuiteStart(test_suite);
44+
}
45+
46+
void ignite_xml_unit_test_result_printer::OnTestSuiteEnd(const ::testing::TestSuite &test_suite) {
47+
m_delegate->OnTestSuiteEnd(test_suite);
48+
}
49+
50+
void ignite_xml_unit_test_result_printer::OnTestCaseStart(const ::testing::TestCase &test_case) {
51+
m_delegate->OnTestCaseStart(test_case);
52+
}
53+
54+
void ignite_xml_unit_test_result_printer::OnTestCaseEnd(const ::testing::TestCase &test_case) {
55+
m_delegate->OnTestCaseEnd(test_case);
56+
}
57+
58+
void ignite_xml_unit_test_result_printer::OnTestStart(const ::testing::TestInfo &test_info) {
59+
m_delegate->OnTestStart(test_info);
60+
}
61+
62+
void ignite_xml_unit_test_result_printer::OnTestDisabled(const testing::TestInfo &test_info) {
63+
m_delegate->OnTestDisabled(test_info);
64+
}
65+
66+
void ignite_xml_unit_test_result_printer::OnTestPartResult(const ::testing::TestPartResult &test_part_result) {
67+
m_delegate->OnTestPartResult(test_part_result);
68+
}
69+
70+
void ignite_xml_unit_test_result_printer::OnTestEnd(const ::testing::TestInfo &test_info) {
71+
m_delegate->OnTestEnd(test_info);
72+
}
73+
74+
void ignite_xml_unit_test_result_printer::OnEnvironmentsTearDownStart(const ::testing::UnitTest &unit_test) {
75+
m_delegate->OnEnvironmentsTearDownStart(unit_test);
76+
}
77+
78+
void ignite_xml_unit_test_result_printer::OnEnvironmentsTearDownEnd(const ::testing::UnitTest &unit_test) {
79+
m_delegate->OnEnvironmentsTearDownEnd(unit_test);
80+
}
81+
82+
void ignite_xml_unit_test_result_printer::OnTestIterationEnd(const ::testing::UnitTest &unit_test, int iteration) {
83+
for (int i = 0; i < unit_test.total_test_case_count(); ++i) {
84+
// We are extracting test suite info to add version info
85+
const testing::TestSuite *ts = unit_test.GetTestSuite(i);
86+
87+
// because underlying storage is std::string we able to override it content without changing length.
88+
char *s = const_cast<char *>(ts->name());
89+
90+
std::string_view sw = s;
91+
92+
std::string_view suffix = "_ign_version";
93+
94+
if (sw.rfind(suffix) != sw.size() - suffix.size()) {
95+
std::stringstream ss;
96+
ss << "Expected test suite name to have suffix '"<< suffix <<"' but got [name = "<< sw << "]";
97+
throw std::runtime_error(ss.str());
98+
}
99+
100+
// it is possible to have more complex version text like 9.1.18-p3, etc.
101+
if (m_version.size() >= suffix.size()) {
102+
std::stringstream ss;
103+
ss << "Expected version string to be shorter than a suffix but got "
104+
<< "[version = " << m_version << "; suf fix = "<< suffix <<"]";
105+
throw std::runtime_error(ss.str());
106+
}
107+
108+
auto s_it = s + (sw.size() - suffix.size() + 1 /*skip leading '_'*/);
109+
auto s_end = s + sw.size();
110+
for (auto it = m_version.begin(); it != m_version.end(); ++it, ++s_it) {
111+
char c = *it;
112+
c = c == '.' ? '_' : c;// Teamcity treats '.' specifically.
113+
*s_it = c;
114+
}
115+
116+
while (s_it != s_end) {
117+
*s_it = '_';
118+
++s_it;
119+
}
120+
}
121+
m_delegate->OnTestIterationEnd(unit_test, iteration);
122+
}
123+
124+
void ignite_xml_unit_test_result_printer::OnTestProgramEnd(const ::testing::UnitTest &unit_test) {
125+
m_delegate->OnTestProgramEnd(unit_test);
126+
}
127+
} // namespace ignite::detail
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one or more
2+
// contributor license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright ownership.
4+
// The ASF licenses this file to You under the Apache License, Version 2.0
5+
// (the "License"); you may not use this file except in compliance with
6+
// the License. You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#pragma once
18+
19+
#include <gtest/gtest.h>
20+
21+
namespace ignite::detail {
22+
/**
23+
* Wrapper for default GTest event listener responsible for xml report.
24+
* We override test suite name to include version information in order to distinguish results on TeamCity output.
25+
* GTest do not provide any API to manipulate test information so some hacks were introduced
26+
* at ignite::detail::ignite_xml_unit_test_result_printer::OnTestIterationEnd
27+
* Name requirement for test suite is enforced: test suite should end with '_ign_version' which would be replaced
28+
* with actual version in xml report.
29+
*/
30+
class ignite_xml_unit_test_result_printer : public ::testing::EmptyTestEventListener {
31+
TestEventListener *m_delegate;
32+
std::string m_version;
33+
public:
34+
ignite_xml_unit_test_result_printer(::testing::TestEventListener *delegate, std::string version);
35+
36+
~ignite_xml_unit_test_result_printer() override {
37+
delete m_delegate;
38+
}
39+
40+
void OnTestProgramStart(const testing::UnitTest &) override;
41+
void OnTestIterationStart(const testing::UnitTest &, int) override;
42+
void OnEnvironmentsSetUpStart(const testing::UnitTest &) override;
43+
void OnEnvironmentsSetUpEnd(const testing::UnitTest &) override;
44+
void OnTestSuiteStart(const testing::TestSuite &) override;
45+
void OnTestCaseStart(const testing::TestCase &) override;
46+
void OnTestStart(const testing::TestInfo &) override;
47+
void OnTestDisabled(const testing::TestInfo &) override;
48+
void OnTestPartResult(const testing::TestPartResult &) override;
49+
void OnTestEnd(const testing::TestInfo &) override;
50+
void OnTestSuiteEnd(const testing::TestSuite &) override;
51+
void OnTestCaseEnd(const testing::TestCase &) override;
52+
void OnEnvironmentsTearDownStart(const testing::UnitTest &) override;
53+
void OnEnvironmentsTearDownEnd(const testing::UnitTest &) override;
54+
void OnTestIterationEnd(const testing::UnitTest &, int) override;
55+
void OnTestProgramEnd(const testing::UnitTest &) override;
56+
};
57+
} // namespace ignite::detail

0 commit comments

Comments
 (0)