forked from Abc-Arbitrage/Disruptor-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRingBufferTestsFixture.h
More file actions
128 lines (87 loc) · 3.97 KB
/
RingBufferTestsFixture.h
File metadata and controls
128 lines (87 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#pragma once
#include <cstdint>
#include <future>
#include <memory>
#include <ostream>
#include <vector>
#include <boost/any.hpp>
#include <boost/test/unit_test.hpp>
#include "Disruptor/IEventTranslator.h"
#include "Disruptor/IEventTranslatorVararg.h"
#include "Disruptor/NoOpEventProcessor.h"
#include "Disruptor/RingBuffer.h"
#include "Disruptor.Tests/StubEvent.h"
#include "Disruptor.Tests/TestWaiter.h"
namespace Disruptor
{
namespace Tests
{
struct RingBufferTestsFixture
{
class NoArgEventTranslator;
class OneArgEventTranslator;
class TestEventProcessor;
class ThreeArgEventTranslator;
class TwoArgEventTranslator;
RingBufferTestsFixture();
std::future< std::vector< StubEvent > > getEvents(std::int64_t initial, std::int64_t toWaitFor);
void assertHandleResetAndNotWrap(const std::shared_ptr< RingBuffer< StubEvent > >& rb);
static void assertEmptyRingBuffer(const RingBuffer< boost::any >& ringBuffer);
class RingBufferEquals
{
public:
RingBufferEquals(const std::initializer_list< boost::any >& values);
bool operator==(const RingBuffer< boost::any >& ringBuffer) const;
void writeDescriptionTo(std::ostream& stream) const;
private:
// http://stackoverflow.com/questions/6029092/compare-boostany-contents
static bool anyEqual(const boost::any& lhs, const boost::any& rhs);
static std::string anyToString(const boost::any& value);
std::vector< boost::any > m_values;
};
std::shared_ptr< RingBuffer< StubEvent > > m_ringBuffer;
std::shared_ptr< ISequenceBarrier > m_sequenceBarrier;
std::function< RingBufferEquals(const boost::any&, const boost::any&) > m_ringBufferWithEvents =
[](const boost::any& l1, const boost::any& l2) { return RingBufferEquals({ l1, l2 }); };
std::function< RingBufferEquals(const boost::any&, const boost::any&, const boost::any&, const boost::any&) > m_ringBufferWithEvents4 =
[](const boost::any& l1, const boost::any& l2, const boost::any& l3, const boost::any& l4) { return RingBufferEquals({ l1, l2, l3, l4 }); };
};
class RingBufferTestsFixture::NoArgEventTranslator : public IEventTranslator< boost::any >
{
public:
void translateTo(boost::any& eventData, std::int64_t sequence) override;
};
class RingBufferTestsFixture::ThreeArgEventTranslator : public IEventTranslatorVararg< boost::any, std::string, std::string, std::string >
{
public:
void translateTo(boost::any& eventData, std::int64_t sequence, const std::string& arg0, const std::string& arg1, const std::string& arg2) override;
};
class RingBufferTestsFixture::TwoArgEventTranslator : public IEventTranslatorVararg< boost::any, std::string, std::string >
{
public:
void translateTo(boost::any& eventData, std::int64_t sequence, const std::string& arg0, const std::string& arg1) override;
};
class RingBufferTestsFixture::OneArgEventTranslator : public IEventTranslatorVararg< boost::any, std::string >
{
public:
void translateTo(boost::any& eventData, std::int64_t sequence, const std::string& arg0) override;
};
class RingBufferTestsFixture::TestEventProcessor : public IEventProcessor
{
public:
explicit TestEventProcessor(const std::shared_ptr< ISequenceBarrier >& sequenceBarrier);
std::shared_ptr< ISequence > sequence() const override;
void halt() override;
void run() override;
bool isRunning() const override;
private:
std::shared_ptr< ISequenceBarrier > m_sequenceBarrier;
std::shared_ptr< ISequence > m_sequence;
bool m_isRunning = false;
};
} // namespace Tests
} // namespace Disruptor
namespace std
{
ostream& operator<<(ostream& stream, const Disruptor::Tests::RingBufferTestsFixture::RingBufferEquals& equals);
} // namespace std