MCPcopy Create free account
hub / github.com/Abc-Arbitrage/Disruptor-cpp / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

Disruptor.Tests/EventPollerTests.cpp:19–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17BOOST_AUTO_TEST_SUITE(EventPollerTests)
18
19BOOST_AUTO_TEST_CASE(ShouldPollForEvents)
20{
21 typedef std::int32_t TestDataType;
22
23 auto pollSequence = std::make_shared< Sequence >();
24 auto bufferSequence = std::make_shared< Sequence >();
25 auto gatingSequence = std::make_shared< Sequence >();
26
27 auto sequencerMock = std::make_shared< testing::NiceMock< SequencerMock< TestDataType > > >();
28
29 auto handled = false;
30 auto handler = [&](TestDataType&, std::int64_t, bool) -> bool
31 {
32 handled = true;
33 return false;
34 };
35
36 auto providerMock = std::make_shared< testing::NiceMock< DataProviderMock< TestDataType > > >();
37 auto poller = EventPoller< TestDataType >::newInstance(providerMock, sequencerMock, pollSequence, bufferSequence, { gatingSequence });
38 auto event = std::int32_t(42);
39
40 auto states = PollState::Idle;
41
42 EXPECT_CALL(*sequencerMock, cursor()).WillRepeatedly(testing::Invoke([&]()
43 {
44 switch (states)
45 {
46 case PollState::Processing:
47 return 0L;
48 case PollState::Gating:
49 return 0L;
50 case PollState::Idle:
51 return -1L;
52 default:
53 DISRUPTOR_THROW_ARGUMENT_OUT_OF_RANGE_EXCEPTION(states);
54 }
55 }));
56
57 EXPECT_CALL(*sequencerMock, getHighestPublishedSequence(0L, -1L)).WillRepeatedly(testing::Return(-1L));
58 EXPECT_CALL(*sequencerMock, getHighestPublishedSequence(0L, 0L)).WillRepeatedly(testing::Return(0L));
59
60 EXPECT_CALL(*providerMock, indexer(0)).WillRepeatedly(testing::ReturnRef(event));
61
62 // Initial State - nothing published.
63 states = PollState::Idle;
64 BOOST_CHECK_EQUAL(poller->poll(handler), PollState::Idle);
65
66 // Publish Event.
67 states = PollState::Gating;
68 bufferSequence->incrementAndGet();
69 BOOST_CHECK_EQUAL(poller->poll(handler), PollState::Gating);
70
71 states = PollState::Processing;
72 gatingSequence->incrementAndGet();
73 BOOST_CHECK_EQUAL(poller->poll(handler), PollState::Processing);
74
75 BOOST_CHECK_EQUAL(handled, true);
76}

Callers

nothing calls this directly

Calls 10

InvokeFunction · 0.85
ReturnRefFunction · 0.85
pollMethod · 0.80
ReturnClass · 0.50
incrementAndGetMethod · 0.45
newPollerMethod · 0.45
addGatingSequencesMethod · 0.45
sequenceMethod · 0.45
nextMethod · 0.45
publishMethod · 0.45

Tested by

no test coverage detected