forked from real-logic/aeron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C++]: archive API test fixture to start archiving media driver and s…
…hut it down on end of test.
- Loading branch information
1 parent
c037cd3
commit 47f49d0
Showing
3 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |