You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by is...@apache.org on 2023/01/24 09:31:09 UTC

[ignite-3] 01/02: IGNITE-18583 Single node mode

This is an automated email from the ASF dual-hosted git repository.

isapego pushed a commit to branch ignite-18583
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit e23756c71a1b5b812ca920111caae4784233f186
Author: Igor Sapego <is...@apache.org>
AuthorDate: Tue Jan 24 13:15:09 2023 +0400

    IGNITE-18583 Single node mode
---
 .../cpp/tests/client-test/ignite_client_test.cpp        |  2 +-
 .../cpp/tests/client-test/ignite_runner_suite.h         | 16 +++++++++++++++-
 modules/platforms/cpp/tests/client-test/main.cpp        |  6 ++++++
 .../cpp/tests/client-test/record_binary_view_test.cpp   |  2 +-
 modules/platforms/cpp/tests/client-test/sql_test.cpp    |  6 +++---
 modules/platforms/cpp/tests/client-test/tables_test.cpp | 10 +++++-----
 .../cpp/tests/client-test/transactions_test.cpp         |  2 +-
 modules/platforms/cpp/tests/test-common/test_utils.cpp  | 12 ++++++++++--
 modules/platforms/cpp/tests/test-common/test_utils.h    | 17 +++++++++++++++++
 9 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/modules/platforms/cpp/tests/client-test/ignite_client_test.cpp b/modules/platforms/cpp/tests/client-test/ignite_client_test.cpp
index 143476505d..548dff30fa 100644
--- a/modules/platforms/cpp/tests/client-test/ignite_client_test.cpp
+++ b/modules/platforms/cpp/tests/client-test/ignite_client_test.cpp
@@ -32,7 +32,7 @@ using namespace ignite;
 class client_test : public ignite_runner_suite {};
 
 TEST_F(client_test, get_configuration) {
-    ignite_client_configuration cfg{NODE_ADDRS};
+    ignite_client_configuration cfg{get_node_addrs()};
     cfg.set_logger(get_logger());
     cfg.set_connection_limit(42);
 
diff --git a/modules/platforms/cpp/tests/client-test/ignite_runner_suite.h b/modules/platforms/cpp/tests/client-test/ignite_runner_suite.h
index 0801326e7d..20e152e735 100644
--- a/modules/platforms/cpp/tests/client-test/ignite_runner_suite.h
+++ b/modules/platforms/cpp/tests/client-test/ignite_runner_suite.h
@@ -21,6 +21,7 @@
 #include "ignite/client/ignite_client_configuration.h"
 
 #include "gtest_logger.h"
+#include "test_utils.h"
 
 #include <gtest/gtest.h>
 
@@ -36,12 +37,25 @@ using namespace std::string_view_literals;
  */
 class ignite_runner_suite : public ::testing::Test {
 protected:
+    static constexpr std::initializer_list<std::string_view> SINGLE_NODE_ADDR = {"127.0.0.1:10942"sv};
     static constexpr std::initializer_list<std::string_view> NODE_ADDRS = {"127.0.0.1:10942"sv, "127.0.0.1:10943"sv};
     static constexpr std::string_view TABLE_1 = "tbl1"sv;
 
     static constexpr const char *KEY_COLUMN = "key";
     static constexpr const char *VAL_COLUMN = "val";
 
+    /**
+     * Get node addresses to use for tests.
+     *
+     * @return Addresses.
+     */
+    static std::initializer_list<std::string_view> get_node_addrs() {
+        if (single_node_mode())
+            return SINGLE_NODE_ADDR;
+
+        return NODE_ADDRS;
+    }
+
     /**
      * Get logger.
      *
@@ -72,7 +86,7 @@ protected:
      * Clear table @c TABLE_1.
      */
     static void clear_table1() {
-        ignite_client_configuration cfg{NODE_ADDRS};
+        ignite_client_configuration cfg{get_node_addrs()};
         cfg.set_logger(get_logger());
         auto client = ignite_client::start(cfg, std::chrono::seconds(30));
 
diff --git a/modules/platforms/cpp/tests/client-test/main.cpp b/modules/platforms/cpp/tests/client-test/main.cpp
index 90cb01ecc1..00a871e5d6 100644
--- a/modules/platforms/cpp/tests/client-test/main.cpp
+++ b/modules/platforms/cpp/tests/client-test/main.cpp
@@ -16,6 +16,7 @@
  */
 
 #include "ignite_runner.h"
+#include "test_utils.h"
 
 #include <ignite/common/ignite_error.h>
 
@@ -58,6 +59,11 @@ void set_process_abort_handler(std::function<void(int)> handler) {
 }
 
 int main(int argc, char **argv) {
+    if (ignite::single_node_mode())
+        std::cout << "Tests run in a single-node mode." << std::endl;
+    else
+        std::cout << "Tests run in a multi-node mode." << std::endl;
+
     ignite::IgniteRunner runner;
 
     set_process_abort_handler([&](int signal) {
diff --git a/modules/platforms/cpp/tests/client-test/record_binary_view_test.cpp b/modules/platforms/cpp/tests/client-test/record_binary_view_test.cpp
index 01fc414f8f..e282a963ab 100644
--- a/modules/platforms/cpp/tests/client-test/record_binary_view_test.cpp
+++ b/modules/platforms/cpp/tests/client-test/record_binary_view_test.cpp
@@ -33,7 +33,7 @@ using namespace ignite;
 class record_binary_view_test : public ignite_runner_suite {
 protected:
     void SetUp() override {
-        ignite_client_configuration cfg{NODE_ADDRS};
+        ignite_client_configuration cfg{get_node_addrs()};
         cfg.set_logger(get_logger());
 
         m_client = ignite_client::start(cfg, std::chrono::seconds(30));
diff --git a/modules/platforms/cpp/tests/client-test/sql_test.cpp b/modules/platforms/cpp/tests/client-test/sql_test.cpp
index 97c2bbca8f..b1e6ec67d4 100644
--- a/modules/platforms/cpp/tests/client-test/sql_test.cpp
+++ b/modules/platforms/cpp/tests/client-test/sql_test.cpp
@@ -33,7 +33,7 @@ using namespace ignite;
 class sql_test : public ignite_runner_suite {
 protected:
     static void SetUpTestSuite() {
-        ignite_client_configuration cfg{NODE_ADDRS};
+        ignite_client_configuration cfg{get_node_addrs()};
         cfg.set_logger(get_logger());
         auto client = ignite_client::start(cfg, std::chrono::seconds(30));
 
@@ -50,7 +50,7 @@ protected:
     }
 
     static void TearDownTestSuite() {
-        ignite_client_configuration cfg{NODE_ADDRS};
+        ignite_client_configuration cfg{get_node_addrs()};
         cfg.set_logger(get_logger());
         auto client = ignite_client::start(cfg, std::chrono::seconds(30));
 
@@ -59,7 +59,7 @@ protected:
     }
 
     void SetUp() override {
-        ignite_client_configuration cfg{NODE_ADDRS};
+        ignite_client_configuration cfg{get_node_addrs()};
         cfg.set_logger(get_logger());
 
         m_client = ignite_client::start(cfg, std::chrono::seconds(30));
diff --git a/modules/platforms/cpp/tests/client-test/tables_test.cpp b/modules/platforms/cpp/tests/client-test/tables_test.cpp
index 04f6bc49e0..a56d562fa4 100644
--- a/modules/platforms/cpp/tests/client-test/tables_test.cpp
+++ b/modules/platforms/cpp/tests/client-test/tables_test.cpp
@@ -34,7 +34,7 @@ using namespace ignite;
 class tables_test : public ignite_runner_suite {};
 
 TEST_F(tables_test, tables_get_table) {
-    ignite_client_configuration cfg{NODE_ADDRS};
+    ignite_client_configuration cfg{get_node_addrs()};
     cfg.set_logger(get_logger());
 
     auto client = ignite_client::start(cfg, std::chrono::seconds(30));
@@ -49,7 +49,7 @@ TEST_F(tables_test, tables_get_table) {
 }
 
 TEST_F(tables_test, tables_get_table_async_promises) {
-    ignite_client_configuration cfg{NODE_ADDRS};
+    ignite_client_configuration cfg{get_node_addrs()};
     cfg.set_logger(get_logger());
 
     auto clientPromise = std::make_shared<std::promise<ignite_client>>();
@@ -78,7 +78,7 @@ TEST_F(tables_test, tables_get_table_async_callbacks) {
     auto operation1 = std::make_shared<std::promise<void>>();
     auto operation2 = std::make_shared<std::promise<void>>();
 
-    ignite_client_configuration cfg{NODE_ADDRS};
+    ignite_client_configuration cfg{get_node_addrs()};
     cfg.set_logger(get_logger());
 
     ignite_client client;
@@ -130,7 +130,7 @@ TEST_F(tables_test, tables_get_table_async_callbacks) {
 }
 
 TEST_F(tables_test, tables_get_tables) {
-    ignite_client_configuration cfg{NODE_ADDRS};
+    ignite_client_configuration cfg{get_node_addrs()};
     cfg.set_logger(get_logger());
 
     auto client = ignite_client::start(cfg, std::chrono::seconds(30));
@@ -146,7 +146,7 @@ TEST_F(tables_test, tables_get_tables) {
 }
 
 TEST_F(tables_test, tables_get_tables_async_promises) {
-    ignite_client_configuration cfg{NODE_ADDRS};
+    ignite_client_configuration cfg{get_node_addrs()};
     cfg.set_logger(get_logger());
 
     auto client = ignite_client::start(cfg, std::chrono::seconds(30));
diff --git a/modules/platforms/cpp/tests/client-test/transactions_test.cpp b/modules/platforms/cpp/tests/client-test/transactions_test.cpp
index f9b522476a..744387a95a 100644
--- a/modules/platforms/cpp/tests/client-test/transactions_test.cpp
+++ b/modules/platforms/cpp/tests/client-test/transactions_test.cpp
@@ -38,7 +38,7 @@ protected:
     void SetUp() override {
         clear_table1();
 
-        ignite_client_configuration cfg{NODE_ADDRS};
+        ignite_client_configuration cfg{get_node_addrs()};
         cfg.set_logger(get_logger());
 
         m_client = ignite_client::start(cfg, std::chrono::seconds(30));
diff --git a/modules/platforms/cpp/tests/test-common/test_utils.cpp b/modules/platforms/cpp/tests/test-common/test_utils.cpp
index 977fa2667d..21d43d14e8 100644
--- a/modules/platforms/cpp/tests/test-common/test_utils.cpp
+++ b/modules/platforms/cpp/tests/test-common/test_utils.cpp
@@ -24,6 +24,14 @@
 
 namespace ignite {
 
+std::optional<std::string> get_env(const std::string& name) {
+    const char *env = std::getenv(name.c_str());
+    if (!env)
+        return {};
+
+    return env;
+}
+
 /**
  * Checks if the path looks like binary release home directory.
  * Internally checks for presence of core library.
@@ -64,9 +72,9 @@ std::string resolveIgniteHome(const std::string &path) {
     if (!error && std::filesystem::is_directory(path))
         return home.string();
 
-    const char *env = std::getenv("IGNITE_HOME");
+    auto env = get_env("IGNITE_HOME");
     if (env) {
-        home = std::filesystem::canonical(env, error);
+        home = std::filesystem::canonical(env.value(), error);
         if (!error && std::filesystem::is_directory(home))
             return home.string();
     }
diff --git a/modules/platforms/cpp/tests/test-common/test_utils.h b/modules/platforms/cpp/tests/test-common/test_utils.h
index 81d89be641..84f257e0cf 100644
--- a/modules/platforms/cpp/tests/test-common/test_utils.h
+++ b/modules/platforms/cpp/tests/test-common/test_utils.h
@@ -27,6 +27,23 @@
 
 namespace ignite {
 
+/**
+ * Get environment variable.
+ *
+ * @param name Variable name.
+ * @return Variable value if it is set, or @c std::nullopt otherwise.
+ */
+std::optional<std::string> get_env(const std::string& name);
+
+/**
+ * Check whether tests run in single node mode.
+ *
+ * @return @c true if tests run in single node mode.
+ */
+static bool single_node_mode() {
+    return ignite::get_env("IGNITE_CPP_TESTS_USE_SINGLE_NODE").has_value();
+}
+
 /**
  * Resolve IGNITE_HOME directory. Resolution is performed in several steps:
  * 1) Check for path provided as argument.