blob: 62353108b2308b43592277b120102de3cfc32f91 [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Ashlesh Gawande6a5157f2019-12-09 11:49:07 -06003 * Copyright (c) 2014-2020, The University of Memphis
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05004 *
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 Gawande0cf4b602019-01-18 15:58:17 -06009 * of the GNU Lesser General Public License as published by the Free Software Foundation,
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050010 * 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 Gawande0cf4b602019-01-18 15:58:17 -060014 * PURPOSE. See the GNU Lesser General Public License for more details.
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050015 *
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -060016 * You should have received a copy of the GNU Lesser General Public License along with
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050017 * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Ashlesh Gawande8ab75722020-08-02 22:42:28 -070018 */
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050019
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060020#include "PSync/partial-producer.hpp"
21#include "PSync/consumer.hpp"
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050022
Davide Pesavento5b3cf762020-04-03 16:20:04 -040023#include "tests/boost-test.hpp"
Davide Pesaventof91d1df2020-11-25 14:50:41 -050024#include "tests/io-fixture.hpp"
Davide Pesavento5b3cf762020-04-03 16:20:04 -040025
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050026#include <ndn-cxx/name.hpp>
27#include <ndn-cxx/util/dummy-client-face.hpp>
28
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050029namespace psync {
30
31using namespace ndn;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050032
Davide Pesaventof91d1df2020-11-25 14:50:41 -050033class PartialSyncFixture : public tests::IoFixture
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050034{
35public:
36 PartialSyncFixture()
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050037 {
38 producer = make_shared<PartialProducer>(40, face, syncPrefix, userPrefix);
39 addUserNodes("testUser", 10);
40 }
41
Davide Pesaventof91d1df2020-11-25 14:50:41 -050042 ~PartialSyncFixture() override
Ashlesh Gawandeec43b362018-08-01 15:15:01 -050043 {
Davide Pesaventof91d1df2020-11-25 14:50:41 -050044 for (const auto& consumer : consumers) {
Ashlesh Gawandeec43b362018-08-01 15:15:01 -050045 if (consumer) {
46 consumer->stop();
47 }
48 }
49 }
50
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050051 void
Davide Pesavento5b3cf762020-04-03 16:20:04 -040052 addConsumer(int id, const std::vector<std::string>& subscribeTo, bool linkToProducer = true)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050053 {
Davide Pesaventof91d1df2020-11-25 14:50:41 -050054 consumerFaces[id] =
55 std::make_shared<util::DummyClientFace>(m_io, util::DummyClientFace::Options{true, true});
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050056
Ashlesh Gawandeec43b362018-08-01 15:15:01 -050057 if (linkToProducer) {
58 face.linkTo(*consumerFaces[id]);
59 }
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050060
Davide Pesavento5b3cf762020-04-03 16:20:04 -040061 consumers[id] = std::make_shared<Consumer>(syncPrefix, *consumerFaces[id],
Davide Pesaventof91d1df2020-11-25 14:50:41 -050062 [&, id] (const auto& availableSubs) {
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050063 numHelloDataRcvd++;
Ashlesh Gawandedeb73f82018-08-09 11:08:02 -050064 BOOST_CHECK(checkSubList(availableSubs));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050065
66 checkIBFUpdated(id);
67
68 for (const auto& sub : subscribeTo) {
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -070069 auto it = availableSubs.find(sub);
70 consumers[id]->addSubscription(sub, it->second);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050071 }
72 consumers[id]->sendSyncInterest();
73 },
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -070074 [&, id] (const auto& updates) {
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050075 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 Gawandecbdc0122020-07-13 21:13:00 -070099 checkSubList(const std::map<Name, uint64_t>& availableSubs) const
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500100 {
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400101 for (const auto& prefix : producer->m_prefixes) {
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -0700102 auto it = availableSubs.find(prefix.first);
103 if (it == availableSubs.end()) {
Ashlesh Gawandedeb73f82018-08-09 11:08:02 -0500104 return false;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500105 }
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++) {
115 producer->addUserNode(prefix + "-" + to_string(i));
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 Pesaventof91d1df2020-11-25 14:50:41 -0500134 util::DummyClientFace face{m_io, {true, true}};
135 Name syncPrefix{"psync"};
136 Name userPrefix{"testUser-0"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500137
138 shared_ptr<PartialProducer> producer;
Davide Pesaventof91d1df2020-11-25 14:50:41 -0500139 std::map<Name, uint64_t> oldSeqMap;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500140
141 shared_ptr<Consumer> consumers[3];
142 shared_ptr<util::DummyClientFace> consumerFaces[3];
Davide Pesaventof91d1df2020-11-25 14:50:41 -0500143 int numHelloDataRcvd = 0;
144 int numSyncDataRcvd = 0;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500145};
146
Ashlesh Gawande6a5157f2019-12-09 11:49:07 -0600147BOOST_FIXTURE_TEST_SUITE(TestPartialSync, PartialSyncFixture)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500148
149BOOST_AUTO_TEST_CASE(Simple)
150{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400151 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500152 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
166BOOST_AUTO_TEST_CASE(MissedUpdate)
167{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400168 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500169 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 Gawande8ab75722020-08-02 22:42:28 -0700179 advanceClocks(ndn::time::milliseconds(999));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500180 BOOST_CHECK_EQUAL(numSyncDataRcvd, 0);
181
182 // Next sync interest will bring back the sync data
Ashlesh Gawande8ab75722020-08-02 22:42:28 -0700183 advanceClocks(ndn::time::milliseconds(1));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500184 BOOST_CHECK_EQUAL(numSyncDataRcvd, 1);
185}
186
187BOOST_AUTO_TEST_CASE(LateSubscription)
188{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400189 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500190 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 Gawandecbdc0122020-07-13 21:13:00 -0700199 consumers[0]->addSubscription("testUser-3", 0);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500200 consumers[0]->sendSyncInterest();
201 publishUpdateFor("testUser-3");
202 BOOST_CHECK_EQUAL(numSyncDataRcvd, 2);
203}
204
205BOOST_AUTO_TEST_CASE(ConsumerSyncTimeout)
206{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400207 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500208 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 Gawande8ab75722020-08-02 22:42:28 -0700215 // The next Interest is sent after the first one immediately
216 BOOST_CHECK_EQUAL(producer->m_pendingEntries.size(), 1);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500217 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 Gawande8ab75722020-08-02 22:42:28 -0700225 BOOST_CHECK_EQUAL(numSyncInterests, 3);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500226 BOOST_CHECK_EQUAL(numSyncDataRcvd, 0);
227}
228
229BOOST_AUTO_TEST_CASE(MultipleConsumersWithSameSubList)
230{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400231 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500232 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
250BOOST_AUTO_TEST_CASE(MultipleConsumersWithDifferentSubList)
251{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400252 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500253 addConsumer(0, subscribeTo);
254
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400255 std::vector<std::string> subscribeTo1{"testUser-1", "testUser-3", "testUser-5"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500256 addConsumer(1, subscribeTo1);
257
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400258 std::vector<std::string> subscribeTo2{"testUser-2", "testUser-3"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500259 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
276BOOST_AUTO_TEST_CASE(ReplicatedProducer)
277{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400278 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500279 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 Pesaventof91d1df2020-11-25 14:50:41 -0500291 util::DummyClientFace face2(m_io, {true, true});
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500292 PartialProducer replicatedProducer(40, face2, syncPrefix, userPrefix);
293 for (int i = 1; i < 10; i++) {
294 replicatedProducer.addUserNode("testUser-" + to_string(i));
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
312BOOST_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 Pesavento5b3cf762020-04-03 16:20:04 -0400317 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500318 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 Pesaventof91d1df2020-11-25 14:50:41 -0500329 Name prefix("testUser-" + to_string(i));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500330 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 Gawandea9296472018-08-04 08:21:39 -0500335 // Application should have been notified that new data is available
336 // from the hello itself.
337 BOOST_CHECK_EQUAL(numSyncDataRcvd, 2);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500338
339 bool nackRcvd = false;
340 for (const auto& data : face.sentData) {
Davide Pesaventof91d1df2020-11-25 14:50:41 -0500341 if (data.getContentType() == tlv::ContentType_Nack) {
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500342 nackRcvd = true;
343 break;
344 }
345 }
346 BOOST_CHECK(nackRcvd);
347
Ashlesh Gawandea9296472018-08-04 08:21:39 -0500348 publishUpdateFor("testUser-4");
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500349 advanceClocks(ndn::time::milliseconds(10));
Ashlesh Gawandea9296472018-08-04 08:21:39 -0500350 BOOST_CHECK_EQUAL(numSyncDataRcvd, 3);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500351}
352
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500353BOOST_AUTO_TEST_CASE(SegmentedHello)
354{
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400355 std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"};
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500356 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 Gawande2e82df12018-12-08 21:42:29 -0600363
364 // Simulate sending delayed interest for second segment
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400365 BOOST_REQUIRE(!face.sentData.empty());
Ashlesh Gawande2e82df12018-12-08 21:42:29 -0600366 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 Pesavento5b3cf762020-04-03 16:20:04 -0400376 BOOST_REQUIRE(!face.sentData.empty());
377 BOOST_CHECK_EQUAL(face.sentData.front().getName().at(-1).toSegment(), 1);
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500378}
379
380BOOST_AUTO_TEST_CASE(SegmentedSync)
381{
Davide Pesaventof91d1df2020-11-25 14:50:41 -0500382 Name longNameToExceedDataSize;
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500383 for (int i = 0; i < 100; i++) {
384 longNameToExceedDataSize.append("test-" + std::to_string(i));
385 }
386 addUserNodes(longNameToExceedDataSize.toUri(), 10);
387
Davide Pesavento5b3cf762020-04-03 16:20:04 -0400388 std::vector<std::string> subscribeTo;
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500389 for (int i = 1; i < 10; i++) {
390 subscribeTo.push_back(longNameToExceedDataSize.toUri() + "-" + to_string(i));
391 }
392 addConsumer(0, subscribeTo);
393
394 consumers[0]->sendHelloInterest();
395 advanceClocks(ndn::time::milliseconds(10));
396 BOOST_CHECK_EQUAL(numHelloDataRcvd, 1);
397
Ashlesh Gawande2e82df12018-12-08 21:42:29 -0600398 // To be used later to simulate sending delayed segmented interest
Davide Pesaventof91d1df2020-11-25 14:50:41 -0500399 Name syncInterestName(consumers[0]->m_syncInterestPrefix);
Ashlesh Gawande2e82df12018-12-08 21:42:29 -0600400 consumers[0]->m_bloomFilter.appendToName(syncInterestName);
401 syncInterestName.append(consumers[0]->m_iblt);
402 syncInterestName.appendVersion();
403 syncInterestName.appendSegment(1);
404
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500405 oldSeqMap = producer->m_prefixes;
406 for (int i = 1; i < 10; i++) {
407 producer->updateSeqNo(longNameToExceedDataSize.toUri() + "-" + to_string(i), 1);
408 }
409
Ashlesh Gawande8ab75722020-08-02 22:42:28 -0700410 advanceClocks(ndn::time::milliseconds(999));
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500411 BOOST_CHECK_EQUAL(numSyncDataRcvd, 0);
412
Ashlesh Gawande8ab75722020-08-02 22:42:28 -0700413 advanceClocks(ndn::time::milliseconds(1));
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500414 BOOST_CHECK_EQUAL(numSyncDataRcvd, 1);
Ashlesh Gawande2e82df12018-12-08 21:42:29 -0600415
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 Pesavento5b3cf762020-04-03 16:20:04 -0400428 BOOST_REQUIRE(!face.sentData.empty());
429 BOOST_CHECK_EQUAL(face.sentData.front().getName().at(-1).toSegment(), 1);
Ashlesh Gawandeec43b362018-08-01 15:15:01 -0500430}
431
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -0700432BOOST_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 Gawande0b2897e2018-06-20 14:40:47 -0500449BOOST_AUTO_TEST_SUITE_END()
450
Ashlesh Gawande6a5157f2019-12-09 11:49:07 -0600451} // namespace psync