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

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

commit 00dc41547f43cd25db2c5f57c529530359db3819
Author: Igor Sapego <[email protected]>
AuthorDate: Mon Mar 20 17:58:27 2023 +0300

    IGNITE-17607 Add test
---
 .../platforms/cpp/ignite/client/compute/compute.cpp    |  2 +-
 modules/platforms/cpp/ignite/client/compute/compute.h  | 18 +++++++++++++++++-
 .../cpp/ignite/client/detail/compute/compute_impl.cpp  |  9 ++++-----
 .../cpp/ignite/client/detail/compute/compute_impl.h    |  2 +-
 .../platforms/cpp/tests/client-test/compute_test.cpp   | 18 ++++++++++++++++++
 5 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/modules/platforms/cpp/ignite/client/compute/compute.cpp 
b/modules/platforms/cpp/ignite/client/compute/compute.cpp
index 7f710bffb6..3bf267bbba 100644
--- a/modules/platforms/cpp/ignite/client/compute/compute.cpp
+++ b/modules/platforms/cpp/ignite/client/compute/compute.cpp
@@ -79,7 +79,7 @@ void compute::broadcast_async(const std::set<cluster_node>& 
nodes, std::string_v
     }
 }
 
-void compute::execute_colocated_async(const std::string &table_name, const 
ignite_tuple &key,
+void compute::execute_colocated_async(std::string_view table_name, const 
ignite_tuple &key,
     std::string_view job_class_name, const std::vector<primitive> &args,
     ignite_callback<std::optional<primitive>> callback) {
     detail::arg_check::container_non_empty(table_name, "Table name");
diff --git a/modules/platforms/cpp/ignite/client/compute/compute.h 
b/modules/platforms/cpp/ignite/client/compute/compute.h
index 130ebb7abf..1ef28478b0 100644
--- a/modules/platforms/cpp/ignite/client/compute/compute.h
+++ b/modules/platforms/cpp/ignite/client/compute/compute.h
@@ -109,10 +109,26 @@ public:
      * @param args Job arguments.
      * @param callback A callback called on operation completion with job 
execution result.
      */
-    IGNITE_API void execute_colocated_async(const std::string &table_name, 
const ignite_tuple& key,
+    IGNITE_API void execute_colocated_async(std::string_view table_name, const 
ignite_tuple& key,
         std::string_view job_class_name, const std::vector<primitive>& args,
         ignite_callback<std::optional<primitive>> callback);
 
+    /**
+     * Synchronously executes a job represented by the given class on one node 
where the given key is located.
+     *
+     * @param tableName Name of the table to be used with @c key to determine 
target node.
+     * @param key Table key to be used to determine the target node for job 
execution.
+     * @param job_class_name Java class name of the job to execute.
+     * @param args Job arguments.
+     * @return Job execution result.
+     */
+    IGNITE_API std::optional<primitive> execute_colocated(std::string_view 
table_name, const ignite_tuple& key,
+        std::string_view job_class_name, const std::vector<primitive>& args) {
+        return sync<std::optional<primitive>>([this, &table_name, &key, 
job_class_name, &args](auto callback) mutable {
+            execute_colocated_async(table_name, key, job_class_name, args, 
std::move(callback));
+        });
+    }
+
 private:
     /**
      * Constructor
diff --git 
a/modules/platforms/cpp/ignite/client/detail/compute/compute_impl.cpp 
b/modules/platforms/cpp/ignite/client/detail/compute/compute_impl.cpp
index b6ebd4dc0b..eec73996a8 100644
--- a/modules/platforms/cpp/ignite/client/detail/compute/compute_impl.cpp
+++ b/modules/platforms/cpp/ignite/client/detail/compute/compute_impl.cpp
@@ -83,11 +83,10 @@ void compute_impl::execute_on_one_node(cluster_node node, 
std::string_view job_c
         client_operation::COMPUTE_EXECUTE, writer_func, 
std::move(reader_func), std::move(callback));
 }
 
-void compute_impl::execute_colocated_async(const std::string &table_name, 
const ignite_tuple &key,
-    std::string_view job, const std::vector<primitive> &args,
-    ignite_callback<std::optional<primitive>> callback) {
-    m_tables->get_table_async(table_name,
-        [table_name, callback = std::move(callback), key, job = 
std::string(job), args, conn = m_connection]
+void compute_impl::execute_colocated_async(std::string_view table_name, const 
ignite_tuple &key, std::string_view job,
+    const std::vector<primitive> &args, 
ignite_callback<std::optional<primitive>> callback) {
+    m_tables->get_table_async(table_name, [table_name = 
std::string(table_name), callback = std::move(callback),
+            key, job = std::string(job), args, conn = m_connection]
         (auto &&res) mutable {
         if (res.has_error()) {
             callback({std::move(res.error())});
diff --git a/modules/platforms/cpp/ignite/client/detail/compute/compute_impl.h 
b/modules/platforms/cpp/ignite/client/detail/compute/compute_impl.h
index 222c22481c..f7a29200e9 100644
--- a/modules/platforms/cpp/ignite/client/detail/compute/compute_impl.h
+++ b/modules/platforms/cpp/ignite/client/detail/compute/compute_impl.h
@@ -65,7 +65,7 @@ public:
      * @param args Job arguments.
      * @param callback A callback called on operation completion with job 
execution result.
      */
-    void execute_colocated_async(const std::string &table_name, const 
ignite_tuple& key,
+    void execute_colocated_async(std::string_view table_name, const 
ignite_tuple& key,
         std::string_view job_class_name, const std::vector<primitive>& args,
         ignite_callback<std::optional<primitive>> callback);
 
diff --git a/modules/platforms/cpp/tests/client-test/compute_test.cpp 
b/modules/platforms/cpp/tests/client-test/compute_test.cpp
index 02004ee99d..318549b636 100644
--- a/modules/platforms/cpp/tests/client-test/compute_test.cpp
+++ b/modules/platforms/cpp/tests/client-test/compute_test.cpp
@@ -240,3 +240,21 @@ TEST_F(compute_test, all_arg_types) {
     check_argument<uuid>({0x123e4567e89b12d3, 0x7456426614174000}, 
"123e4567-e89b-12d3-7456-426614174000");
 }
 
+TEST_F(compute_test, execute_colocated) {
+    std::map<std::int32_t, std::string> nodes_for_values = {
+        {1, ""},
+        {2, "_2"},
+        {3, ""},
+        {5, "_2"}
+    };
+
+    for (const auto &var : nodes_for_values) {
+        SCOPED_TRACE("key=" + std::to_string(var.first) + ", node=" + 
var.second);
+        auto key = get_tuple(var.first);
+
+        auto resNodeName = m_client.get_compute().execute_colocated(TABLE_1, 
key, NODE_NAME_JOB, {});
+        auto expectedNodeName = PLATFORM_TEST_NODE_RUNNER + var.second;
+
+        EXPECT_EQ(expectedNodeName, resNodeName);
+    }
+}

Reply via email to