Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, The University of Memphis |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 4 | * |
| 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 Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 9 | * of the GNU Lesser General Public License as published by the Free Software Foundation, |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 10 | * 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 Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 14 | * PURPOSE. See the GNU Lesser General Public License for more details. |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 15 | * |
Ashlesh Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 16 | * You should have received a copy of the GNU Lesser General Public License along with |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 17 | * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 18 | */ |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 19 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 20 | #include "PSync/consumer.hpp" |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 21 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 22 | #include "tests/boost-test.hpp" |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 23 | #include "tests/io-fixture.hpp" |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 24 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 25 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 26 | |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 27 | namespace psync::tests { |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 28 | |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 29 | using ndn::Name; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 30 | |
| 31 | BOOST_AUTO_TEST_SUITE(TestConsumer) |
| 32 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 33 | BOOST_AUTO_TEST_CASE(AddSubscription) |
| 34 | { |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 35 | ndn::DummyClientFace face; |
Junxiao Shi | 7639daa | 2023-08-11 16:40:54 +0000 | [diff] [blame] | 36 | Consumer::Options opts; |
| 37 | opts.bfCount = 40; |
| 38 | Consumer consumer(face, "/psync", opts); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 39 | |
| 40 | Name subscription("test"); |
| 41 | |
| 42 | BOOST_CHECK(!consumer.isSubscribed(subscription)); |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 43 | BOOST_CHECK(consumer.addSubscription(subscription, 0)); |
| 44 | BOOST_CHECK(!consumer.addSubscription(subscription, 0)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 45 | } |
| 46 | |
Saurab Dulal | 737f2de | 2022-11-09 17:14:46 +0000 | [diff] [blame] | 47 | BOOST_AUTO_TEST_CASE(RemoveSubscription) |
| 48 | { |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 49 | ndn::DummyClientFace face; |
Junxiao Shi | 7639daa | 2023-08-11 16:40:54 +0000 | [diff] [blame] | 50 | Consumer::Options opts; |
| 51 | opts.bfCount = 40; |
| 52 | Consumer consumer(face, "/psync", opts); |
Saurab Dulal | 737f2de | 2022-11-09 17:14:46 +0000 | [diff] [blame] | 53 | |
| 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 Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 63 | BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, IoFixture) |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 64 | { |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 65 | ndn::DummyClientFace face(m_io); |
Junxiao Shi | 7639daa | 2023-08-11 16:40:54 +0000 | [diff] [blame] | 66 | Consumer::Options opts; |
| 67 | opts.bfCount = 40; |
| 68 | opts.helloInterestLifetime = 4_s; |
| 69 | opts.syncInterestLifetime = 4_s; |
| 70 | Consumer consumer(face, "/psync", opts); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 71 | |
| 72 | consumer.sendHelloInterest(); |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 73 | advanceClocks(4_s); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 74 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 75 | face.sentInterests.clear(); |
| 76 | consumer.stop(); |
| 77 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 78 | consumer.m_iblt = Name("test"); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 79 | consumer.sendSyncInterest(); |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 80 | advanceClocks(3999_ms); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 81 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 82 | consumer.stop(); |
| 83 | } |
| 84 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 85 | BOOST_AUTO_TEST_SUITE_END() |
| 86 | |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 87 | } // namespace psync::tests |