blob: 9057c1b7bfbdb34810c03246a6cc3f771812ba7a [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento47eb6d92024-02-12 20:25:51 -05003 * Copyright (c) 2014-2024, 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
Davide Pesavento47eb6d92024-02-12 20:25:51 -050027namespace psync::tests {
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050028
Junxiao Shic5f5eb12023-08-11 08:05:23 +000029using ndn::Name;
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{
Junxiao Shic5f5eb12023-08-11 08:05:23 +000035 ndn::DummyClientFace face;
Junxiao Shi7639daa2023-08-11 16:40:54 +000036 Consumer::Options opts;
37 opts.bfCount = 40;
38 Consumer consumer(face, "/psync", opts);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050039
40 Name subscription("test");
41
42 BOOST_CHECK(!consumer.isSubscribed(subscription));
Ashlesh Gawandecbdc0122020-07-13 21:13:00 -070043 BOOST_CHECK(consumer.addSubscription(subscription, 0));
44 BOOST_CHECK(!consumer.addSubscription(subscription, 0));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050045}
46
Saurab Dulal737f2de2022-11-09 17:14:46 +000047BOOST_AUTO_TEST_CASE(RemoveSubscription)
48{
Junxiao Shic5f5eb12023-08-11 08:05:23 +000049 ndn::DummyClientFace face;
Junxiao Shi7639daa2023-08-11 16:40:54 +000050 Consumer::Options opts;
51 opts.bfCount = 40;
52 Consumer consumer(face, "/psync", opts);
Saurab Dulal737f2de2022-11-09 17:14:46 +000053
54 Name subscription("test");
55 consumer.addSubscription(subscription, 0);
56
57 BOOST_CHECK(consumer.isSubscribed(subscription));
58 BOOST_CHECK(consumer.removeSubscription(subscription));
59 BOOST_CHECK(!consumer.removeSubscription(subscription));
60 BOOST_CHECK(!consumer.isSubscribed(subscription));
61}
62
Davide Pesavento47eb6d92024-02-12 20:25:51 -050063BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, IoFixture)
Ashlesh Gawande584e1202019-05-19 16:15:33 -070064{
Junxiao Shic5f5eb12023-08-11 08:05:23 +000065 ndn::DummyClientFace face(m_io);
Junxiao Shi7639daa2023-08-11 16:40:54 +000066 Consumer::Options opts;
67 opts.bfCount = 40;
68 opts.helloInterestLifetime = 4_s;
69 opts.syncInterestLifetime = 4_s;
70 Consumer consumer(face, "/psync", opts);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070071
72 consumer.sendHelloInterest();
Ashlesh Gawande8ab75722020-08-02 22:42:28 -070073 advanceClocks(4_s);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070074 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
75 face.sentInterests.clear();
76 consumer.stop();
77
Davide Pesaventof91d1df2020-11-25 14:50:41 -050078 consumer.m_iblt = Name("test");
Ashlesh Gawande584e1202019-05-19 16:15:33 -070079 consumer.sendSyncInterest();
Ashlesh Gawande8ab75722020-08-02 22:42:28 -070080 advanceClocks(3999_ms);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070081 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
82 consumer.stop();
83}
84
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050085BOOST_AUTO_TEST_SUITE_END()
86
Davide Pesavento47eb6d92024-02-12 20:25:51 -050087} // namespace psync::tests