2017-08-21 23:44:35 +02:00
|
|
|
#include <gtest/gtest.h>
|
2017-08-22 01:03:04 +02:00
|
|
|
#include "blockstore/implementations/caching/CachingBlockStore2.h"
|
|
|
|
#include "blockstore/implementations/inmemory/InMemoryBlockStore2.h"
|
2017-08-21 23:44:35 +02:00
|
|
|
|
|
|
|
using ::testing::Test;
|
|
|
|
|
|
|
|
using cpputils::Data;
|
|
|
|
|
2017-08-22 01:03:04 +02:00
|
|
|
using blockstore::inmemory::InMemoryBlockStore2;
|
2017-08-21 23:44:35 +02:00
|
|
|
|
|
|
|
using namespace blockstore::caching;
|
|
|
|
|
|
|
|
class CachingBlockStore2Test: public Test {
|
|
|
|
public:
|
|
|
|
CachingBlockStore2Test():
|
2017-08-22 01:03:04 +02:00
|
|
|
baseBlockStore(new InMemoryBlockStore2),
|
|
|
|
blockStore(std::move(cpputils::nullcheck(std::unique_ptr<InMemoryBlockStore2>(baseBlockStore)).value())) {
|
2017-08-21 23:44:35 +02:00
|
|
|
}
|
2017-08-22 01:03:04 +02:00
|
|
|
InMemoryBlockStore2 *baseBlockStore;
|
|
|
|
CachingBlockStore2 blockStore;
|
2017-08-21 23:44:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(CachingBlockStore2Test, PhysicalBlockSize_zerophysical) {
|
|
|
|
EXPECT_EQ(0u, blockStore.blockSizeFromPhysicalBlockSize(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CachingBlockStore2Test, PhysicalBlockSize_zerovirtual) {
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = blockStore.create(Data(0));
|
2017-08-22 01:03:04 +02:00
|
|
|
blockStore.flush();
|
2017-09-17 03:07:27 +02:00
|
|
|
auto base = baseBlockStore->load(blockId).value();
|
2017-08-22 01:03:04 +02:00
|
|
|
EXPECT_EQ(0u, blockStore.blockSizeFromPhysicalBlockSize(base.size()));
|
2017-08-21 23:44:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CachingBlockStore2Test, PhysicalBlockSize_negativeboundaries) {
|
|
|
|
// This tests that a potential if/else in blockSizeFromPhysicalBlockSize that catches negative values has the
|
|
|
|
// correct boundary set. We test the highest value that is negative and the smallest value that is positive.
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = blockStore.create(Data(0));
|
2017-08-22 01:03:04 +02:00
|
|
|
blockStore.flush();
|
2017-09-17 03:07:27 +02:00
|
|
|
auto physicalSizeForVirtualSizeZero = baseBlockStore->load(blockId).value().size();
|
2017-08-21 23:44:35 +02:00
|
|
|
if (physicalSizeForVirtualSizeZero > 0) {
|
|
|
|
EXPECT_EQ(0u, blockStore.blockSizeFromPhysicalBlockSize(physicalSizeForVirtualSizeZero - 1));
|
|
|
|
}
|
|
|
|
EXPECT_EQ(0u, blockStore.blockSizeFromPhysicalBlockSize(physicalSizeForVirtualSizeZero));
|
|
|
|
EXPECT_EQ(1u, blockStore.blockSizeFromPhysicalBlockSize(physicalSizeForVirtualSizeZero + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CachingBlockStore2Test, PhysicalBlockSize_positive) {
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = blockStore.create(Data(10*1024u));
|
2017-08-22 01:03:04 +02:00
|
|
|
blockStore.flush();
|
2017-09-17 03:07:27 +02:00
|
|
|
auto base = baseBlockStore->load(blockId).value();
|
2017-08-22 01:03:04 +02:00
|
|
|
EXPECT_EQ(10*1024u, blockStore.blockSizeFromPhysicalBlockSize(base.size()));
|
2017-08-21 23:44:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Add test cases that flushing the block store doesn't destroy things (i.e. all test cases from BlockStoreTest, but with flushes inbetween)
|