/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2012-2014 University of California, Los Angeles
 *
 * This file is part of ChronoSync, synchronization library for distributed realtime
 * applications for NDN.
 *
 * ChronoSync is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * ChronoSync, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
using boost::test_tools::output_test_stream;

#include <boost/make_shared.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

#include "sync-logging.h"
#include "sync-socket.h"
#include "sync-validator.h"
#include <ndn-cxx/security/validator-null.hpp>

extern "C" {
#include <unistd.h>
}

using namespace Sync;
using namespace std;
using namespace boost;

INIT_LOGGER ("Test.AppSocket");

#define PRINT
// std::cout << "Line: " << __LINE__ << std::endl;

class TestSocketApp {
public:
  TestSocketApp()
    : sum(0)
  {}

  map<ndn::Name, string> data;
  void set(const ndn::shared_ptr<const ndn::Data>& dataPacket) {
    // _LOG_FUNCTION (this << ", " << str1);
    ndn::Name dataName(dataPacket->getName());
    string str2(reinterpret_cast<const char*>(dataPacket->getContent().value()), dataPacket->getContent().value_size());
    data.insert(make_pair(dataName, str2));
    // cout << str1 << ", " << str2 << endl;
  }

  void set(ndn::Name name, const char * buf, int len) {
    string str2(buf, len);
    data.insert(make_pair(name, str2));
  }

  void setNum(const ndn::shared_ptr<const ndn::Data>& data) {
    int n = data->getContent().value_size() / 4;
    uint32_t *numbers = new uint32_t [n];
    memcpy(numbers, data->getContent().value(), data->getContent().value_size());
    for (int i = 0; i < n; i++) {
      sum += numbers[i];
    }
    delete numbers;

  }

  void setNum(ndn::Name name, const char * buf, int len) {
    int n = len / 4;
    int *numbers = new int [n];
    memcpy(numbers, buf, len);
    for (int i = 0; i < n; i++) {
      sum += numbers[i];
    }
    delete numbers;
  }

  uint32_t sum;

  void fetchAll(const vector<MissingDataInfo> &v, SyncSocket *socket) {
    int n = v.size();

    PRINT

    for (int i = 0; i < n; i++) {
      for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
        //PRINT
        socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::set, this, _1));
      }
    }
  }

  void fetchNumbers(const vector<MissingDataInfo> &v, SyncSocket *socket) {
    int n = v.size();

    PRINT

    // std::cout << "In fetchNumbers. size of v is:  " << n << std::endl;
    for (int i = 0; i < n; i++) {
      // 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;
      for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
        PRINT
        socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::setNum, this, _1));
      }
    }
  }

  void pass(const string &prefix) {
  }

  string toString(){
    map<ndn::Name, string>::iterator it = data.begin();
    string str = "\n";
    for (; it != data.end(); ++it){
      str += "<";
      str += it->first.toUri();
      str += "|";
      str += it->second;
      str += ">";
      str += "\n";
    }

    return str;
  }

};

class TestSet1{
public:
  TestSet1(ndn::shared_ptr<boost::asio::io_service> ioService)
    : m_face1(new ndn::Face(*ioService))
    , m_face2(new ndn::Face(*ioService))
    , m_face3(new ndn::Face(*ioService))
    , m_name1("/irl.cs.ucla.edu/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
    , m_name2("/yakshi.org/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
    , m_name3("/google.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
  {
    m_id1 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name1));
    m_id2 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name2));
    m_id3 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name3));

    m_rule = ndn::make_shared<ndn::SecRuleRelative>("^(<>*)<><>$",
                                                    "^(<>*)<><KEY><ksk-.*><ID-CERT>$",
                                                    "==", "\\1", "\\1", true);
  }

  void
  createSyncSocket1()
  {
    _LOG_DEBUG ("s1");

    m_s1 = ndn::shared_ptr<SyncSocket>
      (new SyncSocket("/let/us/sync",
                      "/irl.cs.ucla.edu",
                      0,
                      false,
                      "/",
                      m_face1,
                      *m_id1,
                      m_rule,
                      bind(&TestSocketApp::fetchAll, &m_a1, _1, _2),
                      bind(&TestSocketApp::pass, &m_a1, _1)));

    m_s1->addParticipant(*m_id2);
  }

  void
  createSyncSocket2()
  {
    _LOG_DEBUG ("s2");

    m_s2 = ndn::shared_ptr<SyncSocket>
      (new SyncSocket("/let/us/sync",
                      "/yakshi.org",
                      0,
                      false,
                      "/",
                      m_face2,
                      *m_id2,
                      m_rule,
                      bind(&TestSocketApp::fetchAll, &m_a2, _1, _2),
                      bind(&TestSocketApp::pass, &m_a2, _1)));

    m_s2->addParticipant(*m_id1);
    m_s2->addParticipant(*m_id3);
  }

  void
  createSyncSocket3()
  {
    _LOG_DEBUG ("s3");

    m_s3 = ndn::shared_ptr<SyncSocket>
      (new SyncSocket("/let/us/sync",
                      "/google.com",
                      0,
                      false,
                      "/",
                      m_face3,
                      *m_id3,
                      m_rule,
                      bind(&TestSocketApp::fetchAll, &m_a3, _1, _2),
                      bind(&TestSocketApp::pass, &m_a3, _1)));

    m_s3->addParticipant(*m_id2);
  }

  void
  publishSocket1(string data)
  {
    _LOG_DEBUG ("s1 publish");
    m_s1->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000);
  }

  void
  publishSocket2(string data)
  {
    _LOG_DEBUG ("s2 publish");
    m_s2->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000);
  }

  void
  publishSocket3(string data)
  {
    _LOG_DEBUG ("s3 publish");
    m_s3->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000);
  }

  void
  setSocket1(string suffix, string data)
  {
    _LOG_DEBUG ("a1 set");
    ndn::Name name("/irl.cs.ucla.edu");
    name.append(suffix);
    m_a1.set (name, data.c_str(), data.size());
  }

  void
  setSocket2(string suffix, string data)
  {
    _LOG_DEBUG ("a2 set");
    ndn::Name name("/yakshi.org");
    name.append(suffix);
    m_a2.set (name, data.c_str(), data.size());
  }

  void
  setSocket3(string suffix, string data)
  {
    _LOG_DEBUG ("a3 set");
    ndn::Name name("/google.com");
    name.append(suffix);
    m_a3.set (name, data.c_str(), data.size());
  }

  void
  check(int round)
  {
    BOOST_CHECK_EQUAL(m_a1.toString(), m_a2.toString());
    BOOST_CHECK_EQUAL(m_a2.toString(), m_a3.toString());
  }

  void
  done(ndn::shared_ptr<boost::asio::io_service> ioService)
  {
    m_s1.reset();
    m_s2.reset();
    m_s3.reset();

    m_keyChain.deleteIdentity(m_name1);
    m_keyChain.deleteIdentity(m_name2);
    m_keyChain.deleteIdentity(m_name3);

    ioService->stop();
  }

  ndn::KeyChain m_keyChain;
  ndn::shared_ptr<ndn::SecRuleRelative> m_rule;

  ndn::shared_ptr<ndn::Face> m_face1, m_face2, m_face3;
  ndn::Name m_name1, m_name2, m_name3;
  TestSocketApp m_a1, m_a2, m_a3;
  ndn::shared_ptr<ndn::IdentityCertificate> m_id1, m_id2, m_id3;
  ndn::shared_ptr<SyncSocket> m_s1, m_s2, m_s3;
};

class TestSet2{
public:
  TestSet2(ndn::shared_ptr<boost::asio::io_service> ioService)
    : m_face1(new ndn::Face(*ioService))
    , m_face2(new ndn::Face(*ioService))
    , m_name1("/xiaonei.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
    , m_name2("/mitbbs.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
  {
    m_id1 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name1));
    m_id2 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name2));

    m_rule = ndn::make_shared<ndn::SecRuleRelative>("^(<>*)<><>$",
                                                    "^(<>*)<><KEY><ksk-.*><ID-CERT>$",
                                                    "==", "\\1", "\\1", true);
  }

  void
  createSyncSocket1()
  {
    _LOG_DEBUG ("s1");

    m_s1 = ndn::shared_ptr<SyncSocket>
      (new SyncSocket("/this/is/the/prefix",
                      "/xiaonei.com",
                      0,
                      false,
                      "/",
                      m_face1,
                      *m_id1,
                      m_rule,
                      bind(&TestSocketApp::fetchNumbers, &m_a1, _1, _2),
                      bind(&TestSocketApp::pass, &m_a1, _1)));

    m_s1->addParticipant(*m_id2);
  }

  void
  createSyncSocket2()
  {
    _LOG_DEBUG ("s2");

    m_s2 = ndn::shared_ptr<SyncSocket>
      (new SyncSocket("/this/is/the/prefix",
                      "/mitbbs.com",
                      0,
                      false,
                      "/",
                      m_face2,
                      *m_id2,
                      m_rule,
                      bind(&TestSocketApp::fetchNumbers, &m_a2, _1, _2),
                      bind(&TestSocketApp::pass, &m_a2, _1)));

    m_s2->addParticipant(*m_id1);
  }

  void
  publishSocket1(string data)
  {
    _LOG_DEBUG ("s1 publish");
    m_s1->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000);
  }

  void
  publishSocket2(string data)
  {
    _LOG_DEBUG ("s2 publish");
    m_s2->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000);
  }

  void
  setSocket1(const char* ptr, size_t size)
  {
    _LOG_DEBUG ("a1 setNum");
    m_a1.setNum ("/xiaonei.com", ptr, size);
  }

  void
  setSocket2(const char* ptr, size_t size)
  {
    _LOG_DEBUG ("a2 setNum");
    m_a2.setNum ("/mitbbs.com", ptr, size);
  }

  void
  check(int num)
  {
    _LOG_DEBUG ("codnum " << num);
    _LOG_DEBUG ("a1 sum " << m_a1.sum);
    _LOG_DEBUG ("a2 sum " << m_a2.sum);

    BOOST_CHECK(m_a1.sum == m_a2.sum && m_a1.sum == num);
  }

  void
  done(ndn::shared_ptr<boost::asio::io_service> ioService)
  {
    m_s1.reset();
    m_s2.reset();

    m_keyChain.deleteIdentity(m_name1);
    m_keyChain.deleteIdentity(m_name2);

    ioService->stop();
  }

  ndn::KeyChain m_keyChain;
  ndn::shared_ptr<ndn::SecRuleRelative> m_rule;

  TestSocketApp m_a1, m_a2;
  ndn::shared_ptr<ndn::IdentityCertificate> m_id1, m_id2;
  ndn::shared_ptr<ndn::Face> m_face1, m_face2;
  ndn::Name m_name1, m_name2;
  ndn::shared_ptr<SyncSocket> m_s1, m_s2;
};



class TestSet3{
public:
  TestSet3(ndn::shared_ptr<boost::asio::io_service> ioService)
    : m_face1(new ndn::Face(*ioService))
    , m_face2(new ndn::Face(*ioService))
    , m_name1("/xiaonei.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
    , m_name2("/mitbbs.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
  {
    m_id1 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name1));
    m_id2 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name2));

    m_rule = ndn::make_shared<ndn::SecRuleRelative>("^(<>*)<><>$",
                                                    "^(<>*)<><KEY><ksk-.*><ID-CERT>$",
                                                    "==", "\\1", "\\1", true);
  }

  void
  createSyncSocket1()
  {
    _LOG_DEBUG ("s1");

    m_s1 = ndn::shared_ptr<SyncSocket>
      (new SyncSocket("/this/is/the/prefix",
                      "/xiaonei.com",
                      1,
                      true,
                      "/abc",
                      m_face1,
                      *m_id1,
                      m_rule,
                      bind(&TestSocketApp::fetchNumbers, &m_a1, _1, _2),
                      bind(&TestSocketApp::pass, &m_a1, _1)));

    m_s1->addParticipant(*m_id2);
  }

  void
  createSyncSocket2()
  {
    _LOG_DEBUG ("s2");

    m_s2 = ndn::shared_ptr<SyncSocket>
      (new SyncSocket("/this/is/the/prefix",
                      "/mitbbs.com",
                      1,
                      false,
                      "/",
                      m_face2,
                      *m_id2,
                      m_rule,
                      bind(&TestSocketApp::fetchNumbers, &m_a2, _1, _2),
                      bind(&TestSocketApp::pass, &m_a2, _1)));

    m_s2->addParticipant(*m_id1);
  }

  void
  publishSocket1(string data)
  {
    _LOG_DEBUG ("s1 publish");
    m_s1->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000);
  }

  void
  publishSocket2(string data)
  {
    _LOG_DEBUG ("s2 publish");
    m_s2->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000);
  }

  void
  setSocket1(const char* ptr, size_t size)
  {
    _LOG_DEBUG ("a1 setNum");
    m_a1.setNum ("/xiaonei.com", ptr, size);
  }

  void
  setSocket2(const char* ptr, size_t size)
  {
    _LOG_DEBUG ("a2 setNum");
    m_a2.setNum ("/mitbbs.com", ptr, size);
  }

  void
  check(int num)
  {
    _LOG_DEBUG ("codnum " << num);
    _LOG_DEBUG ("a1 sum " << m_a1.sum);
    _LOG_DEBUG ("a2 sum " << m_a2.sum);

    BOOST_CHECK(m_a1.sum == m_a2.sum && m_a1.sum == num);
  }

  void
  done(ndn::shared_ptr<boost::asio::io_service> ioService)
  {
    m_s1.reset();
    m_s2.reset();

    m_keyChain.deleteIdentity(m_name1);
    m_keyChain.deleteIdentity(m_name2);

    ioService->stop();
  }

  ndn::KeyChain m_keyChain;
  ndn::shared_ptr<ndn::SecRuleRelative> m_rule;

  TestSocketApp m_a1, m_a2;
  ndn::shared_ptr<ndn::IdentityCertificate> m_id1, m_id2;
  ndn::shared_ptr<ndn::Face> m_face1, m_face2;
  ndn::Name m_name1, m_name2;
  ndn::shared_ptr<SyncSocket> m_s1, m_s2;
};

BOOST_AUTO_TEST_CASE (AppSocketTest1)
{
  INIT_LOGGERS ();

  ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>();
  ndn::Scheduler scheduler(*ioService);
  TestSet1 testSet1(ioService);

  scheduler.scheduleEvent(ndn::time::milliseconds(0), ndn::bind(&TestSet1::createSyncSocket1, &testSet1));
  scheduler.scheduleEvent(ndn::time::milliseconds(50), ndn::bind(&TestSet1::createSyncSocket2, &testSet1));
  scheduler.scheduleEvent(ndn::time::milliseconds(100), ndn::bind(&TestSet1::createSyncSocket3, &testSet1));
  string data0 = "Very funny Scotty, now beam down my clothes";
  scheduler.scheduleEvent(ndn::time::milliseconds(150), ndn::bind(&TestSet1::publishSocket1, &testSet1, data0));
  scheduler.scheduleEvent(ndn::time::milliseconds(1150), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/1", data0));
  scheduler.scheduleEvent(ndn::time::milliseconds(1160), ndn::bind(&TestSet1::check, &testSet1, 1));
  string data1 = "Yes, give me that ketchup";
  string data2 = "Don't look conspicuous, it draws fire";
  scheduler.scheduleEvent(ndn::time::milliseconds(1170), ndn::bind(&TestSet1::publishSocket1, &testSet1, data1));
  scheduler.scheduleEvent(ndn::time::milliseconds(1180), ndn::bind(&TestSet1::publishSocket1, &testSet1, data2));
  scheduler.scheduleEvent(ndn::time::milliseconds(2150), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/2", data1));
  scheduler.scheduleEvent(ndn::time::milliseconds(2160), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/3", data2));
  scheduler.scheduleEvent(ndn::time::milliseconds(2170), ndn::bind(&TestSet1::check, &testSet1, 2));
  string data3 = "You surf the Internet, I surf the real world";
  string data4 = "I got a fortune cookie once that said 'You like Chinese food'";
  string data5 = "Real men wear pink. Why? Because their wives make them";
  scheduler.scheduleEvent(ndn::time::milliseconds(3180), ndn::bind(&TestSet1::publishSocket3, &testSet1, data3));
  scheduler.scheduleEvent(ndn::time::milliseconds(3200), ndn::bind(&TestSet1::publishSocket2, &testSet1, data4));
  scheduler.scheduleEvent(ndn::time::milliseconds(3210), ndn::bind(&TestSet1::publishSocket2, &testSet1, data5));
  scheduler.scheduleEvent(ndn::time::milliseconds(4710), ndn::bind(&TestSet1::setSocket3, &testSet1, "/0/1", data3));
  scheduler.scheduleEvent(ndn::time::milliseconds(4720), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/2", data4));
  scheduler.scheduleEvent(ndn::time::milliseconds(4730), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/3", data5));
  scheduler.scheduleEvent(ndn::time::milliseconds(4800), ndn::bind(&TestSet1::check, &testSet1, 3));
  // not sure weither this is simultanous data generation from multiple sources
  _LOG_DEBUG ("Simultaneous publishing");
  string data6 = "Shakespeare says: 'Prose before hos.'";
  string data7 = "Pick good people, talent never wears out";
  scheduler.scheduleEvent(ndn::time::milliseconds(5500), ndn::bind(&TestSet1::publishSocket1, &testSet1, data6));
  scheduler.scheduleEvent(ndn::time::milliseconds(5500), ndn::bind(&TestSet1::publishSocket2, &testSet1, data7));
  scheduler.scheduleEvent(ndn::time::milliseconds(6800), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/4", data6));
  scheduler.scheduleEvent(ndn::time::milliseconds(6800), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/4", data7));
  scheduler.scheduleEvent(ndn::time::milliseconds(6900), ndn::bind(&TestSet1::check, &testSet1, 4));
  scheduler.scheduleEvent(ndn::time::milliseconds(7000), ndn::bind(&TestSet1::done, &testSet1, ioService));

  ioService->run();
}

BOOST_AUTO_TEST_CASE (AppSocketTest2)
{
  ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>();
  ndn::Scheduler scheduler(*ioService);
  TestSet2 testSet2(ioService);

  scheduler.scheduleEvent(ndn::time::milliseconds(0), ndn::bind(&TestSet2::createSyncSocket1, &testSet2));
  scheduler.scheduleEvent(ndn::time::milliseconds(50), ndn::bind(&TestSet2::createSyncSocket2, &testSet2));
  uint32_t num[5] = {0, 1, 2, 3, 4};
  string data0((const char *) num, sizeof(num));
  scheduler.scheduleEvent(ndn::time::milliseconds(100), ndn::bind(&TestSet2::publishSocket1, &testSet2, data0));
  scheduler.scheduleEvent(ndn::time::milliseconds(150), ndn::bind(&TestSet2::setSocket1, &testSet2, (const char *) num, sizeof (num)));
  scheduler.scheduleEvent(ndn::time::milliseconds(1000), ndn::bind(&TestSet2::check, &testSet2, 10));
  uint32_t newNum[5] = {9, 7, 2, 1, 1};
  string data1((const char *) newNum, sizeof(newNum));
  scheduler.scheduleEvent(ndn::time::milliseconds(1100), ndn::bind(&TestSet2::publishSocket2, &testSet2, data1));
  scheduler.scheduleEvent(ndn::time::milliseconds(1150), ndn::bind(&TestSet2::setSocket2, &testSet2, (const char *) newNum, sizeof (newNum)));
  scheduler.scheduleEvent(ndn::time::milliseconds(2000), ndn::bind(&TestSet2::check, &testSet2, 30));
  scheduler.scheduleEvent(ndn::time::milliseconds(7000), ndn::bind(&TestSet2::done, &testSet2, ioService));

  ioService->run();
}

BOOST_AUTO_TEST_CASE (AppSocketTest3)
{
  ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>();
  ndn::Scheduler scheduler(*ioService);
  TestSet3 testSet3(ioService);

  scheduler.scheduleEvent(ndn::time::milliseconds(0), ndn::bind(&TestSet3::createSyncSocket1, &testSet3));
  scheduler.scheduleEvent(ndn::time::milliseconds(200), ndn::bind(&TestSet3::createSyncSocket2, &testSet3));
  uint32_t num[5] = {0, 1, 2, 3, 4};
  string data0((const char *) num, sizeof(num));
  scheduler.scheduleEvent(ndn::time::milliseconds(1000), ndn::bind(&TestSet3::publishSocket1, &testSet3, data0));
  scheduler.scheduleEvent(ndn::time::milliseconds(1500), ndn::bind(&TestSet3::setSocket1, &testSet3, (const char *) num, sizeof (num)));
  scheduler.scheduleEvent(ndn::time::milliseconds(2000), ndn::bind(&TestSet3::check, &testSet3, 10));
  uint32_t newNum[5] = {9, 7, 2, 1, 1};
  string data1((const char *) newNum, sizeof(newNum));
  scheduler.scheduleEvent(ndn::time::milliseconds(3000), ndn::bind(&TestSet3::publishSocket2, &testSet3, data1));
  scheduler.scheduleEvent(ndn::time::milliseconds(3500), ndn::bind(&TestSet3::setSocket2, &testSet3, (const char *) newNum, sizeof (newNum)));
  scheduler.scheduleEvent(ndn::time::milliseconds(5000), ndn::bind(&TestSet3::check, &testSet3, 30));
  scheduler.scheduleEvent(ndn::time::milliseconds(7000), ndn::bind(&TestSet3::done, &testSet3, ioService));

  ioService->run();
}
