Fix compiler error in test cases
This commit is contained in:
parent
260bc1056a
commit
210c2c2811
1
implementations/caching/cache/QueueMap.h
vendored
1
implementations/caching/cache/QueueMap.h
vendored
@ -7,6 +7,7 @@
|
||||
#include <cassert>
|
||||
#include <boost/optional.hpp>
|
||||
#include <messmer/cpp-utils/macros.h>
|
||||
#include <messmer/cpp-utils/assert/assert.h>
|
||||
|
||||
namespace blockstore {
|
||||
namespace caching {
|
||||
|
@ -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<Cache<MinimalKeyType, CopyableMovableValueType>>()) {
|
||||
CacheTest_MoveConstructor(): cache(make_unique_ref<Cache<MinimalKeyType, CopyableMovableValueType, 100>>()) {
|
||||
CopyableMovableValueType::numCopyConstructorCalled = 0;
|
||||
}
|
||||
unique_ref<Cache<MinimalKeyType, CopyableMovableValueType>> cache;
|
||||
unique_ref<Cache<MinimalKeyType, CopyableMovableValueType, 100>> cache;
|
||||
};
|
||||
|
||||
TEST_F(CacheTest_MoveConstructor, MoveIntoCache) {
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,9 @@ class CacheTest_RaceCondition: public ::testing::Test {
|
||||
public:
|
||||
CacheTest_RaceCondition(): cache(), destructorStarted(), destructorFinished(false) {}
|
||||
|
||||
Cache<int, unique_ptr<ObjectWithLongDestructor>> cache;
|
||||
static constexpr unsigned int MAX_ENTRIES = 100;
|
||||
|
||||
Cache<int, unique_ptr<ObjectWithLongDestructor>, MAX_ENTRIES> cache;
|
||||
ConditionBarrier destructorStarted;
|
||||
bool destructorFinished;
|
||||
|
||||
@ -53,8 +55,8 @@ public:
|
||||
future<void> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -16,7 +16,9 @@ public:
|
||||
void push(int key, int value);
|
||||
boost::optional<int> pop(int key);
|
||||
|
||||
using Cache = blockstore::caching::Cache<MinimalKeyType, MinimalValueType>;
|
||||
static constexpr unsigned int MAX_ENTRIES = 100;
|
||||
|
||||
using Cache = blockstore::caching::Cache<MinimalKeyType, MinimalValueType, MAX_ENTRIES>;
|
||||
|
||||
private:
|
||||
Cache _cache;
|
||||
|
Loading…
x
Reference in New Issue
Block a user