Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2014-2018, The University of Memphis |
| 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 |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 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 |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
| 19 | |
| 20 | #include "producer-base.hpp" |
| 21 | #include "detail/util.hpp" |
| 22 | |
| 23 | #include <boost/test/unit_test.hpp> |
| 24 | #include <ndn-cxx/name.hpp> |
| 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(); |
| 54 | uint32_t hash = producerBase.m_prefix2hash[prefixWithSeq]; |
| 55 | BOOST_CHECK_EQUAL(producerBase.m_hash2prefix[hash], userNode.toUri()); |
| 56 | |
| 57 | producerBase.removeUserNode(userNode); |
| 58 | BOOST_CHECK(producerBase.getSeqNo(userNode.toUri()) == ndn::nullopt); |
| 59 | BOOST_CHECK(producerBase.m_prefix2hash.find(prefixWithSeq) == producerBase.m_prefix2hash.end()); |
| 60 | BOOST_CHECK(producerBase.m_hash2prefix.find(hash) == producerBase.m_hash2prefix.end()); |
| 61 | |
| 62 | Name nonExistentUserNode("/notAUser"); |
| 63 | producerBase.updateSeqNo(nonExistentUserNode, 1); |
| 64 | BOOST_CHECK(producerBase.m_prefix2hash.find(Name(nonExistentUserNode).appendNumber(1).toUri()) == |
| 65 | producerBase.m_prefix2hash.end()); |
| 66 | } |
| 67 | |
| 68 | BOOST_AUTO_TEST_CASE(ApplicationNack) |
| 69 | { |
| 70 | util::DummyClientFace face; |
| 71 | ProducerBase producerBase(40, face, Name("/psync"), Name("/testUser")); |
| 72 | |
| 73 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
| 74 | producerBase.m_syncReplyFreshness = time::milliseconds(1000); |
| 75 | producerBase.sendApplicationNack(Name("test")); |
| 76 | face.processEvents(time::milliseconds(10)); |
| 77 | BOOST_CHECK_EQUAL(face.sentData.size(), 1); |
| 78 | |
| 79 | Data data = *face.sentData.begin(); |
| 80 | BOOST_CHECK_EQUAL(data.getContentType(), ndn::tlv::ContentType_Nack); |
| 81 | } |
| 82 | |
| 83 | BOOST_AUTO_TEST_SUITE_END() |
| 84 | |
| 85 | } // namespace psync |