Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 3 | * Copyright (c) 2012-2017 University of California, Los Angeles |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 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" |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 21 | |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 22 | #include "boost-test.hpp" |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 23 | #include "../identity-management-fixture.hpp" |
| 24 | |
| 25 | #include "dummy-forwarder.hpp" |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 26 | |
| 27 | namespace chronosync { |
| 28 | namespace test { |
| 29 | |
| 30 | using std::vector; |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 31 | using ndn::chronosync::DummyForwarder; |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 32 | |
| 33 | class Handler |
| 34 | { |
| 35 | public: |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 36 | Handler(ndn::Face& face, |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 37 | const Name& syncPrefix, |
| 38 | const Name& userPrefix) |
| 39 | : logic(face, |
| 40 | syncPrefix, |
| 41 | userPrefix, |
| 42 | bind(&Handler::onUpdate, this, _1)) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | void |
| 47 | onUpdate(const vector<MissingDataInfo>& v) |
| 48 | { |
| 49 | for (size_t i = 0; i < v.size(); i++) { |
| 50 | update(v[i].session, v[i].high, v[i].low); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | update(const Name& p, const SeqNo& high, const SeqNo& low) |
| 56 | { |
| 57 | map[p] = high; |
| 58 | } |
| 59 | |
| 60 | void |
| 61 | updateSeqNo(const SeqNo& seqNo) |
| 62 | { |
| 63 | logic.updateSeqNo(seqNo); |
| 64 | } |
| 65 | |
Junxiao Shi | 0c7f56a | 2016-07-14 15:27:14 +0000 | [diff] [blame] | 66 | public: |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 67 | Logic logic; |
| 68 | std::map<Name, SeqNo> map; |
| 69 | }; |
| 70 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 71 | class LogicFixture : public ndn::tests::IdentityManagementTimeFixture |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 72 | { |
| 73 | public: |
| 74 | LogicFixture() |
| 75 | : syncPrefix("/ndn/broadcast/sync") |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 76 | , fw(io, m_keyChain) |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 77 | { |
| 78 | syncPrefix.appendVersion(); |
| 79 | userPrefix[0] = Name("/user0"); |
| 80 | userPrefix[1] = Name("/user1"); |
| 81 | userPrefix[2] = Name("/user2"); |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 82 | userPrefix[3] = Name("/user3"); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Junxiao Shi | 0c7f56a | 2016-07-14 15:27:14 +0000 | [diff] [blame] | 85 | public: |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 86 | Name syncPrefix; |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 87 | Name userPrefix[4]; |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 88 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 89 | DummyForwarder fw; |
| 90 | // std::unique_ptr<DummyClientFace> faces[4]; |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 91 | shared_ptr<Handler> handler[4]; |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 92 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 93 | // size_t readInterestOffset[4]; |
| 94 | // size_t readDataOffset[4]; |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | BOOST_FIXTURE_TEST_SUITE(LogicTests, LogicFixture) |
| 98 | |
| 99 | void |
| 100 | onUpdate(const vector<MissingDataInfo>& v) |
| 101 | { |
| 102 | } |
| 103 | |
| 104 | BOOST_AUTO_TEST_CASE(Constructor) |
| 105 | { |
| 106 | Name syncPrefix("/ndn/broadcast/sync"); |
| 107 | Name userPrefix("/user"); |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 108 | ndn::util::DummyClientFace face(io, {true, true}); |
| 109 | BOOST_REQUIRE_NO_THROW(Logic(face, syncPrefix, userPrefix, bind(onUpdate, _1))); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | BOOST_AUTO_TEST_CASE(TwoBasic) |
| 113 | { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 114 | handler[0] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[0]); |
| 115 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 116 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 117 | handler[1] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[1]); |
| 118 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 119 | |
| 120 | handler[0]->updateSeqNo(1); |
| 121 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 122 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 123 | |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 124 | BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1); |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 125 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 126 | |
| 127 | handler[0]->updateSeqNo(2); |
| 128 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 129 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 130 | BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 2); |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 131 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 132 | |
| 133 | handler[1]->updateSeqNo(2); |
| 134 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 135 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 136 | BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2); |
| 137 | } |
| 138 | |
| 139 | BOOST_AUTO_TEST_CASE(ThreeBasic) |
| 140 | { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 141 | handler[0] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[0]); |
| 142 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 143 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 144 | handler[1] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[1]); |
| 145 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 146 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 147 | handler[2] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[2]); |
| 148 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 149 | |
| 150 | handler[0]->updateSeqNo(1); |
| 151 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 152 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 153 | BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1); |
| 154 | BOOST_CHECK_EQUAL(handler[2]->map[handler[0]->logic.getSessionName()], 1); |
| 155 | |
| 156 | handler[1]->updateSeqNo(2); |
| 157 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 158 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 159 | BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2); |
| 160 | BOOST_CHECK_EQUAL(handler[2]->map[handler[1]->logic.getSessionName()], 2); |
| 161 | |
| 162 | handler[2]->updateSeqNo(4); |
| 163 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 164 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 165 | BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 4); |
| 166 | BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 4); |
| 167 | } |
| 168 | |
| 169 | BOOST_AUTO_TEST_CASE(ResetRecover) |
| 170 | { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 171 | handler[0] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[0]); |
| 172 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 173 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 174 | handler[1] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[1]); |
| 175 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 176 | |
| 177 | handler[0]->updateSeqNo(1); |
| 178 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 179 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 180 | BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1); |
| 181 | |
| 182 | handler[1]->updateSeqNo(2); |
| 183 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 184 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 185 | BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2); |
| 186 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 187 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 188 | handler[2] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[2]); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 189 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 190 | advanceClocks(ndn::time::milliseconds(10), 100); |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 191 | BOOST_CHECK_EQUAL(handler[2]->map[handler[0]->logic.getSessionName()], 1); |
| 192 | BOOST_CHECK_EQUAL(handler[2]->map[handler[1]->logic.getSessionName()], 2); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 193 | |
| 194 | handler[2]->updateSeqNo(4); |
| 195 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 196 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 197 | BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 4); |
| 198 | BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 4); |
| 199 | } |
| 200 | |
| 201 | BOOST_AUTO_TEST_CASE(RecoverConflict) |
| 202 | { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 203 | handler[0] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[0]); |
| 204 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 205 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 206 | handler[1] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[1]); |
| 207 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 208 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 209 | handler[2] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[2]); |
| 210 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 211 | |
| 212 | handler[0]->updateSeqNo(1); |
| 213 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 214 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 215 | BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1); |
| 216 | BOOST_CHECK_EQUAL(handler[2]->map[handler[0]->logic.getSessionName()], 1); |
| 217 | |
| 218 | handler[1]->updateSeqNo(2); |
| 219 | handler[2]->updateSeqNo(4); |
| 220 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 221 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 222 | BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2); |
| 223 | BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 4); |
| 224 | BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 4); |
| 225 | BOOST_CHECK_EQUAL(handler[2]->map[handler[1]->logic.getSessionName()], 2); |
| 226 | } |
| 227 | |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 228 | BOOST_AUTO_TEST_CASE(PartitionRecover) |
| 229 | { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 230 | handler[0] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[0]); |
| 231 | advanceClocks(ndn::time::milliseconds(10), 100); |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 232 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 233 | handler[1] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[1]); |
| 234 | advanceClocks(ndn::time::milliseconds(10), 100); |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 235 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 236 | handler[2] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[2]); |
| 237 | advanceClocks(ndn::time::milliseconds(10), 100); |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 238 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 239 | handler[3] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[3]); |
| 240 | advanceClocks(ndn::time::milliseconds(10), 100); |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 241 | |
| 242 | handler[0]->updateSeqNo(1); |
| 243 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 244 | advanceClocks(ndn::time::milliseconds(10), 100); |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 245 | BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1); |
| 246 | BOOST_CHECK_EQUAL(handler[2]->map[handler[0]->logic.getSessionName()], 1); |
| 247 | BOOST_CHECK_EQUAL(handler[3]->map[handler[0]->logic.getSessionName()], 1); |
| 248 | |
| 249 | handler[2]->updateSeqNo(2); |
| 250 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 251 | advanceClocks(ndn::time::milliseconds(10), 100); |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 252 | BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 2); |
| 253 | BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 2); |
| 254 | BOOST_CHECK_EQUAL(handler[3]->map[handler[2]->logic.getSessionName()], 2); |
| 255 | |
| 256 | // Network Partition start |
| 257 | |
| 258 | handler[1]->updateSeqNo(3); |
| 259 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 260 | advanceClocks(ndn::time::milliseconds(10), 100); |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 261 | BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 3); |
| 262 | handler[2]->map[handler[1]->logic.getSessionName()] = 0; |
| 263 | handler[3]->map[handler[1]->logic.getSessionName()] = 0; |
| 264 | |
| 265 | handler[3]->updateSeqNo(4); |
| 266 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 267 | advanceClocks(ndn::time::milliseconds(10), 100); |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 268 | BOOST_CHECK_EQUAL(handler[2]->map[handler[3]->logic.getSessionName()], 4); |
| 269 | handler[0]->map[handler[3]->logic.getSessionName()] = 0; |
| 270 | handler[1]->map[handler[3]->logic.getSessionName()] = 0; |
| 271 | |
| 272 | // Network partition over |
| 273 | |
| 274 | handler[0]->updateSeqNo(5); |
| 275 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 276 | advanceClocks(ndn::time::milliseconds(10), 100); |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 277 | BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 5); |
| 278 | BOOST_CHECK_EQUAL(handler[2]->map[handler[0]->logic.getSessionName()], 5); |
| 279 | BOOST_CHECK_EQUAL(handler[3]->map[handler[0]->logic.getSessionName()], 5); |
| 280 | |
| 281 | handler[2]->updateSeqNo(6); |
| 282 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 283 | advanceClocks(ndn::time::milliseconds(10), 100); |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame] | 284 | BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 6); |
| 285 | BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 6); |
| 286 | BOOST_CHECK_EQUAL(handler[3]->map[handler[2]->logic.getSessionName()], 6); |
| 287 | } |
| 288 | |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 289 | BOOST_AUTO_TEST_CASE(MultipleUserUnderOneLogic) |
| 290 | { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 291 | handler[0] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[0]); |
| 292 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 293 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 294 | handler[1] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[2]); |
| 295 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 296 | |
| 297 | handler[0]->logic.addUserNode(userPrefix[1]); |
| 298 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 299 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 300 | |
| 301 | handler[0]->updateSeqNo(1); |
| 302 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 303 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 304 | BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1); |
| 305 | |
| 306 | handler[0]->logic.updateSeqNo(2, userPrefix[1]); |
| 307 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 308 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 309 | BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName(userPrefix[1])], 2); |
| 310 | |
| 311 | handler[1]->updateSeqNo(4); |
| 312 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 313 | advanceClocks(ndn::time::milliseconds(10), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 314 | BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 4); |
| 315 | |
| 316 | handler[0]->logic.removeUserNode(userPrefix[0]); |
| 317 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 318 | advanceClocks(ndn::time::milliseconds(50), 100); |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 319 | BOOST_CHECK_EQUAL(handler[1]->logic.getSessionNames().size(), 2); |
| 320 | } |
| 321 | |
| 322 | BOOST_AUTO_TEST_SUITE_END() |
| 323 | |
| 324 | } // namespace test |
| 325 | } // namespace chronosync |