15 #include <gmock/gmock.h>
16 #include <gtest/gtest.h>
23 #include "mock/mockWorkspace.hpp"
53 using namespace ::testing;
57 std::filesystem::space_info status = {};
58 status.available = 123;
60 status.capacity = 789;
62 EXPECT_CALL(m_ws_mock, QueryStorageStatus()).WillOnce(Return(status));
65 EXPECT_CALL(m_mal_mock, getDataEntityUnsafe(_,
"daqif_StorageStatus"))
66 .WillOnce(Return(fake_reply))
67 .RetiresOnSaturation();
70 auto fut = m_service->QueryStorageStatus();
73 ASSERT_TRUE(fut.is_ready());
74 auto daqif_status = fut.get();
75 EXPECT_EQ(daqif_status->getCapacity(), status.capacity);
76 EXPECT_EQ(daqif_status->getFree(), status.free);
77 EXPECT_EQ(daqif_status->getAvailable(), status.available);
82 EXPECT_CALL(m_ws_mock, QueryStorageStatus()).WillOnce(Throw(std::runtime_error(
"ERROR")));
85 auto fut = m_service->QueryStorageStatus();
88 ASSERT_TRUE(fut.is_ready());
89 EXPECT_THROW(fut.get(), daqif::Exception);
95 EXPECT_CALL(m_mal_mock, getDataEntityUnsafe(_,
"daqif_DaqReply"))
96 .WillOnce(Return(fake_reply))
97 .RetiresOnSaturation();
98 EXPECT_CALL(m_scheduler_mock, QueueDaq(
"SPEC")).WillOnce(Return(
"ID"));
101 auto fut = m_service->QueueDaq(
"SPEC");
104 ASSERT_TRUE(fut.is_ready());
105 auto reply = fut.get();
111 EXPECT_CALL(m_scheduler_mock, QueueDaq(
"SPEC")).WillOnce(Throw(std::runtime_error(
"ID")));
114 auto fut = m_service->QueueDaq(
"SPEC");
117 ASSERT_TRUE(fut.is_ready());
118 EXPECT_THROW(fut.get(), daqif::DaqException);
124 EXPECT_CALL(m_mal_mock, getDataEntityUnsafe(_,
"daqif_DaqReply"))
125 .WillOnce(Return(fake_reply))
126 .RetiresOnSaturation();
127 EXPECT_CALL(m_scheduler_mock, AbortDaq(
"TEST.ID")).Times(1);
130 auto fut = m_service->AbortDaq(
"TEST.ID");
133 ASSERT_TRUE(fut.is_ready());
134 auto reply = fut.get();
136 EXPECT_FALSE(reply->getError());
141 EXPECT_CALL(m_scheduler_mock, AbortDaq(
"ID")).WillOnce(Throw(std::runtime_error(
"ID")));
144 auto fut = m_service->AbortDaq(
"ID");
147 ASSERT_TRUE(fut.is_ready());
148 EXPECT_THROW(fut.get(), daqif::DaqException);
154 EXPECT_CALL(m_mal_mock, getDataEntityUnsafe(_,
"daqif_DaqStatus"))
155 .WillOnce(Return(fake_reply))
156 .RetiresOnSaturation();
159 status.
id =
"TEST.ID";
161 EXPECT_CALL(m_scheduler_mock, GetDaqStatus(
"TEST.ID")).WillOnce(Return(status));
164 auto fut = m_service->GetDaqStatus(
"TEST.ID");
167 ASSERT_TRUE(fut.is_ready());
168 auto reply = fut.get();
170 EXPECT_EQ(reply->getState(), daqif::StateMerging);
171 EXPECT_EQ(reply->getSubState(), daqif::Merging);
172 EXPECT_FALSE(reply->getError());
177 EXPECT_CALL(m_scheduler_mock, GetDaqStatus(
"TEST.ID"))
178 .WillOnce(Throw(std::runtime_error(
"oops")));
181 auto fut = m_service->GetDaqStatus(
"TEST.ID");
184 ASSERT_TRUE(fut.is_ready());
185 EXPECT_THROW(fut.get(), daqif::DaqException);
192 EXPECT_CALL(m_mal_mock, getDataEntityUnsafe(_,
"daqif_DaqStatus"))
193 .WillOnce(Return(fake_reply1))
194 .WillOnce(Return(fake_reply2))
195 .RetiresOnSaturation();
198 status1.
id =
"TEST.ID";
202 status2.
id =
"TEST.ID2";
205 std::vector<std::string> ids = {
"TEST.ID",
"TEST.ID2"};
206 EXPECT_CALL(m_scheduler_mock, GetQueue()).WillOnce(Return(ids));
207 EXPECT_CALL(m_scheduler_mock, GetDaqStatus(
"TEST.ID")).WillOnce(Return(status1));
208 EXPECT_CALL(m_scheduler_mock, GetDaqStatus(
"TEST.ID2")).WillOnce(Return(status2));
211 auto fut = m_service->GetActiveDaqs();
214 ASSERT_TRUE(fut.is_ready());
215 std::vector<std::shared_ptr<::daqif::DaqStatus>> reply = fut.get();
219 EXPECT_EQ(reply[0]->getState(), daqif::StateMerging);
220 EXPECT_EQ(reply[0]->getSubState(), daqif::Transferring);
221 EXPECT_FALSE(reply[0]->getError());
223 EXPECT_EQ(reply[1]->getId(),
"TEST.ID2");
224 EXPECT_EQ(reply[1]->getState(), daqif::StateMerging);
225 EXPECT_EQ(reply[1]->getSubState(), daqif::Aborting);
226 EXPECT_FALSE(reply[1]->getError());
231 std::vector<std::string> ids = {
"TEST.ID",
"TEST.ID2"};
232 EXPECT_CALL(m_scheduler_mock, GetQueue()).WillOnce(Return(ids));
233 EXPECT_CALL(m_scheduler_mock, GetDaqStatus(
"TEST.ID"))
234 .WillOnce(Throw(std::runtime_error(
"oops")));
237 auto fut = m_service->GetActiveDaqs();
240 ASSERT_TRUE(fut.is_ready());
241 EXPECT_THROW(fut.get(), daqif::DaqException);
rad::IoExecutor m_executor
std::unique_ptr< DpmService > m_service
daq::dpm::MockWorkspace m_ws_mock
boost::asio::io_context m_io_ctx
daq::dpm::MockScheduler m_scheduler_mock
Adapts boost::asio::io_context into a compatible boost::thread Executor type.
daq::dpm::DpmService implements MAL services daqif::DpmControl and daqif::DpmDaqControl.
Mocks for daq::dpm::Workspace and daq::dpm::DaqWorkspace.
Mocks for daq::dpm::Scheduler and daq::dpm::DaqScheduler.
TEST_F(TestDaqController, ScheduledTransitionsToTransferring)
@ Merging
DAQ is being merged.
@ AbortingMerging
Transitional state for aborting during merging.
@ Transferring
Input files are being transferred.
Defines shared test progress utilities.
daq::dpm::Scheduler and related class declarations.
Non observable status object that keeps stores status of data acquisition.
EXPECT_EQ(meta.rr_uri, "zpb.rr://meta")
ASSERT_EQ(meta.keyword_rules.size(), 1u)