blob: deab560be84d7d0240e3ffb7fb328bce65c42f8c [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Junxiao Shi32ccfc42022-01-09 21:26:22 +00003 * 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/>.
18 **/
19
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060020#include "PSync/producer-base.hpp"
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050021
Davide Pesavento5b3cf762020-04-03 16:20:04 -040022#include "tests/boost-test.hpp"
23
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050024#include <ndn-cxx/data.hpp>
25#include <ndn-cxx/interest.hpp>
26#include <ndn-cxx/util/dummy-client-face.hpp>
27
28namespace psync {
29
30using namespace ndn;
31
32BOOST_AUTO_TEST_SUITE(TestProducerBase)
33
Davide Pesaventodb789562020-12-19 23:01:08 -050034BOOST_AUTO_TEST_CASE(Constructor)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050035{
36 util::DummyClientFace face;
Davide Pesaventoc407dee2022-07-21 23:56:05 -040037 BOOST_CHECK_NO_THROW(ProducerBase(40, face, Name("/psync"), Name("/testUser")));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050038}
39
40BOOST_AUTO_TEST_CASE(Basic)
41{
42 util::DummyClientFace face;
43 Name userNode("/testUser");
44 ProducerBase producerBase(40, face, Name("/psync"), userNode);
45 // Hash table size should be 40 + 40/2 = 60 (which is perfectly divisible by N_HASH = 3)
46 BOOST_CHECK_EQUAL(producerBase.m_iblt.getHashTable().size(), 60);
47 BOOST_CHECK_EQUAL(producerBase.getSeqNo(userNode).value(), 0);
48
49 producerBase.updateSeqNo(userNode, 1);
Junxiao Shi32ccfc42022-01-09 21:26:22 +000050 BOOST_CHECK(producerBase.getSeqNo(userNode).value() == 1);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050051
Junxiao Shi32ccfc42022-01-09 21:26:22 +000052 auto prefixWithSeq = Name(userNode).appendNumber(1);
Ashlesh Gawande6a5157f2019-12-09 11:49:07 -060053 uint32_t hash = producerBase.m_biMap.right.find(prefixWithSeq)->second;
54 Name prefix(producerBase.m_biMap.left.find(hash)->second);
55 BOOST_CHECK_EQUAL(prefix.getPrefix(-1), userNode);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050056
57 producerBase.removeUserNode(userNode);
Davide Pesaventoc407dee2022-07-21 23:56:05 -040058 BOOST_CHECK(producerBase.getSeqNo(userNode) == std::nullopt);
Ashlesh Gawande6a5157f2019-12-09 11:49:07 -060059 BOOST_CHECK(producerBase.m_biMap.right.find(prefixWithSeq) == producerBase.m_biMap.right.end());
60 BOOST_CHECK(producerBase.m_biMap.left.find(hash) == producerBase.m_biMap.left.end());
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050061
62 Name nonExistentUserNode("/notAUser");
63 producerBase.updateSeqNo(nonExistentUserNode, 1);
Junxiao Shi32ccfc42022-01-09 21:26:22 +000064 BOOST_CHECK(producerBase.m_biMap.right.find(Name(nonExistentUserNode).appendNumber(1)) ==
Ashlesh Gawande6a5157f2019-12-09 11:49:07 -060065 producerBase.m_biMap.right.end());
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050066}
67
68BOOST_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);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050074 producerBase.m_syncReplyFreshness = 1_s;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050075 producerBase.sendApplicationNack(Name("test"));
Davide Pesaventof91d1df2020-11-25 14:50:41 -050076 face.processEvents(10_ms);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050077
Davide Pesavento5b3cf762020-04-03 16:20:04 -040078 BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050079 BOOST_CHECK_EQUAL(face.sentData.front().getContentType(), tlv::ContentType_Nack);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050080}
81
82BOOST_AUTO_TEST_SUITE_END()
83
84} // namespace psync