From 47f49d0f45e74aa99f0396b771e65fb3ad2accd5 Mon Sep 17 00:00:00 2001 From: "Todd L. Montgomery" Date: Sun, 3 Mar 2019 17:11:54 -0800 Subject: [PATCH] [C++]: archive API test fixture to start archiving media driver and shut it down on end of test. --- CMakeLists.txt | 10 ++- .../src/test/cpp/AeronArchiveTest.cpp | 81 +++++++++++++++++++ aeron-archive/src/test/cpp/CMakeLists.txt | 37 +++++++++ 3 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 aeron-archive/src/test/cpp/AeronArchiveTest.cpp create mode 100644 aeron-archive/src/test/cpp/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c6dd9c0a3..afb14ad7de 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,7 +247,7 @@ set(AERON_ARCHIVE_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-archive/src/mai if(AERON_TESTS) set(AERON_CLIENT_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-client/src/test/cpp") set(AERON_DRIVER_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-driver/src/test/c") - set(AERON_ARCHIVE_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}}/aeron-archive/src/test/cpp") + set(AERON_ARCHIVE_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aeron-archive/src/test/cpp") # gmock - includes gtest include_directories(${GMOCK_SOURCE_DIR}/googletest/include) @@ -289,9 +289,11 @@ if(BUILD_AERON_ARCHIVE_API) set(ARCHIVE_CODEC_WORKING_DIR "${CMAKE_CURRENT_SOURCE_DIR}") add_subdirectory(${AERON_ARCHIVE_SOURCE_PATH}) -# if(AERON_TESTS) -# add_subdirectory(${AERON_ARCHIVE_TEST_PATH}) -# endif() + if(AERON_TESTS) + set(AERON_ALL_JAR "${CMAKE_CURRENT_SOURCE_DIR}/aeron-all/build/libs/aeron-all-${AERON_VERSION_TXT}.jar") + + add_subdirectory(${AERON_ARCHIVE_TEST_PATH}) + endif() endif(BUILD_AERON_ARCHIVE_API) ########################################################## # doc target diff --git a/aeron-archive/src/test/cpp/AeronArchiveTest.cpp b/aeron-archive/src/test/cpp/AeronArchiveTest.cpp new file mode 100644 index 0000000000..0576f2abef --- /dev/null +++ b/aeron-archive/src/test/cpp/AeronArchiveTest.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2014-2019 Real Logic Ltd. + * + * Licensed 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. + */ + +#if defined(__linux__) || defined(Darwin) +#include +#include +#else +#error "must spawn Java archive per test" +#endif + +#include +#include + +#include + +#include "client/AeronArchive.h" + +class AeronArchiveTest : public testing::Test +{ +public: + virtual void SetUp() + { + m_pid = ::fork(); + if (0 == m_pid) + { + if (::execl(m_java.c_str(), + "java", + "-cp", + m_aeronAllJar.c_str(), + "io.aeron.archive.ArchivingMediaDriver", + NULL) < 0) + { + perror("execl"); + ::exit(EXIT_FAILURE); + } + } + + std::cout << "PID " << std::to_string(m_pid) << std::endl; + } + + virtual void TearDown() + { + if (0 != m_pid) + { + int result = ::kill(m_pid, SIGINT); + std::cout << "Shutting down " << m_pid << " " << result << std::endl; + if (result < 0) + { + perror("kill"); + } + + ::wait(NULL); + } + } +protected: + const std::string m_java = JAVA_EXECUTABLE; + const std::string m_aeronAllJar = AERON_ALL_JAR; + pid_t m_pid = 0; +}; + +TEST_F(AeronArchiveTest, shouldSpinUpArchiveAndShutdown) +{ + std::cout << m_java << std::endl; + std::cout << m_aeronAllJar << std::endl; + + std::this_thread::sleep_for(std::chrono::seconds(2)); +} + diff --git a/aeron-archive/src/test/cpp/CMakeLists.txt b/aeron-archive/src/test/cpp/CMakeLists.txt new file mode 100644 index 0000000000..aa91845ac1 --- /dev/null +++ b/aeron-archive/src/test/cpp/CMakeLists.txt @@ -0,0 +1,37 @@ +# +# Copyright 2014-2019 Real Logic Ltd. +# +# Licensed 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. +# + +find_package(Java REQUIRED) + +include_directories(${AERON_CLIENT_SOURCE_PATH}) +include_directories(${AERON_ARCHIVE_SOURCE_PATH}) + +#set(TEST_HEADERS +# ClientConductorFixture.h +# util/TestUtils.h +# concurrent/MockAtomicBuffer.h) + +add_definitions(-DAERON_ALL_JAR="${AERON_ALL_JAR}") +add_definitions(-DJAVA_EXECUTABLE="${Java_JAVA_EXECUTABLE}") + +function(aeron_archive_client_test name file) + add_executable(${name} ${file}) + target_link_libraries(${name} aeron_client aeron_archive_client ${GMOCK_LIBS} ${CMAKE_THREAD_LIBS_INIT}) + add_dependencies(${name} gmock) + add_test(NAME ${name} COMMAND ${name}) +endfunction() + +aeron_archive_client_test(archiveTest AeronArchiveTest.cpp)