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

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


The following commit(s) were added to refs/heads/main by this push:
     new a4695b99f9e IGNITE-25631 C++ Client: Move verification to 
configuration methods (#6523)
a4695b99f9e is described below

commit a4695b99f9e30b0641f203d46f322259cf820401
Author: Igor Sapego <[email protected]>
AuthorDate: Tue Sep 2 10:23:07 2025 +0200

    IGNITE-25631 C++ Client: Move verification to configuration methods (#6523)
---
 modules/platforms/cpp/ignite/client/CMakeLists.txt |  1 +
 .../platforms/cpp/ignite/client/ignite_client.cpp  |  7 ---
 .../ignite/client/ignite_client_configuration.cpp  | 28 ++++++++++
 .../ignite/client/ignite_client_configuration.h    | 38 ++++++++++----
 modules/platforms/cpp/ignite/client/ssl_mode.h     |  2 +-
 .../cpp/ignite/network/detail/win/sockets.cpp      |  1 -
 .../cpp/tests/client-test/ignite_client_test.cpp   | 60 ++++++++++++++++++++++
 .../cpp/tests/client-test/ignite_runner_suite.h    |  4 +-
 8 files changed, 121 insertions(+), 20 deletions(-)

diff --git a/modules/platforms/cpp/ignite/client/CMakeLists.txt 
b/modules/platforms/cpp/ignite/client/CMakeLists.txt
index 3fdb2bdafcc..5a8f6852d2d 100644
--- a/modules/platforms/cpp/ignite/client/CMakeLists.txt
+++ b/modules/platforms/cpp/ignite/client/CMakeLists.txt
@@ -22,6 +22,7 @@ set(TARGET ${PROJECT_NAME})
 set(SOURCES
     cancel_handle.cpp
     ignite_client.cpp
+    ignite_client_configuration.cpp
     compute/broadcast_job_target.cpp
     compute/compute.cpp
     compute/job_execution.cpp
diff --git a/modules/platforms/cpp/ignite/client/ignite_client.cpp 
b/modules/platforms/cpp/ignite/client/ignite_client.cpp
index f414a0f0e5c..b7861cec4e7 100644
--- a/modules/platforms/cpp/ignite/client/ignite_client.cpp
+++ b/modules/platforms/cpp/ignite/client/ignite_client.cpp
@@ -21,8 +21,6 @@
 
 #include <ignite/common/ignite_error.h>
 
-#include "detail/argument_check_utils.h"
-
 namespace ignite {
 
 void ignite_client::start_async(ignite_client_configuration configuration, 
std::chrono::milliseconds timeout,
@@ -37,11 +35,6 @@ void ignite_client::start_async(ignite_client_configuration 
configuration, std::
 }
 
 ignite_client ignite_client::start(ignite_client_configuration configuration, 
std::chrono::milliseconds timeout) {
-    detail::arg_check::container_non_empty(configuration.get_endpoints(), 
"Connection endpoint list");
-
-    if (configuration.get_heartbeat_interval().count() < 0) {
-        throw ignite_error(error::code::ILLEGAL_ARGUMENT, "Heartbeat interval 
can not be negative");
-    }
 
     auto impl = 
std::make_shared<detail::ignite_client_impl>(std::move(configuration));
 
diff --git 
a/modules/platforms/cpp/ignite/client/ignite_client_configuration.cpp 
b/modules/platforms/cpp/ignite/client/ignite_client_configuration.cpp
new file mode 100644
index 00000000000..009095ddf8b
--- /dev/null
+++ b/modules/platforms/cpp/ignite/client/ignite_client_configuration.cpp
@@ -0,0 +1,28 @@
+/*
+ * 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 <ignite/client/ignite_client_configuration.h>
+#include <ignite/client/detail/argument_check_utils.h>
+
+
+namespace ignite {
+
+void ignite_client_configuration::check_endpoints_non_empty(const 
std::vector<std::string>& endpoints) {
+    detail::arg_check::container_non_empty(endpoints, "Connection endpoint 
list");
+}
+
+} // namespace ignite
diff --git a/modules/platforms/cpp/ignite/client/ignite_client_configuration.h 
b/modules/platforms/cpp/ignite/client/ignite_client_configuration.h
index 178be34a09e..63a304ef0d4 100644
--- a/modules/platforms/cpp/ignite/client/ignite_client_configuration.h
+++ b/modules/platforms/cpp/ignite/client/ignite_client_configuration.h
@@ -21,11 +21,14 @@
 #include <ignite/client/ignite_logger.h>
 #include <ignite/client/ssl_mode.h>
 
+#include <ignite/common/ignite_error.h>
+
 #include <initializer_list>
 #include <memory>
 #include <chrono>
 #include <string>
 #include <vector>
+#include <detail/config.h>
 
 namespace ignite {
 
@@ -37,7 +40,7 @@ public:
     /**
      * TCP port used by client by default if not specified explicitly.
      */
-    static constexpr uint16_t DEFAULT_PORT = 10800;
+    static constexpr std::uint16_t DEFAULT_PORT = 10800;
 
     /**
      * Default heartbeat interval.
@@ -53,7 +56,9 @@ public:
      * @param endpoints Endpoints list.
      */
     ignite_client_configuration(std::initializer_list<std::string_view> 
endpoints)
-        : m_endpoints(endpoints.begin(), endpoints.end()) {}
+        : m_endpoints(endpoints.begin(), endpoints.end()) {
+        check_endpoints_non_empty(m_endpoints);
+    }
 
     /**
      * Constructor.
@@ -61,7 +66,9 @@ public:
      * @param endpoints Endpoints list.
      */
     ignite_client_configuration(std::vector<std::string> endpoints) // 
NOLINT(google-explicit-constructor)
-        : m_endpoints(std::move(endpoints)) {}
+        : m_endpoints(std::move(endpoints)) {
+        check_endpoints_non_empty(m_endpoints);
+    }
 
     /**
      * Get endpoints.
@@ -86,7 +93,8 @@ public:
      * @param endpoints Endpoints.
      */
     void set_endpoints(std::initializer_list<std::string_view> endpoints) {
-        ignite_client_configuration::m_endpoints.assign(endpoints.begin(), 
endpoints.end());
+        std::vector<std::string> endpoints0(endpoints.begin(), 
endpoints.end());
+        set_endpoints(endpoints0);
     }
 
     /**
@@ -103,7 +111,8 @@ public:
      * @param endpoints Endpoints.
      */
     void set_endpoints(std::vector<std::string> endpoints) {
-        ignite_client_configuration::m_endpoints = std::move(endpoints);
+        check_endpoints_non_empty(endpoints);
+        m_endpoints = std::move(endpoints);
     }
 
     /**
@@ -135,7 +144,7 @@ public:
      *
      * @return Active connection limit.
      */
-    [[nodiscard]] uint32_t get_connection_limit() const { return 
m_connection_limit; }
+    [[nodiscard]] std::uint32_t get_connection_limit() const { return 
m_connection_limit; }
 
     /**
      * Set the connection limit.
@@ -144,7 +153,7 @@ public:
      *
      * @param limit Connections limit to set.
      */
-    void set_connection_limit(uint32_t limit) { m_connection_limit = limit; }
+    void set_connection_limit(std::uint32_t limit) { m_connection_limit = 
limit; }
 
     /**
      * Get a heartbeat interval.
@@ -170,6 +179,11 @@ public:
      * @param heartbeat_interval Heartbeat interval.
      */
     void set_heartbeat_interval(std::chrono::microseconds heartbeat_interval) {
+        if (heartbeat_interval.count() < 0) {
+            throw ignite_error(error::code::ILLEGAL_ARGUMENT, "Heartbeat 
interval can not be negative: "
+                + std::to_string(heartbeat_interval.count()) + " 
microseconds");
+        }
+
         m_heartbeat_interval = heartbeat_interval;
     }
 
@@ -269,8 +283,14 @@ public:
         m_ssl_ca_file = ssl_ca_file;
     }
 
-
 private:
+    /**
+     * Check that endpoints are not empty.
+     *
+     * @param endpoints Endpoint list.
+     */
+    IGNITE_API static void check_endpoints_non_empty(const 
std::vector<std::string>& endpoints);
+
     /** Endpoints. */
     std::vector<std::string> m_endpoints{"localhost"};
 
@@ -281,7 +301,7 @@ private:
     std::shared_ptr<ignite_client_authenticator> m_authenticator{};
 
     /** Active connections limit. */
-    uint32_t m_connection_limit{0};
+    std::uint32_t m_connection_limit{0};
 
     /** Heartbeat interval. */
     std::chrono::microseconds m_heartbeat_interval{DEFAULT_HEARTBEAT_INTERVAL};
diff --git a/modules/platforms/cpp/ignite/client/ssl_mode.h 
b/modules/platforms/cpp/ignite/client/ssl_mode.h
index bc9cc8b756f..355fb9eeafb 100644
--- a/modules/platforms/cpp/ignite/client/ssl_mode.h
+++ b/modules/platforms/cpp/ignite/client/ssl_mode.h
@@ -28,7 +28,7 @@ namespace ignite
 /** SSL Mode. */
 enum class ssl_mode
 {
-    /** Do not try establish SSL/TLS connection. */
+    /** Do not try to establish SSL/TLS connection. */
     DISABLE = 0,
 
     /** Try to establish SSL/TLS connection. Fail if the server does not 
support SSL/TLS. */
diff --git a/modules/platforms/cpp/ignite/network/detail/win/sockets.cpp 
b/modules/platforms/cpp/ignite/network/detail/win/sockets.cpp
index 53bf286d5bc..cadb976cff5 100644
--- a/modules/platforms/cpp/ignite/network/detail/win/sockets.cpp
+++ b/modules/platforms/cpp/ignite/network/detail/win/sockets.cpp
@@ -83,7 +83,6 @@ void try_set_socket_options(SOCKET socket, int buf_size, BOOL 
no_delay, BOOL out
 
     int res = setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, 
reinterpret_cast<char *>(&keep_alive), sizeof(keep_alive));
 
-    // TODO: IGNITE-17606 Disable keep-alive once heartbeats are implemented.
     if (keep_alive) {
         if (SOCKET_ERROR == res) {
             // There is no sense in configuring keep alive params if we failed 
to set up keep-alive mode.
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 5fb51d98da1..c98e242ac44 100644
--- a/modules/platforms/cpp/tests/client-test/ignite_client_test.cpp
+++ b/modules/platforms/cpp/tests/client-test/ignite_client_test.cpp
@@ -44,6 +44,66 @@ public:
     }
 };
 
+TEST_F(client_test, configuration_set_invalid_heartbeat) {
+    using namespace std::chrono_literals;
+
+    auto cfg = create_default_client_config();
+
+    EXPECT_THROW(
+        {
+            try {
+                cfg.set_heartbeat_interval(-1s);
+            } catch (const ignite_error &e) {
+                EXPECT_THAT(e.what_str(), testing::HasSubstr("Heartbeat 
interval can not be negative"));
+                throw;
+            }
+        },
+        ignite_error);
+}
+
+TEST_F(client_test, configuration_set_empty_address_constructor) {
+    EXPECT_THROW(
+        {
+            try {
+                ignite_client_configuration _cfg({});
+            } catch (const ignite_error &e) {
+                EXPECT_THAT(e.what_str(), testing::HasSubstr("Connection 
endpoint list can not be empty"));
+                throw;
+            }
+        },
+        ignite_error);
+}
+
+TEST_F(client_test, configuration_set_empty_address_setter_1) {
+    auto cfg = create_default_client_config();
+
+    EXPECT_THROW(
+        {
+            try {
+                cfg.set_endpoints({});
+            } catch (const ignite_error &e) {
+                EXPECT_THAT(e.what_str(), testing::HasSubstr("Connection 
endpoint list can not be empty"));
+                throw;
+            }
+        },
+        ignite_error);
+}
+
+TEST_F(client_test, configuration_set_empty_address_setter_2) {
+    auto cfg = create_default_client_config();
+
+    EXPECT_THROW(
+        {
+            try {
+                cfg.set_endpoints(std::vector<std::string>{});
+            } catch (const ignite_error &e) {
+                EXPECT_THAT(e.what_str(), testing::HasSubstr("Connection 
endpoint list can not be empty"));
+                throw;
+            }
+        },
+        ignite_error);
+}
+
 TEST_F(client_test, get_configuration) {
     using namespace std::chrono_literals;
 
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 98ea34614d7..b3b2aa20432 100644
--- a/modules/platforms/cpp/tests/client-test/ignite_runner_suite.h
+++ b/modules/platforms/cpp/tests/client-test/ignite_runner_suite.h
@@ -128,7 +128,7 @@ public:
     }
 
     /**
-     * Get a path to a SSL file.
+     * Get a path to an SSL file.
      * @param file
      * @return
      */
@@ -143,7 +143,7 @@ public:
     }
 
     /**
-     * Try connect to ssl server successfully.
+     * Try to connect to ssl server successfully.
      * @param timeout Timeout.
      * @return Client.
      */

Reply via email to