16#include <condition_variable>
18#include <gmock/gmock.h>
19#include <gtest/gtest.h>
36using ::testing::InSequence;
37using ::testing::NiceMock;
38using ::testing::Return;
39using ::testing::Sequence;
52 const std::array<
bool,
sizeof...(T)>&
disable = {})
68 return std::string{
".data"};
93 auto lock = std::scoped_lock(callback_lock);
101 auto lock = std::scoped_lock(callback_lock);
102 auto copy = callback;
108 std::mutex callback_lock;
119 std::unique_ptr<EventPublisherIf>
MakePublisher(
const std::string& topic)
override {
121 return std::unique_ptr<MockEventPublisher>(
pub.at(topic));
124 std::unique_ptr<EventSubscriberIf>
MakeSubscriber(
const std::string& topic)
override {
126 return std::unique_ptr<MockEventSubscriber>(
sub.at(topic));
129 std::map<std::string, MockEventPublisher*>
pub;
130 std::map<std::string, MockEventSubscriber*>
sub;
139 es = std::make_shared<MockEventService>();
152 std::shared_ptr<MockEventService>
es;
157 std::chrono::milliseconds
timeout = std::chrono::milliseconds{5000}) {
160 auto state_reached = std::make_shared<std::condition_variable>();
161 std::chrono::steady_clock::time_point
until = std::chrono::steady_clock::now() +
timeout;
172 if (std::chrono::steady_clock::now() >
until) {
173 throw std::runtime_error(
"Timeout!");
Definition helpers.hpp:47
MOCK_METHOD(void, Write,(const std::tuple< T... > &),(override))
MOCK_METHOD(void, SetColumnLength,(size_t, size_t))
std::string DefaultFileExtension() override
Default filename extension for the recorder.
Definition helpers.hpp:67
MOCK_METHOD(void, Close,(),(override))
FakeRecorder(const ColumnDescription &columns, const std::array< bool, sizeof...(T)> &disable={})
Definition helpers.hpp:51
MOCK_METHOD(void, Open,(const std::filesystem::path &),(override))
typename DataRecorder< T... >::ColumnDescription ColumnDescription
Definition helpers.hpp:49
Definition helpers.hpp:76
void Publish(const JsonPayload &sample) override
Publishes a JSON object.
Definition helpers.hpp:80
friend MockEventService
Definition helpers.hpp:78
Definition helpers.hpp:114
std::unique_ptr< EventPublisherIf > MakePublisher(const std::string &topic) override
Creates a new publisher for a specified topic.
Definition helpers.hpp:119
std::map< std::string, MockEventPublisher * > pub
Definition helpers.hpp:129
MockEventService()
Definition helpers.hpp:116
std::map< std::string, MockEventSubscriber * > sub
Definition helpers.hpp:130
std::unique_ptr< EventSubscriberIf > MakeSubscriber(const std::string &topic) override
Creates a new subscriber for a specified topic.
Definition helpers.hpp:124
Definition helpers.hpp:88
std::function< void(const JsonPayload &) GetCallback)()
Definition helpers.hpp:100
void Subscribe(std::function< void(const JsonPayload &)> cb) override
Subscribes to a specified topic.
Definition helpers.hpp:92
MOCK_METHOD(void, SubscribeMock,(std::function< void(const JsonPayload &)>),())
MOCK_METHOD(void, Unsubscribe,(),(override))
friend MockEventService
Definition helpers.hpp:90
Component metrics interface.
Definition componentMetricsIf.hpp:85
This is an abstract class that can be used to implement an OutputStage for a Recording Unit.
Definition dataRecorder.hpp:29
virtual void Close()=0
Close the currently open file.
virtual void Write(const std::tuple< T... > &data)=0
Write a single row of data.
virtual void Open(const std::filesystem::path &file)=0
Open a file.
Interface class for publishing JSON events.
Definition eventServiceIf.hpp:52
Interface class for providing pub/sub facilities for JSON events.
Definition eventServiceIf.hpp:29
Interface class for subscribing to JSON events.
Definition eventServiceIf.hpp:68
virtual void Unsubscribe()=0
Unsubscribes from a specified topic.
Base interface for all OLDB adapters.
Definition oldbIf.hpp:25
Abstract base class for all sources that can be recorded by the MetadataCollector and TelemetryRecord...
Definition recordingUnit.hpp:51
boost::signals2::connection Connect(const std::function< void(const std::string &, const State &)> &function)
Connect to State change signal.
Definition recordingUnit.cpp:169
State
Definition recordingUnit.hpp:53
State GetState()
Get the current state of the Recording Unit.
Definition recordingUnit.cpp:154
The RtctkException class is the base class for all Rtctk exceptions.
Definition exceptions.hpp:211
Base interface for all Runtime Configuration Repository adapters.
Definition runtimeRepoIf.hpp:27
Container class that holds services of any type.
Definition serviceContainer.hpp:39
void Add(Service &&service, const std::string &name="")
Insert new service into the container.
Definition serviceContainer.hpp:62
ACTION(Throw)
Definition helpers.hpp:184
void AwaitState(RecordingUnit &unit, RecordingUnit::State state, std::chrono::milliseconds timeout=std::chrono::milliseconds{5000})
Definition helpers.hpp:155
Header file for ComponentMetricsIf.
Recording Unit that can record RTR datapoints.
Low-level interface of the event service.
Declaration of helper mock class for ComponentMetricsIf.
Header file providing a FakeOldbIf.
Header file providing a FakeRuntimeRepoIf.
Header file providing a mock of RepositoryIf.
Definition fakeClock.cpp:15
Definition commandReplier.cpp:22
nlohmann::json JsonPayload
Type requirements:
Definition jsonPayload.hpp:25
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Abstract base class defining functionality common to all recording units.
Definition helpers.hpp:133
std::shared_ptr< MockEventService > es
Definition helpers.hpp:152
ServiceContainer & operator*()
Definition helpers.hpp:143
FakeServices()
Definition helpers.hpp:134
MockEventService & Es()
Definition helpers.hpp:147
ServiceContainer services
Definition helpers.hpp:151