libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
fix_simulators.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2015 by J.M.McGuiness, isimud@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 #include "stdafx.h"
20 
21 #define BOOST_TEST_MODULE isimud_tests
22 #include <boost/test/included/unit_test.hpp>
23 
24 #include <boost/mpl/list.hpp>
25 
26 #include "../exchanges/FIX/v5.0sp2/fix.hpp"
27 #include "../exchanges/FIX/v5.0sp2/fix_sim.hpp"
28 
29 #include "core/latency_timestamps.hpp"
30 
31 using namespace libjmmcg;
32 using namespace libisimud;
33 
34 const boost::asio::ip::address localhost(boost::asio::ip::address_v4::loopback());
35 const unsigned short unused_primary_port=12347u;
36 
37 typedef boost::mpl::list<
40 
41 using api_thread_traits=ppd::thread_params<ppd::platform_api>;
42 
43 BOOST_AUTO_TEST_SUITE(exchange_gateways)
44 
45 BOOST_AUTO_TEST_SUITE(links)
46 
47 /**
48  \test "Connectivity Policy" Test: gateway unavailable.
49  ================================================
50  Verify that more than 1*5 seconds passes if both gateways are unavailable.
51 */
52 BOOST_AUTO_TEST_CASE_TEMPLATE(gateway_unavailable, exchg_t, exchg_t_types) {
53  using connection_t=typename exchg_t::first_type;
54  using conn_pol_t=typename connection_t::conn_pol_t;
55  typename conn_pol_t::gateways_t gateways(
56  std::make_pair(localhost, unused_primary_port)
57  );
58  conn_pol_t conn_pol(gateways);
59  auto const &begin=std::chrono::system_clock::now();
60  BOOST_CHECK_THROW(
61  typename exchg_t::first_type link(
62  conn_pol,
63  exchg_t::first_type::skt_mgr_t::socket_t::socket_priority::high,
64  exchanges::common::thread_traits::client_to_exchange_thread.core
65  ),
66  std::exception
67  );
68  auto const &end=std::chrono::system_clock::now();
69  BOOST_CHECK_GE(std::chrono::duration_cast<std::chrono::seconds>(end-begin).count(), (conn_pol_t::max_attempts*conn_pol_t::min_timeout).count());
70 }
71 
72 /**
73  \test "Connectivity Policy" Test: primary gateway available.
74  ======================================================
75  Verify that less than 5 seconds passes if just the primary gateway is available.
76 */
77 BOOST_AUTO_TEST_CASE_TEMPLATE(gateway_available, exchg_t, exchg_t_types) {
78  using connection_t=typename exchg_t::first_type;
79  using simulator_t=typename exchg_t::second_type;
80  using conn_pol_t=typename connection_t::conn_pol_t;
81  typename simulator_t::proc_rules_t proc_rules;
82  no_latency_timestamps ts(0);
83  simulator_t svr(
84  boost::asio::ip::address(),
86  simulator_t::socket_t::socket_priority::high,
87  api_thread_traits::processor_mask_type(exchanges::common::thread_traits::exchange_simulator_thread.core),
88  exchanges::common::thread_traits::exchange_simulator_thread.priority,
89  proc_rules,
90  ts,
91  "sim" LIBJMMCG_ENQUOTE(__LINE__)
92  );
93  typename conn_pol_t::gateways_t gateways(
94  std::make_pair(localhost, unused_primary_port)
95  );
96  conn_pol_t conn_pol(gateways);
97  auto const &begin=std::chrono::system_clock::now();
98  BOOST_CHECK_NO_THROW(
99  typename exchg_t::first_type link(
100  conn_pol,
101  exchg_t::first_type::skt_mgr_t::socket_t::socket_priority::high,
102  exchanges::common::thread_traits::client_to_exchange_thread.core
103  )
104  );
105  auto const &end=std::chrono::system_clock::now();
106  BOOST_CHECK_LT(std::chrono::duration_cast<std::chrono::seconds>(end-begin).count(), conn_pol_t::min_timeout.count());
107 }
108 
109 BOOST_AUTO_TEST_SUITE_END()
110 
111 BOOST_AUTO_TEST_SUITE(admin)
112 
113 /**
114  \test "Heartbeats" Test: Client Heartbeat.
115  ====================================
116  Verify that the response to a Heartbeat is nothing.
117 */
118 BOOST_AUTO_TEST_CASE_TEMPLATE(client_heartbeat, exchg_t, exchg_t_types) {
119  using connection_t=typename exchg_t::first_type;
120  using simulator_t=typename exchg_t::second_type;
121  using conn_pol_t=typename connection_t::conn_pol_t;
122  typename simulator_t::proc_rules_t proc_rules;
123  no_latency_timestamps ts(0);
124  simulator_t svr(
125  boost::asio::ip::address(),
127  simulator_t::socket_t::socket_priority::high,
128  api_thread_traits::processor_mask_type(exchanges::common::thread_traits::exchange_simulator_thread.core),
129  exchanges::common::thread_traits::exchange_simulator_thread.priority,
130  proc_rules,
131  ts,
132  "sim" LIBJMMCG_ENQUOTE(__LINE__)
133  );
134  typename conn_pol_t::gateways_t gateways(
135  std::make_pair(localhost, unused_primary_port)
136  );
137  conn_pol_t conn_pol(gateways);
138  typename exchg_t::first_type link(
139  conn_pol,
140  exchg_t::first_type::skt_mgr_t::socket_t::socket_priority::high,
141  exchanges::common::thread_traits::client_to_exchange_thread.core
142  );
143  ALIGN_TO_L1_CACHE const exchanges::FIX::common::underlying_fix_data_buffer fix_buffer={
144  "8=FIX.5.0\0019=005\00135=0\00110=000\001"
145  };
146  typename connection_t::msg_details_t::ClientHeartbeat const &msg=reinterpret_cast<typename connection_t::msg_details_t::ClientHeartbeat const &>(*fix_buffer.begin());
147  BOOST_CHECK(msg.is_valid());
148  BOOST_CHECK_NO_THROW(link.send(msg));
149 }
150 
151 BOOST_AUTO_TEST_SUITE_END()
152 
153 BOOST_AUTO_TEST_SUITE_END()