mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
feat!: Remove deprecated components sdk, sdk_commands, dds_plugin
BREAKING CHANGE: Components have been moved to ODC project, see https://github.com/FairRootGroup/FairMQ/discussions/392 for details.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# Copyright (C) 2014-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
@@ -292,56 +292,3 @@ add_testsuite(MemoryResources
|
||||
TIMEOUT 5
|
||||
${definitions}
|
||||
)
|
||||
|
||||
if(BUILD_SDK)
|
||||
# configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sdk/test_topo.xml
|
||||
# ${CMAKE_BINARY_DIR}/test_topo.xml)
|
||||
# add_testsuite(SDK
|
||||
# SOURCES
|
||||
# ${CMAKE_CURRENT_BINARY_DIR}/runner.cxx
|
||||
# sdk/_async_op.cxx
|
||||
# sdk/_dds.cxx
|
||||
# sdk/_topology.cxx
|
||||
# sdk/Fixtures.h
|
||||
#
|
||||
# LINKS
|
||||
# SDK
|
||||
# Tools
|
||||
# DDS::dds_topology_lib
|
||||
# DDS::dds_tools_lib
|
||||
# INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
# ${CMAKE_CURRENT_BINARY_DIR}
|
||||
# TIMEOUT 30
|
||||
# ${definitions}
|
||||
# )
|
||||
|
||||
if(DDS_TESTS)
|
||||
foreach(i RANGE 1 ${DDS_TESTS})
|
||||
add_test(NAME DDSToolsAPIStabilityTest_${i}
|
||||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/testsuite_SDK --gtest_filter=TopologyHelper.MakeTopology --gtest_also_run_disabled_tests
|
||||
)
|
||||
set_tests_properties(DDSToolsAPIStabilityTest_${i} PROPERTIES TIMEOUT 10)
|
||||
endforeach()
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/DDSToolsAPIStabilityTest.cmake.in
|
||||
${CMAKE_BINARY_DIR}/DDSToolsAPIStabilityTest.cmake
|
||||
@ONLY
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_SDK_COMMANDS)
|
||||
add_testsuite(Commands
|
||||
SOURCES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/runner.cxx
|
||||
commands/_commands.cxx
|
||||
|
||||
LINKS
|
||||
Commands
|
||||
StateMachine
|
||||
Tools
|
||||
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
TIMEOUT 30
|
||||
${definitions}
|
||||
)
|
||||
endif()
|
||||
|
@@ -1,24 +0,0 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
include(@CMAKE_SOURCE_DIR@/CTestConfig.cmake)
|
||||
|
||||
cmake_host_system_information(RESULT fqdn QUERY FQDN)
|
||||
set(CTEST_SITE ${fqdn})
|
||||
set(CTEST_BUILD_NAME "@CMAKE_SYSTEM@ - @CMAKE_CXX_COMPILER_ID@ @CMAKE_CXX_COMPILER_VERSION@ - DDS Stability Test (@DDS_TESTS@ iterations, DDS: @DDS_VERSION@, FairMQ: @PROJECT_GIT_VERSION@, Boost: @Boost_VERSION@)")
|
||||
set(CTEST_SOURCE_DIRECTORY @CMAKE_SOURCE_DIR@)
|
||||
set(CTEST_BINARY_DIRECTORY @CMAKE_BINARY_DIR@)
|
||||
file(REMOVE_RECURSE ${CTEST_BINARY_DIRECTORY}/test/.DDS)
|
||||
|
||||
ctest_start(Experimental)
|
||||
ctest_test(INCLUDE "DDSToolsAPIStabilityTest")
|
||||
ctest_submit()
|
||||
|
||||
set(dds_logs @CMAKE_BINARY_DIR@/dds_logs.tar.gz)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E tar "cfvz" "${dds_logs}" "@CMAKE_BINARY_DIR@/test/.DDS" OUTPUT_QUIET)
|
||||
message("DDS logs packed: ${dds_logs}")
|
@@ -1,241 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <fairmq/sdk/commands/Commands.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace fair::mq;
|
||||
using namespace fair::mq::sdk::cmd;
|
||||
|
||||
TEST(Format, Construction)
|
||||
{
|
||||
auto const props(std::vector<std::pair<std::string, std::string>>({{"k1", "v1"}, {"k2", "v2"}}));
|
||||
|
||||
Cmds checkStateCmds(make<CheckState>());
|
||||
Cmds changeStateCmds(make<ChangeState>(Transition::Stop));
|
||||
Cmds dumpConfigCmds(make<DumpConfig>());
|
||||
Cmds subscribeToStateChangeCmds(make<SubscribeToStateChange>(60000));
|
||||
Cmds unsubscribeFromStateChangeCmds(make<UnsubscribeFromStateChange>());
|
||||
Cmds stateChangeExitingReceivedCmds(make<StateChangeExitingReceived>());
|
||||
Cmds getPropertiesCmds(make<GetProperties>(66, "k[12]"));
|
||||
Cmds setPropertiesCmds(make<SetProperties>(42, props));
|
||||
Cmds subscriptionHeartbeatCmds(make<SubscriptionHeartbeat>(60000));
|
||||
Cmds currentStateCmds(make<CurrentState>("somedeviceid", State::Running));
|
||||
Cmds transitionStatusCmds(make<TransitionStatus>("somedeviceid", 123456, Result::Ok, Transition::Stop, State::Running));
|
||||
Cmds configCmds(make<Config>("somedeviceid", "someconfig"));
|
||||
Cmds stateChangeSubscriptionCmds(make<StateChangeSubscription>("somedeviceid", 123456, Result::Ok));
|
||||
Cmds stateChangeUnsubscriptionCmds(make<StateChangeUnsubscription>("somedeviceid", 123456, Result::Ok));
|
||||
Cmds stateChangeCmds(make<StateChange>("somedeviceid", 123456, State::Running, State::Ready));
|
||||
Cmds propertiesCmds(make<Properties>("somedeviceid", 66, Result::Ok, props));
|
||||
Cmds propertiesSetCmds(make<PropertiesSet>("somedeviceid", 42, Result::Ok));
|
||||
|
||||
ASSERT_EQ(checkStateCmds.At(0).GetType(), Type::check_state);
|
||||
ASSERT_EQ(changeStateCmds.At(0).GetType(), Type::change_state);
|
||||
ASSERT_EQ(static_cast<ChangeState&>(changeStateCmds.At(0)).GetTransition(), Transition::Stop);
|
||||
ASSERT_EQ(dumpConfigCmds.At(0).GetType(), Type::dump_config);
|
||||
ASSERT_EQ(subscribeToStateChangeCmds.At(0).GetType(), Type::subscribe_to_state_change);
|
||||
ASSERT_EQ(static_cast<SubscribeToStateChange&>(subscribeToStateChangeCmds.At(0)).GetInterval(), 60000);
|
||||
ASSERT_EQ(unsubscribeFromStateChangeCmds.At(0).GetType(), Type::unsubscribe_from_state_change);
|
||||
ASSERT_EQ(stateChangeExitingReceivedCmds.At(0).GetType(), Type::state_change_exiting_received);
|
||||
ASSERT_EQ(getPropertiesCmds.At(0).GetType(), Type::get_properties);
|
||||
ASSERT_EQ(static_cast<GetProperties&>(getPropertiesCmds.At(0)).GetRequestId(), 66);
|
||||
ASSERT_EQ(static_cast<GetProperties&>(getPropertiesCmds.At(0)).GetQuery(), "k[12]");
|
||||
ASSERT_EQ(setPropertiesCmds.At(0).GetType(), Type::set_properties);
|
||||
ASSERT_EQ(static_cast<SetProperties&>(setPropertiesCmds.At(0)).GetRequestId(), 42);
|
||||
ASSERT_EQ(static_cast<SetProperties&>(setPropertiesCmds.At(0)).GetProps(), props);
|
||||
ASSERT_EQ(subscriptionHeartbeatCmds.At(0).GetType(), Type::subscription_heartbeat);
|
||||
ASSERT_EQ(static_cast<SubscriptionHeartbeat&>(subscriptionHeartbeatCmds.At(0)).GetInterval(), 60000);
|
||||
ASSERT_EQ(currentStateCmds.At(0).GetType(), Type::current_state);
|
||||
ASSERT_EQ(static_cast<CurrentState&>(currentStateCmds.At(0)).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<CurrentState&>(currentStateCmds.At(0)).GetCurrentState(), State::Running);
|
||||
ASSERT_EQ(transitionStatusCmds.At(0).GetType(), Type::transition_status);
|
||||
ASSERT_EQ(static_cast<TransitionStatus&>(transitionStatusCmds.At(0)).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<TransitionStatus&>(transitionStatusCmds.At(0)).GetTaskId(), 123456);
|
||||
ASSERT_EQ(static_cast<TransitionStatus&>(transitionStatusCmds.At(0)).GetResult(), Result::Ok);
|
||||
ASSERT_EQ(static_cast<TransitionStatus&>(transitionStatusCmds.At(0)).GetTransition(), Transition::Stop);
|
||||
ASSERT_EQ(static_cast<TransitionStatus&>(transitionStatusCmds.At(0)).GetCurrentState(), State::Running);
|
||||
ASSERT_EQ(configCmds.At(0).GetType(), Type::config);
|
||||
ASSERT_EQ(static_cast<Config&>(configCmds.At(0)).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<Config&>(configCmds.At(0)).GetConfig(), "someconfig");
|
||||
ASSERT_EQ(stateChangeSubscriptionCmds.At(0).GetType(), Type::state_change_subscription);
|
||||
ASSERT_EQ(static_cast<StateChangeSubscription&>(stateChangeSubscriptionCmds.At(0)).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<StateChangeSubscription&>(stateChangeSubscriptionCmds.At(0)).GetTaskId(), 123456);
|
||||
ASSERT_EQ(static_cast<StateChangeSubscription&>(stateChangeSubscriptionCmds.At(0)).GetResult(), Result::Ok);
|
||||
ASSERT_EQ(stateChangeUnsubscriptionCmds.At(0).GetType(), Type::state_change_unsubscription);
|
||||
ASSERT_EQ(static_cast<StateChangeUnsubscription&>(stateChangeUnsubscriptionCmds.At(0)).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<StateChangeUnsubscription&>(stateChangeUnsubscriptionCmds.At(0)).GetTaskId(), 123456);
|
||||
ASSERT_EQ(static_cast<StateChangeUnsubscription&>(stateChangeUnsubscriptionCmds.At(0)).GetResult(), Result::Ok);
|
||||
ASSERT_EQ(stateChangeCmds.At(0).GetType(), Type::state_change);
|
||||
ASSERT_EQ(static_cast<StateChange&>(stateChangeCmds.At(0)).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<StateChange&>(stateChangeCmds.At(0)).GetTaskId(), 123456);
|
||||
ASSERT_EQ(static_cast<StateChange&>(stateChangeCmds.At(0)).GetLastState(), State::Running);
|
||||
ASSERT_EQ(static_cast<StateChange&>(stateChangeCmds.At(0)).GetCurrentState(), State::Ready);
|
||||
ASSERT_EQ(propertiesCmds.At(0).GetType(), Type::properties);
|
||||
ASSERT_EQ(static_cast<Properties&>(propertiesCmds.At(0)).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<Properties&>(propertiesCmds.At(0)).GetRequestId(), 66);
|
||||
ASSERT_EQ(static_cast<Properties&>(propertiesCmds.At(0)).GetResult(), Result::Ok);
|
||||
ASSERT_EQ(static_cast<Properties&>(propertiesCmds.At(0)).GetProps(), props);
|
||||
ASSERT_EQ(propertiesSetCmds.At(0).GetType(), Type::properties_set);
|
||||
ASSERT_EQ(static_cast<PropertiesSet&>(propertiesSetCmds.At(0)).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<PropertiesSet&>(propertiesSetCmds.At(0)).GetRequestId(), 42);
|
||||
ASSERT_EQ(static_cast<PropertiesSet&>(propertiesSetCmds.At(0)).GetResult(), Result::Ok);
|
||||
}
|
||||
|
||||
void fillCommands(Cmds& cmds)
|
||||
{
|
||||
auto const props(std::vector<std::pair<std::string, std::string>>({{"k1", "v1"}, {"k2", "v2"}}));
|
||||
|
||||
cmds.Add<CheckState>();
|
||||
cmds.Add<ChangeState>(Transition::Stop);
|
||||
cmds.Add<DumpConfig>();
|
||||
cmds.Add<SubscribeToStateChange>(60000);
|
||||
cmds.Add<UnsubscribeFromStateChange>();
|
||||
cmds.Add<StateChangeExitingReceived>();
|
||||
cmds.Add<GetProperties>(66, "k[12]");
|
||||
cmds.Add<SetProperties>(42, props);
|
||||
cmds.Add<SubscriptionHeartbeat>(60000);
|
||||
cmds.Add<CurrentState>("somedeviceid", State::Running);
|
||||
cmds.Add<TransitionStatus>("somedeviceid", 123456, Result::Ok, Transition::Stop, State::Running);
|
||||
cmds.Add<Config>("somedeviceid", "someconfig");
|
||||
cmds.Add<StateChangeSubscription>("somedeviceid", 123456, Result::Ok);
|
||||
cmds.Add<StateChangeUnsubscription>("somedeviceid", 123456, Result::Ok);
|
||||
cmds.Add<StateChange>("somedeviceid", 123456, State::Running, State::Ready);
|
||||
cmds.Add<Properties>("somedeviceid", 66, Result::Ok, props);
|
||||
cmds.Add<PropertiesSet>("somedeviceid", 42, Result::Ok);
|
||||
}
|
||||
|
||||
void checkCommands(Cmds& cmds)
|
||||
{
|
||||
ASSERT_EQ(cmds.Size(), 17);
|
||||
|
||||
int count = 0;
|
||||
auto const props(std::vector<std::pair<std::string, std::string>>({{"k1", "v1"}, {"k2", "v2"}}));
|
||||
|
||||
for (const auto& cmd : cmds) {
|
||||
switch (cmd->GetType()) {
|
||||
case Type::check_state:
|
||||
++count;
|
||||
break;
|
||||
case Type::change_state:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<ChangeState&>(*cmd).GetTransition(), Transition::Stop);
|
||||
break;
|
||||
case Type::dump_config:
|
||||
++count;
|
||||
break;
|
||||
case Type::subscribe_to_state_change:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<SubscribeToStateChange&>(*cmd).GetInterval(), 60000);
|
||||
break;
|
||||
case Type::unsubscribe_from_state_change:
|
||||
++count;
|
||||
break;
|
||||
case Type::state_change_exiting_received:
|
||||
++count;
|
||||
break;
|
||||
case Type::get_properties:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<GetProperties&>(*cmd).GetRequestId(), 66);
|
||||
ASSERT_EQ(static_cast<GetProperties&>(*cmd).GetQuery(), "k[12]");
|
||||
break;
|
||||
case Type::set_properties:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<SetProperties&>(*cmd).GetRequestId(), 42);
|
||||
ASSERT_EQ(static_cast<SetProperties&>(*cmd).GetProps(), props);
|
||||
break;
|
||||
case Type::subscription_heartbeat:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<SubscriptionHeartbeat&>(*cmd).GetInterval(), 60000);
|
||||
break;
|
||||
case Type::current_state:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<CurrentState&>(*cmd).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<CurrentState&>(*cmd).GetCurrentState(), State::Running);
|
||||
break;
|
||||
case Type::transition_status:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<TransitionStatus&>(*cmd).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<TransitionStatus&>(*cmd).GetTaskId(), 123456);
|
||||
ASSERT_EQ(static_cast<TransitionStatus&>(*cmd).GetResult(), Result::Ok);
|
||||
ASSERT_EQ(static_cast<TransitionStatus&>(*cmd).GetTransition(), Transition::Stop);
|
||||
ASSERT_EQ(static_cast<TransitionStatus&>(*cmd).GetCurrentState(), State::Running);
|
||||
break;
|
||||
case Type::config:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<Config&>(*cmd).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<Config&>(*cmd).GetConfig(), "someconfig");
|
||||
break;
|
||||
case Type::state_change_subscription:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<StateChangeSubscription&>(*cmd).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<StateChangeSubscription&>(*cmd).GetTaskId(), 123456);
|
||||
ASSERT_EQ(static_cast<StateChangeSubscription&>(*cmd).GetResult(), Result::Ok);
|
||||
break;
|
||||
case Type::state_change_unsubscription:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<StateChangeUnsubscription&>(*cmd).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<StateChangeUnsubscription&>(*cmd).GetTaskId(), 123456);
|
||||
ASSERT_EQ(static_cast<StateChangeUnsubscription&>(*cmd).GetResult(), Result::Ok);
|
||||
break;
|
||||
case Type::state_change:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<StateChange&>(*cmd).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<StateChange&>(*cmd).GetTaskId(), 123456);
|
||||
ASSERT_EQ(static_cast<StateChange&>(*cmd).GetLastState(), State::Running);
|
||||
ASSERT_EQ(static_cast<StateChange&>(*cmd).GetCurrentState(), State::Ready);
|
||||
break;
|
||||
case Type::properties:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<Properties&>(*cmd).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<Properties&>(*cmd).GetRequestId(), 66);
|
||||
ASSERT_EQ(static_cast<Properties&>(*cmd).GetResult(), Result::Ok);
|
||||
ASSERT_EQ(static_cast<Properties&>(*cmd).GetProps(), props);
|
||||
break;
|
||||
case Type::properties_set:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<PropertiesSet&>(*cmd).GetDeviceId(), "somedeviceid");
|
||||
ASSERT_EQ(static_cast<PropertiesSet&>(*cmd).GetRequestId(), 42);
|
||||
ASSERT_EQ(static_cast<PropertiesSet&>(*cmd).GetResult(), Result::Ok);
|
||||
break;
|
||||
default:
|
||||
ASSERT_TRUE(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_EQ(count, 17);
|
||||
}
|
||||
|
||||
TEST(Format, SerializationBinary)
|
||||
{
|
||||
Cmds outCmds;
|
||||
fillCommands(outCmds);
|
||||
std::string buffer(outCmds.Serialize());
|
||||
|
||||
Cmds inCmds;
|
||||
inCmds.Deserialize(buffer);
|
||||
checkCommands(inCmds);
|
||||
}
|
||||
|
||||
TEST(Format, SerializationJSON)
|
||||
{
|
||||
Cmds outCmds;
|
||||
fillCommands(outCmds);
|
||||
std::string buffer(outCmds.Serialize(Format::JSON));
|
||||
|
||||
Cmds inCmds;
|
||||
inCmds.Deserialize(buffer, Format::JSON);
|
||||
checkCommands(inCmds);
|
||||
}
|
||||
|
||||
} // namespace
|
@@ -1,169 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIR_MQ_TEST_FIXTURES
|
||||
#define FAIR_MQ_TEST_FIXTURES
|
||||
|
||||
#include "TestEnvironment.h"
|
||||
|
||||
#include <fairmq/SDK.h>
|
||||
#include <fairmq/tools/Strings.h>
|
||||
|
||||
#include <fairlogger/Logger.h>
|
||||
|
||||
#include <asio/io_context.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <algorithm> // for_each
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <thread>
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
struct LoggerConfig
|
||||
{
|
||||
LoggerConfig()
|
||||
{
|
||||
Logger::SetConsoleSeverity("debug");
|
||||
Logger::DefineVerbosity("user1",
|
||||
fair::VerbositySpec::Make(VerbositySpec::Info::timestamp_us,
|
||||
VerbositySpec::Info::severity));
|
||||
Logger::SetVerbosity("user1");
|
||||
Logger::SetConsoleColor();
|
||||
|
||||
std::string path(std::getenv("PATH"));
|
||||
path = tools::ToString(FAIRMQ_TEST_ENVIRONMENT, ":", path);
|
||||
setenv("PATH", path.c_str(), 1);
|
||||
}
|
||||
};
|
||||
|
||||
struct TopologyFixture : ::testing::Test
|
||||
{
|
||||
TopologyFixture()
|
||||
: mDDSTopoFile(tools::ToString(SDK_TESTSUITE_SOURCE_DIR, "/test_topo.xml"))
|
||||
, mDDSEnv(CMAKE_CURRENT_BINARY_DIR)
|
||||
, mDDSSession(mDDSEnv)
|
||||
, mDDSTopo(sdk::DDSTopology::Path(mDDSTopoFile), mDDSEnv)
|
||||
{
|
||||
mDDSSession.StopOnDestruction();
|
||||
}
|
||||
|
||||
auto SetUp() -> void override {
|
||||
LOG(info) << mDDSEnv;
|
||||
LOG(info) << mDDSSession;
|
||||
LOG(info) << mDDSTopo;
|
||||
auto n(mDDSTopo.GetNumRequiredAgents());
|
||||
mDDSSession.SubmitAgents(n);
|
||||
mDDSSession.ActivateTopology(mDDSTopo);
|
||||
|
||||
std::vector<sdk::DDSAgent> agents = mDDSSession.RequestAgentInfo();
|
||||
LOG(debug) << "##### AgentInfo:";
|
||||
LOG(debug) << "size: " << agents.size();
|
||||
for (const auto& a : agents) {
|
||||
LOG(debug) << a;
|
||||
}
|
||||
|
||||
std::vector<sdk::DDSTask> tasks = mDDSSession.RequestTaskInfo();
|
||||
LOG(debug) << "##### TaskInfo:";
|
||||
LOG(debug) << "size: " << tasks.size();
|
||||
for (const auto& t : tasks) {
|
||||
LOG(debug) << t;
|
||||
}
|
||||
|
||||
std::vector<sdk::DDSCollection> collections = mDDSTopo.GetCollections();
|
||||
LOG(debug) << "##### CollectionInfo:";
|
||||
LOG(debug) << "size: " << collections.size();
|
||||
for (const auto& c : collections) {
|
||||
LOG(debug) << c;
|
||||
}
|
||||
}
|
||||
|
||||
auto TearDown() -> void override {}
|
||||
|
||||
LoggerConfig mLoggerConfig;
|
||||
std::string mDDSTopoFile;
|
||||
sdk::DDSEnvironment mDDSEnv;
|
||||
sdk::DDSSession mDDSSession;
|
||||
sdk::DDSTopology mDDSTopo;
|
||||
asio::io_context mIoContext;
|
||||
};
|
||||
|
||||
struct MultipleTopologiesFixture : ::testing::Test
|
||||
{
|
||||
MultipleTopologiesFixture()
|
||||
: mDDSTopoFile(tools::ToString(SDK_TESTSUITE_SOURCE_DIR, "/test_topo.xml"))
|
||||
, mDDSEnv(CMAKE_CURRENT_BINARY_DIR)
|
||||
, mDDSSessions{ sdk::DDSSession(mDDSEnv),
|
||||
sdk::DDSSession(mDDSEnv) }
|
||||
, mDDSTopologies{ sdk::DDSTopology(sdk::DDSTopology::Path(mDDSTopoFile), mDDSEnv),
|
||||
sdk::DDSTopology(sdk::DDSTopology::Path(mDDSTopoFile), mDDSEnv) }
|
||||
{
|
||||
std::for_each(mDDSSessions.begin(), mDDSSessions.end(), [](sdk::DDSSession& s) {
|
||||
s.StopOnDestruction();
|
||||
});
|
||||
}
|
||||
|
||||
auto SetUp() -> void override
|
||||
{
|
||||
LOG(info) << mDDSEnv;
|
||||
for (int i = 0; i < mNumSessions; ++i) {
|
||||
LOG(info) << "##### SESSION " << i << " #####";
|
||||
LOG(info) << mDDSSessions[i];
|
||||
LOG(info) << mDDSTopologies[i];
|
||||
auto n(mDDSTopologies[i].GetNumRequiredAgents());
|
||||
mDDSSessions[i].SubmitAgents(n);
|
||||
mDDSSessions[i].ActivateTopology(mDDSTopologies[i]);
|
||||
|
||||
std::vector<sdk::DDSAgent> agents = mDDSSessions[i].RequestAgentInfo();
|
||||
LOG(info) << "##### AgentInfo:";
|
||||
LOG(info) << "size: " << agents.size();
|
||||
for (const auto& a : agents) {
|
||||
LOG(info) << a;
|
||||
}
|
||||
|
||||
std::vector<sdk::DDSTask> tasks = mDDSSessions[i].RequestTaskInfo();
|
||||
LOG(info) << "##### TaskInfo:";
|
||||
LOG(info) << "size: " << tasks.size();
|
||||
for (const auto& t : tasks) {
|
||||
LOG(info) << t;
|
||||
}
|
||||
|
||||
std::vector<sdk::DDSCollection> collections = mDDSTopologies[i].GetCollections();
|
||||
LOG(info) << "##### CollectionInfo:";
|
||||
LOG(info) << "size: " << collections.size();
|
||||
for (const auto& c : collections) {
|
||||
LOG(info) << c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto TearDown() -> void override {}
|
||||
|
||||
static constexpr int mNumSessions = 2;
|
||||
LoggerConfig mLoggerConfig;
|
||||
std::string mDDSTopoFile;
|
||||
sdk::DDSEnvironment mDDSEnv;
|
||||
std::array<sdk::DDSSession, mNumSessions> mDDSSessions;
|
||||
std::array<sdk::DDSTopology, mNumSessions> mDDSTopologies;
|
||||
};
|
||||
|
||||
struct AsyncOpFixture : ::testing::Test
|
||||
{
|
||||
auto SetUp() -> void override {}
|
||||
auto TearDown() -> void override {}
|
||||
|
||||
LoggerConfig mLoggerConfig;
|
||||
asio::io_context mIoContext;
|
||||
};
|
||||
|
||||
} // namespace fair::mq::test
|
||||
|
||||
#endif /* FAIR_MQ_TEST_FIXTURES */
|
@@ -1,118 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "Fixtures.h"
|
||||
|
||||
#include <fairmq/sdk/AsioBase.h>
|
||||
#include <fairmq/sdk/AsioAsyncOp.h>
|
||||
#include <asio/steady_timer.hpp>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
namespace {
|
||||
|
||||
using AsyncOp = fair::mq::test::AsyncOpFixture;
|
||||
|
||||
// template <typename Executor, typename Allocator>
|
||||
// class : public AsioBase<Executor, Allocator>
|
||||
|
||||
TEST_F(AsyncOp, DefaultConstruction)
|
||||
{
|
||||
using namespace fair::mq::sdk;
|
||||
|
||||
AsioAsyncOp<DefaultExecutor, DefaultAllocator, void(std::error_code, int)> op;
|
||||
EXPECT_TRUE(op.IsCompleted());
|
||||
}
|
||||
|
||||
TEST_F(AsyncOp, ConstructionWithHandler)
|
||||
{
|
||||
using namespace fair::mq::sdk;
|
||||
|
||||
AsioAsyncOp<DefaultExecutor, DefaultAllocator, void(std::error_code, int)> op(
|
||||
[](std::error_code, int) {});
|
||||
EXPECT_FALSE(op.IsCompleted());
|
||||
}
|
||||
|
||||
TEST_F(AsyncOp, Complete)
|
||||
{
|
||||
using namespace fair::mq::sdk;
|
||||
|
||||
AsioAsyncOp<DefaultExecutor, DefaultAllocator, void(std::error_code, int)> op(
|
||||
[](std::error_code ec, int v) {
|
||||
EXPECT_FALSE(ec); // success
|
||||
EXPECT_EQ(v, 42);
|
||||
});
|
||||
|
||||
EXPECT_FALSE(op.IsCompleted());
|
||||
op.Complete(42);
|
||||
EXPECT_TRUE(op.IsCompleted());
|
||||
|
||||
EXPECT_THROW(op.Complete(6), RuntimeError); // No double completion!
|
||||
}
|
||||
|
||||
TEST_F(AsyncOp, Cancel)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
sdk::AsioAsyncOp<sdk::DefaultExecutor, sdk::DefaultAllocator, void(std::error_code)> op(
|
||||
[](std::error_code ec) {
|
||||
EXPECT_TRUE(ec); // error
|
||||
EXPECT_EQ(ec, MakeErrorCode(ErrorCode::OperationCanceled));
|
||||
});
|
||||
|
||||
op.Cancel();
|
||||
}
|
||||
|
||||
TEST_F(AsyncOp, Timeout)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
asio::steady_timer timer(mIoContext.get_executor(), std::chrono::milliseconds(50));
|
||||
sdk::AsioAsyncOp<sdk::DefaultExecutor, sdk::DefaultAllocator, void(std::error_code)> op(
|
||||
mIoContext.get_executor(),
|
||||
[&timer](std::error_code ec) {
|
||||
timer.cancel();
|
||||
std::cout << "Completion with: " << ec.message() << std::endl;
|
||||
EXPECT_TRUE(ec); // error
|
||||
EXPECT_EQ(ec, MakeErrorCode(ErrorCode::OperationTimeout));
|
||||
});
|
||||
timer.async_wait([&op](asio::error_code ec) {
|
||||
std::cout << "Timer event" << std::endl;
|
||||
if (ec != asio::error::operation_aborted) {
|
||||
op.Timeout();
|
||||
}
|
||||
});
|
||||
|
||||
mIoContext.run();
|
||||
EXPECT_THROW(op.Complete(), sdk::RuntimeError);
|
||||
}
|
||||
|
||||
TEST_F(AsyncOp, Timeout2)
|
||||
{
|
||||
using namespace fair::mq::sdk;
|
||||
|
||||
asio::steady_timer timer(mIoContext.get_executor(), std::chrono::milliseconds(50));
|
||||
AsioAsyncOp<DefaultExecutor, DefaultAllocator, void(std::error_code)> op(
|
||||
mIoContext.get_executor(),
|
||||
[&timer](std::error_code ec) {
|
||||
timer.cancel();
|
||||
std::cout << "Completion with: " << ec.message() << std::endl;
|
||||
EXPECT_FALSE(ec); // success
|
||||
});
|
||||
op.Complete(); // Complete before timer
|
||||
timer.async_wait([&op](asio::error_code ec) {
|
||||
std::cout << "Timer event" << std::endl;
|
||||
if (ec != asio::error::operation_aborted) {
|
||||
op.Timeout();
|
||||
}
|
||||
});
|
||||
|
||||
mIoContext.run();
|
||||
EXPECT_THROW(op.Complete(), RuntimeError);
|
||||
}
|
||||
} // namespace
|
@@ -1,50 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "Fixtures.h"
|
||||
|
||||
#define BOOST_BIND_GLOBAL_PLACEHOLDERS
|
||||
#include <dds/dds.h>
|
||||
#undef BOOST_BIND_GLOBAL_PLACEHOLDERS
|
||||
|
||||
namespace {
|
||||
|
||||
TEST(DDSEnvironment, Construction)
|
||||
{
|
||||
fair::mq::test::LoggerConfig cfg;
|
||||
fair::mq::sdk::DDSEnvironment env(CMAKE_CURRENT_BINARY_DIR);
|
||||
|
||||
LOG(debug) << env;
|
||||
}
|
||||
|
||||
TEST(DDSSession, Construction)
|
||||
{
|
||||
fair::mq::test::LoggerConfig cfg;
|
||||
fair::mq::sdk::DDSEnvironment env(CMAKE_CURRENT_BINARY_DIR);
|
||||
|
||||
fair::mq::sdk::DDSSession session(env);
|
||||
session.StopOnDestruction();
|
||||
LOG(debug) << session;
|
||||
}
|
||||
|
||||
TEST(DDSSession, Construction2)
|
||||
{
|
||||
fair::mq::test::LoggerConfig cfg;
|
||||
fair::mq::sdk::DDSEnvironment env(CMAKE_CURRENT_BINARY_DIR);
|
||||
|
||||
auto nativeSession(std::make_shared<dds::tools_api::CSession>());
|
||||
nativeSession->create();
|
||||
|
||||
fair::mq::sdk::DDSSession session(nativeSession, env);
|
||||
session.StopOnDestruction();
|
||||
LOG(debug) << session;
|
||||
|
||||
session.RequestCommanderInfo();
|
||||
}
|
||||
|
||||
} // namespace
|
@@ -1,589 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "Fixtures.h"
|
||||
|
||||
#include <asio.hpp>
|
||||
#define BOOST_BIND_GLOBAL_PLACEHOLDERS
|
||||
#include <dds/dds.h>
|
||||
#undef BOOST_BIND_GLOBAL_PLACEHOLDERS
|
||||
#include <fairmq/sdk/Topology.h>
|
||||
#include <fairmq/tools/Strings.h>
|
||||
#include <fairmq/tools/Semaphore.h>
|
||||
|
||||
#include <thread>
|
||||
|
||||
namespace {
|
||||
|
||||
using Topology = fair::mq::test::TopologyFixture;
|
||||
using MultipleTopologies = fair::mq::test::MultipleTopologiesFixture;
|
||||
|
||||
void control(fair::mq::sdk::Topology& topo)
|
||||
{
|
||||
using fair::mq::sdk::TopologyTransition;
|
||||
|
||||
for (auto transition : {TopologyTransition::InitDevice,
|
||||
TopologyTransition::CompleteInit,
|
||||
TopologyTransition::Bind,
|
||||
TopologyTransition::Connect,
|
||||
TopologyTransition::InitTask,
|
||||
TopologyTransition::Run,
|
||||
TopologyTransition::Stop,
|
||||
TopologyTransition::ResetTask,
|
||||
TopologyTransition::ResetDevice,
|
||||
TopologyTransition::End}) {
|
||||
ASSERT_EQ(topo.ChangeState(transition).first, std::error_code());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TopologyHelper, MakeTopology)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
// This is only needed for this unit test
|
||||
test::LoggerConfig cfg;
|
||||
sdk::DDSEnv env(CMAKE_CURRENT_BINARY_DIR);
|
||||
|
||||
std::string topoFile(tools::ToString(SDK_TESTSUITE_SOURCE_DIR, "/test_topo.xml"));
|
||||
dds::topology_api::CTopology nativeTopo(topoFile);
|
||||
auto nativeSession(std::make_shared<dds::tools_api::CSession>());
|
||||
nativeSession->create();
|
||||
EXPECT_THROW(sdk::MakeTopology(nativeTopo, nativeSession, env), sdk::RuntimeError);
|
||||
nativeSession->shutdown();
|
||||
}
|
||||
|
||||
TEST_F(MultipleTopologies, Construction)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
std::array<sdk::Topology, mNumSessions> topos{
|
||||
sdk::Topology(mDDSTopologies[0], mDDSSessions[0]),
|
||||
sdk::Topology(mDDSTopologies[1], mDDSSessions[1])
|
||||
};
|
||||
}
|
||||
|
||||
TEST_F(MultipleTopologies, ChangeStateFullDeviceLifecycle)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
std::array<sdk::Topology, mNumSessions> topos{
|
||||
sdk::Topology(mDDSTopologies[0], mDDSSessions[0]),
|
||||
sdk::Topology(mDDSTopologies[1], mDDSSessions[1])
|
||||
};
|
||||
|
||||
for (int i = 0; i < mNumSessions; ++i) {
|
||||
using fair::mq::sdk::TopologyTransition;
|
||||
|
||||
for (auto transition : {TopologyTransition::InitDevice,
|
||||
TopologyTransition::CompleteInit,
|
||||
TopologyTransition::Bind,
|
||||
TopologyTransition::Connect,
|
||||
TopologyTransition::InitTask,
|
||||
TopologyTransition::Run,
|
||||
TopologyTransition::Stop,
|
||||
TopologyTransition::ResetTask,
|
||||
TopologyTransition::ResetDevice,
|
||||
TopologyTransition::End}) {
|
||||
ASSERT_EQ(topos[i].ChangeState(transition).first, std::error_code());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MultipleTopologies, ChangeStateFullDeviceLifecycleConcurrent)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
std::array<sdk::Topology, mNumSessions> topos{
|
||||
sdk::Topology(mDDSTopologies[0], mDDSSessions[0]),
|
||||
sdk::Topology(mDDSTopologies[1], mDDSSessions[1])
|
||||
};
|
||||
|
||||
std::thread t0(control, std::ref(topos[0]));
|
||||
std::thread t1(control, std::ref(topos[1]));
|
||||
t0.join();
|
||||
t1.join();
|
||||
}
|
||||
|
||||
|
||||
TEST_F(Topology, Construction)
|
||||
{
|
||||
fair::mq::sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
}
|
||||
|
||||
TEST_F(Topology, Construction2)
|
||||
{
|
||||
fair::mq::sdk::Topology topo(mIoContext.get_executor(), mDDSTopo, mDDSSession);
|
||||
}
|
||||
|
||||
TEST_F(Topology, AsyncChangeState)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
tools::SharedSemaphore blocker;
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
topo.AsyncChangeState(
|
||||
sdk::TopologyTransition::InitDevice,
|
||||
[=](std::error_code ec, sdk::TopologyState) mutable {
|
||||
LOG(info) << ec;
|
||||
EXPECT_EQ(ec, std::error_code());
|
||||
blocker.Signal();
|
||||
});
|
||||
blocker.Wait();
|
||||
}
|
||||
|
||||
TEST_F(Topology, AsyncChangeStateWithCustomExecutor)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
sdk::Topology topo(mIoContext.get_executor(), mDDSTopo, mDDSSession);
|
||||
topo.AsyncChangeState(
|
||||
sdk::TopologyTransition::InitDevice,
|
||||
[](std::error_code ec, sdk::TopologyState) {
|
||||
LOG(info) << ec;
|
||||
EXPECT_EQ(ec, std::error_code());
|
||||
});
|
||||
|
||||
mIoContext.run();
|
||||
}
|
||||
|
||||
TEST_F(Topology, AsyncChangeStateFuture)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
sdk::Topology topo(mIoContext.get_executor(), mDDSTopo, mDDSSession);
|
||||
auto fut(topo.AsyncChangeState(
|
||||
sdk::TopologyTransition::InitDevice,
|
||||
asio::use_future));
|
||||
std::thread t([&]() { mIoContext.run(); });
|
||||
bool success(false);
|
||||
|
||||
try {
|
||||
sdk::TopologyState state = fut.get();
|
||||
success = true;
|
||||
} catch (const std::system_error& ex) {
|
||||
LOG(error) << ex.what();
|
||||
}
|
||||
|
||||
EXPECT_TRUE(success);
|
||||
t.join();
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_CO_AWAIT)
|
||||
TEST_F(Topology, AsyncChangeStateCoroutine)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
bool success(false);
|
||||
asio::co_spawn(
|
||||
mIoContext.get_executor(),
|
||||
[&]() mutable -> asio::awaitable<void> {
|
||||
auto executor = co_await asio::this_coro::executor;
|
||||
sdk::Topology topo(executor, mDDSTopo, mDDSSession);
|
||||
try {
|
||||
sdk::TopologyState state = co_await topo.AsyncChangeState(
|
||||
sdk::TopologyTransition::InitDevice, asio::use_awaitable);
|
||||
success = true;
|
||||
} catch (const std::system_error& ex) {
|
||||
LOG(error) << ex.what();
|
||||
}
|
||||
},
|
||||
asio::detached);
|
||||
|
||||
mIoContext.run();
|
||||
EXPECT_TRUE(success);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(Topology, ChangeState)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
auto result(topo.ChangeState(sdk::TopologyTransition::InitDevice));
|
||||
LOG(info) << result.first;
|
||||
|
||||
EXPECT_EQ(result.first, std::error_code());
|
||||
EXPECT_NO_THROW(sdk::AggregateState(result.second));
|
||||
EXPECT_EQ(sdk::StateEqualsTo(result.second, sdk::DeviceState::InitializingDevice), true);
|
||||
auto const currentState = topo.GetCurrentState();
|
||||
EXPECT_NO_THROW(sdk::AggregateState(currentState));
|
||||
EXPECT_EQ(sdk::StateEqualsTo(currentState, sdk::DeviceState::InitializingDevice), true);
|
||||
}
|
||||
|
||||
TEST_F(Topology, MixedState)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
auto result1(topo.ChangeState(sdk::TopologyTransition::InitDevice, "main/Sampler.*"));
|
||||
LOG(info) << result1.first;
|
||||
|
||||
EXPECT_EQ(result1.first, std::error_code());
|
||||
EXPECT_EQ(sdk::AggregateState(result1.second), sdk::AggregatedTopologyState::Mixed);
|
||||
EXPECT_EQ(sdk::StateEqualsTo(result1.second, sdk::DeviceState::InitializingDevice), false);
|
||||
auto const currentState1 = topo.GetCurrentState();
|
||||
EXPECT_EQ(sdk::AggregateState(currentState1), sdk::AggregatedTopologyState::Mixed);
|
||||
EXPECT_EQ(sdk::StateEqualsTo(currentState1, sdk::DeviceState::InitializingDevice), false);
|
||||
|
||||
auto result2(topo.ChangeState(sdk::TopologyTransition::InitDevice, "main/SinkGroup/.*"));
|
||||
LOG(info) << result2.first;
|
||||
|
||||
EXPECT_EQ(result2.first, std::error_code());
|
||||
EXPECT_EQ(sdk::AggregateState(result2.second), sdk::AggregatedTopologyState::InitializingDevice);
|
||||
EXPECT_EQ(sdk::StateEqualsTo(result2.second, sdk::DeviceState::InitializingDevice), true);
|
||||
auto const currentState2 = topo.GetCurrentState();
|
||||
EXPECT_EQ(sdk::AggregateState(currentState2), sdk::AggregatedTopologyState::InitializingDevice);
|
||||
EXPECT_EQ(sdk::StateEqualsTo(currentState2, sdk::DeviceState::InitializingDevice), true);
|
||||
}
|
||||
|
||||
TEST_F(Topology, AsyncChangeStateConcurrent)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
topo.AsyncChangeState(sdk::TopologyTransition::InitDevice, "main/Sampler.*",
|
||||
[](std::error_code ec, sdk::TopologyState) mutable {
|
||||
LOG(info) << "ChangeState for Sampler: " << ec;
|
||||
EXPECT_EQ(ec, std::error_code());
|
||||
});
|
||||
topo.AsyncChangeState(sdk::TopologyTransition::InitDevice, "main/SinkGroup/.*",
|
||||
[](std::error_code ec, sdk::TopologyState) mutable {
|
||||
LOG(info) << "ChangeState for Sinks: " << ec;
|
||||
EXPECT_EQ(ec, std::error_code());
|
||||
});
|
||||
|
||||
topo.WaitForState(sdk::DeviceState::InitializingDevice);
|
||||
auto const currentState = topo.GetCurrentState();
|
||||
EXPECT_NO_THROW(sdk::AggregateState(currentState));
|
||||
EXPECT_EQ(sdk::StateEqualsTo(currentState, sdk::DeviceState::InitializingDevice), true);
|
||||
}
|
||||
|
||||
TEST_F(Topology, AsyncChangeStateTimeout)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
sdk::Topology topo(mIoContext.get_executor(), mDDSTopo, mDDSSession);
|
||||
topo.AsyncChangeState(sdk::TopologyTransition::InitDevice,
|
||||
std::chrono::milliseconds(1),
|
||||
[](std::error_code ec, sdk::TopologyState) {
|
||||
LOG(info) << ec;
|
||||
EXPECT_EQ(ec, MakeErrorCode(ErrorCode::OperationTimeout));
|
||||
});
|
||||
|
||||
mIoContext.run();
|
||||
}
|
||||
|
||||
TEST_F(Topology, AsyncChangeStateCollectionView)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
|
||||
tools::SharedSemaphore blocker;
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
topo.AsyncChangeState(
|
||||
sdk::TopologyTransition::InitDevice,
|
||||
[=](std::error_code ec, sdk::TopologyState state) mutable {
|
||||
LOG(info) << ec;
|
||||
sdk::TopologyStateByCollection cstate(sdk::GroupByCollectionId(state));
|
||||
LOG(debug) << "num collections: " << cstate.size();
|
||||
ASSERT_EQ(cstate.size(), 5);
|
||||
for (const auto& c : cstate) {
|
||||
LOG(debug) << "\t" << c.first;
|
||||
sdk::AggregatedTopologyState s;
|
||||
ASSERT_NO_THROW(s = sdk::AggregateState(c.second));
|
||||
ASSERT_EQ(s, static_cast<sdk::AggregatedTopologyState>(State::InitializingDevice));
|
||||
LOG(debug) << "\tAggregated state: " << s;
|
||||
for (const auto& ds : c.second) {
|
||||
LOG(debug) << "\t\t" << ds.state;
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(ec, std::error_code());
|
||||
blocker.Signal();
|
||||
});
|
||||
blocker.Wait();
|
||||
}
|
||||
|
||||
TEST_F(Topology, ChangeStateFullDeviceLifecycle)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
using fair::mq::sdk::TopologyTransition;
|
||||
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
for (auto transition : {TopologyTransition::InitDevice,
|
||||
TopologyTransition::CompleteInit,
|
||||
TopologyTransition::Bind,
|
||||
TopologyTransition::Connect,
|
||||
TopologyTransition::InitTask,
|
||||
TopologyTransition::Run,
|
||||
TopologyTransition::Stop,
|
||||
TopologyTransition::ResetTask,
|
||||
TopologyTransition::ResetDevice,
|
||||
TopologyTransition::End}) {
|
||||
ASSERT_EQ(topo.ChangeState(transition).first, std::error_code());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(Topology, WaitForStateFullDeviceLifecycle)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
using fair::mq::sdk::TopologyTransition;
|
||||
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
topo.AsyncWaitForState(sdk::DeviceState::ResettingDevice, [](std::error_code ec){
|
||||
ASSERT_EQ(ec, std::error_code());
|
||||
});
|
||||
for (auto transition : {TopologyTransition::InitDevice,
|
||||
TopologyTransition::CompleteInit,
|
||||
TopologyTransition::Bind,
|
||||
TopologyTransition::Connect,
|
||||
TopologyTransition::InitTask,
|
||||
TopologyTransition::Run,
|
||||
TopologyTransition::Stop,
|
||||
TopologyTransition::ResetTask,
|
||||
TopologyTransition::ResetDevice,
|
||||
TopologyTransition::End}) {
|
||||
topo.ChangeState(transition);
|
||||
ASSERT_EQ(topo.WaitForState(sdk::expectedState.at(transition)), std::error_code());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(Topology, ChangeStateFullDeviceLifecycle2)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
using fair::mq::sdk::TopologyTransition;
|
||||
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
for (int i(0); i < 10; ++i) {
|
||||
for (auto transition : {TopologyTransition::InitDevice,
|
||||
TopologyTransition::CompleteInit,
|
||||
TopologyTransition::Bind,
|
||||
TopologyTransition::Connect,
|
||||
TopologyTransition::InitTask,
|
||||
TopologyTransition::Run}) {
|
||||
ASSERT_EQ(topo.ChangeState(transition).first, std::error_code());
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
for (auto transition : {TopologyTransition::Stop,
|
||||
TopologyTransition::ResetTask,
|
||||
TopologyTransition::ResetDevice}) {
|
||||
ASSERT_EQ(topo.ChangeState(transition).first, std::error_code());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(Topology, SetProperties)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
using fair::mq::sdk::TopologyTransition;
|
||||
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::InitDevice).first, std::error_code());
|
||||
|
||||
auto const result1 = topo.SetProperties({{"key1", "val1"}});
|
||||
LOG(info) << result1.first;
|
||||
ASSERT_EQ(result1.first, std::error_code());
|
||||
ASSERT_EQ(result1.second.size(), 0);
|
||||
auto const result2 = topo.SetProperties({{"key2", "val2"}, {"key3", "val3"}});
|
||||
LOG(info) << result2.first;
|
||||
ASSERT_EQ(result2.first, std::error_code());
|
||||
ASSERT_EQ(result2.second.size(), 0);
|
||||
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::CompleteInit).first, std::error_code());
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::ResetDevice).first, std::error_code());
|
||||
}
|
||||
|
||||
TEST_F(Topology, AsyncSetPropertiesConcurrent)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
using fair::mq::sdk::TopologyTransition;
|
||||
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::InitDevice).first, std::error_code());
|
||||
|
||||
tools::SharedSemaphore blocker(2);
|
||||
topo.AsyncSetProperties(
|
||||
{{"key1", "val1"}},
|
||||
[=](std::error_code ec, sdk::FailedDevices failed) mutable {
|
||||
LOG(info) << ec;
|
||||
ASSERT_EQ(ec, std::error_code());
|
||||
ASSERT_EQ(failed.size(), 0);
|
||||
blocker.Signal();
|
||||
});
|
||||
topo.AsyncSetProperties(
|
||||
{{"key2", "val2"}, {"key3", "val3"}},
|
||||
[=](std::error_code ec, sdk::FailedDevices failed) mutable {
|
||||
LOG(info) << ec;
|
||||
ASSERT_EQ(ec, std::error_code());
|
||||
ASSERT_EQ(failed.size(), 0);
|
||||
blocker.Signal();
|
||||
});
|
||||
blocker.Wait();
|
||||
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::CompleteInit).first, std::error_code());
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::ResetDevice).first, std::error_code());
|
||||
}
|
||||
|
||||
TEST_F(Topology, AsyncSetPropertiesTimeout)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
using fair::mq::sdk::TopologyTransition;
|
||||
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::InitDevice).first, std::error_code());
|
||||
|
||||
topo.AsyncSetProperties({{"key1", "val1"}},
|
||||
"",
|
||||
std::chrono::microseconds(1),
|
||||
[=](std::error_code ec, sdk::FailedDevices) mutable {
|
||||
LOG(info) << ec;
|
||||
EXPECT_EQ(ec, MakeErrorCode(ErrorCode::OperationTimeout));
|
||||
});
|
||||
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::CompleteInit).first, std::error_code());
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::ResetDevice).first, std::error_code());
|
||||
}
|
||||
|
||||
TEST_F(Topology, SetPropertiesMixed)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
using fair::mq::sdk::TopologyTransition;
|
||||
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::InitDevice).first, std::error_code());
|
||||
|
||||
tools::SharedSemaphore blocker;
|
||||
topo.AsyncSetProperties(
|
||||
{{"key1", "val1"}},
|
||||
[=](std::error_code ec, sdk::FailedDevices failed) mutable {
|
||||
LOG(info) << ec;
|
||||
ASSERT_EQ(ec, std::error_code());
|
||||
ASSERT_EQ(failed.size(), 0);
|
||||
blocker.Signal();
|
||||
});
|
||||
|
||||
auto result = topo.SetProperties({{"key2", "val2"}});
|
||||
LOG(info) << result.first;
|
||||
ASSERT_EQ(result.first, std::error_code());
|
||||
ASSERT_EQ(result.second.size(), 0);
|
||||
|
||||
blocker.Wait();
|
||||
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::CompleteInit).first, std::error_code());
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::ResetDevice).first, std::error_code());
|
||||
}
|
||||
|
||||
TEST_F(Topology, GetProperties)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
using fair::mq::sdk::TopologyTransition;
|
||||
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::InitDevice).first, std::error_code());
|
||||
|
||||
auto const result = topo.GetProperties("^(session|id)$");
|
||||
LOG(info) << result.first;
|
||||
ASSERT_EQ(result.first, std::error_code());
|
||||
ASSERT_EQ(result.second.failed.size(), 0);
|
||||
for (auto const& d : result.second.devices) {
|
||||
LOG(info) << d.first;
|
||||
ASSERT_EQ(d.second.props.size(), 2);
|
||||
for (auto const& p : d.second.props) {
|
||||
LOG(info) << p.first << " : " << p.second;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::CompleteInit).first, std::error_code());
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::ResetDevice).first, std::error_code());
|
||||
}
|
||||
|
||||
TEST_F(Topology, SetAndGetProperties)
|
||||
{
|
||||
using namespace fair::mq;
|
||||
using fair::mq::sdk::TopologyTransition;
|
||||
|
||||
sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::InitDevice).first, std::error_code());
|
||||
|
||||
sdk::DeviceProperties const props{{"key1", "val1"}, {"key2", "val2"}};
|
||||
|
||||
auto const result1 = topo.SetProperties(props);
|
||||
LOG(info) << result1.first;
|
||||
ASSERT_EQ(result1.first, std::error_code());
|
||||
ASSERT_EQ(result1.second.size(), 0);
|
||||
|
||||
auto const result2 = topo.GetProperties("^key.*");
|
||||
LOG(info) << result2.first;
|
||||
ASSERT_EQ(result2.first, std::error_code());
|
||||
ASSERT_EQ(result2.second.failed.size(), 0);
|
||||
ASSERT_EQ(result2.second.devices.size(), 6);
|
||||
for (auto const& d : result2.second.devices) {
|
||||
ASSERT_EQ(d.second.props, props);
|
||||
}
|
||||
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::CompleteInit).first, std::error_code());
|
||||
ASSERT_EQ(topo.ChangeState(TopologyTransition::ResetDevice).first, std::error_code());
|
||||
}
|
||||
|
||||
TEST(Topology2, AggregatedTopologyStateComparison)
|
||||
{
|
||||
using namespace fair::mq::sdk;
|
||||
ASSERT_TRUE(DeviceState::Undefined == AggregatedTopologyState::Undefined);
|
||||
ASSERT_TRUE(AggregatedTopologyState::Undefined == DeviceState::Undefined);
|
||||
ASSERT_TRUE(DeviceState::Ok == AggregatedTopologyState::Ok);
|
||||
ASSERT_TRUE(DeviceState::Error == AggregatedTopologyState::Error);
|
||||
ASSERT_TRUE(DeviceState::Idle == AggregatedTopologyState::Idle);
|
||||
ASSERT_TRUE(DeviceState::InitializingDevice == AggregatedTopologyState::InitializingDevice);
|
||||
ASSERT_TRUE(DeviceState::Initialized == AggregatedTopologyState::Initialized);
|
||||
ASSERT_TRUE(DeviceState::Binding == AggregatedTopologyState::Binding);
|
||||
ASSERT_TRUE(DeviceState::Bound == AggregatedTopologyState::Bound);
|
||||
ASSERT_TRUE(DeviceState::Connecting == AggregatedTopologyState::Connecting);
|
||||
ASSERT_TRUE(DeviceState::DeviceReady == AggregatedTopologyState::DeviceReady);
|
||||
ASSERT_TRUE(DeviceState::InitializingTask == AggregatedTopologyState::InitializingTask);
|
||||
ASSERT_TRUE(DeviceState::Ready == AggregatedTopologyState::Ready);
|
||||
ASSERT_TRUE(DeviceState::Running == AggregatedTopologyState::Running);
|
||||
ASSERT_TRUE(DeviceState::ResettingTask == AggregatedTopologyState::ResettingTask);
|
||||
ASSERT_TRUE(DeviceState::ResettingDevice == AggregatedTopologyState::ResettingDevice);
|
||||
ASSERT_TRUE(DeviceState::Exiting == AggregatedTopologyState::Exiting);
|
||||
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("UNDEFINED") == AggregatedTopologyState::Undefined);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("OK") == AggregatedTopologyState::Ok);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("ERROR") == AggregatedTopologyState::Error);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("IDLE") == AggregatedTopologyState::Idle);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("INITIALIZING DEVICE") == AggregatedTopologyState::InitializingDevice);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("INITIALIZED") == AggregatedTopologyState::Initialized);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("BINDING") == AggregatedTopologyState::Binding);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("BOUND") == AggregatedTopologyState::Bound);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("CONNECTING") == AggregatedTopologyState::Connecting);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("DEVICE READY") == AggregatedTopologyState::DeviceReady);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("INITIALIZING TASK") == AggregatedTopologyState::InitializingTask);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("READY") == AggregatedTopologyState::Ready);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("RUNNING") == AggregatedTopologyState::Running);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("RESETTING TASK") == AggregatedTopologyState::ResettingTask);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("RESETTING DEVICE") == AggregatedTopologyState::ResettingDevice);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("EXITING") == AggregatedTopologyState::Exiting);
|
||||
ASSERT_TRUE(GetAggregatedTopologyState("MIXED") == AggregatedTopologyState::Mixed);
|
||||
|
||||
ASSERT_TRUE("UNDEFINED" == GetAggregatedTopologyStateName(AggregatedTopologyState::Undefined));
|
||||
ASSERT_TRUE("OK" == GetAggregatedTopologyStateName(AggregatedTopologyState::Ok));
|
||||
ASSERT_TRUE("ERROR" == GetAggregatedTopologyStateName(AggregatedTopologyState::Error));
|
||||
ASSERT_TRUE("IDLE" == GetAggregatedTopologyStateName(AggregatedTopologyState::Idle));
|
||||
ASSERT_TRUE("INITIALIZING DEVICE" == GetAggregatedTopologyStateName(AggregatedTopologyState::InitializingDevice));
|
||||
ASSERT_TRUE("INITIALIZED" == GetAggregatedTopologyStateName(AggregatedTopologyState::Initialized));
|
||||
ASSERT_TRUE("BINDING" == GetAggregatedTopologyStateName(AggregatedTopologyState::Binding));
|
||||
ASSERT_TRUE("BOUND" == GetAggregatedTopologyStateName(AggregatedTopologyState::Bound));
|
||||
ASSERT_TRUE("CONNECTING" == GetAggregatedTopologyStateName(AggregatedTopologyState::Connecting));
|
||||
ASSERT_TRUE("DEVICE READY" == GetAggregatedTopologyStateName(AggregatedTopologyState::DeviceReady));
|
||||
ASSERT_TRUE("INITIALIZING TASK" == GetAggregatedTopologyStateName(AggregatedTopologyState::InitializingTask));
|
||||
ASSERT_TRUE("READY" == GetAggregatedTopologyStateName(AggregatedTopologyState::Ready));
|
||||
ASSERT_TRUE("RUNNING" == GetAggregatedTopologyStateName(AggregatedTopologyState::Running));
|
||||
ASSERT_TRUE("RESETTING TASK" == GetAggregatedTopologyStateName(AggregatedTopologyState::ResettingTask));
|
||||
ASSERT_TRUE("RESETTING DEVICE" == GetAggregatedTopologyStateName(AggregatedTopologyState::ResettingDevice));
|
||||
ASSERT_TRUE("EXITING" == GetAggregatedTopologyStateName(AggregatedTopologyState::Exiting));
|
||||
ASSERT_TRUE("MIXED" == GetAggregatedTopologyStateName(AggregatedTopologyState::Mixed));
|
||||
}
|
||||
|
||||
} // namespace
|
@@ -1,42 +0,0 @@
|
||||
<topology name="sdk-test-topo">
|
||||
|
||||
<property name="fmqchan_data" />
|
||||
|
||||
<declrequirement name="SamplerWorker" type="wnname" value="sampler"/>
|
||||
<declrequirement name="SinkWorker" type="wnname" value="sink"/>
|
||||
|
||||
<decltask name="Sampler">
|
||||
<exe reachable="true">fairmq-bsampler --color false --channel-config name=data,type=push,method=bind -P dds --msg-rate 10 --severity trace --verbosity veryhigh</exe>
|
||||
<requirements>
|
||||
<name>SamplerWorker</name>
|
||||
</requirements>
|
||||
<properties>
|
||||
<name access="write">fmqchan_data</name>
|
||||
</properties>
|
||||
</decltask>
|
||||
|
||||
<decltask name="Sink">
|
||||
<exe reachable="true">fairmq-sink --color false --channel-config name=data,type=pull,method=connect -P dds --severity trace --verbosity veryhigh</exe>
|
||||
<requirements>
|
||||
<name>SinkWorker</name>
|
||||
</requirements>
|
||||
<properties>
|
||||
<name access="read">fmqchan_data</name>
|
||||
</properties>
|
||||
</decltask>
|
||||
|
||||
<declcollection name="Sinks">
|
||||
<tasks>
|
||||
<name>Sink</name>
|
||||
</tasks>
|
||||
</declcollection>
|
||||
|
||||
<main name="main">
|
||||
<task>Sampler</task>
|
||||
<group name="SinkGroup" n="5">
|
||||
<collection>Sinks</collection>
|
||||
</group>
|
||||
</main>
|
||||
|
||||
</topology>
|
||||
|
Reference in New Issue
Block a user