blob: 7cca0ebc6a93df5b09ea13c27ef9c2d3e911a6d5 [file] [log] [blame]
Alexander Afanasyeva022f3d2012-03-11 18:14:48 -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>
19 * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
20 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
23#include <boost/test/unit_test.hpp>
24#include <boost/test/output_test_stream.hpp>
25#include <map>
26using boost::test_tools::output_test_stream;
27
28#include <boost/make_shared.hpp>
29
30#include "../model/sync-interest-table.h"
Alexander Afanasyev387ac952012-03-11 23:49:27 -070031#include "../model/sync-logic.h"
Alexander Afanasyeva022f3d2012-03-11 18:14:48 -070032
33using namespace Sync;
34using namespace std;
35using namespace boost;
36
37BOOST_AUTO_TEST_CASE (InterestTableTest)
38{
39 SyncInterestTable *table = 0;
40 BOOST_CHECK_NO_THROW (table = new SyncInterestTable ());
41
42 BOOST_CHECK_NO_THROW (delete table);
43}
44
Alexander Afanasyev387ac952012-03-11 23:49:27 -070045void func (const std::string &, uint32_t, uint32_t)
46{
47 cout << "func\n";
48}
49
50BOOST_AUTO_TEST_CASE (SyncLogicTest)
51{
52 SyncLogic *logic = 0;
53 BOOST_CHECK_NO_THROW (logic = new SyncLogic ("/prefix", func, make_shared<CcnxWrapper> ()));
54 BOOST_CHECK_EQUAL (logic->getListChecksSize (), 0);
55
56 // 0s
57 BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"));
58 sleep (1);
59
60 // 1s
61 BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"));
62 sleep (1);
63
64 // 2s
65 // cout << "Wait queue size: " << logic->getListChecksSize () << endl;
66 BOOST_CHECK_EQUAL (logic->getListChecksSize (), 1);
67
68 // 2s
69 BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"));
70 // cout << "Wait queue size: " << logic->getListChecksSize () << endl;
71 BOOST_CHECK_EQUAL (logic->getListChecksSize (), 2);
72
73 this_thread::sleep (posix_time::milliseconds (2500)); // make two interests expire
74
75 // 4.5s
76 // cout << "(after 3.3s) Wait queue size: " << logic->getListChecksSize () << endl;
77 BOOST_CHECK_EQUAL (logic->getListChecksSize (), 1);
78
79 BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"));
80 sleep (5);
81 BOOST_CHECK_EQUAL (logic->getListChecksSize (), 0);
82
83 BOOST_CHECK_NO_THROW (delete logic);
84}
85