16 #include "mock/mockWorkspace.hpp"
18 #include <gmock/gmock.h>
19 #include <gtest/gtest.h>
26 auto daq = std::make_unique<MockDaqController>();
72 "fileId": "TEST.FILEID",
75 "origin": "dcs-host:/path/to/somefile.fits",
76 "path": "dcs/somefile.fits"
83 "origin": "fcs-host:/path/to/somefile.fits",
84 "path": "fcs/somefile.fits"
109 using namespace ::testing;
113 EXPECT_CALL(m_ws_mock, LoadQueue()).WillOnce(Return(m_queue));
119 auto daq_ws = std::make_unique<MockDaqWorkspace>();
121 status.
id =
"TEST.ID";
122 status.
file_id =
"TEST.FILEID";
123 status.
state = State::Scheduled;
124 status.
error =
false;
126 EXPECT_CALL(*daq_ws, StoreStatus(status));
127 EXPECT_CALL(*daq_ws, StoreSpecification(m_spec_str));
128 EXPECT_CALL(m_ws_mock, InitializeDaq(
"TEST.ID")).WillOnce(Return(ByMove(std::move(daq_ws))));
129 EXPECT_CALL(m_ws_mock, StoreQueue(std::vector<std::string>{
"TEST.ID"}));
134 m_scheduler->QueueDaq(m_spec_str);
135 EXPECT_TRUE(m_scheduler->IsQueued(
"TEST.ID"));
138 EXPECT_THROW(m_scheduler->QueueDaq(m_spec_str), std::invalid_argument);
139 EXPECT_TRUE(m_scheduler->IsQueued(
"TEST.ID"));
144 auto daq_ws = std::make_unique<MockDaqWorkspace>();
146 status.
id =
"TEST.ID";
147 status.
file_id =
"TEST.FILEID";
148 status.
state = State::Scheduled;
150 Sequence init, rollback;
152 EXPECT_CALL(m_ws_mock, GetPath()).Times(AnyNumber()).WillRepeatedly(Return(
"/tmp/workspace"));
154 EXPECT_CALL(*daq_ws, StoreStatus(status));
155 EXPECT_CALL(*daq_ws, StoreSpecification(m_spec_str));
156 EXPECT_CALL(m_ws_mock, InitializeDaq(
"TEST.ID"))
157 .InSequence(init, rollback)
158 .WillOnce(Return(ByMove(std::move(daq_ws))));
159 EXPECT_CALL(m_ws_mock, StoreQueue(std::vector<std::string>{
"TEST.ID"}))
160 .InSequence(init, rollback)
161 .WillRepeatedly(Throw(std::runtime_error(
"FAILED")));
164 EXPECT_CALL(m_ws_mock, RemoveDaq(
"TEST.ID")).InSequence(rollback);
169 EXPECT_THROW(m_scheduler->QueueDaq(m_spec_str), std::exception);
170 EXPECT_FALSE(m_scheduler->IsQueued(
"TEST.ID"));
175 auto daq_ws = std::make_unique<MockDaqWorkspace>();
177 status.
id =
"TEST.ID";
178 status.
file_id =
"TEST.FILEID";
179 status.
state = State::Scheduled;
181 Sequence init, rollback;
183 EXPECT_CALL(m_ws_mock, GetPath()).Times(AnyNumber()).WillRepeatedly(Return(
"/tmp/workspace"));
185 EXPECT_CALL(*daq_ws, StoreStatus(status));
186 EXPECT_CALL(*daq_ws, StoreSpecification(m_spec_str))
187 .WillOnce(Throw(std::runtime_error(
"ERROR")));
189 EXPECT_CALL(m_ws_mock, InitializeDaq(
"TEST.ID"))
190 .InSequence(init, rollback)
191 .WillOnce(Return(ByMove(std::move(daq_ws))));
194 EXPECT_CALL(m_ws_mock, RemoveDaq(
"TEST.ID")).InSequence(rollback);
199 EXPECT_THROW(m_scheduler->QueueDaq(m_spec_str), std::exception);
200 EXPECT_FALSE(m_scheduler->IsQueued(
"TEST.ID"));
205 Sequence init, rollback;
206 EXPECT_CALL(m_ws_mock, GetPath()).Times(AnyNumber()).WillRepeatedly(Return(
"/tmp/workspace"));
208 EXPECT_CALL(m_ws_mock, InitializeDaq(
"TEST.ID"))
209 .InSequence(init, rollback)
210 .WillRepeatedly(Throw(std::runtime_error(
"ERROR")));
213 EXPECT_CALL(m_ws_mock, RemoveDaq(
"TEST.ID")).InSequence(rollback);
218 EXPECT_THROW(m_scheduler->QueueDaq(m_spec_str), std::exception);
219 EXPECT_FALSE(m_scheduler->IsQueued(
"TEST.ID"));
224 Sequence init, rollback;
225 EXPECT_CALL(m_ws_mock, GetPath()).Times(AnyNumber()).WillRepeatedly(Return(
"/tmp/workspace"));
227 EXPECT_CALL(m_ws_mock, InitializeDaq(
"TEST.ID")).Times(0);
232 EXPECT_THROW(m_scheduler->QueueDaq(
"not a specification"), std::invalid_argument);
233 EXPECT_FALSE(m_scheduler->IsQueued(
"TEST.ID"));
239 m_scheduler->Start();
241 auto daq_ws = std::make_unique<MockDaqWorkspace>();
243 status.
id =
"TEST.ID";
244 status.
file_id =
"TEST.FILEID";
245 status.
state = State::Scheduled;
247 EXPECT_CALL(*daq_ws, StoreStatus(status));
248 EXPECT_CALL(*daq_ws, StoreSpecification(m_spec_str));
249 EXPECT_CALL(m_ws_mock, InitializeDaq(
"TEST.ID")).WillOnce(Return(ByMove(std::move(daq_ws))));
250 EXPECT_CALL(m_ws_mock, StoreQueue(std::vector<std::string>{
"TEST.ID"}));
252 m_scheduler->QueueDaq(m_spec_str);
253 EXPECT_TRUE(m_scheduler->IsQueued(
"TEST.ID"));
256 EXPECT_THROW(m_scheduler->QueueDaq(m_spec_str), std::invalid_argument);
257 EXPECT_TRUE(m_scheduler->IsQueued(
"TEST.ID"));
261 daq_ws = std::make_unique<MockDaqWorkspace>();
262 EXPECT_CALL(m_ws_mock, LoadDaq(
"TEST.ID")).WillOnce(Return(ByMove(std::move(daq_ws))));
264 EXPECT_CALL(mock, GetStatus()).WillOnce(ReturnRef(m_status));
265 EXPECT_CALL(mock, GetId()).WillRepeatedly(ReturnRef(m_status.GetId()));
267 EXPECT_CALL(mock, Start());
276 m_queue = {
"TEST.ID"};
279 auto daq_ws = std::make_unique<MockDaqWorkspace>();
282 EXPECT_TRUE(m_scheduler->IsQueued(
"TEST.ID"));
285 daq_ws = std::make_unique<MockDaqWorkspace>();
287 EXPECT_CALL(m_ws_mock, LoadDaq(
"TEST.ID")).WillOnce(Return(ByMove(std::move(daq_ws))));
288 EXPECT_CALL(m_ws_mock, ArchiveDaq(
"TEST.ID"));
289 EXPECT_CALL(m_ws_mock, StoreQueue(std::vector<std::string>()));
292 EXPECT_CALL(mock, GetStatus()).WillOnce(ReturnRef(m_status));
293 EXPECT_CALL(mock, GetId()).WillRepeatedly(ReturnRef(m_status.GetId()));
294 EXPECT_CALL(mock, GetState())
300 EXPECT_CALL(mock, Start()).WillOnce(Invoke([&]() { m_status.SetState(
State::Completed); }));
305 m_scheduler->Start();
311 m_queue = {
"TEST.ID"};
313 auto daq_ws = std::make_unique<MockDaqWorkspace>();
315 status.
id =
"TEST.ID";
316 status.
file_id =
"TEST.FILEID";
317 status.
state = State::Scheduled;
318 status.
error =
false;
320 EXPECT_CALL(*daq_ws, LoadStatus()).WillOnce(Return(status));
321 EXPECT_CALL(m_ws_mock, LoadDaq(
"TEST.ID")).WillOnce(Return(ByMove(std::move(daq_ws))));
322 EXPECT_CALL(m_ws_mock, StoreQueue(std::vector<std::string>{}));
323 EXPECT_CALL(m_ws_mock, RemoveDaq(
"TEST.ID"));
328 ASSERT_TRUE(m_scheduler->IsQueued(status.
id));
329 m_scheduler->AbortDaq(status.
id);
330 EXPECT_FALSE(m_scheduler->IsQueued(status.
id));
335 m_queue = {
"TEST.ID"};
336 m_status.SetState(State::Scheduled);
337 auto daq_ws_init = std::make_unique<MockDaqWorkspace>();
338 auto daq_ws_abort = std::make_unique<MockDaqWorkspace>();
340 EXPECT_CALL(*daq_ws_init, LoadStatus()).WillRepeatedly(Return(m_status.GetStatus()));
341 EXPECT_CALL(m_ws_mock, LoadDaq(
"TEST.ID")).WillOnce(Return(ByMove(std::move(daq_ws_init))));
344 EXPECT_CALL(mock, GetStatus()).WillOnce(ReturnRef(m_status));
345 EXPECT_CALL(mock, GetId()).WillRepeatedly(ReturnRef(m_status.GetId()));
347 EXPECT_CALL(mock, Start());
353 m_scheduler->Start();
356 EXPECT_CALL(*daq_ws_abort, LoadStatus()).WillRepeatedly(Return(m_status.GetStatus()));
357 EXPECT_CALL(m_ws_mock, LoadDaq(
"TEST.ID")).WillOnce(Return(ByMove(std::move(daq_ws_abort))));
358 EXPECT_CALL(m_ws_mock, RemoveDaq(
"TEST.ID"));
359 EXPECT_CALL(m_ws_mock, StoreQueue(std::vector<std::string>{}));
362 ASSERT_TRUE(m_scheduler->IsQueued(
"TEST.ID"));
363 m_scheduler->AbortDaq(
"TEST.ID");
364 EXPECT_FALSE(m_scheduler->IsQueued(
"TEST.ID"));
372 EXPECT_THROW(m_scheduler->AbortDaq(
"UNKOWN"), std::runtime_error);
377 m_queue = {
"TEST.ID"};
378 auto daq_ws = std::make_unique<MockDaqWorkspace>();
380 EXPECT_CALL(*daq_ws, LoadStatus()).WillRepeatedly(Return(m_status.GetStatus()));
381 EXPECT_CALL(m_ws_mock, LoadDaq(
"TEST.ID")).WillOnce(Return(ByMove(std::move(daq_ws))));
386 ASSERT_TRUE(m_scheduler->IsQueued(
"TEST.ID"));
387 auto status = m_scheduler->GetDaqStatus(
"TEST.ID");
388 EXPECT_EQ(status.id,
"TEST.ID");
389 EXPECT_EQ(status.state, m_status.GetState());