Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2013-2023 Regents of the University of California. |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/ims/in-memory-storage-lfu.hpp" |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 23 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 24 | #include "tests/test-common.hpp" |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 25 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame^] | 26 | namespace ndn::tests { |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 27 | |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame] | 28 | BOOST_AUTO_TEST_SUITE(Ims) |
| 29 | BOOST_AUTO_TEST_SUITE(TestInMemoryStorageLfu) |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 30 | |
| 31 | BOOST_AUTO_TEST_CASE(FrequencyQueue) |
| 32 | { |
| 33 | InMemoryStorageLfu ims; |
| 34 | |
| 35 | Name name1("/insert/1"); |
| 36 | shared_ptr<Data> data1 = makeData(name1); |
| 37 | ims.insert(*data1); |
| 38 | |
| 39 | Name name2("/insert/2"); |
| 40 | shared_ptr<Data> data2 = makeData(name2); |
| 41 | ims.insert(*data2); |
| 42 | |
| 43 | Name name3("/insert/3"); |
| 44 | shared_ptr<Data> data3 = makeData(name3); |
| 45 | ims.insert(*data3); |
| 46 | |
| 47 | shared_ptr<Interest> interest1 = makeInterest(name1); |
| 48 | shared_ptr<Interest> interest2 = makeInterest(name2); |
| 49 | shared_ptr<Interest> interest3 = makeInterest(name3); |
| 50 | |
| 51 | ims.find(*interest1); |
| 52 | ims.find(*interest2); |
| 53 | ims.find(*interest3); |
| 54 | ims.find(*interest1); |
| 55 | ims.find(*interest3); |
| 56 | ims.find(*interest3); |
| 57 | |
| 58 | ims.evictItem(); |
| 59 | BOOST_CHECK_EQUAL(ims.size(), 2); |
| 60 | |
| 61 | shared_ptr<const Data> found2 = ims.find(*interest2); |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 62 | BOOST_CHECK(found2 == nullptr); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 63 | |
| 64 | shared_ptr<const Data> found1 = ims.find(*interest1); |
| 65 | BOOST_CHECK_EQUAL(found1->getName(), name1); |
| 66 | shared_ptr<const Data> found3 = ims.find(*interest3); |
| 67 | BOOST_CHECK_EQUAL(found3->getName(), name3); |
| 68 | } |
| 69 | |
| 70 | BOOST_AUTO_TEST_CASE(FrequencyQueue2) |
| 71 | { |
| 72 | InMemoryStorageLfu ims; |
| 73 | |
| 74 | Name name1("/insert/1"); |
| 75 | shared_ptr<Data> data1 = makeData(name1); |
| 76 | ims.insert(*data1); |
| 77 | |
| 78 | Name name2("/insert/2"); |
| 79 | shared_ptr<Data> data2 = makeData(name2); |
| 80 | ims.insert(*data2); |
| 81 | |
| 82 | Name name3("/insert/3"); |
| 83 | shared_ptr<Data> data3 = makeData(name3); |
| 84 | ims.insert(*data3); |
| 85 | |
| 86 | shared_ptr<Interest> interest1 = makeInterest(name1); |
| 87 | shared_ptr<Interest> interest2 = makeInterest(name2); |
| 88 | shared_ptr<Interest> interest3 = makeInterest(name3); |
| 89 | |
| 90 | ims.find(*interest1); |
| 91 | ims.find(*interest2); |
| 92 | ims.find(*interest3); |
| 93 | ims.find(*interest1); |
| 94 | ims.find(*interest3); |
| 95 | ims.find(*interest3); |
| 96 | |
| 97 | ims.evictItem(); |
| 98 | BOOST_CHECK_EQUAL(ims.size(), 2); |
| 99 | |
| 100 | shared_ptr<const Data> found2 = ims.find(*interest2); |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 101 | BOOST_CHECK(found2 == nullptr); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 102 | |
| 103 | shared_ptr<const Data> found1 = ims.find(*interest1); |
| 104 | BOOST_CHECK_EQUAL(found1->getName(), name1); |
| 105 | shared_ptr<const Data> found3 = ims.find(*interest3); |
| 106 | BOOST_CHECK_EQUAL(found3->getName(), name3); |
| 107 | |
| 108 | Name name4("/insert/4"); |
| 109 | shared_ptr<Data> data4 = makeData(name4); |
| 110 | ims.insert(*data4); |
| 111 | |
| 112 | shared_ptr<Interest> interest4 = makeInterest(name4); |
| 113 | ims.find(*interest4); |
| 114 | |
| 115 | ims.evictItem(); |
| 116 | BOOST_CHECK_EQUAL(ims.size(), 2); |
| 117 | |
| 118 | shared_ptr<const Data> found4 = ims.find(*interest4); |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 119 | BOOST_CHECK(found4 == nullptr); |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 120 | |
| 121 | found1 = ims.find(*interest1); |
| 122 | BOOST_CHECK_EQUAL(found1->getName(), name1); |
| 123 | found3 = ims.find(*interest3); |
| 124 | BOOST_CHECK_EQUAL(found3->getName(), name3); |
| 125 | } |
| 126 | |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame] | 127 | BOOST_AUTO_TEST_SUITE_END() // TestInMemoryStorageLfu |
| 128 | BOOST_AUTO_TEST_SUITE_END() // Ims |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 129 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame^] | 130 | } // namespace ndn::tests |