13#ifndef RTCTK_COMPONENTFRAMEWORK_TEST_REPOSITORYSUBSCRIBERIFTESTSUITE_HPP
14#define RTCTK_COMPONENTFRAMEWORK_TEST_REPOSITORYSUBSCRIBERIFTESTSUITE_HPP
19#include <gtest/gtest.h>
27static std::shared_ptr<RepositorySubscriberIf> MakeRepository();
33 std::lock_guard
lock{m_mutex};
34 m_data.push_back(path);
38 std::lock_guard
lock{m_mutex};
39 return m_data.at(
idx);
43 std::lock_guard
lock{m_mutex};
48 std::lock_guard
lock{m_mutex};
49 auto it = std::find(m_data.begin(), m_data.end(),
val);
50 return it != m_data.end();
54 auto t_start = std::chrono::steady_clock::now();
56 std::this_thread::sleep_for(std::chrono::microseconds(100));
58 FAIL() <<
"ThreadSafeQ::AwaitSize: Timed out waiting for size "
66 std::vector<T> m_data;
80 repo = MakeRepository();
81 path1 =
"/foo"_dppath;
82 path2 =
"/bar"_dppath;
83 link =
"/link"_dppath;
87 if (
repo ==
nullptr) {
103 std::shared_ptr<RepositorySubscriberIf>
repo;
115 repo->SendRequest(req).Wait();
126 auto sub1 = repo->Subscribe<
int>(
135 [&](std::exception_ptr error) {
error_q_1.PushBack(error); });
137 auto sub2 = repo->Subscribe(
152 repo->SendRequest(req).Wait();
172 repo->SendRequest(req).Wait();
175 std::this_thread::sleep_for(std::chrono::milliseconds(200));
186 repo->CreateDataPoint(path1, 0);
193 auto sub1 = repo->Subscribe(
201 auto sub2 = repo->Subscribe(
212 repo->WriteDataPoint(path1, 3);
225 repo->WriteDataPoint(path1, 4);
230 std::this_thread::sleep_for(std::chrono::milliseconds(200));
242 repo->SendRequest(req).Wait();
245 std::atomic_bool stop =
false;
250 while (stop ==
false) {
251 repo->WriteDataPoint(path1, value);
258 for (
unsigned i = 0;
i < 1000;
i++) {
261 auto sub = repo->Subscribe(
287 repo->SendRequest(req).Wait();
296 auto sub = repo->Subscribe<
int>(
305 [&](std::exception_ptr error) {
error_q.PushBack(error); });
329 std::this_thread::sleep_for(std::chrono::milliseconds(200));
347 [&](std::exception_ptr error) {
error_q.PushBack(error); });
354 repo->SendRequest(req).Wait();
367 repo->SendRequest(req).Wait();
382 repo->SendRequest(req).Wait();
385 std::this_thread::sleep_for(std::chrono::milliseconds(200));
403 [&](std::exception_ptr error) {
error_q.PushBack(error); });
410 repo->SendRequest(req).Wait();
423 repo->SendRequest(req).Wait();
438 repo->SendRequest(req).Wait();
441 std::this_thread::sleep_for(std::chrono::milliseconds(200));
452 auto sub = repo->Subscribe<
int>(
458 [&](std::exception_ptr error) {});
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:74
An object representing one or more asynchronous I/O requests to a repository.
Definition repositoryIf.hpp:683
void DeleteDataPoint(const DataPointPath &path, const CallbackType &callback=nullptr)
Definition repositoryIf.cpp:295
void CreateSymlink(const DataPointPath &dp, const DataPointPath &link, const CallbackType &callback=nullptr)
Definition repositoryIf.cpp:326
void CreateDataPoint(const DataPointPath &path, const T &initial_value, std::optional< std::reference_wrapper< const MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr)
Add a request to create a new datapoint.
Definition repositoryIf.ipp:1338
void WriteDataPoint(const DataPointPath &path, const T &buffer, std::optional< std::reference_wrapper< const MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr)
Definition repositoryIf.ipp:1471
Definition repositoryIf.hpp:131
Definition repositorySubscriberIfTestSuite.hpp:77
void TearDown() override
Definition repositorySubscriberIfTestSuite.hpp:86
DataPointPath path2
Definition repositorySubscriberIfTestSuite.hpp:105
void SetUp() override
Definition repositorySubscriberIfTestSuite.hpp:79
std::shared_ptr< RepositorySubscriberIf > repo
Definition repositorySubscriberIfTestSuite.hpp:103
DataPointPath path1
Definition repositorySubscriberIfTestSuite.hpp:104
DataPointPath link
Definition repositorySubscriberIfTestSuite.hpp:106
Definition repositorySubscriberIfTestSuite.hpp:30
size_t Size()
Definition repositorySubscriberIfTestSuite.hpp:42
void AwaitSize(size_t target_size, std::chrono::seconds timeout=std::chrono::seconds(5))
Definition repositorySubscriberIfTestSuite.hpp:53
void PushBack(const T &path)
Definition repositorySubscriberIfTestSuite.hpp:32
T operator[](size_t idx)
Definition repositorySubscriberIfTestSuite.hpp:37
bool Contains(const T &val)
Definition repositorySubscriberIfTestSuite.hpp:47
Definition fakeClock.cpp:15
std::chrono::milliseconds g_sleep_duration
Definition repositorySubscriberIfTestSuite.hpp:69
TEST_F(Callbacks, CreateDataPointCallback)
Definition repositoryIfTestSuite.hpp:1223
void Sleep()
Definition repositorySubscriberIfTestSuite.hpp:71
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Header file for RepositorySubscriberIf and related base classes.