blob: e4791c253a8b8ee207e3bd3a7bc664bc9851fd1c [file] [log] [blame]
Zhenkai Zhu64db03a2012-03-12 19:25:56 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
Chaoyi Bian3e1eb162012-04-03 16:59:32 -070019 * Chaoyi Bian <bcy@pku.edu.cn>
Zhenkai Zhu64db03a2012-03-12 19:25:56 -070020 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
23#include <boost/test/unit_test.hpp>
24#include <boost/test/output_test_stream.hpp>
25using boost::test_tools::output_test_stream;
26
27#include <boost/make_shared.hpp>
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070028#include <boost/date_time/posix_time/posix_time.hpp>
29
Alexander Afanasyevf46eac52013-07-26 11:27:39 -070030#include "sync-logging.h"
Alexander Afanasyevd95c2312013-11-07 13:45:34 -080031#include "sync-socket.h"
Yingdi Yu0eee6002014-02-11 15:54:17 -080032#include "sync-validator.h"
Yingdi Yu280bb962014-01-30 09:52:43 -080033#include <ndn-cpp-dev/security/validator-null.hpp>
Alexander Afanasyevf46eac52013-07-26 11:27:39 -070034
Zhenkai Zhu64db03a2012-03-12 19:25:56 -070035extern "C" {
36#include <unistd.h>
37}
38
39using namespace Sync;
40using namespace std;
41using namespace boost;
42
Alexander Afanasyev7df73332012-03-15 12:31:49 -070043INIT_LOGGER ("Test.AppSocket");
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070044
Zhenkai Zhua30e1782012-06-01 11:52:57 -070045#define PRINT
46//std::cout << "Line: " << __LINE__ << std::endl;
47
Zhenkai Zhu00304002012-03-12 21:32:30 -070048class TestSocketApp {
Zhenkai Zhu64db03a2012-03-12 19:25:56 -070049public:
Alexander Afanasyev531803b2014-02-05 15:57:35 -080050 TestSocketApp()
51 : sum(0)
52 {}
53
Yingdi Yu280bb962014-01-30 09:52:43 -080054 map<ndn::Name, string> data;
55 void set(const ndn::shared_ptr<const ndn::Data>& dataPacket) {
Alexander Afanasyev235c6d72012-03-15 22:28:43 -070056 // _LOG_FUNCTION (this << ", " << str1);
Yingdi Yu280bb962014-01-30 09:52:43 -080057 ndn::Name dataName(dataPacket->getName());
58 string str2(reinterpret_cast<const char*>(dataPacket->getContent().value()), dataPacket->getContent().value_size());
59 data.insert(make_pair(dataName, str2));
Alexander Afanasyev1b449c42012-03-13 20:24:07 -070060 // cout << str1 << ", " << str2 << endl;
Zhenkai Zhu64db03a2012-03-12 19:25:56 -070061 }
Yingdi Yu43e71612013-10-30 22:19:31 -070062
Yingdi Yu280bb962014-01-30 09:52:43 -080063 void set(ndn::Name name, const char * buf, int len) {
Yingdi Yu43e71612013-10-30 22:19:31 -070064 string str2(buf, len);
Yingdi Yu280bb962014-01-30 09:52:43 -080065 data.insert(make_pair(name, str2));
Yingdi Yu43e71612013-10-30 22:19:31 -070066 }
Zhenkai Zhudc70a292012-06-01 14:00:59 -070067
Yingdi Yu280bb962014-01-30 09:52:43 -080068 void setNum(const ndn::shared_ptr<const ndn::Data>& dataPacket) {
69 int n = dataPacket->getContent().value_size() / 4;
Alexander Afanasyev531803b2014-02-05 15:57:35 -080070 uint32_t *numbers = new uint32_t [n];
Yingdi Yu280bb962014-01-30 09:52:43 -080071 memcpy(numbers, dataPacket->getContent().value(), dataPacket->getContent().value_size());
Zhenkai Zhudc70a292012-06-01 14:00:59 -070072 for (int i = 0; i < n; i++) {
73 sum += numbers[i];
74 }
75 delete numbers;
76
77 }
78
Yingdi Yu280bb962014-01-30 09:52:43 -080079 void setNum(ndn::Name name, const char * buf, int len) {
Yingdi Yu43e71612013-10-30 22:19:31 -070080 int n = len / 4;
81 int *numbers = new int [n];
82 memcpy(numbers, buf, len);
83 for (int i = 0; i < n; i++) {
84 sum += numbers[i];
85 }
86 delete numbers;
87 }
88
Alexander Afanasyev531803b2014-02-05 15:57:35 -080089 uint32_t sum;
Zhenkai Zhu64db03a2012-03-12 19:25:56 -070090
Yingdi Yu43e71612013-10-30 22:19:31 -070091 void fetchAll(const vector<MissingDataInfo> &v, SyncSocket *socket) {
Zhenkai Zhu1cb29292012-05-31 22:54:34 -070092 int n = v.size();
Zhenkai Zhua30e1782012-06-01 11:52:57 -070093
94 PRINT
95
Zhenkai Zhu1cb29292012-05-31 22:54:34 -070096 for (int i = 0; i < n; i++) {
Zhenkai Zhua30e1782012-06-01 11:52:57 -070097 for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
Zhenkai Zhudc70a292012-06-01 14:00:59 -070098 //PRINT
Yingdi Yu43e71612013-10-30 22:19:31 -070099 socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::set, this, _1));
Zhenkai Zhu1cb29292012-05-31 22:54:34 -0700100 }
101 }
102 }
103
Yingdi Yu43e71612013-10-30 22:19:31 -0700104 void fetchNumbers(const vector<MissingDataInfo> &v, SyncSocket *socket) {
Zhenkai Zhudc70a292012-06-01 14:00:59 -0700105 int n = v.size();
106
107 PRINT
108
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800109 // std::cout << "In fetchNumbers. size of v is: " << n << std::endl;
Zhenkai Zhudc70a292012-06-01 14:00:59 -0700110 for (int i = 0; i < n; i++) {
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800111 // std::cout << "In fetchNumbers. v[i].low is (" <<v[i].low.getSession() <<", " << v[i].low.getSeq() << ") v[i].high is ("<<v[i].high.getSession() <<", " <<v[i].high.getSeq()<<")" << std::endl;
Zhenkai Zhudc70a292012-06-01 14:00:59 -0700112 for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
113 PRINT
Yingdi Yu43e71612013-10-30 22:19:31 -0700114 socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::setNum, this, _1));
Zhenkai Zhudc70a292012-06-01 14:00:59 -0700115 }
116 }
117 }
118
Zhenkai Zhu1cb29292012-05-31 22:54:34 -0700119 void pass(const string &prefix) {
120 }
121
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700122 string toString(){
Yingdi Yu280bb962014-01-30 09:52:43 -0800123 map<ndn::Name, string>::iterator it = data.begin();
Zhenkai Zhu1a0fd5d2012-03-12 21:34:42 -0700124 string str = "\n";
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700125 for (; it != data.end(); ++it){
126 str += "<";
Yingdi Yu280bb962014-01-30 09:52:43 -0800127 str += it->first.toUri();
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700128 str += "|";
129 str += it->second;
130 str += ">";
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700131 str += "\n";
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700132 }
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700133
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700134 return str;
135 }
136
137};
138
Yingdi Yu280bb962014-01-30 09:52:43 -0800139class TestSet1{
140public:
141 TestSet1(ndn::shared_ptr<boost::asio::io_service> ioService)
Yingdi Yu0eee6002014-02-11 15:54:17 -0800142 : m_face1(new ndn::Face(ioService))
Yingdi Yu280bb962014-01-30 09:52:43 -0800143 , m_face2(new ndn::Face(ioService))
144 , m_face3(new ndn::Face(ioService))
145 , m_p1("/irl.cs.ucla.edu")
146 , m_p2("/yakshi.org")
147 , m_p3("/google.com")
Yingdi Yu51c80252014-02-10 19:32:05 -0800148 , m_syncPrefix("/let/us/sync")
Yingdi Yu0eee6002014-02-11 15:54:17 -0800149 {
150 ndn::KeyChain keyChain;
151 m_name1 = m_p1;
152 m_name1.append(boost::lexical_cast<std::string>(ndn::time::now()));
153 ndn::Name certName1 = keyChain.createIdentity(m_name1);
154 m_id1 = keyChain.getCertificate(certName1);
155
156 m_name2 = m_p2;
157 m_name2.append(boost::lexical_cast<std::string>(ndn::time::now()));
158 ndn::Name certName2 = keyChain.createIdentity(m_name2);
159 m_id2 = keyChain.getCertificate(certName2);
160
161 m_name3 = m_p3;
162 m_name3.append(boost::lexical_cast<std::string>(ndn::time::now()));
163 ndn::Name certName3 = keyChain.createIdentity(m_name3);
164 m_id3 = keyChain.getCertificate(certName3);
165
166 ndn::shared_ptr<ndn::SecRuleRelative> rule = ndn::make_shared<ndn::SecRuleRelative>("^(<>*)<><>$",
167 "^(<>*)<><KEY><ksk-.*><ID-CERT>$",
168 "==", "\\1", "\\1", true);
169
170 m_v1 = ndn::make_shared<SyncValidator>(m_syncPrefix, *m_id1, m_face1, rule);
171 m_v1->addParticipant(*m_id2);
172 m_v2 = ndn::make_shared<SyncValidator>(m_syncPrefix, *m_id2, m_face2, rule);
173 m_v2->addParticipant(*m_id1);
174 m_v2->addParticipant(*m_id3);
175 m_v3 = ndn::make_shared<SyncValidator>(m_syncPrefix, *m_id3, m_face3, rule);
176 m_v3->addParticipant(*m_id2);
177 }
Yingdi Yu280bb962014-01-30 09:52:43 -0800178
179 void
180 createSyncSocket1()
181 {
182 _LOG_DEBUG ("s1");
Yingdi Yu0eee6002014-02-11 15:54:17 -0800183 m_s1 = ndn::make_shared<SyncSocket>(m_syncPrefix, m_name1, m_v1, m_face1,
Yingdi Yu280bb962014-01-30 09:52:43 -0800184 bind(&TestSocketApp::fetchAll, &m_a1, _1, _2),
185 bind(&TestSocketApp::pass, &m_a1, _1));
186 }
187
188 void
189 createSyncSocket2()
190 {
191 _LOG_DEBUG ("s2");
Yingdi Yu0eee6002014-02-11 15:54:17 -0800192 m_s2 = ndn::make_shared<SyncSocket>(m_syncPrefix, m_name2, m_v2, m_face2,
Yingdi Yu280bb962014-01-30 09:52:43 -0800193 bind(&TestSocketApp::fetchAll, &m_a2, _1, _2),
194 bind(&TestSocketApp::pass, &m_a2, _1));
195 }
196
197 void
198 createSyncSocket3()
199 {
200 _LOG_DEBUG ("s3");
Yingdi Yu0eee6002014-02-11 15:54:17 -0800201 m_s3 = ndn::make_shared<SyncSocket>(m_syncPrefix, m_name3, m_v3, m_face3,
Yingdi Yu280bb962014-01-30 09:52:43 -0800202 bind(&TestSocketApp::fetchAll, &m_a3, _1, _2),
203 bind(&TestSocketApp::pass, &m_a3, _1));
204 }
205
206 void
207 publishSocket1(uint32_t session, string data)
208 {
209 _LOG_DEBUG ("s1 publish");
210 m_s1->publishData (m_p1, session, data.c_str(), data.size(), 1000);
211 }
212
213 void
214 publishSocket2(uint32_t session, string data)
215 {
216 _LOG_DEBUG ("s2 publish");
217 m_s2->publishData (m_p2, session, data.c_str(), data.size(), 1000);
218 }
219
220 void
221 publishSocket3(uint32_t session, string data)
222 {
223 _LOG_DEBUG ("s3 publish");
224 m_s3->publishData (m_p3, session, data.c_str(), data.size(), 1000);
225 }
226
227 void
228 setSocket1(string suffix, string data)
229 {
230 _LOG_DEBUG ("a1 set");
231 ndn::Name name = m_p1;
232 name.append(suffix);
233 m_a1.set (name, data.c_str(), data.size());
234 }
235
236 void
237 setSocket2(string suffix, string data)
238 {
239 _LOG_DEBUG ("a2 set");
240 ndn::Name name = m_p2;
241 name.append(suffix);
242 m_a2.set (name, data.c_str(), data.size());
243 }
244
245 void
246 setSocket3(string suffix, string data)
247 {
248 _LOG_DEBUG ("a3 set");
249 ndn::Name name = m_p3;
250 name.append(suffix);
251 m_a3.set (name, data.c_str(), data.size());
252 }
253
254 void
Yingdi Yu7ad4e4f2014-02-03 18:27:36 -0800255 check(int round)
Yingdi Yu280bb962014-01-30 09:52:43 -0800256 {
257 BOOST_CHECK_EQUAL(m_a1.toString(), m_a2.toString());
258 BOOST_CHECK_EQUAL(m_a2.toString(), m_a3.toString());
259 }
260
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800261 void
262 done()
263 {
264 m_s1.reset();
265 m_s2.reset();
266 m_s3.reset();
Yingdi Yu0eee6002014-02-11 15:54:17 -0800267 m_v1.reset();
268 m_v2.reset();
269 m_v3.reset();
270
271 ndn::KeyChain keyChain;
272 keyChain.deleteIdentity(m_name1);
273 keyChain.deleteIdentity(m_name2);
274 keyChain.deleteIdentity(m_name3);
275
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800276 }
Yingdi Yu280bb962014-01-30 09:52:43 -0800277
278
279 TestSocketApp m_a1, m_a2, m_a3;
Yingdi Yu0eee6002014-02-11 15:54:17 -0800280 ndn::shared_ptr<ndn::IdentityCertificate> m_id1, m_id2, m_id3;
281 ndn::shared_ptr<Sync::SyncValidator> m_v1, m_v2, m_v3;
Yingdi Yu280bb962014-01-30 09:52:43 -0800282 ndn::shared_ptr<ndn::Face> m_face1, m_face2, m_face3;
Yingdi Yu0eee6002014-02-11 15:54:17 -0800283 ndn::Name m_name1, m_name2, m_name3;
Yingdi Yu280bb962014-01-30 09:52:43 -0800284 ndn::Name m_p1, m_p2, m_p3;
285 ndn::shared_ptr<SyncSocket> m_s1, m_s2, m_s3;
286 ndn::Name m_syncPrefix;
287};
288
289class TestSet2{
290public:
291 TestSet2(ndn::shared_ptr<boost::asio::io_service> ioService)
Yingdi Yu0eee6002014-02-11 15:54:17 -0800292 : m_face1(new ndn::Face(ioService))
Yingdi Yu280bb962014-01-30 09:52:43 -0800293 , m_face2(new ndn::Face(ioService))
294 , m_p1("/xiaonei.com")
295 , m_p2("/mitbbs.com")
Yingdi Yu51c80252014-02-10 19:32:05 -0800296 , m_syncPrefix("/this/is/the/prefix")
Yingdi Yu0eee6002014-02-11 15:54:17 -0800297 {
298 ndn::KeyChain keyChain;
299 m_name1 = m_p1;
300 m_name1.append(boost::lexical_cast<string>(ndn::time::now()));
301 ndn::Name certName1 = keyChain.createIdentity(m_name1);
302 m_id1 = keyChain.getCertificate(certName1);
303
304 m_name2 = m_p2;
305 m_name2.append(boost::lexical_cast<string>(ndn::time::now()));
306 ndn::Name certName2 = keyChain.createIdentity(m_name2);
307 m_id2 = keyChain.getCertificate(certName2);
308
309 ndn::shared_ptr<ndn::SecRuleRelative> rule = ndn::make_shared<ndn::SecRuleRelative>("^(<>*)<><>$",
310 "^(<>*)<><KEY><ksk-.*><ID-CERT>$",
311 "==", "\\1", "\\1", true);
312
313 m_v1 = ndn::make_shared<SyncValidator>(m_syncPrefix, *m_id1, m_face1, rule);
314 m_v1->addParticipant(*m_id2);
315 m_v2 = ndn::make_shared<SyncValidator>(m_syncPrefix, *m_id2, m_face2, rule);
316 m_v2->addParticipant(*m_id1);
317
318 }
Yingdi Yu280bb962014-01-30 09:52:43 -0800319
320 void
321 createSyncSocket1()
322 {
323 _LOG_DEBUG ("s1");
Yingdi Yu0eee6002014-02-11 15:54:17 -0800324 m_s1 = ndn::make_shared<SyncSocket>(m_syncPrefix, m_name1, m_v1, m_face1,
Yingdi Yu280bb962014-01-30 09:52:43 -0800325 bind(&TestSocketApp::fetchNumbers, &m_a1, _1, _2),
326 bind(&TestSocketApp::pass, &m_a1, _1));
327 }
328
329 void
330 createSyncSocket2()
331 {
332 _LOG_DEBUG ("s2");
Yingdi Yu0eee6002014-02-11 15:54:17 -0800333 m_s2 = ndn::make_shared<SyncSocket>(m_syncPrefix, m_name2, m_v2, m_face2,
Yingdi Yu280bb962014-01-30 09:52:43 -0800334 bind(&TestSocketApp::fetchNumbers, &m_a2, _1, _2),
335 bind(&TestSocketApp::pass, &m_a2, _1));
336 }
337
338 void
339 publishSocket1(uint32_t session, string data)
340 {
341 _LOG_DEBUG ("s1 publish");
342 m_s1->publishData (m_p1, session, data.c_str(), data.size(), 1000);
343 }
344
345 void
346 publishSocket2(uint32_t session, string data)
347 {
348 _LOG_DEBUG ("s2 publish");
349 m_s2->publishData (m_p2, session, data.c_str(), data.size(), 1000);
350 }
351
352 void
353 setSocket1(const char* ptr, size_t size)
354 {
355 _LOG_DEBUG ("a1 setNum");
356 m_a1.setNum (m_p1, ptr, size);
357 }
358
359 void
360 setSocket2(const char* ptr, size_t size)
361 {
362 _LOG_DEBUG ("a2 setNum");
363 m_a2.setNum (m_p2, ptr, size);
364 }
365
366 void
367 check(int num)
368 {
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800369 _LOG_DEBUG ("codnum " << num);
370 _LOG_DEBUG ("a1 sum " << m_a1.sum);
371 _LOG_DEBUG ("a2 sum " << m_a2.sum);
372
Yingdi Yu280bb962014-01-30 09:52:43 -0800373 BOOST_CHECK(m_a1.sum == m_a2.sum && m_a1.sum == num);
374 }
375
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800376 void
377 done()
378 {
379 m_s1.reset();
380 m_s2.reset();
Yingdi Yu0eee6002014-02-11 15:54:17 -0800381 m_v1.reset();
382 m_v2.reset();
383
384 ndn::KeyChain keyChain;
385 keyChain.deleteIdentity(m_name1);
386 keyChain.deleteIdentity(m_name2);
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800387 }
Yingdi Yu280bb962014-01-30 09:52:43 -0800388
389 TestSocketApp m_a1, m_a2;
Yingdi Yu0eee6002014-02-11 15:54:17 -0800390 ndn::shared_ptr<ndn::IdentityCertificate> m_id1, m_id2;
391 ndn::shared_ptr<Sync::SyncValidator> m_v1, m_v2;
Yingdi Yu280bb962014-01-30 09:52:43 -0800392 ndn::shared_ptr<ndn::Face> m_face1, m_face2;
393 ndn::Name m_p1, m_p2;
Yingdi Yu0eee6002014-02-11 15:54:17 -0800394 ndn::Name m_name1, m_name2;
Yingdi Yu280bb962014-01-30 09:52:43 -0800395 ndn::shared_ptr<SyncSocket> m_s1, m_s2;
396 ndn::Name m_syncPrefix;
397};
398
399BOOST_AUTO_TEST_CASE (AppSocketTest1)
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700400{
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700401 INIT_LOGGERS ();
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700402
Yingdi Yu280bb962014-01-30 09:52:43 -0800403 ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>();
404 ndn::Scheduler scheduler(*ioService);
405 TestSet1 testSet1(ioService);
Yingdi Yu43e71612013-10-30 22:19:31 -0700406
Yingdi Yu280bb962014-01-30 09:52:43 -0800407 scheduler.scheduleEvent(ndn::time::seconds(0.00), ndn::bind(&TestSet1::createSyncSocket1, &testSet1));
408 scheduler.scheduleEvent(ndn::time::seconds(0.05), ndn::bind(&TestSet1::createSyncSocket2, &testSet1));
409 scheduler.scheduleEvent(ndn::time::seconds(0.10), ndn::bind(&TestSet1::createSyncSocket3, &testSet1));
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700410 string data0 = "Very funny Scotty, now beam down my clothes";
Yingdi Yu280bb962014-01-30 09:52:43 -0800411 scheduler.scheduleEvent(ndn::time::seconds(0.15), ndn::bind(&TestSet1::publishSocket1, &testSet1, 0, data0));
412 scheduler.scheduleEvent(ndn::time::seconds(1.15), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/0", data0));
Yingdi Yu7ad4e4f2014-02-03 18:27:36 -0800413 scheduler.scheduleEvent(ndn::time::seconds(1.16), ndn::bind(&TestSet1::check, &testSet1, 1));
Yingdi Yu280bb962014-01-30 09:52:43 -0800414 string data1 = "Yes, give me that ketchup";
415 string data2 = "Don't look conspicuous, it draws fire";
416 scheduler.scheduleEvent(ndn::time::seconds(1.17), ndn::bind(&TestSet1::publishSocket1, &testSet1, 0, data1));
417 scheduler.scheduleEvent(ndn::time::seconds(1.18), ndn::bind(&TestSet1::publishSocket1, &testSet1, 0, data2));
418 scheduler.scheduleEvent(ndn::time::seconds(2.15), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/1", data1));
419 scheduler.scheduleEvent(ndn::time::seconds(2.16), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/2", data2));
Yingdi Yu7ad4e4f2014-02-03 18:27:36 -0800420 scheduler.scheduleEvent(ndn::time::seconds(2.17), ndn::bind(&TestSet1::check, &testSet1, 2));
Yingdi Yu280bb962014-01-30 09:52:43 -0800421 string data3 = "You surf the Internet, I surf the real world";
422 string data4 = "I got a fortune cookie once that said 'You like Chinese food'";
423 string data5 = "Real men wear pink. Why? Because their wives make them";
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800424 scheduler.scheduleEvent(ndn::time::seconds(3.18), ndn::bind(&TestSet1::publishSocket3, &testSet1, 0, data3));
425 scheduler.scheduleEvent(ndn::time::seconds(3.20), ndn::bind(&TestSet1::publishSocket2, &testSet1, 0, data4));
426 scheduler.scheduleEvent(ndn::time::seconds(3.21), ndn::bind(&TestSet1::publishSocket2, &testSet1, 0, data5));
427 scheduler.scheduleEvent(ndn::time::seconds(4.21), ndn::bind(&TestSet1::setSocket3, &testSet1, "/0/0", data3));
428 scheduler.scheduleEvent(ndn::time::seconds(4.22), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/0", data4));
429 scheduler.scheduleEvent(ndn::time::seconds(4.23), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/1", data5));
430 scheduler.scheduleEvent(ndn::time::seconds(4.30), ndn::bind(&TestSet1::check, &testSet1, 3));
Yingdi Yu280bb962014-01-30 09:52:43 -0800431 // not sure weither this is simultanous data generation from multiple sources
432 _LOG_DEBUG ("Simultaneous publishing");
433 string data6 = "Shakespeare says: 'Prose before hos.'";
434 string data7 = "Pick good people, talent never wears out";
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800435 scheduler.scheduleEvent(ndn::time::seconds(5.50), ndn::bind(&TestSet1::publishSocket1, &testSet1, 0, data6));
436 scheduler.scheduleEvent(ndn::time::seconds(5.50), ndn::bind(&TestSet1::publishSocket2, &testSet1, 0, data7));
437 scheduler.scheduleEvent(ndn::time::seconds(6.80), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/3", data6));
438 scheduler.scheduleEvent(ndn::time::seconds(6.80), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/2", data7));
439 scheduler.scheduleEvent(ndn::time::seconds(6.90), ndn::bind(&TestSet1::check, &testSet1, 4));
440 scheduler.scheduleEvent(ndn::time::seconds(7.00), ndn::bind(&TestSet1::done, &testSet1));
Zhenkai Zhu00304002012-03-12 21:32:30 -0700441
Yingdi Yu280bb962014-01-30 09:52:43 -0800442 ioService->run();
443}
Zhenkai Zhu00304002012-03-12 21:32:30 -0700444
Yingdi Yu280bb962014-01-30 09:52:43 -0800445BOOST_AUTO_TEST_CASE (AppSocketTest2)
446{
447 ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>();
448 ndn::Scheduler scheduler(*ioService);
449 TestSet2 testSet2(ioService);
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700450
Yingdi Yu280bb962014-01-30 09:52:43 -0800451 scheduler.scheduleEvent(ndn::time::seconds(0.00), ndn::bind(&TestSet2::createSyncSocket1, &testSet2));
452 scheduler.scheduleEvent(ndn::time::seconds(0.05), ndn::bind(&TestSet2::createSyncSocket2, &testSet2));
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800453 uint32_t num[5] = {0, 1, 2, 3, 4};
Yingdi Yu280bb962014-01-30 09:52:43 -0800454 string data0((const char *) num, sizeof(num));
455 scheduler.scheduleEvent(ndn::time::seconds(0.10), ndn::bind(&TestSet2::publishSocket1, &testSet2, 0, data0));
456 scheduler.scheduleEvent(ndn::time::seconds(0.15), ndn::bind(&TestSet2::setSocket1, &testSet2, (const char *) num, sizeof (num)));
457 scheduler.scheduleEvent(ndn::time::seconds(1.00), ndn::bind(&TestSet2::check, &testSet2, 10));
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800458 uint32_t newNum[5] = {9, 7, 2, 1, 1};
Yingdi Yu280bb962014-01-30 09:52:43 -0800459 string data1((const char *) newNum, sizeof(newNum));
460 scheduler.scheduleEvent(ndn::time::seconds(1.10), ndn::bind(&TestSet2::publishSocket2, &testSet2, 0, data1));
461 scheduler.scheduleEvent(ndn::time::seconds(1.15), ndn::bind(&TestSet2::setSocket2, &testSet2, (const char *) newNum, sizeof (newNum)));
462 scheduler.scheduleEvent(ndn::time::seconds(2.00), ndn::bind(&TestSet2::check, &testSet2, 30));
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800463 scheduler.scheduleEvent(ndn::time::seconds(7.00), ndn::bind(&TestSet2::done, &testSet2));
Zhenkai Zhu00304002012-03-12 21:32:30 -0700464
Yingdi Yu280bb962014-01-30 09:52:43 -0800465 ioService->run();
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700466}