blob: d7e4efcccd12dedeca7e3dc89b53932dd41ecdc2 [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"
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070028#include "../identity-management-time-fixture.hpp"
29#include "../make-interest-data.hpp"
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070030
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
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070040class DispatcherFixture : public IdentityManagementTimeFixture
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070041{
42public:
43 DispatcherFixture()
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070044 : face(io, m_keyChain, {true, true})
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080045 , dispatcher(face, m_keyChain, security::SigningInfo())
Yanbiao Li4b4f7542016-03-11 02:04:43 +080046 , storage(dispatcher.m_storage)
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070047 {
48 }
49
50public:
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080051 util::DummyClientFace face;
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070052 mgmt::Dispatcher dispatcher;
Yanbiao Li4b4f7542016-03-11 02:04:43 +080053 util::InMemoryStorageFifo& storage;
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070054};
55
56class VoidParameters : public mgmt::ControlParameters
57{
58public:
59 explicit
60 VoidParameters(const Block& wire)
61 {
62 wireDecode(wire);
63 }
64
65 virtual Block
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020066 wireEncode() const final
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070067 {
68 return Block(128);
69 }
70
71 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020072 wireDecode(const Block& wire) final
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070073 {
74 if (wire.type() != 128)
75 throw tlv::Error("Expecting TLV type 128");
76 }
77};
78
79static Authorization
80makeTestAuthorization()
81{
82 return [] (const Name& prefix,
83 const Interest& interest,
84 const ControlParameters* params,
85 AcceptContinuation accept,
86 RejectContinuation reject) {
87 if (interest.getName()[-1] == name::Component("valid")) {
88 accept("");
89 }
90 else {
91 if (interest.getName()[-1] == name::Component("silent")) {
92 reject(RejectReply::SILENT);
93 }
94 else {
95 reject(RejectReply::STATUS403);
96 }
97 }
98 };
99}
100
101BOOST_FIXTURE_TEST_CASE(BasicUsageSemantics, DispatcherFixture)
102{
103 BOOST_CHECK_NO_THROW(dispatcher
104 .addControlCommand<VoidParameters>("test/1", makeAcceptAllAuthorization(),
105 bind([] { return true; }),
106 bind([]{})));
107 BOOST_CHECK_NO_THROW(dispatcher
108 .addControlCommand<VoidParameters>("test/2", makeAcceptAllAuthorization(),
109 bind([] { return true; }),
110 bind([]{})));
111
112 BOOST_CHECK_THROW(dispatcher
113 .addControlCommand<VoidParameters>("test", makeAcceptAllAuthorization(),
114 bind([] { return true; }),
115 bind([]{})),
116 std::out_of_range);
117
118 BOOST_CHECK_NO_THROW(dispatcher.addStatusDataset("status/1",
119 makeAcceptAllAuthorization(), bind([]{})));
120 BOOST_CHECK_NO_THROW(dispatcher.addStatusDataset("status/2",
121 makeAcceptAllAuthorization(), bind([]{})));
122 BOOST_CHECK_THROW(dispatcher.addStatusDataset("status",
123 makeAcceptAllAuthorization(), bind([]{})),
124 std::out_of_range);
125
126 BOOST_CHECK_NO_THROW(dispatcher.addNotificationStream("stream/1"));
127 BOOST_CHECK_NO_THROW(dispatcher.addNotificationStream("stream/2"));
128 BOOST_CHECK_THROW(dispatcher.addNotificationStream("stream"), std::out_of_range);
129
130
131 BOOST_CHECK_NO_THROW(dispatcher.addTopPrefix("/root/1"));
132 BOOST_CHECK_NO_THROW(dispatcher.addTopPrefix("/root/2"));
133 BOOST_CHECK_THROW(dispatcher.addTopPrefix("/root"), std::out_of_range);
134
135 BOOST_CHECK_THROW(dispatcher
136 .addControlCommand<VoidParameters>("test/3", makeAcceptAllAuthorization(),
137 bind([] { return true; }),
138 bind([]{})),
139 std::domain_error);
140
141 BOOST_CHECK_THROW(dispatcher.addStatusDataset("status/3",
142 makeAcceptAllAuthorization(), bind([]{})),
143 std::domain_error);
144
145 BOOST_CHECK_THROW(dispatcher.addNotificationStream("stream/3"), std::domain_error);
146}
147
148BOOST_FIXTURE_TEST_CASE(AddRemoveTopPrefix, DispatcherFixture)
149{
150 std::map<std::string, size_t> nCallbackCalled;
151 dispatcher
152 .addControlCommand<VoidParameters>("test/1", makeAcceptAllAuthorization(),
153 bind([] { return true; }),
154 bind([&nCallbackCalled] { ++nCallbackCalled["test/1"]; }));
155
156 dispatcher
157 .addControlCommand<VoidParameters>("test/2", makeAcceptAllAuthorization(),
158 bind([] { return true; }),
159 bind([&nCallbackCalled] { ++nCallbackCalled["test/2"]; }));
160
Junxiao Shi85d90832016-08-04 03:19:46 +0000161 face.receive(*makeInterest("/root/1/test/1/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700162 advanceClocks(time::milliseconds(1));
163 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 0);
164 BOOST_CHECK_EQUAL(nCallbackCalled["test/2"], 0);
165
166 dispatcher.addTopPrefix("/root/1");
167 advanceClocks(time::milliseconds(1));
168
Junxiao Shi85d90832016-08-04 03:19:46 +0000169 face.receive(*makeInterest("/root/1/test/1/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700170 advanceClocks(time::milliseconds(1));
171 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 1);
172 BOOST_CHECK_EQUAL(nCallbackCalled["test/2"], 0);
173
Junxiao Shi85d90832016-08-04 03:19:46 +0000174 face.receive(*makeInterest("/root/1/test/2/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700175 advanceClocks(time::milliseconds(1));
176 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 1);
177 BOOST_CHECK_EQUAL(nCallbackCalled["test/2"], 1);
178
Junxiao Shi85d90832016-08-04 03:19:46 +0000179 face.receive(*makeInterest("/root/2/test/1/%80%00"));
180 face.receive(*makeInterest("/root/2/test/2/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700181 advanceClocks(time::milliseconds(1));
182 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 1);
183 BOOST_CHECK_EQUAL(nCallbackCalled["test/2"], 1);
184
185 dispatcher.addTopPrefix("/root/2");
186 advanceClocks(time::milliseconds(1));
187
Junxiao Shi85d90832016-08-04 03:19:46 +0000188 face.receive(*makeInterest("/root/1/test/1/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700189 advanceClocks(time::milliseconds(1));
190 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 2);
191
Junxiao Shi85d90832016-08-04 03:19:46 +0000192 face.receive(*makeInterest("/root/2/test/1/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700193 advanceClocks(time::milliseconds(1));
194 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 3);
195
196 dispatcher.removeTopPrefix("/root/1");
197 advanceClocks(time::milliseconds(1));
198
Junxiao Shi85d90832016-08-04 03:19:46 +0000199 face.receive(*makeInterest("/root/1/test/1/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700200 advanceClocks(time::milliseconds(1));
201 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 3);
202
Junxiao Shi85d90832016-08-04 03:19:46 +0000203 face.receive(*makeInterest("/root/2/test/1/%80%00"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700204 advanceClocks(time::milliseconds(1));
205 BOOST_CHECK_EQUAL(nCallbackCalled["test/1"], 4);
206}
207
208BOOST_FIXTURE_TEST_CASE(ControlCommand, DispatcherFixture)
209{
210 size_t nCallbackCalled = 0;
211 dispatcher
212 .addControlCommand<VoidParameters>("test",
213 makeTestAuthorization(),
214 bind([] { return true; }),
215 bind([&nCallbackCalled] { ++nCallbackCalled; }));
216
217 dispatcher.addTopPrefix("/root");
218 advanceClocks(time::milliseconds(1));
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800219 face.sentData.clear();
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700220
Junxiao Shi85d90832016-08-04 03:19:46 +0000221 face.receive(*makeInterest("/root/test/%80%00")); // returns 403
222 face.receive(*makeInterest("/root/test/%80%00/invalid")); // returns 403
223 face.receive(*makeInterest("/root/test/%80%00/silent")); // silently ignored
224 face.receive(*makeInterest("/root/test/.../invalid")); // silently ignored (wrong format)
225 face.receive(*makeInterest("/root/test/.../valid")); // silently ignored (wrong format)
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700226 advanceClocks(time::milliseconds(1), 20);
227 BOOST_CHECK_EQUAL(nCallbackCalled, 0);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800228 BOOST_CHECK_EQUAL(face.sentData.size(), 2);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700229
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800230 BOOST_CHECK(face.sentData[0].getContentType() == tlv::ContentType_Blob);
231 BOOST_CHECK_EQUAL(ControlResponse(face.sentData[0].getContent().blockFromValue()).getCode(), 403);
232 BOOST_CHECK(face.sentData[1].getContentType() == tlv::ContentType_Blob);
233 BOOST_CHECK_EQUAL(ControlResponse(face.sentData[1].getContent().blockFromValue()).getCode(), 403);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700234
Junxiao Shi85d90832016-08-04 03:19:46 +0000235 face.receive(*makeInterest("/root/test/%80%00/valid"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700236 advanceClocks(time::milliseconds(1), 10);
237 BOOST_CHECK_EQUAL(nCallbackCalled, 1);
238}
239
240BOOST_FIXTURE_TEST_CASE(StatusDataset, DispatcherFixture)
241{
242 static Block smallBlock("\x81\x01\0x01", 3);
243 static Block largeBlock = [] () -> Block {
244 EncodingBuffer encoder;
245 for (size_t i = 0; i < 2500; ++i) {
246 encoder.prependByte(1);
247 }
248 encoder.prependVarNumber(2500);
249 encoder.prependVarNumber(129);
250 return encoder.block();
251 }();
252
253 dispatcher.addStatusDataset("test/small",
254 makeTestAuthorization(),
255 [] (const Name& prefix, const Interest& interest,
Junxiao Shif65a3362015-09-06 20:54:54 -0700256 StatusDatasetContext& context) {
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700257 context.append(smallBlock);
258 context.append(smallBlock);
259 context.append(smallBlock);
260 context.end();
261 });
262
263 dispatcher.addStatusDataset("test/large",
264 makeTestAuthorization(),
265 [] (const Name& prefix, const Interest& interest,
Junxiao Shif65a3362015-09-06 20:54:54 -0700266 StatusDatasetContext& context) {
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700267 context.append(largeBlock);
268 context.append(largeBlock);
269 context.append(largeBlock);
270 context.end();
271 });
272
273 dispatcher.addStatusDataset("test/reject",
274 makeTestAuthorization(),
275 [] (const Name& prefix, const Interest& interest,
Junxiao Shif65a3362015-09-06 20:54:54 -0700276 StatusDatasetContext& context) {
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700277 context.reject();
278 });
279
280 dispatcher.addTopPrefix("/root");
281 advanceClocks(time::milliseconds(1));
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800282 face.sentData.clear();
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700283
Junxiao Shi85d90832016-08-04 03:19:46 +0000284 face.receive(*makeInterest("/root/test/small/%80%00")); // returns 403
285 face.receive(*makeInterest("/root/test/small/%80%00/invalid")); // returns 403
286 face.receive(*makeInterest("/root/test/small/%80%00/silent")); // silently ignored
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700287 advanceClocks(time::milliseconds(1), 20);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800288 BOOST_CHECK_EQUAL(face.sentData.size(), 2);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700289
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800290 BOOST_CHECK(face.sentData[0].getContentType() == tlv::ContentType_Blob);
291 BOOST_CHECK_EQUAL(ControlResponse(face.sentData[0].getContent().blockFromValue()).getCode(), 403);
292 BOOST_CHECK(face.sentData[1].getContentType() == tlv::ContentType_Blob);
293 BOOST_CHECK_EQUAL(ControlResponse(face.sentData[1].getContent().blockFromValue()).getCode(), 403);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700294
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800295 face.sentData.clear();
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800296
Junxiao Shi85d90832016-08-04 03:19:46 +0000297 auto interestSmall = *makeInterest("/root/test/small/valid");
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800298 face.receive(interestSmall);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700299 advanceClocks(time::milliseconds(1), 10);
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800300
301 // one data packet is generated and sent to both places
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800302 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800303 BOOST_CHECK_EQUAL(storage.size(), 1);
304
305 auto fetchedData = storage.find(interestSmall);
306 BOOST_REQUIRE(fetchedData != nullptr);
307 BOOST_CHECK(face.sentData[0].wireEncode() == fetchedData->wireEncode());
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700308
Junxiao Shi85d90832016-08-04 03:19:46 +0000309 face.receive(*makeInterest(Name("/root/test/small/valid").appendVersion(10))); // should be ignored
310 face.receive(*makeInterest(Name("/root/test/small/valid").appendSegment(20))); // should be ignored
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700311 advanceClocks(time::milliseconds(1), 10);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800312 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800313 BOOST_CHECK_EQUAL(storage.size(), 1);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700314
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800315 Block content = face.sentData[0].getContent();
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700316 BOOST_CHECK_NO_THROW(content.parse());
317
318 BOOST_CHECK_EQUAL(content.elements().size(), 3);
319 BOOST_CHECK(content.elements()[0] == smallBlock);
320 BOOST_CHECK(content.elements()[1] == smallBlock);
321 BOOST_CHECK(content.elements()[2] == smallBlock);
322
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800323 storage.erase("/", true); // clear the storage
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800324 face.sentData.clear();
Junxiao Shi85d90832016-08-04 03:19:46 +0000325 face.receive(*makeInterest("/root/test/large/valid"));
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700326 advanceClocks(time::milliseconds(1), 10);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700327
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800328 // two data packets are generated, the first one will be sent to both places
329 // while the second one will only be inserted into the in-memory storage
330 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
331 BOOST_CHECK_EQUAL(storage.size(), 2);
332
333 // segment0 should be sent through the face
334 const auto& component = face.sentData[0].getName().at(-1);
335 BOOST_CHECK(component.isSegment());
336 BOOST_CHECK_EQUAL(component.toSegment(), 0);
337
338 std::vector<Data> dataInStorage;
339 std::copy(storage.begin(), storage.end(), std::back_inserter(dataInStorage));
340
341 // the Data sent through the face should be the same as the first Data in the storage
342 BOOST_CHECK_EQUAL(face.sentData[0].getName(), dataInStorage[0].getName());
343 BOOST_CHECK(face.sentData[0].getContent() == dataInStorage[0].getContent());
344
345 content = [&dataInStorage] () -> Block {
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700346 EncodingBuffer encoder;
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800347 size_t valueLength = encoder.prependByteArray(dataInStorage[1].getContent().value(),
348 dataInStorage[1].getContent().value_size());
349 valueLength += encoder.prependByteArray(dataInStorage[0].getContent().value(),
350 dataInStorage[0].getContent().value_size());
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700351 encoder.prependVarNumber(valueLength);
352 encoder.prependVarNumber(tlv::Content);
353 return encoder.block();
354 }();
355
356 BOOST_CHECK_NO_THROW(content.parse());
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700357 BOOST_CHECK_EQUAL(content.elements().size(), 3);
358 BOOST_CHECK(content.elements()[0] == largeBlock);
359 BOOST_CHECK(content.elements()[1] == largeBlock);
360 BOOST_CHECK(content.elements()[2] == largeBlock);
361
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800362 storage.erase("/", true);// clear the storage
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800363 face.sentData.clear();
Junxiao Shi85d90832016-08-04 03:19:46 +0000364 face.receive(*makeInterest("/root/test/reject/%80%00/valid")); // returns nack
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700365 advanceClocks(time::milliseconds(1));
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800366 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
367 BOOST_CHECK(face.sentData[0].getContentType() == tlv::ContentType_Nack);
368 BOOST_CHECK_EQUAL(ControlResponse(face.sentData[0].getContent().blockFromValue()).getCode(), 400);
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800369 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 -0700370}
371
372BOOST_FIXTURE_TEST_CASE(NotificationStream, DispatcherFixture)
373{
374 static Block block("\x82\x01\x02", 3);
375
376 auto post = dispatcher.addNotificationStream("test");
377
378 post(block);
379 advanceClocks(time::milliseconds(1));
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800380 BOOST_CHECK_EQUAL(face.sentData.size(), 0);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700381
382 dispatcher.addTopPrefix("/root");
383 advanceClocks(time::milliseconds(1));
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800384 face.sentData.clear();
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700385
386 post(block);
387 advanceClocks(time::milliseconds(1));
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800388 BOOST_CHECK_EQUAL(face.sentData.size(), 1);
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800389 BOOST_CHECK_EQUAL(storage.size(), 1);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700390
391 post(block);
392 post(block);
393 post(block);
394 advanceClocks(time::milliseconds(1), 10);
395
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800396 BOOST_CHECK_EQUAL(face.sentData.size(), 4);
397 BOOST_CHECK_EQUAL(face.sentData[0].getName(), "/root/test/%FE%00");
398 BOOST_CHECK_EQUAL(face.sentData[1].getName(), "/root/test/%FE%01");
399 BOOST_CHECK_EQUAL(face.sentData[2].getName(), "/root/test/%FE%02");
400 BOOST_CHECK_EQUAL(face.sentData[3].getName(), "/root/test/%FE%03");
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700401
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -0800402 BOOST_CHECK(face.sentData[0].getContent().blockFromValue() == block);
403 BOOST_CHECK(face.sentData[1].getContent().blockFromValue() == block);
404 BOOST_CHECK(face.sentData[2].getContent().blockFromValue() == block);
405 BOOST_CHECK(face.sentData[3].getContent().blockFromValue() == block);
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800406
407 // each version of notification will be sent to both places
408 std::vector<Data> dataInStorage;
409 std::copy(storage.begin(), storage.end(), std::back_inserter(dataInStorage));
410 BOOST_CHECK_EQUAL(dataInStorage.size(), 4);
411 BOOST_CHECK_EQUAL(dataInStorage[0].getName(), "/root/test/%FE%00");
412 BOOST_CHECK_EQUAL(dataInStorage[1].getName(), "/root/test/%FE%01");
413 BOOST_CHECK_EQUAL(dataInStorage[2].getName(), "/root/test/%FE%02");
414 BOOST_CHECK_EQUAL(dataInStorage[3].getName(), "/root/test/%FE%03");
415
416 BOOST_CHECK(dataInStorage[0].getContent().blockFromValue() == block);
417 BOOST_CHECK(dataInStorage[1].getContent().blockFromValue() == block);
418 BOOST_CHECK(dataInStorage[2].getContent().blockFromValue() == block);
419 BOOST_CHECK(dataInStorage[3].getContent().blockFromValue() == block);
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700420}
421
Yanbiao Li4b4f7542016-03-11 02:04:43 +0800422BOOST_AUTO_TEST_SUITE_END() // TestDispatcher
423BOOST_AUTO_TEST_SUITE_END() // Mgmt
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700424
425} // namespace tests
426} // namespace mgmt
427} // namespace ndn