mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
SDK: Add Topology::AsyncSetProperties
Co-Author: Alexey Rybalchenko <alexryba@gmail.com>
This commit is contained in:
committed by
Dennis Klein
parent
25658370fa
commit
1c8ad03f3c
@@ -19,6 +19,8 @@ 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>());
|
||||
@@ -27,6 +29,7 @@ TEST(Format, Construction)
|
||||
Cmds subscribeToStateChangeCmds(make<SubscribeToStateChange>());
|
||||
Cmds unsubscribeFromStateChangeCmds(make<UnsubscribeFromStateChange>());
|
||||
Cmds stateChangeExitingReceivedCmds(make<StateChangeExitingReceived>());
|
||||
Cmds setPropertiesCmds(make<SetProperties>(42, props));
|
||||
Cmds currentStateCmds(make<CurrentState>("somedeviceid", State::Running));
|
||||
Cmds transitionStatusCmds(make<TransitionStatus>("somedeviceid", Result::Ok, Transition::Stop));
|
||||
Cmds configCmds(make<Config>("somedeviceid", "someconfig"));
|
||||
@@ -36,6 +39,7 @@ TEST(Format, Construction)
|
||||
Cmds stateChangeSubscriptionCmds(make<StateChangeSubscription>("somedeviceid", Result::Ok));
|
||||
Cmds stateChangeUnsubscriptionCmds(make<StateChangeUnsubscription>("somedeviceid", Result::Ok));
|
||||
Cmds stateChangeCmds(make<StateChange>("somedeviceid", 123456, State::Running, State::Ready));
|
||||
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);
|
||||
@@ -46,6 +50,9 @@ TEST(Format, Construction)
|
||||
ASSERT_EQ(subscribeToStateChangeCmds.At(0).GetType(), Type::subscribe_to_state_change);
|
||||
ASSERT_EQ(unsubscribeFromStateChangeCmds.At(0).GetType(), Type::unsubscribe_from_state_change);
|
||||
ASSERT_EQ(stateChangeExitingReceivedCmds.At(0).GetType(), Type::state_change_exiting_received);
|
||||
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(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);
|
||||
@@ -75,10 +82,16 @@ TEST(Format, Construction)
|
||||
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(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>();
|
||||
@@ -87,6 +100,7 @@ void fillCommands(Cmds& cmds)
|
||||
cmds.Add<SubscribeToStateChange>();
|
||||
cmds.Add<UnsubscribeFromStateChange>();
|
||||
cmds.Add<StateChangeExitingReceived>();
|
||||
cmds.Add<SetProperties>(42, props);
|
||||
cmds.Add<CurrentState>("somedeviceid", State::Running);
|
||||
cmds.Add<TransitionStatus>("somedeviceid", Result::Ok, Transition::Stop);
|
||||
cmds.Add<Config>("somedeviceid", "someconfig");
|
||||
@@ -96,13 +110,15 @@ void fillCommands(Cmds& cmds)
|
||||
cmds.Add<StateChangeSubscription>("somedeviceid", Result::Ok);
|
||||
cmds.Add<StateChangeUnsubscription>("somedeviceid", Result::Ok);
|
||||
cmds.Add<StateChange>("somedeviceid", 123456, State::Running, State::Ready);
|
||||
cmds.Add<PropertiesSet>("somedeviceid", 42, Result::Ok);
|
||||
}
|
||||
|
||||
void checkCommands(Cmds& cmds)
|
||||
{
|
||||
ASSERT_EQ(cmds.Size(), 17);
|
||||
ASSERT_EQ(cmds.Size(), 19);
|
||||
|
||||
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()) {
|
||||
@@ -131,6 +147,11 @@ void checkCommands(Cmds& cmds)
|
||||
case Type::state_change_exiting_received:
|
||||
++count;
|
||||
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::current_state:
|
||||
++count;
|
||||
ASSERT_EQ(static_cast<CurrentState&>(*cmd).GetDeviceId(), "somedeviceid");
|
||||
@@ -178,13 +199,19 @@ void checkCommands(Cmds& cmds)
|
||||
ASSERT_EQ(static_cast<StateChange&>(*cmd).GetLastState(), State::Running);
|
||||
ASSERT_EQ(static_cast<StateChange&>(*cmd).GetCurrentState(), State::Ready);
|
||||
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);
|
||||
ASSERT_EQ(count, 19);
|
||||
}
|
||||
|
||||
TEST(Format, SerializationBinary)
|
||||
|
@@ -243,4 +243,104 @@ TEST_F(Topology, ChangeStateFullDeviceLifecycle2)
|
||||
}
|
||||
}
|
||||
|
||||
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::Topology::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::Topology::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::milliseconds(1),
|
||||
[=](std::error_code ec, sdk::Topology::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::Topology::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());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user