Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, The University of Memphis |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 4 | * |
| 5 | * This file is part of PSync. |
| 6 | * See AUTHORS.md for complete list of PSync authors and contributors. |
| 7 | * |
| 8 | * PSync is free software: you can redistribute it and/or modify it under the terms |
Ashlesh Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 9 | * of the GNU Lesser General Public License as published by the Free Software Foundation, |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * PSync 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 |
Ashlesh Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 14 | * PURPOSE. See the GNU Lesser General Public License for more details. |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 15 | * |
Ashlesh Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 16 | * You should have received a copy of the GNU Lesser General Public License along with |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 17 | * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 18 | */ |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 19 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 20 | #include "PSync/partial-producer.hpp" |
| 21 | #include "PSync/consumer.hpp" |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 22 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 23 | #include "tests/boost-test.hpp" |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 24 | #include "tests/io-fixture.hpp" |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 25 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 26 | #include <ndn-cxx/name.hpp> |
| 27 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 28 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 29 | namespace psync { |
| 30 | |
| 31 | using namespace ndn; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 32 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 33 | class PartialSyncFixture : public tests::IoFixture |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 34 | { |
| 35 | public: |
| 36 | PartialSyncFixture() |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 37 | { |
| 38 | producer = make_shared<PartialProducer>(40, face, syncPrefix, userPrefix); |
| 39 | addUserNodes("testUser", 10); |
| 40 | } |
| 41 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 42 | ~PartialSyncFixture() override |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 43 | { |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 44 | for (const auto& consumer : consumers) { |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 45 | if (consumer) { |
| 46 | consumer->stop(); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 51 | void |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 52 | addConsumer(int id, const std::vector<std::string>& subscribeTo, bool linkToProducer = true) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 53 | { |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 54 | consumerFaces[id] = |
| 55 | std::make_shared<util::DummyClientFace>(m_io, util::DummyClientFace::Options{true, true}); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 56 | |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 57 | if (linkToProducer) { |
| 58 | face.linkTo(*consumerFaces[id]); |
| 59 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 60 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 61 | consumers[id] = std::make_shared<Consumer>(syncPrefix, *consumerFaces[id], |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 62 | [&, id] (const auto& availableSubs) { |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 63 | numHelloDataRcvd++; |
Ashlesh Gawande | deb73f8 | 2018-08-09 11:08:02 -0500 | [diff] [blame] | 64 | BOOST_CHECK(checkSubList(availableSubs)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 65 | |
| 66 | checkIBFUpdated(id); |
| 67 | |
| 68 | for (const auto& sub : subscribeTo) { |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 69 | auto it = availableSubs.find(sub); |
| 70 | consumers[id]->addSubscription(sub, it->second); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 71 | } |
| 72 | consumers[id]->sendSyncInterest(); |
| 73 | }, |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 74 | [&, id] (const auto& updates) { |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 75 | numSyncDataRcvd++; |
| 76 | |
| 77 | checkIBFUpdated(id); |
| 78 | |
| 79 | for (const auto& update : updates) { |
| 80 | BOOST_CHECK(consumers[id]->isSubscribed(update.prefix)); |
| 81 | BOOST_CHECK_EQUAL(oldSeqMap.at(update.prefix) + 1, update.lowSeq); |
| 82 | BOOST_CHECK_EQUAL(producer->m_prefixes.at(update.prefix), update.highSeq); |
| 83 | BOOST_CHECK_EQUAL(consumers[id]->getSeqNo(update.prefix).value(), update.highSeq); |
| 84 | } |
| 85 | }, 40, 0.001); |
| 86 | |
| 87 | advanceClocks(ndn::time::milliseconds(10)); |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | checkIBFUpdated(int id) |
| 92 | { |
| 93 | Name emptyName; |
| 94 | producer->m_iblt.appendToName(emptyName); |
| 95 | BOOST_CHECK_EQUAL(consumers[id]->m_iblt, emptyName); |
| 96 | } |
| 97 | |
| 98 | bool |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 99 | checkSubList(const std::map<Name, uint64_t>& availableSubs) const |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 100 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 101 | for (const auto& prefix : producer->m_prefixes) { |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 102 | auto it = availableSubs.find(prefix.first); |
| 103 | if (it == availableSubs.end()) { |
Ashlesh Gawande | deb73f8 | 2018-08-09 11:08:02 -0500 | [diff] [blame] | 104 | return false; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | addUserNodes(const std::string& prefix, int numOfUserNodes) |
| 112 | { |
| 113 | // zeroth is added through constructor |
| 114 | for (int i = 1; i < numOfUserNodes; i++) { |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 115 | producer->addUserNode(prefix + "-" + std::to_string(i)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
| 119 | void |
| 120 | publishUpdateFor(const std::string& prefix) |
| 121 | { |
| 122 | oldSeqMap = producer->m_prefixes; |
| 123 | producer->publishName(prefix); |
| 124 | advanceClocks(ndn::time::milliseconds(10)); |
| 125 | } |
| 126 | |
| 127 | void |
| 128 | updateSeqFor(const std::string& prefix, uint64_t seq) |
| 129 | { |
| 130 | oldSeqMap = producer->m_prefixes; |
| 131 | producer->updateSeqNo(prefix, seq); |
| 132 | } |
| 133 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 134 | util::DummyClientFace face{m_io, {true, true}}; |
| 135 | Name syncPrefix{"psync"}; |
| 136 | Name userPrefix{"testUser-0"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 137 | |
| 138 | shared_ptr<PartialProducer> producer; |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 139 | std::map<Name, uint64_t> oldSeqMap; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 140 | |
| 141 | shared_ptr<Consumer> consumers[3]; |
| 142 | shared_ptr<util::DummyClientFace> consumerFaces[3]; |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 143 | int numHelloDataRcvd = 0; |
| 144 | int numSyncDataRcvd = 0; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 145 | }; |
| 146 | |
Ashlesh Gawande | 6a5157f | 2019-12-09 11:49:07 -0600 | [diff] [blame] | 147 | BOOST_FIXTURE_TEST_SUITE(TestPartialSync, PartialSyncFixture) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 148 | |
| 149 | BOOST_AUTO_TEST_CASE(Simple) |
| 150 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 151 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 152 | addConsumer(0, subscribeTo); |
| 153 | |
| 154 | consumers[0]->sendHelloInterest(); |
| 155 | advanceClocks(ndn::time::milliseconds(10)); |
| 156 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 157 | |
| 158 | publishUpdateFor("testUser-2"); |
| 159 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 160 | publishUpdateFor("testUser-3"); |
| 161 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 162 | publishUpdateFor("testUser-2"); |
| 163 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 2); |
| 164 | } |
| 165 | |
| 166 | BOOST_AUTO_TEST_CASE(MissedUpdate) |
| 167 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 168 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 169 | addConsumer(0, subscribeTo); |
| 170 | |
| 171 | consumers[0]->sendHelloInterest(); |
| 172 | advanceClocks(ndn::time::milliseconds(10)); |
| 173 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 174 | |
| 175 | updateSeqFor("testUser-2", 3); |
| 176 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 0); |
| 177 | |
| 178 | // The sync interest sent after hello will timeout |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 179 | advanceClocks(ndn::time::milliseconds(999)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 180 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 0); |
| 181 | |
| 182 | // Next sync interest will bring back the sync data |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 183 | advanceClocks(ndn::time::milliseconds(1)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 184 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 185 | } |
| 186 | |
| 187 | BOOST_AUTO_TEST_CASE(LateSubscription) |
| 188 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 189 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 190 | addConsumer(0, subscribeTo); |
| 191 | |
| 192 | consumers[0]->sendHelloInterest(); |
| 193 | advanceClocks(ndn::time::milliseconds(10)); |
| 194 | |
| 195 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 196 | publishUpdateFor("testUser-2"); |
| 197 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 198 | |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 199 | consumers[0]->addSubscription("testUser-3", 0); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 200 | consumers[0]->sendSyncInterest(); |
| 201 | publishUpdateFor("testUser-3"); |
| 202 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 2); |
| 203 | } |
| 204 | |
| 205 | BOOST_AUTO_TEST_CASE(ConsumerSyncTimeout) |
| 206 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 207 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 208 | addConsumer(0, subscribeTo); |
| 209 | |
| 210 | consumers[0]->sendHelloInterest(); |
| 211 | BOOST_CHECK_EQUAL(producer->m_pendingEntries.size(), 0); |
| 212 | advanceClocks(ndn::time::milliseconds(10)); |
| 213 | BOOST_CHECK_EQUAL(producer->m_pendingEntries.size(), 1); |
| 214 | advanceClocks(ndn::time::milliseconds(10), 100); |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 215 | // The next Interest is sent after the first one immediately |
| 216 | BOOST_CHECK_EQUAL(producer->m_pendingEntries.size(), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 217 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 218 | |
| 219 | int numSyncInterests = 0; |
| 220 | for (const auto& interest : consumerFaces[0]->sentInterests) { |
| 221 | if (interest.getName().getSubName(0, 2) == Name("/psync/sync")) { |
| 222 | numSyncInterests++; |
| 223 | } |
| 224 | } |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 225 | BOOST_CHECK_EQUAL(numSyncInterests, 3); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 226 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 0); |
| 227 | } |
| 228 | |
| 229 | BOOST_AUTO_TEST_CASE(MultipleConsumersWithSameSubList) |
| 230 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 231 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 232 | addConsumer(0, subscribeTo); |
| 233 | addConsumer(1, subscribeTo); |
| 234 | addConsumer(2, subscribeTo); |
| 235 | |
| 236 | consumers[0]->sendHelloInterest(); |
| 237 | consumers[1]->sendHelloInterest(); |
| 238 | consumers[2]->sendHelloInterest(); |
| 239 | advanceClocks(ndn::time::milliseconds(10)); |
| 240 | |
| 241 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 3); |
| 242 | |
| 243 | publishUpdateFor("testUser-2"); |
| 244 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 3); |
| 245 | |
| 246 | publishUpdateFor("testUser-3"); |
| 247 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 3); |
| 248 | } |
| 249 | |
| 250 | BOOST_AUTO_TEST_CASE(MultipleConsumersWithDifferentSubList) |
| 251 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 252 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 253 | addConsumer(0, subscribeTo); |
| 254 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 255 | std::vector<std::string> subscribeTo1{"testUser-1", "testUser-3", "testUser-5"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 256 | addConsumer(1, subscribeTo1); |
| 257 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 258 | std::vector<std::string> subscribeTo2{"testUser-2", "testUser-3"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 259 | addConsumer(2, subscribeTo2); |
| 260 | |
| 261 | consumers[0]->sendHelloInterest(); |
| 262 | consumers[1]->sendHelloInterest(); |
| 263 | consumers[2]->sendHelloInterest(); |
| 264 | advanceClocks(ndn::time::milliseconds(10)); |
| 265 | |
| 266 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 3); |
| 267 | |
| 268 | publishUpdateFor("testUser-2"); |
| 269 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 2); |
| 270 | |
| 271 | numSyncDataRcvd = 0; |
| 272 | publishUpdateFor("testUser-3"); |
| 273 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 2); |
| 274 | } |
| 275 | |
| 276 | BOOST_AUTO_TEST_CASE(ReplicatedProducer) |
| 277 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 278 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 279 | addConsumer(0, subscribeTo); |
| 280 | |
| 281 | consumers[0]->sendHelloInterest(); |
| 282 | advanceClocks(ndn::time::milliseconds(10)); |
| 283 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 284 | |
| 285 | publishUpdateFor("testUser-2"); |
| 286 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 287 | |
| 288 | // Link to first producer goes down |
| 289 | face.unlink(); |
| 290 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 291 | util::DummyClientFace face2(m_io, {true, true}); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 292 | PartialProducer replicatedProducer(40, face2, syncPrefix, userPrefix); |
| 293 | for (int i = 1; i < 10; i++) { |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 294 | replicatedProducer.addUserNode("testUser-" + std::to_string(i)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 295 | } |
| 296 | advanceClocks(ndn::time::milliseconds(10)); |
| 297 | replicatedProducer.publishName("testUser-2"); |
| 298 | // Link to a replicated producer comes up |
| 299 | face2.linkTo(*consumerFaces[0]); |
| 300 | |
| 301 | BOOST_CHECK_EQUAL(face2.sentData.size(), 0); |
| 302 | |
| 303 | // Update in first producer as well so consumer on sync data |
| 304 | // callback checks still pass |
| 305 | publishUpdateFor("testUser-2"); |
| 306 | replicatedProducer.publishName("testUser-2"); |
| 307 | advanceClocks(ndn::time::milliseconds(15), 100); |
| 308 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 2); |
| 309 | BOOST_CHECK_EQUAL(face2.sentData.size(), 1); |
| 310 | } |
| 311 | |
| 312 | BOOST_AUTO_TEST_CASE(ApplicationNack) |
| 313 | { |
| 314 | // 50 is more than expected number of entries of 40 in the producer's IBF |
| 315 | addUserNodes("testUser", 50); |
| 316 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 317 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 318 | addConsumer(0, subscribeTo); |
| 319 | |
| 320 | consumers[0]->sendHelloInterest(); |
| 321 | advanceClocks(ndn::time::milliseconds(10)); |
| 322 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 323 | |
| 324 | publishUpdateFor("testUser-2"); |
| 325 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 326 | |
| 327 | oldSeqMap = producer->m_prefixes; |
| 328 | for (int i = 0; i < 50; i++) { |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 329 | Name prefix("testUser-" + std::to_string(i)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 330 | producer->updateSeqNo(prefix, producer->getSeqNo(prefix).value() + 1); |
| 331 | } |
| 332 | // Next sync interest should trigger the nack |
| 333 | advanceClocks(ndn::time::milliseconds(15), 100); |
| 334 | |
Ashlesh Gawande | a929647 | 2018-08-04 08:21:39 -0500 | [diff] [blame] | 335 | // Application should have been notified that new data is available |
| 336 | // from the hello itself. |
| 337 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 2); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 338 | |
| 339 | bool nackRcvd = false; |
| 340 | for (const auto& data : face.sentData) { |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 341 | if (data.getContentType() == tlv::ContentType_Nack) { |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 342 | nackRcvd = true; |
| 343 | break; |
| 344 | } |
| 345 | } |
| 346 | BOOST_CHECK(nackRcvd); |
| 347 | |
Ashlesh Gawande | a929647 | 2018-08-04 08:21:39 -0500 | [diff] [blame] | 348 | publishUpdateFor("testUser-4"); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 349 | advanceClocks(ndn::time::milliseconds(10)); |
Ashlesh Gawande | a929647 | 2018-08-04 08:21:39 -0500 | [diff] [blame] | 350 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 3); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 351 | } |
| 352 | |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 353 | BOOST_AUTO_TEST_CASE(SegmentedHello) |
| 354 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 355 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 356 | addConsumer(0, subscribeTo); |
| 357 | |
| 358 | addUserNodes("testUser", 400); |
| 359 | |
| 360 | consumers[0]->sendHelloInterest(); |
| 361 | advanceClocks(ndn::time::milliseconds(10)); |
| 362 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 363 | |
| 364 | // Simulate sending delayed interest for second segment |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 365 | BOOST_REQUIRE(!face.sentData.empty()); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 366 | Name dataName = face.sentData.back().getName(); |
| 367 | face.sentData.clear(); |
| 368 | BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2); |
| 369 | |
| 370 | advanceClocks(ndn::time::milliseconds(1000)); |
| 371 | BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 0); |
| 372 | |
| 373 | producer->onHelloInterest(consumers[0]->m_helloInterestPrefix, Interest(dataName)); |
| 374 | advanceClocks(ndn::time::milliseconds(10)); |
| 375 | BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2); |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 376 | BOOST_REQUIRE(!face.sentData.empty()); |
| 377 | BOOST_CHECK_EQUAL(face.sentData.front().getName().at(-1).toSegment(), 1); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | BOOST_AUTO_TEST_CASE(SegmentedSync) |
| 381 | { |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 382 | Name longNameToExceedDataSize; |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 383 | for (int i = 0; i < 100; i++) { |
| 384 | longNameToExceedDataSize.append("test-" + std::to_string(i)); |
| 385 | } |
| 386 | addUserNodes(longNameToExceedDataSize.toUri(), 10); |
| 387 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 388 | std::vector<std::string> subscribeTo; |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 389 | for (int i = 1; i < 10; i++) { |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 390 | subscribeTo.push_back(longNameToExceedDataSize.toUri() + "-" + std::to_string(i)); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 391 | } |
| 392 | addConsumer(0, subscribeTo); |
| 393 | |
| 394 | consumers[0]->sendHelloInterest(); |
| 395 | advanceClocks(ndn::time::milliseconds(10)); |
| 396 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 397 | |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 398 | // To be used later to simulate sending delayed segmented interest |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 399 | Name syncInterestName(consumers[0]->m_syncInterestPrefix); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 400 | consumers[0]->m_bloomFilter.appendToName(syncInterestName); |
| 401 | syncInterestName.append(consumers[0]->m_iblt); |
| 402 | syncInterestName.appendVersion(); |
| 403 | syncInterestName.appendSegment(1); |
| 404 | |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 405 | oldSeqMap = producer->m_prefixes; |
| 406 | for (int i = 1; i < 10; i++) { |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 407 | producer->updateSeqNo(longNameToExceedDataSize.toUri() + "-" + std::to_string(i), 1); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 408 | } |
| 409 | |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 410 | advanceClocks(ndn::time::milliseconds(999)); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 411 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 0); |
| 412 | |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 413 | advanceClocks(ndn::time::milliseconds(1)); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 414 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 415 | |
| 416 | // Simulate sending delayed interest for second segment |
| 417 | face.sentData.clear(); |
| 418 | consumerFaces[0]->sentData.clear(); |
| 419 | |
| 420 | BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2); |
| 421 | |
| 422 | advanceClocks(ndn::time::milliseconds(2000)); |
| 423 | BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 0); |
| 424 | |
| 425 | producer->onSyncInterest(consumers[0]->m_syncInterestPrefix, Interest(syncInterestName)); |
| 426 | advanceClocks(ndn::time::milliseconds(10)); |
| 427 | BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2); |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 428 | BOOST_REQUIRE(!face.sentData.empty()); |
| 429 | BOOST_CHECK_EQUAL(face.sentData.front().getName().at(-1).toSegment(), 1); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 430 | } |
| 431 | |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 432 | BOOST_AUTO_TEST_CASE(DelayedSubscription) // #5122 |
| 433 | { |
| 434 | publishUpdateFor("testUser-2"); |
| 435 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4"}; |
| 436 | addConsumer(0, subscribeTo); |
| 437 | |
| 438 | consumers[0]->sendHelloInterest(); |
| 439 | advanceClocks(ndn::time::milliseconds(10)); |
| 440 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 441 | |
| 442 | // Application came up late and subscribed to testUser-2 |
| 443 | // after Producer had already published the first update. |
| 444 | // So by default Consumer will let the application know that |
| 445 | // the prefix it subscribed to has already some updates |
| 446 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 447 | } |
| 448 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 449 | BOOST_AUTO_TEST_SUITE_END() |
| 450 | |
Ashlesh Gawande | 6a5157f | 2019-12-09 11:49:07 -0600 | [diff] [blame] | 451 | } // namespace psync |