Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Ashlesh Gawande | 6a5157f | 2019-12-09 11:49:07 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, 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/>. |
| 18 | **/ |
| 19 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 20 | #include "PSync/producer-base.hpp" |
| 21 | #include "PSync/detail/util.hpp" |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 22 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 23 | #include "tests/boost-test.hpp" |
| 24 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 25 | #include <ndn-cxx/data.hpp> |
| 26 | #include <ndn-cxx/interest.hpp> |
| 27 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 28 | |
| 29 | namespace psync { |
| 30 | |
| 31 | using namespace ndn; |
| 32 | |
| 33 | BOOST_AUTO_TEST_SUITE(TestProducerBase) |
| 34 | |
| 35 | BOOST_AUTO_TEST_CASE(Ctor) |
| 36 | { |
| 37 | util::DummyClientFace face; |
| 38 | BOOST_REQUIRE_NO_THROW(ProducerBase(40, face, Name("/psync"), Name("/testUser"))); |
| 39 | } |
| 40 | |
| 41 | BOOST_AUTO_TEST_CASE(Basic) |
| 42 | { |
| 43 | util::DummyClientFace face; |
| 44 | Name userNode("/testUser"); |
| 45 | ProducerBase producerBase(40, face, Name("/psync"), userNode); |
| 46 | // Hash table size should be 40 + 40/2 = 60 (which is perfectly divisible by N_HASH = 3) |
| 47 | BOOST_CHECK_EQUAL(producerBase.m_iblt.getHashTable().size(), 60); |
| 48 | BOOST_CHECK_EQUAL(producerBase.getSeqNo(userNode).value(), 0); |
| 49 | |
| 50 | producerBase.updateSeqNo(userNode, 1); |
| 51 | BOOST_CHECK(producerBase.getSeqNo(userNode.toUri()).value() == 1); |
| 52 | |
| 53 | std::string prefixWithSeq = Name(userNode).appendNumber(1).toUri(); |
Ashlesh Gawande | 6a5157f | 2019-12-09 11:49:07 -0600 | [diff] [blame] | 54 | uint32_t hash = producerBase.m_biMap.right.find(prefixWithSeq)->second; |
| 55 | Name prefix(producerBase.m_biMap.left.find(hash)->second); |
| 56 | BOOST_CHECK_EQUAL(prefix.getPrefix(-1), userNode); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 57 | |
| 58 | producerBase.removeUserNode(userNode); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame^] | 59 | BOOST_CHECK(producerBase.getSeqNo(userNode.toUri()) == nullopt); |
Ashlesh Gawande | 6a5157f | 2019-12-09 11:49:07 -0600 | [diff] [blame] | 60 | BOOST_CHECK(producerBase.m_biMap.right.find(prefixWithSeq) == producerBase.m_biMap.right.end()); |
| 61 | BOOST_CHECK(producerBase.m_biMap.left.find(hash) == producerBase.m_biMap.left.end()); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 62 | |
| 63 | Name nonExistentUserNode("/notAUser"); |
| 64 | producerBase.updateSeqNo(nonExistentUserNode, 1); |
Ashlesh Gawande | 6a5157f | 2019-12-09 11:49:07 -0600 | [diff] [blame] | 65 | BOOST_CHECK(producerBase.m_biMap.right.find(Name(nonExistentUserNode).appendNumber(1).toUri()) == |
| 66 | producerBase.m_biMap.right.end()); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | BOOST_AUTO_TEST_CASE(ApplicationNack) |
| 70 | { |
| 71 | util::DummyClientFace face; |
| 72 | ProducerBase producerBase(40, face, Name("/psync"), Name("/testUser")); |
| 73 | |
| 74 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame^] | 75 | producerBase.m_syncReplyFreshness = 1_s; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 76 | producerBase.sendApplicationNack(Name("test")); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame^] | 77 | face.processEvents(10_ms); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 78 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 79 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 1); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame^] | 80 | BOOST_CHECK_EQUAL(face.sentData.front().getContentType(), tlv::ContentType_Nack); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | BOOST_AUTO_TEST_SUITE_END() |
| 84 | |
| 85 | } // namespace psync |