This is an automated email from the ASF dual-hosted git repository. isapego pushed a commit to branch ignite-17424 in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit e07dda19358470963d9c41ce9625a0a83f652c44 Author: Igor Sapego <[email protected]> AuthorDate: Mon Aug 29 14:28:49 2022 +0400 IGNITE-17424 Start Ignite node --- modules/platforms/cpp/CMakeLists.txt | 6 ++-- .../cpp/client-test/src/ignite_client_test.cpp | 27 +++++++++++++++- .../cpp/test-common/include/ignite_node.h | 34 +++++++++++++------- .../platforms/cpp/test-common/include/test_utils.h | 26 +++++++++++++++ .../platforms/cpp/test-common/src/ignite_node.cpp | 31 ++++++++++++++++-- .../platforms/cpp/test-common/src/test_utils.cpp | 37 +++++++++++++++++++--- 6 files changed, 139 insertions(+), 22 deletions(-) diff --git a/modules/platforms/cpp/CMakeLists.txt b/modules/platforms/cpp/CMakeLists.txt index 54fc4ed113..ca11746ca4 100644 --- a/modules/platforms/cpp/CMakeLists.txt +++ b/modules/platforms/cpp/CMakeLists.txt @@ -23,8 +23,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_PROJECT_VERSION ${PROJECT_VERSION}) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() +if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) + include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) + conan_basic_setup() +endif() if (UNIX) include(GNUInstallDirs) diff --git a/modules/platforms/cpp/client-test/src/ignite_client_test.cpp b/modules/platforms/cpp/client-test/src/ignite_client_test.cpp index 416ca4af6b..2413b1839b 100644 --- a/modules/platforms/cpp/client-test/src/ignite_client_test.cpp +++ b/modules/platforms/cpp/client-test/src/ignite_client_test.cpp @@ -15,8 +15,13 @@ * limitations under the License. */ +#include <thread> +#include <chrono> + #include <gtest/gtest.h> +#include "ignite_node.h" + class ClientTest : public ::testing::Test { protected: ClientTest() = default; @@ -37,5 +42,25 @@ protected: TEST_F(ClientTest, TestTest) { - EXPECT_EQ(1, 1); + std::cout << "Hello" << std::endl; + + ignite::IgniteNode node; + + node.start(); + + for (int i = 0; i < 20; ++i) + { + std::cout << node.getOutput(); + + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + + node.stop(); + + for (int i = 0; i < 2; ++i) + { + std::cout << node.getOutput(); + + std::this_thread::sleep_for(std::chrono::seconds(1)); + } } \ No newline at end of file diff --git a/modules/platforms/cpp/test-common/include/ignite_node.h b/modules/platforms/cpp/test-common/include/ignite_node.h index ad0a889336..224aa3e124 100644 --- a/modules/platforms/cpp/test-common/include/ignite_node.h +++ b/modules/platforms/cpp/test-common/include/ignite_node.h @@ -15,24 +15,25 @@ * limitations under the License. */ -#pragma once +#ifndef TEST_COMMON_IGNITE_NODE +#define TEST_COMMON_IGNITE_NODE -#include <cstdio> +//#include <cstdio> namespace ignite { class IgniteNode { public: - /** - * Constructor. - */ - IgniteNode() = default; +// /** +// * Constructor. +// */ +// IgniteNode() = default; - /** - * Destructor. - */ - ~IgniteNode() = default; +// /** +// * Destructor. +// */ +// ~IgniteNode() = default; /** * Start node. @@ -44,7 +45,16 @@ namespace ignite */ void stop(); + /** + * Get current node output. + * + * @param max Max bytes to get. + * @return Output. + */ + std::string getOutput(int max = 1024); private: - FILE* file; + FILE* stream; }; -} // namespace ignite \ No newline at end of file +} // namespace ignite + +#endif // TEST_COMMON_IGNITE_NODE diff --git a/modules/platforms/cpp/test-common/include/test_utils.h b/modules/platforms/cpp/test-common/include/test_utils.h index 8905bdbc65..ca0d00a51f 100644 --- a/modules/platforms/cpp/test-common/include/test_utils.h +++ b/modules/platforms/cpp/test-common/include/test_utils.h @@ -17,6 +17,8 @@ #pragma once +#include <cstdio> + #include <string> namespace ignite @@ -33,4 +35,28 @@ namespace ignite * @return Resolved Ignite home. */ std::string resolveIgniteHome(const std::string& path = ""); + + /** + * Get path to maven executable. + */ + std::string getMavenPath(); + + /** + * Open process. + * + * @param command System shell command line instruction. + * @param type Mode of the returned process output stream. Can be one of the following: + * "r" - The calling process can read the spawned command's standard output using the returned stream. + * "w" - The calling process can write to the spawned command's standard input using the returned stream. + * @return File stream for the process. + */ + FILE* processOpen(const char *command, const char *type); + + /** + * Waits for the associated process to terminate and returns the exit status of the command. + * + * @param stream Return value from the previous call to processOpen(). + * @return Returns the exit status of the terminating command processor, or -1 if an error occurs. + */ + int processClose(FILE* stream); } // namespace ignite \ No newline at end of file diff --git a/modules/platforms/cpp/test-common/src/ignite_node.cpp b/modules/platforms/cpp/test-common/src/ignite_node.cpp index 2c2863c122..1fb4bfb6eb 100644 --- a/modules/platforms/cpp/test-common/src/ignite_node.cpp +++ b/modules/platforms/cpp/test-common/src/ignite_node.cpp @@ -16,22 +16,47 @@ */ #include <iostream> -#include <memory> #include <stdexcept> -#include <string> -#include <array> +#include <vector> +#include <utility> #include "ignite_node.h" +#include "test_utils.h" namespace ignite { void IgniteNode::start() { + std::string home = resolveIgniteHome(); + if (home.empty()) + throw std::runtime_error( + "Can not resolve Ignite home directory. Try setting IGNITE_HOME explicitly"); + std::string command = +#ifdef WIN32 + "cmd.exe /c "; +#else + "/bin/bash -c "; +#endif + + command += getMavenPath() + " " + "exec:java@platform-test-node-runner"; + + stream = processOpen(command.c_str(), "r"); } void IgniteNode::stop() { + if (stream) + processClose(stream); + } + + std::string IgniteNode::getOutput(int max) + { + std::string buffer(max, 0); + + size_t actual = std::fread(buffer.data(), 1, max, stream); + buffer.resize(actual); + return buffer; } } // namespace ignite \ No newline at end of file diff --git a/modules/platforms/cpp/test-common/src/test_utils.cpp b/modules/platforms/cpp/test-common/src/test_utils.cpp index 3ca15df6d5..65fe5b8975 100644 --- a/modules/platforms/cpp/test-common/src/test_utils.cpp +++ b/modules/platforms/cpp/test-common/src/test_utils.cpp @@ -15,14 +15,15 @@ * limitations under the License. */ +#include <iostream> #include <filesystem> #include <functional> +#include <vector> #include "test_utils.h" namespace ignite { - /** * Checks if the path looks like binary release home directory. * Internally checks for presence of core library. @@ -66,9 +67,13 @@ namespace ignite if (!error && std::filesystem::is_directory(path)) return home.string(); - home = std::filesystem::canonical(std::getenv("IGNITE_HOME"), error); - if (!error && std::filesystem::is_directory(home)) - return home.string(); + const char *env = std::getenv("IGNITE_HOME"); + if (env) + { + home = std::filesystem::canonical(env, error); + if (!error && std::filesystem::is_directory(home)) + return home.string(); + } home = std::filesystem::current_path(); while (!home.empty() && home.has_relative_path()) @@ -80,4 +85,28 @@ namespace ignite } return home.string(); } + + std::string getMavenPath() + { + // Currently, we only support systems with "mvn" command in PATH + return "mvn"; + } + + FILE *processOpen(const char *command, const char *type) + { +#ifdef WIN32 + return _popen(command, type); +#else + return popen(command, type); +#endif + } + + int processClose(FILE *stream) + { +#ifdef WIN32 + return _pclose(stream); +#else + return pclose(stream); +#endif + } } // namespace ignite \ No newline at end of file
