Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012-2014 University of California, Los Angeles |
| 4 | * |
| 5 | * This file is part of ChronoSync, synchronization library for distributed realtime |
| 6 | * applications for NDN. |
| 7 | * |
| 8 | * ChronoSync is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 10 | * version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "logic.hpp" |
| 21 | |
| 22 | #include "boost-test.hpp" |
| 23 | |
| 24 | namespace chronosync { |
| 25 | namespace test { |
| 26 | |
| 27 | using std::vector; |
| 28 | |
| 29 | class Handler |
| 30 | { |
| 31 | public: |
| 32 | Handler(ndn::Face& face, |
| 33 | const Name& syncPrefix, |
| 34 | const Name& userPrefix) |
| 35 | : logic(face, |
| 36 | syncPrefix, |
| 37 | userPrefix, |
| 38 | bind(&Handler::onUpdate, this, _1)) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | void |
| 43 | onUpdate(const vector<MissingDataInfo>& v) |
| 44 | { |
| 45 | for (size_t i = 0; i < v.size(); i++) { |
| 46 | update(v[i].session, v[i].high, v[i].low); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | update(const Name& p, const SeqNo& high, const SeqNo& low) |
| 52 | { |
| 53 | map[p] = high; |
| 54 | } |
| 55 | |
| 56 | void |
| 57 | updateSeqNo(const SeqNo& seqNo) |
| 58 | { |
| 59 | logic.updateSeqNo(seqNo); |
| 60 | } |
| 61 | |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 62 | Logic logic; |
| 63 | std::map<Name, SeqNo> map; |
| 64 | }; |
| 65 | |
| 66 | class LogicFixture |
| 67 | { |
| 68 | public: |
| 69 | LogicFixture() |
| 70 | : syncPrefix("/ndn/broadcast/sync") |
| 71 | , scheduler(io) |
| 72 | { |
| 73 | syncPrefix.appendVersion(); |
| 74 | userPrefix[0] = Name("/user0"); |
| 75 | userPrefix[1] = Name("/user1"); |
| 76 | userPrefix[2] = Name("/user2"); |
| 77 | |
| 78 | faces[0] = make_shared<ndn::Face>(ref(io)); |
| 79 | faces[1] = make_shared<ndn::Face>(ref(io)); |
| 80 | faces[2] = make_shared<ndn::Face>(ref(io)); |
| 81 | } |
| 82 | |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 83 | Name syncPrefix; |
| 84 | Name userPrefix[3]; |
| 85 | |
| 86 | boost::asio::io_service io; |
| 87 | shared_ptr<ndn::Face> faces[3]; |
| 88 | ndn::Scheduler scheduler; |
| 89 | shared_ptr<Handler> handler[3]; |
| 90 | }; |
| 91 | |
| 92 | BOOST_FIXTURE_TEST_SUITE(LogicTests, LogicFixture) |
| 93 | |
| 94 | void |
| 95 | onUpdate(const vector<MissingDataInfo>& v) |
| 96 | { |
| 97 | } |
| 98 | |
| 99 | BOOST_AUTO_TEST_CASE(Constructor) |
| 100 | { |
| 101 | Name syncPrefix("/ndn/broadcast/sync"); |
| 102 | Name userPrefix("/user"); |
| 103 | ndn::Face face; |
| 104 | BOOST_REQUIRE_NO_THROW(Logic(face, syncPrefix, userPrefix, |
| 105 | bind(onUpdate, _1))); |
| 106 | } |
| 107 | |
| 108 | BOOST_AUTO_TEST_CASE(TwoBasic) |
| 109 | { |
| 110 | scheduler.scheduleEvent(ndn::time::milliseconds(100), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 111 | [this] { handler[0] = make_shared<Handler>(ref(*faces[0]), syncPrefix, userPrefix[0]); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 112 | |
| 113 | scheduler.scheduleEvent(ndn::time::milliseconds(200), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 114 | [this] { handler[1] = make_shared<Handler>(ref(*faces[1]), syncPrefix, userPrefix[1]); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 115 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 116 | scheduler.scheduleEvent(ndn::time::milliseconds(300), [this] { handler[0]->updateSeqNo(1); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 117 | |
| 118 | scheduler.scheduleEvent(ndn::time::milliseconds(1000), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 119 | [this] { BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 120 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 121 | scheduler.scheduleEvent(ndn::time::milliseconds(1100), [this] { handler[0]->updateSeqNo(2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 122 | |
| 123 | scheduler.scheduleEvent(ndn::time::milliseconds(1800), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 124 | [this] { BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 125 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 126 | scheduler.scheduleEvent(ndn::time::milliseconds(1900), [this] { handler[1]->updateSeqNo(2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 127 | |
| 128 | scheduler.scheduleEvent(ndn::time::milliseconds(2600), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 129 | [this] { BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 130 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 131 | scheduler.scheduleEvent(ndn::time::milliseconds(2800), [this] { io.stop(); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 132 | |
| 133 | io.run(); |
| 134 | } |
| 135 | |
| 136 | BOOST_AUTO_TEST_CASE(ThreeBasic) |
| 137 | { |
| 138 | scheduler.scheduleEvent(ndn::time::milliseconds(100), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 139 | [this] { handler[0] = make_shared<Handler>(ref(*faces[0]), syncPrefix, userPrefix[0]); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 140 | |
| 141 | scheduler.scheduleEvent(ndn::time::milliseconds(200), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 142 | [this] { handler[1] = make_shared<Handler>(ref(*faces[1]), syncPrefix, userPrefix[1]); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 143 | |
| 144 | scheduler.scheduleEvent(ndn::time::milliseconds(300), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 145 | [this] { handler[2] = make_shared<Handler>(ref(*faces[2]), syncPrefix, userPrefix[2]); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 146 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 147 | scheduler.scheduleEvent(ndn::time::milliseconds(500), [this] { handler[0]->updateSeqNo(1); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 148 | |
| 149 | scheduler.scheduleEvent(ndn::time::milliseconds(1400), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 150 | [this] { BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 151 | |
| 152 | scheduler.scheduleEvent(ndn::time::milliseconds(1450), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 153 | [this] { BOOST_CHECK_EQUAL(handler[2]->map[handler[0]->logic.getSessionName()], 1); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 154 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 155 | scheduler.scheduleEvent(ndn::time::milliseconds(1500), [this] { handler[1]->updateSeqNo(2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 156 | |
| 157 | scheduler.scheduleEvent(ndn::time::milliseconds(2400), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 158 | [this] { BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 159 | |
| 160 | scheduler.scheduleEvent(ndn::time::milliseconds(2450), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 161 | [this] { BOOST_CHECK_EQUAL(handler[2]->map[handler[1]->logic.getSessionName()], 2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 162 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 163 | scheduler.scheduleEvent(ndn::time::milliseconds(2500), [this] { handler[2]->updateSeqNo(4); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 164 | |
| 165 | scheduler.scheduleEvent(ndn::time::milliseconds(4400), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 166 | [this] { BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 4); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 167 | |
| 168 | scheduler.scheduleEvent(ndn::time::milliseconds(4450), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 169 | [this] { BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 4); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 170 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 171 | scheduler.scheduleEvent(ndn::time::milliseconds(4500), [this] { io.stop(); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 172 | |
| 173 | io.run(); |
| 174 | } |
| 175 | |
| 176 | BOOST_AUTO_TEST_CASE(ResetRecover) |
| 177 | { |
| 178 | scheduler.scheduleEvent(ndn::time::milliseconds(100), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 179 | [this] { handler[0] = make_shared<Handler>(ref(*faces[0]), syncPrefix, userPrefix[0]); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 180 | |
| 181 | scheduler.scheduleEvent(ndn::time::milliseconds(200), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 182 | [this] { handler[1] = make_shared<Handler>(ref(*faces[1]), syncPrefix, userPrefix[1]); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 183 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 184 | scheduler.scheduleEvent(ndn::time::milliseconds(500), [this] { handler[0]->updateSeqNo(1); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 185 | |
| 186 | scheduler.scheduleEvent(ndn::time::milliseconds(1400), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 187 | [this] { BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 188 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 189 | scheduler.scheduleEvent(ndn::time::milliseconds(1500), [this] { handler[1]->updateSeqNo(2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 190 | |
| 191 | scheduler.scheduleEvent(ndn::time::milliseconds(2400), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 192 | [this] { BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 193 | |
| 194 | scheduler.scheduleEvent(ndn::time::milliseconds(2500), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 195 | [this] { handler[2] = make_shared<Handler>(ref(*faces[2]), syncPrefix, userPrefix[2]); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 196 | |
| 197 | scheduler.scheduleEvent(ndn::time::milliseconds(3000), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 198 | [this] { BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 199 | |
| 200 | scheduler.scheduleEvent(ndn::time::milliseconds(3050), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 201 | [this] { BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 202 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 203 | scheduler.scheduleEvent(ndn::time::milliseconds(3100), [this] { handler[2]->updateSeqNo(4); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 204 | |
| 205 | scheduler.scheduleEvent(ndn::time::milliseconds(4000), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 206 | [this] { BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 4); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 207 | |
| 208 | scheduler.scheduleEvent(ndn::time::milliseconds(4050), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 209 | [this] { BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 4); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 210 | |
| 211 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 212 | scheduler.scheduleEvent(ndn::time::milliseconds(4500), [this] { io.stop(); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 213 | |
| 214 | io.run(); |
| 215 | } |
| 216 | |
| 217 | BOOST_AUTO_TEST_CASE(RecoverConflict) |
| 218 | { |
| 219 | scheduler.scheduleEvent(ndn::time::milliseconds(0), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 220 | [this] { handler[0] = make_shared<Handler>(ref(*faces[0]), syncPrefix, userPrefix[0]); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 221 | |
| 222 | scheduler.scheduleEvent(ndn::time::milliseconds(50), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 223 | [this] { handler[1] = make_shared<Handler>(ref(*faces[1]), syncPrefix, userPrefix[1]); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 224 | |
| 225 | scheduler.scheduleEvent(ndn::time::milliseconds(100), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 226 | [this] { handler[2] = make_shared<Handler>(ref(*faces[2]), syncPrefix, userPrefix[2]); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 227 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 228 | scheduler.scheduleEvent(ndn::time::milliseconds(500), [this] { handler[0]->updateSeqNo(1); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 229 | |
| 230 | scheduler.scheduleEvent(ndn::time::milliseconds(1400), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 231 | [this] { BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 232 | |
| 233 | scheduler.scheduleEvent(ndn::time::milliseconds(1400), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 234 | [this] { BOOST_CHECK_EQUAL(handler[2]->map[handler[0]->logic.getSessionName()], 1); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 235 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 236 | scheduler.scheduleEvent(ndn::time::milliseconds(1500), [this] { handler[1]->updateSeqNo(2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 237 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 238 | scheduler.scheduleEvent(ndn::time::milliseconds(1500), [this] { handler[2]->updateSeqNo(4); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 239 | |
| 240 | scheduler.scheduleEvent(ndn::time::milliseconds(2400), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 241 | [this] { BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 242 | |
| 243 | scheduler.scheduleEvent(ndn::time::milliseconds(2450), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 244 | [this] { BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 4); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 245 | |
| 246 | scheduler.scheduleEvent(ndn::time::milliseconds(2500), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 247 | [this] { BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 4); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 248 | |
| 249 | scheduler.scheduleEvent(ndn::time::milliseconds(2550), |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 250 | [this] { BOOST_CHECK_EQUAL(handler[2]->map[handler[1]->logic.getSessionName()], 2); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 251 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 252 | scheduler.scheduleEvent(ndn::time::milliseconds(4500), [this] { io.stop(); }); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 253 | |
| 254 | io.run(); |
| 255 | } |
| 256 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 257 | BOOST_AUTO_TEST_CASE(MultipleUserUnderOneLogic) |
| 258 | { |
| 259 | scheduler.scheduleEvent(ndn::time::milliseconds(0), |
| 260 | [this] { handler[0] = make_shared<Handler>(ref(*faces[0]), syncPrefix, userPrefix[0]); }); |
| 261 | |
| 262 | scheduler.scheduleEvent(ndn::time::milliseconds(50), |
| 263 | [this] { handler[1] = make_shared<Handler>(ref(*faces[1]), syncPrefix, userPrefix[2]); }); |
| 264 | |
| 265 | scheduler.scheduleEvent(ndn::time::milliseconds(100), |
| 266 | [this] { handler[0]->logic.addUserNode(userPrefix[1]); }); |
| 267 | |
| 268 | scheduler.scheduleEvent(ndn::time::milliseconds(500), [this] { handler[0]->updateSeqNo(1); }); |
| 269 | |
| 270 | scheduler.scheduleEvent(ndn::time::milliseconds(1400), |
| 271 | [this] { BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1); }); |
| 272 | |
| 273 | scheduler.scheduleEvent(ndn::time::milliseconds(1500), |
| 274 | [this] { handler[0]->logic.updateSeqNo(2, userPrefix[1]); }); |
| 275 | |
| 276 | scheduler.scheduleEvent(ndn::time::milliseconds(2400), |
| 277 | [this] { |
| 278 | Name sessionName = handler[0]->logic.getSessionName(userPrefix[1]); |
| 279 | BOOST_CHECK_EQUAL(handler[1]->map[sessionName], 2); |
| 280 | }); |
| 281 | |
| 282 | scheduler.scheduleEvent(ndn::time::milliseconds(2500), [this] { handler[1]->updateSeqNo(4); }); |
| 283 | |
| 284 | scheduler.scheduleEvent(ndn::time::milliseconds(3200), |
| 285 | [this] { BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 4); }); |
| 286 | |
| 287 | scheduler.scheduleEvent(ndn::time::milliseconds(3300), |
| 288 | [this] { handler[0]->logic.removeUserNode(userPrefix[0]); }); |
| 289 | |
| 290 | scheduler.scheduleEvent(ndn::time::milliseconds(4500), |
| 291 | [this] { BOOST_CHECK_EQUAL(handler[1]->logic.getSessionNames().size(), 2); }); |
| 292 | |
| 293 | scheduler.scheduleEvent(ndn::time::milliseconds(5000), [this] { io.stop(); }); |
| 294 | |
| 295 | io.run(); |
| 296 | } |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 297 | |
| 298 | BOOST_AUTO_TEST_SUITE_END() |
| 299 | |
| 300 | } // namespace test |
| 301 | } // namespace chronosync |