diff --git a/implementations/caching/cache/QueueMap.h b/implementations/caching/cache/QueueMap.h index c660dc86..6d36a13c 100644 --- a/implementations/caching/cache/QueueMap.h +++ b/implementations/caching/cache/QueueMap.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace blockstore { namespace caching { diff --git a/test/implementations/caching/cache/CacheTest_MoveConstructor.cpp b/test/implementations/caching/cache/CacheTest_MoveConstructor.cpp index 6bb1d4f6..fa00da2d 100644 --- a/test/implementations/caching/cache/CacheTest_MoveConstructor.cpp +++ b/test/implementations/caching/cache/CacheTest_MoveConstructor.cpp @@ -13,10 +13,10 @@ using ::testing::Test; //Test that Cache uses a move constructor for Value if possible class CacheTest_MoveConstructor: public Test { public: - CacheTest_MoveConstructor(): cache(make_unique_ref>()) { + CacheTest_MoveConstructor(): cache(make_unique_ref>()) { CopyableMovableValueType::numCopyConstructorCalled = 0; } - unique_ref> cache; + unique_ref> cache; }; TEST_F(CacheTest_MoveConstructor, MoveIntoCache) { diff --git a/test/implementations/caching/cache/CacheTest_PushAndPop.cpp b/test/implementations/caching/cache/CacheTest_PushAndPop.cpp index f1efd267..df036f70 100644 --- a/test/implementations/caching/cache/CacheTest_PushAndPop.cpp +++ b/test/implementations/caching/cache/CacheTest_PushAndPop.cpp @@ -22,7 +22,7 @@ TEST_F(CacheTest_PushAndPop, PopNonExistingEntry_NonEmptyCache) { TEST_F(CacheTest_PushAndPop, PopNonExistingEntry_FullCache) { //Add a lot of even numbered keys - for (unsigned int i = 0; i < Cache::MAX_ENTRIES; ++i) { + for (unsigned int i = 0; i < MAX_ENTRIES; ++i) { push(2*i, 2*i); } //Request an odd numbered key @@ -44,34 +44,34 @@ TEST_F(CacheTest_PushAndPop, MultipleEntries) { } TEST_F(CacheTest_PushAndPop, FullCache) { - for(unsigned int i = 0; i < Cache::MAX_ENTRIES; ++i) { + for(unsigned int i = 0; i < MAX_ENTRIES; ++i) { push(i, 2*i); } - for(unsigned int i = 0; i < Cache::MAX_ENTRIES; ++i) { + for(unsigned int i = 0; i < MAX_ENTRIES; ++i) { EXPECT_EQ(2*i, pop(i).value()); } } TEST_F(CacheTest_PushAndPop, FullCache_PushNonOrdered_PopOrdered) { - for(unsigned int i = 1; i < Cache::MAX_ENTRIES; i += 2) { + for(unsigned int i = 1; i < MAX_ENTRIES; i += 2) { push(i, 2*i); } - for(unsigned int i = 0; i < Cache::MAX_ENTRIES; i += 2) { + for(unsigned int i = 0; i < MAX_ENTRIES; i += 2) { push(i, 2*i); } - for(unsigned int i = 0; i < Cache::MAX_ENTRIES; ++i) { + for(unsigned int i = 0; i < MAX_ENTRIES; ++i) { EXPECT_EQ(2*i, pop(i).value()); } } TEST_F(CacheTest_PushAndPop, FullCache_PushOrdered_PopNonOrdered) { - for(unsigned int i = 0; i < Cache::MAX_ENTRIES; ++i) { + for(unsigned int i = 0; i < MAX_ENTRIES; ++i) { push(i, 2*i); } - for(unsigned int i = 1; i < Cache::MAX_ENTRIES; i += 2) { + for(unsigned int i = 1; i < MAX_ENTRIES; i += 2) { EXPECT_EQ(2*i, pop(i).value()); } - for(unsigned int i = 0; i < Cache::MAX_ENTRIES; i += 2) { + for(unsigned int i = 0; i < MAX_ENTRIES; i += 2) { EXPECT_EQ(2*i, pop(i).value()); } } @@ -93,29 +93,29 @@ int roundDownToOdd(int number) { } TEST_F(CacheTest_PushAndPop, FullCache_PushNonOrdered_PopNonOrdered) { - for(int i = roundDownToEven(Cache::MAX_ENTRIES - 1); i >= 0; i -= 2) { + for(int i = roundDownToEven(MAX_ENTRIES - 1); i >= 0; i -= 2) { push(i, 2*i); } - for(unsigned int i = 1; i < Cache::MAX_ENTRIES; i += 2) { + for(unsigned int i = 1; i < MAX_ENTRIES; i += 2) { push(i, 2*i); } - for(int i = roundDownToOdd(Cache::MAX_ENTRIES-1); i >= 0; i -= 2) { + for(int i = roundDownToOdd(MAX_ENTRIES-1); i >= 0; i -= 2) { EXPECT_EQ(2*i, pop(i).value()); } - for(unsigned int i = 0; i < Cache::MAX_ENTRIES; i += 2) { + for(unsigned int i = 0; i < MAX_ENTRIES; i += 2) { EXPECT_EQ(2*i, pop(i).value()); } } TEST_F(CacheTest_PushAndPop, MoreThanFullCache) { - for(unsigned int i = 0; i < Cache::MAX_ENTRIES + 2; ++i) { + for(unsigned int i = 0; i < MAX_ENTRIES + 2; ++i) { push(i, 2*i); } //Check that the oldest two elements got deleted automatically EXPECT_EQ(boost::none, pop(0)); EXPECT_EQ(boost::none, pop(1)); //Check the other elements are still there - for(unsigned int i = 2; i < Cache::MAX_ENTRIES + 2; ++i) { + for(unsigned int i = 2; i < MAX_ENTRIES + 2; ++i) { EXPECT_EQ(2*i, pop(i).value()); } } diff --git a/test/implementations/caching/cache/CacheTest_RaceCondition.cpp b/test/implementations/caching/cache/CacheTest_RaceCondition.cpp index 7a7741ad..685e50f6 100644 --- a/test/implementations/caching/cache/CacheTest_RaceCondition.cpp +++ b/test/implementations/caching/cache/CacheTest_RaceCondition.cpp @@ -36,7 +36,9 @@ class CacheTest_RaceCondition: public ::testing::Test { public: CacheTest_RaceCondition(): cache(), destructorStarted(), destructorFinished(false) {} - Cache> cache; + static constexpr unsigned int MAX_ENTRIES = 100; + + Cache, MAX_ENTRIES> cache; ConditionBarrier destructorStarted; bool destructorFinished; @@ -53,8 +55,8 @@ public: future causeCacheOverflowInOtherThread() { //Add maximum+1 element in another thread (this causes the cache to flush the first element in another thread) return std::async(std::launch::async, [this] { - for(unsigned int i = 0; i < cache.MAX_ENTRIES+1; ++i) { - cache.push(cache.MAX_ENTRIES+i, nullptr); + for(unsigned int i = 0; i < MAX_ENTRIES+1; ++i) { + cache.push(MAX_ENTRIES+i, nullptr); } }); } diff --git a/test/implementations/caching/cache/testutils/CacheTest.h b/test/implementations/caching/cache/testutils/CacheTest.h index 61769936..673e2bbe 100644 --- a/test/implementations/caching/cache/testutils/CacheTest.h +++ b/test/implementations/caching/cache/testutils/CacheTest.h @@ -16,7 +16,9 @@ public: void push(int key, int value); boost::optional pop(int key); - using Cache = blockstore::caching::Cache; + static constexpr unsigned int MAX_ENTRIES = 100; + + using Cache = blockstore::caching::Cache; private: Cache _cache;