blob: 42c3717099782381ea3e0215fe3e4c6dbefa3200 [file] [log] [blame]
Yanbiao Li8ee37ed2015-05-19 12:44:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yanbiao Li4b4f7542016-03-11 02:04:43 +08003 * Copyright (c) 2013-2016 Regents of the University of California.
Yanbiao Li8ee37ed2015-05-19 12:44:04 -07004 *
Alexander Afanasyev80b68e12015-09-17 17:01:04 -07005 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Yanbiao Li8ee37ed2015-05-19 12:44:04 -07006 *
Alexander Afanasyev80b68e12015-09-17 17:01:04 -07007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070010 *
Alexander Afanasyev80b68e12015-09-17 17:01:04 -070011 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070014 *
Alexander Afanasyev80b68e12015-09-17 17:01:04 -070015 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070020 */
21
22#include "mgmt/dispatcher.hpp"
23#include "management/nfd-control-parameters.hpp"
24#include "util/dummy-client-face.hpp"
25
26#include "boost-test.hpp"
27#include "identity-management-fixture.hpp"
28#include "unit-tests/unit-test-time-fixture.hpp"
29#include "unit-tests/make-interest-data.hpp"
30
31namespace ndn {
32namespace mgmt {
33namespace tests {
34
35using namespace ndn::tests;
36
Junxiao Shif65a3362015-09-06 20:54:54 -070037BOOST_AUTO_TEST_SUITE(Mgmt)
38BOOST_AUTO_TEST_SUITE(TestDispatcher)
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070039
40class DispatcherFixture : public UnitTestTimeFixture
41 , public security::IdentityManagementFixture
42{
43public:
44 DispatcherFixture()
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080045 : face(io, {true, true})
46 , dispatcher(face, m_keyChain, security::SigningInfo())
Yanbiao Li4b4f7542016-03-11 02:04:43 +080047 , storage(dispatcher.m_storage)
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070048 {
49 }
50
51public:
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080052 util::DummyClientFace face;
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070053 mgmt::Dispatcher dispatcher;
Yanbiao Li4b4f7542016-03-11 02:04:43 +080054 util::InMemoryStorageFifo& storage;
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070055};
56
57class VoidParameters : public mgmt::ControlParameters
58{
59public:
60 explicit
61 VoidParameters(const Block& wire)
62 {
63 wireDecode(wire);
64 }
65
66 virtual Block
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020067 wireEncode() const final
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070068 {
69 return Block(128);
70 }
71
72 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020073 wireDecode(const Block& wire) final
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070074 {
75 if (wire.type() != 128)
76 throw tlv::Error("Expecting TLV type 128");
77 }
78};
79
80static Authorization
81makeTestAuthorization()
82{
83 return [] (const Name& prefix,
84 const Interest& interest,
85 const ControlParameters* params,
86 AcceptContinuation accept,
87 RejectContinuation reject) {
88 if (interest.getName()[-1] == name::Component("valid")) {
89 accept("");
90 }
91 else {
92 if (interest.getName()[-1] == name::Component("silent")) {
93 reject(RejectReply::SILENT);
94 }
95 else {
96 reject(RejectReply::STATUS403);
97 }
98 }
99 };
100}
101
102BOOST_FIXTURE_TEST_CASE(BasicUsageSemantics, DispatcherFixture)
103{
104 BOOST_CHECK_NO_THROW(dispatcher
105 .addControlCommand<VoidParameters>("test/1", makeAcceptAllAuthorization(),
106 bind([] { return true; }),
107 bind([]{})));
108 BOOST_CHECK_NO_THROW(dispatcher
109 .addControlCommand<VoidParameters>("test/2", makeAcceptAllAuthorization(),
110 bind([] { return true; }),
111 bind([]{})));
112
113 BOOST_CHECK_THROW(dispatcher
114 .addControlCommand<VoidParameters>("test", makeAcceptAllAuthorization(),
115 bind([] { return true; }),
116 bind([]{})),
117 std::out_of_range);
118
119 BOOST_CHECK_NO_THROW(dispatcher.addStatusDataset("status/1",
120 makeAcceptAllAuthorization(), bind([]{})));
121 BOOST_CHECK_NO_THROW(dispatcher.addStatusDataset("status/2",
122 makeAcceptAllAuthorization(), bind([]{})));
123 BOOST_CHECK_THROW(dispatcher.addStatusDataset("status",
124 makeAcceptAllAuthorization(), bind([]{})),
125 std::out_of_range);
126
127 BOOST_CHECK_NO_THROW(dispatcher.addNotificationStream("stream/1"));
128 BOOST_CHECK_NO_THROW(dispatcher.addNotificationStream("stream/2"));
129 BOOST_CHECK_THROW(dispatcher.addNotificationStream("stream"), std::out_of_range);
130
131
132 BOOST_CHECK_NO_THROW(dispatcher.addTopPrefix("/root/1"));
133 BOOST_CHECK_NO_THROW(dispatcher.addTopPrefix("/root/2"));
134 BOOST_CHECK_THROW(dispatcher.addTopPrefix("/root"), std::out_of_range);
135
136 BOOST_CHECK_THROW(dispatcher
137 .addControlCommand<VoidParameters>("test/3", makeAcceptAllAuthorization(),
138 bind([] { return true; }),
139 bind([]{})),
140 std::domain_error);
141
142 BOOST_CHECK_THROW(dispatcher.addStatusDataset("status/3",
143 makeAcceptAllAuthorization(), bind([]{})),
144 std::domain_error);
145
146 BOOST_CHECK_THROW(dispatcher.addNotificationStream("stream/3"), std::domain_error);
147}
148
149BOOST_FIXTURE_TEST_CASE(AddRemoveTopPrefix, DispatcherFixture)
150{
151 std::map<std::string, size_t> nCallbackCalled;
152 dispatcher
153 .addControlCommand<VoidParameters>("test/1", makeAcceptAllAuthorization(),
154 bind([] { return true; }),
155 bind([&nCallbackCalled] { ++nCallbackCalled["test/1"]; }));
156
157 dispatcher
158 .addControlCommand<VoidParameters>("test/2", makeAcceptAllAuthorization(),
159 bind([] { return true; }),
160 bind([&nCallbackCalled] { ++nCallbackCalled["test/2"]; }));
161
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800162 face.receive(*util::makeInterest("/root/1/test/1/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700163 advanceClocks(time::milliseconds(1));
164 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 0);
165 BOOST_CHECK_EQUAL(nCallbackCalled["test/2"], 0);
166
167 dispatcher.addTopPrefix("/root/1");
168 advanceClocks(time::milliseconds(1));
169
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800170 face.receive(*util::makeInterest("/root/1/test/1/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700171 advanceClocks(time::milliseconds(1));
172 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 1);
173 BOOST_CHECK_EQUAL(nCallbackCalled["test/2"], 0);
174
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800175 face.receive(*util::makeInterest("/root/1/test/2/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700176 advanceClocks(time::milliseconds(1));
177 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 1);
178 BOOST_CHECK_EQUAL(nCallbackCalled["test/2"], 1);
179
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800180 face.receive(*util::makeInterest("/root/2/test/1/%80%00"));
181 face.receive(*util::makeInterest("/root/2/test/2/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700182 advanceClocks(time::milliseconds(1));
183 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 1);
184 BOOST_CHECK_EQUAL(nCallbackCalled["test/2"], 1);
185
186 dispatcher.addTopPrefix("/root/2");
187 advanceClocks(time::milliseconds(1));
188
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800189 face.receive(*util::makeInterest("/root/1/test/1/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700190 advanceClocks(time::milliseconds(1));
191 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 2);
192
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800193 face.receive(*util::makeInterest("/root/2/test/1/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700194 advanceClocks(time::milliseconds(1));
195 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 3);
196
197 dispatcher.removeTopPrefix("/root/1");
198 advanceClocks(time::milliseconds(1));
199
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800200 face.receive(*util::makeInterest("/root/1/test/1/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700201 advanceClocks(time::milliseconds(1));
202 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 3);
203
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800204 face.receive(*util::makeInterest("/root/2/test/1/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700205 advanceClocks(time::milliseconds(1));
206 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 4);
207}
208
209BOOST_FIXTURE_TEST_CASE(ControlCommand, DispatcherFixture)
210{
211 size_t nCallbackCalled = 0;
212 dispatcher
213 .addControlCommand<VoidParameters>("test",
214 makeTestAuthorization(),
215 bind([] { return true; }),
216 bind([&nCallbackCalled] { ++nCallbackCalled; }));
217
218 dispatcher.addTopPrefix("/root");
219 advanceClocks(time::milliseconds(1));
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800220 face.sentData.clear();
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700221
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800222 face.receive(*util::makeInterest("/root/test/%80%00")); // returns 403
223 face.receive(*util::makeInterest("/root/test/%80%00/invalid")); // returns 403
224 face.receive(*util::makeInterest("/root/test/%80%00/silent")); // silently ignored
225 face.receive(*util::makeInterest("/root/test/.../invalid")); // silently ignored (wrong format)
226 face.receive(*util::makeInterest("/root/test/.../valid")); // silently ignored (wrong format)
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700227 advanceClocks(time::milliseconds(1), 20);
228 BOOST_CHECK_EQUAL(nCallbackCalled, 0);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800229 BOOST_CHECK_EQUAL(face.sentData.size(), 2);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700230
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800231 BOOST_CHECK(face.sentData[0].getContentType() == tlv::ContentType_Blob);
232 BOOST_CHECK_EQUAL(ControlResponse(face.sentData[0].getContent().blockFromValue()).getCode(), 403);
233 BOOST_CHECK(face.sentData[1].getContentType() == tlv::ContentType_Blob);
234 BOOST_CHECK_EQUAL(ControlResponse(face.sentData[1].getContent().blockFromValue()).getCode(), 403);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700235
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800236 face.receive(*util::makeInterest("/root/test/%80%00/valid"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700237 advanceClocks(time::milliseconds(1), 10);
238 BOOST_CHECK_EQUAL(nCallbackCalled, 1);
239}
240
241BOOST_FIXTURE_TEST_CASE(StatusDataset, DispatcherFixture)
242{
243 static Block smallBlock("\x81\x01\0x01", 3);
244 static Block largeBlock = [] () -> Block {
245 EncodingBuffer encoder;
246 for (size_t i = 0; i < 2500; ++i) {
247 encoder.prependByte(1);
248 }
249 encoder.prependVarNumber(2500);
250 encoder.prependVarNumber(129);
251 return encoder.block();
252 }();
253
254 dispatcher.addStatusDataset("test/small",
255 makeTestAuthorization(),
256 [] (const Name& prefix, const Interest& interest,
Junxiao Shif65a3362015-09-06 20:54:54 -0700257 StatusDatasetContext& context) {
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700258 context.append(smallBlock);
259 context.append(smallBlock);
260 context.append(smallBlock);
261 context.end();
262 });
263
264 dispatcher.addStatusDataset("test/large",
265 makeTestAuthorization(),
266 [] (const Name& prefix, const Interest& interest,
Junxiao Shif65a3362015-09-06 20:54:54 -0700267 StatusDatasetContext& context) {
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700268 context.append(largeBlock);
269 context.append(largeBlock);
270 context.append(largeBlock);
271 context.end();
272 });
273
274 dispatcher.addStatusDataset("test/reject",
275 makeTestAuthorization(),
276 [] (const Name& prefix, const Interest& interest,
Junxiao Shif65a3362015-09-06 20:54:54 -0700277 StatusDatasetContext& context) {
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700278 context.reject();
279 });
280
281 dispatcher.addTopPrefix("/root");
282 advanceClocks(time::milliseconds(1));
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800283 face.sentData.clear();
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700284
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800285 face.receive(*util::makeInterest("/root/test/small/%80%00")); // returns 403
286 face.receive(*util::makeInterest("/root/test/small/%80%00/invalid")); // returns 403
287 face.receive(*util::makeInterest("/root/test/small/%80%00/silent")); // silently ignored
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700288 advanceClocks(time::milliseconds(1), 20);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800289 BOOST_CHECK_EQUAL(face.sentData.size(), 2);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700290
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800291 BOOST_CHECK(face.sentData[0].getContentType() == tlv::ContentType_Blob);
292 BOOST_CHECK_EQUAL(ControlResponse(face.sentData[0].getContent().blockFromValue()).getCode(), 403);
293 BOOST_CHECK(face.sentData[1].getContentType() == tlv::ContentType_Blob);
294 BOOST_CHECK_EQUAL(ControlResponse(face.sentData[1].getContent().blockFromValue()).getCode(), 403);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700295
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800296 face.sentData.clear();
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800297
298 auto interestSmall = *util::makeInterest("/root/test/small/valid");
299 face.receive(interestSmall);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700300 advanceClocks(time::milliseconds(1), 10);
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800301
302 // one data packet is generated and sent to both places
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800303 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800304 BOOST_CHECK_EQUAL(storage.size(), 1);
305
306 auto fetchedData = storage.find(interestSmall);
307 BOOST_REQUIRE(fetchedData != nullptr);
308 BOOST_CHECK(face.sentData[0].wireEncode() == fetchedData->wireEncode());
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700309
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800310 face.receive(*util::makeInterest(Name("/root/test/small/valid").appendVersion(10))); // should be ignored
311 face.receive(*util::makeInterest(Name("/root/test/small/valid").appendSegment(20))); // should be ignored
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700312 advanceClocks(time::milliseconds(1), 10);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800313 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800314 BOOST_CHECK_EQUAL(storage.size(), 1);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700315
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800316 Block content = face.sentData[0].getContent();
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700317 BOOST_CHECK_NO_THROW(content.parse());
318
319 BOOST_CHECK_EQUAL(content.elements().size(), 3);
320 BOOST_CHECK(content.elements()[0] == smallBlock);
321 BOOST_CHECK(content.elements()[1] == smallBlock);
322 BOOST_CHECK(content.elements()[2] == smallBlock);
323
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800324 storage.erase("/", true); // clear the storage
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800325 face.sentData.clear();
326 face.receive(*util::makeInterest("/root/test/large/valid"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700327 advanceClocks(time::milliseconds(1), 10);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700328
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800329 // two data packets are generated, the first one will be sent to both places
330 // while the second one will only be inserted into the in-memory storage
331 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
332 BOOST_CHECK_EQUAL(storage.size(), 2);
333
334 // segment0 should be sent through the face
335 const auto& component = face.sentData[0].getName().at(-1);
336 BOOST_CHECK(component.isSegment());
337 BOOST_CHECK_EQUAL(component.toSegment(), 0);
338
339 std::vector<Data> dataInStorage;
340 std::copy(storage.begin(), storage.end(), std::back_inserter(dataInStorage));
341
342 // the Data sent through the face should be the same as the first Data in the storage
343 BOOST_CHECK_EQUAL(face.sentData[0].getName(), dataInStorage[0].getName());
344 BOOST_CHECK(face.sentData[0].getContent() == dataInStorage[0].getContent());
345
346 content = [&dataInStorage] () -> Block {
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700347 EncodingBuffer encoder;
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800348 size_t valueLength = encoder.prependByteArray(dataInStorage[1].getContent().value(),
349 dataInStorage[1].getContent().value_size());
350 valueLength += encoder.prependByteArray(dataInStorage[0].getContent().value(),
351 dataInStorage[0].getContent().value_size());
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700352 encoder.prependVarNumber(valueLength);
353 encoder.prependVarNumber(tlv::Content);
354 return encoder.block();
355 }();
356
357 BOOST_CHECK_NO_THROW(content.parse());
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700358 BOOST_CHECK_EQUAL(content.elements().size(), 3);
359 BOOST_CHECK(content.elements()[0] == largeBlock);
360 BOOST_CHECK(content.elements()[1] == largeBlock);
361 BOOST_CHECK(content.elements()[2] == largeBlock);
362
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800363 storage.erase("/", true);// clear the storage
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800364 face.sentData.clear();
365 face.receive(*util::makeInterest("/root/test/reject/%80%00/valid")); // returns nack
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700366 advanceClocks(time::milliseconds(1));
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800367 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
368 BOOST_CHECK(face.sentData[0].getContentType() == tlv::ContentType_Nack);
369 BOOST_CHECK_EQUAL(ControlResponse(face.sentData[0].getContent().blockFromValue()).getCode(), 400);
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800370 BOOST_CHECK_EQUAL(storage.size(), 0); // the nack packet will not be inserted into the in-memory storage
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700371}
372
373BOOST_FIXTURE_TEST_CASE(NotificationStream, DispatcherFixture)
374{
375 static Block block("\x82\x01\x02", 3);
376
377 auto post = dispatcher.addNotificationStream("test");
378
379 post(block);
380 advanceClocks(time::milliseconds(1));
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800381 BOOST_CHECK_EQUAL(face.sentData.size(), 0);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700382
383 dispatcher.addTopPrefix("/root");
384 advanceClocks(time::milliseconds(1));
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800385 face.sentData.clear();
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700386
387 post(block);
388 advanceClocks(time::milliseconds(1));
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800389 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800390 BOOST_CHECK_EQUAL(storage.size(), 1);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700391
392 post(block);
393 post(block);
394 post(block);
395 advanceClocks(time::milliseconds(1), 10);
396
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800397 BOOST_CHECK_EQUAL(face.sentData.size(), 4);
398 BOOST_CHECK_EQUAL(face.sentData[0].getName(), "/root/test/%FE%00");
399 BOOST_CHECK_EQUAL(face.sentData[1].getName(), "/root/test/%FE%01");
400 BOOST_CHECK_EQUAL(face.sentData[2].getName(), "/root/test/%FE%02");
401 BOOST_CHECK_EQUAL(face.sentData[3].getName(), "/root/test/%FE%03");
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700402
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800403 BOOST_CHECK(face.sentData[0].getContent().blockFromValue() == block);
404 BOOST_CHECK(face.sentData[1].getContent().blockFromValue() == block);
405 BOOST_CHECK(face.sentData[2].getContent().blockFromValue() == block);
406 BOOST_CHECK(face.sentData[3].getContent().blockFromValue() == block);
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800407
408 // each version of notification will be sent to both places
409 std::vector<Data> dataInStorage;
410 std::copy(storage.begin(), storage.end(), std::back_inserter(dataInStorage));
411 BOOST_CHECK_EQUAL(dataInStorage.size(), 4);
412 BOOST_CHECK_EQUAL(dataInStorage[0].getName(), "/root/test/%FE%00");
413 BOOST_CHECK_EQUAL(dataInStorage[1].getName(), "/root/test/%FE%01");
414 BOOST_CHECK_EQUAL(dataInStorage[2].getName(), "/root/test/%FE%02");
415 BOOST_CHECK_EQUAL(dataInStorage[3].getName(), "/root/test/%FE%03");
416
417 BOOST_CHECK(dataInStorage[0].getContent().blockFromValue() == block);
418 BOOST_CHECK(dataInStorage[1].getContent().blockFromValue() == block);
419 BOOST_CHECK(dataInStorage[2].getContent().blockFromValue() == block);
420 BOOST_CHECK(dataInStorage[3].getContent().blockFromValue() == block);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700421}
422
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800423BOOST_AUTO_TEST_SUITE_END() // TestDispatcher
424BOOST_AUTO_TEST_SUITE_END() // Mgmt
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700425
426} // namespace tests
427} // namespace mgmt
428} // namespace ndn