blob: 62715bb44832276a4c1c904a0e6d585593947622 [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento03426ef2022-09-23 19:49:10 -04003 * Copyright (c) 2014-2022, The University of Memphis
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05004 *
5 * This file is part of PSync.
6 * See AUTHORS.md for complete list of PSync authors and contributors.
7 *
8 * PSync is free software: you can redistribute it and/or modify it under the terms
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -06009 * of the GNU Lesser General Public License as published by the Free Software Foundation,
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050010 * either version 3 of the License, or (at your option) any later version.
11 *
12 * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -060014 * PURPOSE. See the GNU Lesser General Public License for more details.
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050015 *
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -060016 * You should have received a copy of the GNU Lesser General Public License along with
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050017 * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -070018 */
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050019
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060020#include "PSync/consumer.hpp"
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050021
Davide Pesavento5b3cf762020-04-03 16:20:04 -040022#include "tests/boost-test.hpp"
Davide Pesaventof91d1df2020-11-25 14:50:41 -050023#include "tests/io-fixture.hpp"
Davide Pesavento5b3cf762020-04-03 16:20:04 -040024
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050025#include <ndn-cxx/util/dummy-client-face.hpp>
26
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050027namespace psync {
28
29using namespace ndn;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050030
31BOOST_AUTO_TEST_SUITE(TestConsumer)
32
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050033BOOST_AUTO_TEST_CASE(AddSubscription)
34{
Davide Pesavento03426ef2022-09-23 19:49:10 -040035 util::DummyClientFace face;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050036 Consumer consumer(Name("/psync"), face,
Davide Pesavento5b3cf762020-04-03 16:20:04 -040037 [] (const auto&) {},
38 [] (const auto&) {},
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050039 40, 0.001);
40
41 Name subscription("test");
42
43 BOOST_CHECK(!consumer.isSubscribed(subscription));
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -070044 BOOST_CHECK(consumer.addSubscription(subscription, 0));
45 BOOST_CHECK(!consumer.addSubscription(subscription, 0));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050046}
47
Saurab Dulal737f2de2022-11-09 17:14:46 +000048BOOST_AUTO_TEST_CASE(RemoveSubscription)
49{
50 util::DummyClientFace face;
51 Consumer consumer(Name("/psync"), face,
52 [] (const auto&) {},
53 [] (const auto&) {},
54 40, 0.001);
55
56 Name subscription("test");
57 consumer.addSubscription(subscription, 0);
58
59 BOOST_CHECK(consumer.isSubscribed(subscription));
60 BOOST_CHECK(consumer.removeSubscription(subscription));
61 BOOST_CHECK(!consumer.removeSubscription(subscription));
62 BOOST_CHECK(!consumer.isSubscribed(subscription));
63}
64
Davide Pesaventof91d1df2020-11-25 14:50:41 -050065BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::IoFixture)
Ashlesh Gawande584e1202019-05-19 16:15:33 -070066{
Davide Pesavento03426ef2022-09-23 19:49:10 -040067 util::DummyClientFace face(m_io);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070068 Consumer consumer(Name("/psync"), face,
Davide Pesavento5b3cf762020-04-03 16:20:04 -040069 [] (const auto&) {},
70 [] (const auto&) {},
Davide Pesaventof91d1df2020-11-25 14:50:41 -050071 40, 0.001, 4_s, 4_s);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070072
73 consumer.sendHelloInterest();
Ashlesh Gawande8ab75722020-08-02 22:42:28 -070074 advanceClocks(4_s);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070075 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
76 face.sentInterests.clear();
77 consumer.stop();
78
Davide Pesaventof91d1df2020-11-25 14:50:41 -050079 consumer.m_iblt = Name("test");
Ashlesh Gawande584e1202019-05-19 16:15:33 -070080 consumer.sendSyncInterest();
Ashlesh Gawande8ab75722020-08-02 22:42:28 -070081 advanceClocks(3999_ms);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070082 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
83 consumer.stop();
84}
85
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050086BOOST_AUTO_TEST_SUITE_END()
87
Davide Pesavento5b3cf762020-04-03 16:20:04 -040088} // namespace psync