SDK: Add Topology::AsyncGetProperties

Co-Author: Dennis Klein <d.klein@gsi.de>
This commit is contained in:
Alexey Rybalchenko
2020-01-24 07:55:00 +01:00
committed by Dennis Klein
parent 1c8ad03f3c
commit 264a178424
9 changed files with 331 additions and 14 deletions

View File

@@ -29,6 +29,7 @@ TEST(Format, Construction)
Cmds subscribeToStateChangeCmds(make<SubscribeToStateChange>());
Cmds unsubscribeFromStateChangeCmds(make<UnsubscribeFromStateChange>());
Cmds stateChangeExitingReceivedCmds(make<StateChangeExitingReceived>());
Cmds getPropertiesCmds(make<GetProperties>(66, "k[12]"));
Cmds setPropertiesCmds(make<SetProperties>(42, props));
Cmds currentStateCmds(make<CurrentState>("somedeviceid", State::Running));
Cmds transitionStatusCmds(make<TransitionStatus>("somedeviceid", Result::Ok, Transition::Stop));
@@ -39,6 +40,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 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);
@@ -50,6 +52,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(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);
@@ -82,6 +87,11 @@ 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(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);
@@ -100,6 +110,7 @@ void fillCommands(Cmds& cmds)
cmds.Add<SubscribeToStateChange>();
cmds.Add<UnsubscribeFromStateChange>();
cmds.Add<StateChangeExitingReceived>();
cmds.Add<GetProperties>(66, "k[12]");
cmds.Add<SetProperties>(42, props);
cmds.Add<CurrentState>("somedeviceid", State::Running);
cmds.Add<TransitionStatus>("somedeviceid", Result::Ok, Transition::Stop);
@@ -110,12 +121,13 @@ 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<Properties>("somedeviceid", 66, Result::Ok, props);
cmds.Add<PropertiesSet>("somedeviceid", 42, Result::Ok);
}
void checkCommands(Cmds& cmds)
{
ASSERT_EQ(cmds.Size(), 19);
ASSERT_EQ(cmds.Size(), 21);
int count = 0;
auto const props(std::vector<std::pair<std::string, std::string>>({{"k1", "v1"}, {"k2", "v2"}}));
@@ -147,6 +159,11 @@ void checkCommands(Cmds& cmds)
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);
@@ -199,6 +216,13 @@ 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:
++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");
@@ -211,7 +235,7 @@ void checkCommands(Cmds& cmds)
}
}
ASSERT_EQ(count, 19);
ASSERT_EQ(count, 21);
}
TEST(Format, SerializationBinary)

View File

@@ -275,7 +275,7 @@ TEST_F(Topology, AsyncSetPropertiesConcurrent)
tools::SharedSemaphore blocker(2);
topo.AsyncSetProperties(
{{"key1", "val1"}},
[=](std::error_code ec, sdk::Topology::FailedDevices failed) mutable {
[=](std::error_code ec, sdk::FailedDevices failed) mutable {
LOG(info) << ec;
ASSERT_EQ(ec, std::error_code());
ASSERT_EQ(failed.size(), 0);
@@ -283,7 +283,7 @@ TEST_F(Topology, AsyncSetPropertiesConcurrent)
});
topo.AsyncSetProperties(
{{"key2", "val2"}, {"key3", "val3"}},
[=](std::error_code ec, sdk::Topology::FailedDevices failed) mutable {
[=](std::error_code ec, sdk::FailedDevices failed) mutable {
LOG(info) << ec;
ASSERT_EQ(ec, std::error_code());
ASSERT_EQ(failed.size(), 0);
@@ -305,7 +305,7 @@ TEST_F(Topology, AsyncSetPropertiesTimeout)
topo.AsyncSetProperties({{"key1", "val1"}},
std::chrono::milliseconds(1),
[=](std::error_code ec, sdk::Topology::FailedDevices) mutable {
[=](std::error_code ec, sdk::FailedDevices) mutable {
LOG(info) << ec;
EXPECT_EQ(ec, MakeErrorCode(ErrorCode::OperationTimeout));
});
@@ -325,7 +325,7 @@ TEST_F(Topology, SetPropertiesMixed)
tools::SharedSemaphore blocker;
topo.AsyncSetProperties(
{{"key1", "val1"}},
[=](std::error_code ec, sdk::Topology::FailedDevices failed) mutable {
[=](std::error_code ec, sdk::FailedDevices failed) mutable {
LOG(info) << ec;
ASSERT_EQ(ec, std::error_code());
ASSERT_EQ(failed.size(), 0);
@@ -343,4 +343,28 @@ TEST_F(Topology, SetPropertiesMixed)
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());
}
} // namespace