Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | bb6146e | 2017-07-26 23:07:52 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 26 | #include "table/cs-policy-lru.hpp" |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 27 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 28 | #include "tests/daemon/table/cs-fixture.hpp" |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 29 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 30 | namespace nfd::tests { |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 31 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 32 | BOOST_AUTO_TEST_SUITE(Table) |
| 33 | BOOST_AUTO_TEST_SUITE(TestCsLru) |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 34 | |
Junxiao Shi | 7ee00fb | 2016-12-04 21:23:00 +0000 | [diff] [blame] | 35 | BOOST_AUTO_TEST_CASE(Registration) |
| 36 | { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 37 | std::set<std::string> policyNames = cs::Policy::getPolicyNames(); |
Junxiao Shi | 7ee00fb | 2016-12-04 21:23:00 +0000 | [diff] [blame] | 38 | BOOST_CHECK_EQUAL(policyNames.count("lru"), 1); |
| 39 | } |
| 40 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 41 | BOOST_FIXTURE_TEST_CASE(EvictOne, CsFixture) |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 42 | { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 43 | cs.setPolicy(make_unique<cs::LruPolicy>()); |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 44 | cs.setLimit(3); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 45 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 46 | insert(1, "/A"); |
| 47 | insert(2, "/B"); |
| 48 | insert(3, "/C"); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 49 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 50 | |
| 51 | // evict A |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 52 | insert(4, "/D"); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 53 | BOOST_CHECK_EQUAL(cs.size(), 3); |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 54 | startInterest("/A"); |
| 55 | CHECK_CS_FIND(0); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 56 | |
| 57 | // use C then B |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 58 | startInterest("/C"); |
| 59 | CHECK_CS_FIND(3); |
| 60 | startInterest("/B"); |
| 61 | CHECK_CS_FIND(2); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 62 | |
| 63 | // evict D then C |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 64 | insert(5, "/E"); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 65 | BOOST_CHECK_EQUAL(cs.size(), 3); |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 66 | startInterest("/D"); |
| 67 | CHECK_CS_FIND(0); |
| 68 | insert(6, "/F"); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(cs.size(), 3); |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 70 | startInterest("/C"); |
| 71 | CHECK_CS_FIND(0); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 72 | |
| 73 | // refresh B |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 74 | insert(12, "/B"); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 75 | // evict E |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 76 | insert(7, "/G"); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 77 | BOOST_CHECK_EQUAL(cs.size(), 3); |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 78 | startInterest("/E"); |
| 79 | CHECK_CS_FIND(0); |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 80 | } |
| 81 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 82 | BOOST_AUTO_TEST_SUITE_END() // TestCsLru |
| 83 | BOOST_AUTO_TEST_SUITE_END() // Table |
Minsheng Zhang | 0315269 | 2015-07-28 11:53:21 -0500 | [diff] [blame] | 84 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 85 | } // namespace nfd::tests |