blob: ce19f94e913e14e8c6d5d514d7b3c2224ec5fd5f [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis.
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
*
* NFD is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#include "table/cs-policy-lru.hpp"
#include "tests/daemon/table/cs-fixture.hpp"
namespace nfd::tests {
BOOST_AUTO_TEST_SUITE(Table)
BOOST_AUTO_TEST_SUITE(TestCsLru)
BOOST_AUTO_TEST_CASE(Registration)
{
std::set<std::string> policyNames = cs::Policy::getPolicyNames();
BOOST_CHECK_EQUAL(policyNames.count("lru"), 1);
}
BOOST_FIXTURE_TEST_CASE(EvictOne, CsFixture)
{
cs.setPolicy(make_unique<cs::LruPolicy>());
cs.setLimit(3);
insert(1, "/A");
insert(2, "/B");
insert(3, "/C");
BOOST_CHECK_EQUAL(cs.size(), 3);
// evict A
insert(4, "/D");
BOOST_CHECK_EQUAL(cs.size(), 3);
startInterest("/A");
CHECK_CS_FIND(0);
// use C then B
startInterest("/C");
CHECK_CS_FIND(3);
startInterest("/B");
CHECK_CS_FIND(2);
// evict D then C
insert(5, "/E");
BOOST_CHECK_EQUAL(cs.size(), 3);
startInterest("/D");
CHECK_CS_FIND(0);
insert(6, "/F");
BOOST_CHECK_EQUAL(cs.size(), 3);
startInterest("/C");
CHECK_CS_FIND(0);
// refresh B
insert(12, "/B");
// evict E
insert(7, "/G");
BOOST_CHECK_EQUAL(cs.size(), 3);
startInterest("/E");
CHECK_CS_FIND(0);
}
BOOST_AUTO_TEST_SUITE_END() // TestCsLru
BOOST_AUTO_TEST_SUITE_END() // Table
} // namespace nfd::tests