Skip to content

Commit

Permalink
[C++]: archive API test fixture to start archiving media driver and s…
Browse files Browse the repository at this point in the history
…hut it down on end of test.
  • Loading branch information
tmontgomery committed Mar 4, 2019
1 parent c037cd3 commit 47f49d0
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 4 deletions.
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
81 changes: 81 additions & 0 deletions aeron-archive/src/test/cpp/AeronArchiveTest.cpp
Original file line number Diff line number Diff line change
@@ -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 <unistd.h>
#include <signal.h>
#else
#error "must spawn Java archive per test"
#endif

#include <chrono>
#include <thread>

#include <gtest/gtest.h>

#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));
}

37 changes: 37 additions & 0 deletions aeron-archive/src/test/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 47f49d0

Please sign in to comment.