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 2022/09/09 20:00:45 UTC

[ignite-3] 04/17: IGNITE-17424 Basic test utils

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 2e76d35c09343e7a192909a8ea76adb076902673
Author: Igor Sapego <is...@apache.org>
AuthorDate: Mon Aug 29 11:21:39 2022 +0400

    IGNITE-17424 Basic test utils
---
 modules/platforms/cpp/CMakeLists.txt               | 10 ++-
 modules/platforms/cpp/test-common/CMakeLists.txt   |  3 +-
 .../cpp/test-common/include/ignite_node.h          | 50 +++++++++++++
 .../platforms/cpp/test-common/include/test_utils.h | 36 ++++++++++
 .../platforms/cpp/test-common/src/ignite_node.cpp  | 37 ++++++++++
 .../platforms/cpp/test-common/src/test_utils.cpp   | 83 ++++++++++++++++++++++
 6 files changed, 217 insertions(+), 2 deletions(-)

diff --git a/modules/platforms/cpp/CMakeLists.txt b/modules/platforms/cpp/CMakeLists.txt
index 436c8e847e..54fc4ed113 100644
--- a/modules/platforms/cpp/CMakeLists.txt
+++ b/modules/platforms/cpp/CMakeLists.txt
@@ -26,7 +26,15 @@ set(CMAKE_PROJECT_VERSION ${PROJECT_VERSION})
 include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
 conan_basic_setup()
 
-#include(GNUInstallDirs)
+if (UNIX)
+	include(GNUInstallDirs)
+endif()
+
+if (MSVC)
+	add_compile_options(/source-charset:utf-8 /execution-charset:utf-8)
+	add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
+endif()
+
 set(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/ignite)
 
 option(ENABLE_ADDRESS_SANITIZER "If address sanitizer is enabled" OFF)
diff --git a/modules/platforms/cpp/test-common/CMakeLists.txt b/modules/platforms/cpp/test-common/CMakeLists.txt
index eb186ba9ca..396ee4ed72 100644
--- a/modules/platforms/cpp/test-common/CMakeLists.txt
+++ b/modules/platforms/cpp/test-common/CMakeLists.txt
@@ -23,7 +23,8 @@ set(TARGET ${PROJECT_NAME})
 include_directories(include)
 
 set(SOURCES
-	src/test_utils.cpp
+        src/ignite_node.cpp
+        src/test_utils.cpp
 )
 
 add_library(${TARGET} OBJECT ${SOURCES})
diff --git a/modules/platforms/cpp/test-common/include/ignite_node.h b/modules/platforms/cpp/test-common/include/ignite_node.h
new file mode 100644
index 0000000000..ad0a889336
--- /dev/null
+++ b/modules/platforms/cpp/test-common/include/ignite_node.h
@@ -0,0 +1,50 @@
+/*
+ * 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 <cstdio>
+
+namespace ignite
+{
+    class IgniteNode
+    {
+    public:
+        /**
+         * Constructor.
+         */
+        IgniteNode() = default;
+
+        /**
+         * Destructor.
+         */
+        ~IgniteNode() = default;
+
+        /**
+         * Start node.
+         */
+        void start();
+
+        /**
+         * Stop node.
+         */
+        void stop();
+
+    private:
+        FILE* file;
+    };
+} // namespace ignite
\ No newline at end of file
diff --git a/modules/platforms/cpp/test-common/include/test_utils.h b/modules/platforms/cpp/test-common/include/test_utils.h
index e69de29bb2..8905bdbc65 100644
--- a/modules/platforms/cpp/test-common/include/test_utils.h
+++ b/modules/platforms/cpp/test-common/include/test_utils.h
@@ -0,0 +1,36 @@
+/*
+ * 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 <string>
+
+namespace ignite
+{
+    /**
+     * Resolve IGNITE_HOME directory. Resolution is performed in several steps:
+     * 1) Check for path provided as argument.
+     * 2) Check for environment variable.
+     * 3) Check for current working directory.
+     * Result of these checks are evaluated based on existence of certain predefined folders inside possible Ignite
+     * home. If they are found, IGNITE_HOME is considered resolved.
+     *
+     * @param path Optional path to check.
+     * @return Resolved Ignite home.
+     */
+    std::string resolveIgniteHome(const std::string& path = "");
+} // 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
new file mode 100644
index 0000000000..2c2863c122
--- /dev/null
+++ b/modules/platforms/cpp/test-common/src/ignite_node.cpp
@@ -0,0 +1,37 @@
+/*
+ * 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 <iostream>
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <array>
+
+#include "ignite_node.h"
+
+namespace ignite
+{
+    void IgniteNode::start()
+    {
+
+    }
+
+    void IgniteNode::stop()
+    {
+
+    }
+} // 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 e69de29bb2..3ca15df6d5 100644
--- a/modules/platforms/cpp/test-common/src/test_utils.cpp
+++ b/modules/platforms/cpp/test-common/src/test_utils.cpp
@@ -0,0 +1,83 @@
+/*
+ * 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 <filesystem>
+#include <functional>
+
+#include "test_utils.h"
+
+namespace ignite
+{
+
+    /**
+     * Checks if the path looks like binary release home directory.
+     * Internally checks for presence of core library.
+     * @return @c true if the path looks like binary release home directory.
+     */
+    bool looksLikeBinaryReleaseHome(const std::filesystem::path& path)
+    {
+        std::filesystem::path coreLibPath = path / "libs";
+        if (!is_directory(coreLibPath))
+            return false;
+
+        auto iter = std::filesystem::directory_iterator{coreLibPath};
+        return std::any_of(iter, std::filesystem::end(iter), [](auto entry) {
+            const std::filesystem::path& entryPath = entry.path();
+            if (entryPath.extension() != "jar")
+                return false;
+
+            std::string stem = entryPath.stem().string();
+            return stem.find("ignite-core") == 0;
+        });
+    }
+
+    /**
+     * Checks if the path looks like source release home directory.
+     * Internally checks for presence of core source directory.
+     * @return @c true if the path looks like binary release home directory.
+     */
+    bool looksLikeSourceReleaseHome(const std::filesystem::path& path)
+    {
+        std::filesystem::path coreSourcePath =
+                path / "modules" / "core" / "src" / "main" / "java" / "org" / "apache" / "ignite";
+
+        return std::filesystem::is_directory(coreSourcePath);
+    }
+
+    std::string resolveIgniteHome(const std::string& path)
+    {
+        std::error_code error;
+
+        std::filesystem::path home = std::filesystem::canonical(path, error);
+        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();
+
+        home = std::filesystem::current_path();
+        while (!home.empty() && home.has_relative_path())
+        {
+            if (looksLikeBinaryReleaseHome(home) || looksLikeSourceReleaseHome(home))
+                return home.string();
+
+            home = home.parent_path();
+        }
+        return home.string();
+    }
+} // namespace ignite
\ No newline at end of file