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 a661c397633d38d7507fc988395954ec750831fd
Author: Igor Sapego <[email protected]>
AuthorDate: Thu Mar 16 12:02:13 2023 +0300

    IGNITE-17607 Re-factor argument checks
---
 .../cpp/ignite/client/compute/compute.cpp          | 31 +++++------
 .../platforms/cpp/ignite/client/compute/compute.h  | 14 +++++
 .../ignite/client/detail/argument_check_utils.h    | 65 ++++++++++++++++++++++
 .../cpp/ignite/client/table/key_value_view.cpp     | 59 +++++++-------------
 .../cpp/ignite/client/table/record_view.cpp        | 32 ++++-------
 .../cpp/tests/client-test/compute_test.cpp         |  5 --
 6 files changed, 126 insertions(+), 80 deletions(-)

diff --git a/modules/platforms/cpp/ignite/client/compute/compute.cpp 
b/modules/platforms/cpp/ignite/client/compute/compute.cpp
index eab6b63092..77e803d306 100644
--- a/modules/platforms/cpp/ignite/client/compute/compute.cpp
+++ b/modules/platforms/cpp/ignite/client/compute/compute.cpp
@@ -16,6 +16,7 @@
  */
 
 #include "ignite/client/compute/compute.h"
+#include "ignite/client/detail/argument_check_utils.h"
 #include "ignite/client/detail/compute/compute_impl.h"
 
 #include <random>
@@ -38,15 +39,12 @@ typename T::value_type get_random_element(const T &cont) {
     return cont[distrib(gen)];
 }
 
-/**
- * Check value argument.
- *
- * @param value Value tuple.
- */
-template<typename T>
-void inline check_non_empty(const T &cont, const std::string& title) {
-    if (cont.empty())
-        throw ignite_error(title + " can not be empty");
+void compute::execute_async(const std::vector<cluster_node>& nodes, 
std::string_view job_class_name,
+    const std::vector<primitive>& args, 
ignite_callback<std::optional<primitive>> callback) {
+    detail::arg_check::container_non_empty(nodes, "Nodes container");
+    detail::arg_check::container_non_empty(job_class_name, "Job class name");
+
+    m_impl->execute_on_one_node(get_random_element(nodes), job_class_name, 
args, std::move(callback));
 }
 
 void compute::broadcast_async(const std::set<cluster_node>& nodes, 
std::string_view job_class_name,
@@ -54,8 +52,8 @@ void compute::broadcast_async(const std::set<cluster_node>& 
nodes, std::string_v
     ignite_callback<std::map<cluster_node, 
ignite_result<std::optional<primitive>>>> callback) {
     typedef std::map<cluster_node, ignite_result<std::optional<primitive>>> 
result_type;
 
-    check_non_empty(nodes, "Nodes set");
-    check_non_empty(job_class_name, "Job class name");
+    detail::arg_check::container_non_empty(nodes, "Nodes set");
+    detail::arg_check::container_non_empty(job_class_name, "Job class name");
 
     struct result_group {
         explicit result_group(std::int32_t cnt, ignite_callback<result_type> 
&&cb) : m_cnt(cnt), m_callback(cb) {}
@@ -81,12 +79,13 @@ void compute::broadcast_async(const std::set<cluster_node>& 
nodes, std::string_v
     }
 }
 
-void compute::execute_async(const std::vector<cluster_node>& nodes, 
std::string_view job_class_name,
-    const std::vector<primitive>& args, 
ignite_callback<std::optional<primitive>> callback) {
-    check_non_empty(nodes, "Nodes container");
-    check_non_empty(job_class_name, "Job class name");
+void compute::execute_colocated_async(const std::string &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");
+    detail::arg_check::container_non_empty(job_class_name, "Job class name");
 
-    m_impl->execute_on_one_node(get_random_element(nodes), job_class_name, 
args, std::move(callback));
+    // TODO: Implement me.
 }
 
 } // namespace ignite
diff --git a/modules/platforms/cpp/ignite/client/compute/compute.h 
b/modules/platforms/cpp/ignite/client/compute/compute.h
index 312bc04875..ff40355d8a 100644
--- a/modules/platforms/cpp/ignite/client/compute/compute.h
+++ b/modules/platforms/cpp/ignite/client/compute/compute.h
@@ -19,6 +19,7 @@
 
 #include "ignite/client/network/cluster_node.h"
 #include "ignite/client/primitive.h"
+#include "ignite/client/table/ignite_tuple.h"
 #include "ignite/client/transaction/transaction.h"
 #include "ignite/common/config.h"
 #include "ignite/common/ignite_result.h"
@@ -99,6 +100,19 @@ public:
             });
     }
 
+    /**
+     * Executes a compute job represented by the given class on one of the 
specified nodes asynchronously.
+     *
+     * @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.
+     * @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,
+        std::string_view job_class_name, const std::vector<primitive>& args,
+        ignite_callback<std::optional<primitive>> callback);
+
 private:
     /**
      * Constructor
diff --git a/modules/platforms/cpp/ignite/client/detail/argument_check_utils.h 
b/modules/platforms/cpp/ignite/client/detail/argument_check_utils.h
new file mode 100644
index 0000000000..fac3b86e45
--- /dev/null
+++ b/modules/platforms/cpp/ignite/client/detail/argument_check_utils.h
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "ignite/client/table/ignite_tuple.h"
+
+#include <string>
+
+namespace ignite::detail::arg_check {
+
+/**
+ * Check key argument.
+ *
+ * @param key Key tuple.
+ */
+void inline tuple_non_empty(const ignite_tuple &value, const std::string& 
title) {
+    if (0 == value.column_count())
+        throw ignite_error(title + " can not be empty");
+}
+
+/**
+ * Check key argument.
+ *
+ * @param key Key tuple.
+ */
+void inline key_tuple_non_empty(const ignite_tuple &key) {
+    tuple_non_empty(key, "Key tuple");
+}
+
+/**
+ * Check value argument.
+ *
+ * @param value Value tuple.
+ */
+void inline value_tuple_non_empty(const ignite_tuple &value) {
+    tuple_non_empty(value, "Value tuple");
+}
+
+/**
+ * Check value argument.
+ *
+ * @param value Value tuple.
+ */
+template<typename T>
+void inline container_non_empty(const T &cont, const std::string& title) {
+    if (cont.empty())
+        throw ignite_error(title + " can not be empty");
+}
+
+} // namespace ignite::detail::arg_check
diff --git a/modules/platforms/cpp/ignite/client/table/key_value_view.cpp 
b/modules/platforms/cpp/ignite/client/table/key_value_view.cpp
index ccd229041b..bb54ac2992 100644
--- a/modules/platforms/cpp/ignite/client/table/key_value_view.cpp
+++ b/modules/platforms/cpp/ignite/client/table/key_value_view.cpp
@@ -16,30 +16,11 @@
  */
 
 #include "ignite/client/table/key_value_view.h"
+#include "ignite/client/detail/argument_check_utils.h"
 #include "ignite/client/detail/table/table_impl.h"
 
 namespace ignite {
 
-/**
- * Check key argument.
- *
- * @param key Key tuple.
- */
-void inline check_key_argument(const ignite_tuple &key) {
-    if (0 == key.column_count())
-        throw ignite_error("Key tuple can not be empty");
-}
-
-/**
- * Check value argument.
- *
- * @param value Value tuple.
- */
-void inline check_value_argument(const ignite_tuple &value) {
-    if (0 == value.column_count())
-        throw ignite_error("Value tuple can not be empty");
-}
-
 /**
  * Process multiple kv pairs by uniting key and value part of the tuple
  * to a single record.
@@ -58,15 +39,15 @@ std::vector<ignite_tuple> concat_records(const 
std::vector<std::pair<ignite_tupl
 
 void key_value_view<ignite_tuple, ignite_tuple>::get_async(
     transaction *tx, const ignite_tuple &key, 
ignite_callback<std::optional<value_type>> callback) {
-    check_key_argument(key);
+    detail::arg_check::key_tuple_non_empty(key);
 
     m_impl->get_async(tx, key, std::move(callback));
 }
 
 void key_value_view<ignite_tuple, ignite_tuple>::put_async(
     transaction *tx, const key_type &key, const value_type &value, 
ignite_callback<void> callback) {
-    check_key_argument(key);
-    check_value_argument(value);
+    detail::arg_check::key_tuple_non_empty(key);
+    detail::arg_check::value_tuple_non_empty(value);
 
     m_impl->upsert_async(tx, detail::concat(key, value), std::move(callback));
 }
@@ -83,7 +64,7 @@ void key_value_view<ignite_tuple, 
ignite_tuple>::get_all_async(
 
 void key_value_view<ignite_tuple, ignite_tuple>::contains_async(
     transaction *tx, const ignite_tuple &key, ignite_callback<bool> callback) {
-    check_key_argument(key);
+    detail::arg_check::key_tuple_non_empty(key);
 
     m_impl->contains_async(tx, key, std::move(callback));
 }
@@ -100,31 +81,31 @@ void key_value_view<ignite_tuple, 
ignite_tuple>::put_all_async(
 
 void key_value_view<ignite_tuple, ignite_tuple>::get_and_put_async(transaction 
*tx, const key_type &key,
     const value_type &value, ignite_callback<std::optional<value_type>> 
callback) {
-    check_key_argument(key);
-    check_value_argument(value);
+    detail::arg_check::key_tuple_non_empty(key);
+    detail::arg_check::value_tuple_non_empty(value);
 
     m_impl->get_and_upsert_async(tx, detail::concat(key, value), 
std::move(callback));
 }
 
 void key_value_view<ignite_tuple, ignite_tuple>::put_if_absent_async(
     transaction *tx, const key_type &key, const value_type &value, 
ignite_callback<bool> callback) {
-    check_key_argument(key);
-    check_value_argument(value);
+    detail::arg_check::key_tuple_non_empty(key);
+    detail::arg_check::value_tuple_non_empty(value);
 
     m_impl->insert_async(tx, detail::concat(key, value), std::move(callback));
 }
 
 void key_value_view<ignite_tuple, ignite_tuple>::remove_async(
     transaction *tx, const ignite_tuple &key, ignite_callback<bool> callback) {
-    check_key_argument(key);
+    detail::arg_check::key_tuple_non_empty(key);
 
     m_impl->remove_async(tx, key, std::move(callback));
 }
 
 void key_value_view<ignite_tuple, ignite_tuple>::remove_async(
     transaction *tx, const key_type &key, const value_type &value, 
ignite_callback<bool> callback) {
-    check_key_argument(key);
-    check_value_argument(value);
+    detail::arg_check::key_tuple_non_empty(key);
+    detail::arg_check::value_tuple_non_empty(value);
 
     m_impl->remove_exact_async(tx, detail::concat(key, value), 
std::move(callback));
 }
@@ -151,32 +132,32 @@ void key_value_view<ignite_tuple, 
ignite_tuple>::remove_all_async(transaction *t
 
 void key_value_view<ignite_tuple, ignite_tuple>::get_and_remove_async(
     transaction *tx, const ignite_tuple &key, 
ignite_callback<std::optional<value_type>> callback) {
-    check_key_argument(key);
+    detail::arg_check::key_tuple_non_empty(key);
 
     m_impl->get_and_remove_async(tx, key, std::move(callback));
 }
 
 void key_value_view<ignite_tuple, ignite_tuple>::replace_async(
     transaction *tx, const key_type &key, const value_type &value, 
ignite_callback<bool> callback) {
-    check_key_argument(key);
-    check_value_argument(value);
+    detail::arg_check::key_tuple_non_empty(key);
+    detail::arg_check::value_tuple_non_empty(value);
 
     m_impl->replace_async(tx, detail::concat(key, value), std::move(callback));
 }
 
 void key_value_view<ignite_tuple, ignite_tuple>::replace_async(transaction 
*tx, const key_type &key,
     const value_type &old_value, const value_type &new_value, 
ignite_callback<bool> callback) {
-    check_key_argument(key);
-    check_value_argument(old_value);
-    check_value_argument(new_value);
+    detail::arg_check::key_tuple_non_empty(key);
+    detail::arg_check::value_tuple_non_empty(old_value);
+    detail::arg_check::value_tuple_non_empty(new_value);
 
     m_impl->replace_async(tx, detail::concat(key, old_value), 
detail::concat(key, new_value), std::move(callback));
 }
 
 void key_value_view<ignite_tuple, 
ignite_tuple>::get_and_replace_async(transaction *tx, const key_type &key,
     const value_type &value, ignite_callback<std::optional<value_type>> 
callback) {
-    check_key_argument(key);
-    check_value_argument(value);
+    detail::arg_check::key_tuple_non_empty(key);
+    detail::arg_check::value_tuple_non_empty(value);
 
     m_impl->get_and_replace_async(tx, detail::concat(key, value), 
std::move(callback));
 }
diff --git a/modules/platforms/cpp/ignite/client/table/record_view.cpp 
b/modules/platforms/cpp/ignite/client/table/record_view.cpp
index 392b115525..a21ffe01b7 100644
--- a/modules/platforms/cpp/ignite/client/table/record_view.cpp
+++ b/modules/platforms/cpp/ignite/client/table/record_view.cpp
@@ -17,21 +17,20 @@
 
 #include "ignite/client/table/record_view.h"
 #include "ignite/client/detail/table/table_impl.h"
+#include "ignite/client/detail/argument_check_utils.h"
 
 namespace ignite {
 
 void record_view<ignite_tuple>::get_async(
     transaction *tx, const ignite_tuple &key, 
ignite_callback<std::optional<value_type>> callback) {
-    if (0 == key.column_count())
-        throw ignite_error("Tuple can not be empty");
+    detail::arg_check::tuple_non_empty(key, "Tuple");
 
     m_impl->get_async(tx, key, std::move(callback));
 }
 
 void record_view<ignite_tuple>::upsert_async(
     transaction *tx, const ignite_tuple &record, ignite_callback<void> 
callback) {
-    if (0 == record.column_count())
-        throw ignite_error("Tuple can not be empty");
+    detail::arg_check::tuple_non_empty(record, "Tuple");
 
     m_impl->upsert_async(tx, record, std::move(callback));
 }
@@ -58,16 +57,14 @@ void record_view<ignite_tuple>::upsert_all_async(
 
 void record_view<ignite_tuple>::get_and_upsert_async(
     transaction *tx, const ignite_tuple &record, 
ignite_callback<std::optional<value_type>> callback) {
-    if (0 == record.column_count())
-        throw ignite_error("Tuple can not be empty");
+    detail::arg_check::tuple_non_empty(record, "Tuple");
 
     m_impl->get_and_upsert_async(tx, record, std::move(callback));
 }
 
 void record_view<ignite_tuple>::insert_async(
     transaction *tx, const ignite_tuple &record, ignite_callback<bool> 
callback) {
-    if (0 == record.column_count())
-        throw ignite_error("Tuple can not be empty");
+    detail::arg_check::tuple_non_empty(record, "Tuple");
 
     m_impl->insert_async(tx, record, std::move(callback));
 }
@@ -84,47 +81,42 @@ void record_view<ignite_tuple>::insert_all_async(
 
 void record_view<ignite_tuple>::replace_async(
     transaction *tx, const ignite_tuple &record, ignite_callback<bool> 
callback) {
-    if (0 == record.column_count())
-        throw ignite_error("Tuple can not be empty");
+    detail::arg_check::tuple_non_empty(record, "Tuple");
 
     m_impl->replace_async(tx, record, std::move(callback));
 }
 
 void record_view<ignite_tuple>::replace_async(
     transaction *tx, const ignite_tuple &record, const ignite_tuple 
&new_record, ignite_callback<bool> callback) {
-    if (0 == record.column_count() || 0 == new_record.column_count())
-        throw ignite_error("Tuple can not be empty");
+    detail::arg_check::tuple_non_empty(record, "Tuple");
+    detail::arg_check::tuple_non_empty(new_record, "Tuple");
 
     m_impl->replace_async(tx, record, new_record, std::move(callback));
 }
 
 void record_view<ignite_tuple>::get_and_replace_async(
     transaction *tx, const ignite_tuple &record, 
ignite_callback<std::optional<value_type>> callback) {
-    if (0 == record.column_count())
-        throw ignite_error("Tuple can not be empty");
+    detail::arg_check::tuple_non_empty(record, "Tuple");
 
     m_impl->get_and_replace_async(tx, record, std::move(callback));
 }
 
 void record_view<ignite_tuple>::remove_async(transaction *tx, const 
ignite_tuple &key, ignite_callback<bool> callback) {
-    if (0 == key.column_count())
-        throw ignite_error("Tuple can not be empty");
+    detail::arg_check::tuple_non_empty(key, "Tuple");
 
     m_impl->remove_async(tx, key, std::move(callback));
 }
 
 void record_view<ignite_tuple>::remove_exact_async(
     transaction *tx, const ignite_tuple &record, ignite_callback<bool> 
callback) {
-    if (0 == record.column_count())
-        throw ignite_error("Tuple can not be empty");
+    detail::arg_check::tuple_non_empty(record, "Tuple");
 
     m_impl->remove_exact_async(tx, record, std::move(callback));
 }
 
 void record_view<ignite_tuple>::get_and_remove_async(
     transaction *tx, const ignite_tuple &key, 
ignite_callback<std::optional<value_type>> callback) {
-    if (0 == key.column_count())
-        throw ignite_error("Tuple can not be empty");
+    detail::arg_check::tuple_non_empty(key, "Tuple");
 
     m_impl->get_and_remove_async(tx, key, std::move(callback));
 }
diff --git a/modules/platforms/cpp/tests/client-test/compute_test.cpp 
b/modules/platforms/cpp/tests/client-test/compute_test.cpp
index 4414e7ec3f..02004ee99d 100644
--- a/modules/platforms/cpp/tests/client-test/compute_test.cpp
+++ b/modules/platforms/cpp/tests/client-test/compute_test.cpp
@@ -25,7 +25,6 @@
 
 #include <chrono>
 #include <limits>
-#include <sstream>
 
 using namespace ignite;
 
@@ -241,7 +240,3 @@ TEST_F(compute_test, all_arg_types) {
     check_argument<uuid>({0x123e4567e89b12d3, 0x7456426614174000}, 
"123e4567-e89b-12d3-7456-426614174000");
 }
 
-
-
-
-

Reply via email to