Create a FakeBlockStore and use it instead of InMemoryBlockStore in tests

This commit is contained in:
Sebastian Messmer 2014-12-11 01:31:21 +01:00
parent eaf9277d81
commit fb2b511d06
4 changed files with 21 additions and 15 deletions

View File

@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include "blockstore/implementations/inmemory/InMemoryBlockStore.h"
#include "blockstore/implementations/inmemory/InMemoryBlock.h"
#include "blockstore/implementations/testfake/FakeBlockStore.h"
#include "blockstore/implementations/testfake/FakeBlock.h"
#include "blobstore/implementations/onblocks/BlobStoreOnBlocks.h"
#include "blobstore/implementations/onblocks/impl/DataLeafNode.h"
#include "test/testutils/DataBlockFixture.h"
@ -16,7 +16,7 @@ using std::string;
using blockstore::BlockStore;
using blockstore::BlockWithKey;
using blockstore::Data;
using blockstore::inmemory::InMemoryBlockStore;
using blockstore::testfake::FakeBlockStore;
using namespace blobstore;
using namespace blobstore::onblocks;
@ -28,7 +28,7 @@ public:
DataLeafNodeTest():
ZEROES(DataLeafNode::MAX_STORED_BYTES),
randomData(DataLeafNode::MAX_STORED_BYTES),
blockStore(make_unique<InMemoryBlockStore>()),
blockStore(make_unique<FakeBlockStore>()),
block(blockStore->create(DataNodeView::BLOCKSIZE_BYTES)),
leafblock(blockStore->create(DataNodeView::BLOCKSIZE_BYTES)),
leafblockdata((uint8_t*)leafblock.block->data()),

View File

@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include "blockstore/implementations/inmemory/InMemoryBlockStore.h"
#include "blockstore/implementations/inmemory/InMemoryBlock.h"
#include "blockstore/implementations/testfake/FakeBlockStore.h"
#include "blockstore/implementations/testfake/FakeBlock.h"
#include "blobstore/implementations/onblocks/BlobStoreOnBlocks.h"
#include "blobstore/implementations/onblocks/impl/DataNode.h"
#include "blobstore/implementations/onblocks/impl/DataLeafNode.h"
@ -13,13 +13,13 @@ using std::make_unique;
using std::string;
using blockstore::BlockStore;
using blockstore::inmemory::InMemoryBlockStore;
using blockstore::testfake::FakeBlockStore;
using namespace blobstore;
using namespace blobstore::onblocks;
class DataNodeTest: public Test {
public:
unique_ptr<BlockStore> blockStore = make_unique<InMemoryBlockStore>();
unique_ptr<BlockStore> blockStore = make_unique<FakeBlockStore>();
};
#define EXPECT_IS_PTR_TYPE(Type, ptr) EXPECT_NE(nullptr, dynamic_cast<Type*>(ptr)) << "Given pointer cannot be cast to the given type"

View File

@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include "blockstore/implementations/inmemory/InMemoryBlockStore.h"
#include "blockstore/implementations/inmemory/InMemoryBlock.h"
#include "blockstore/implementations/testfake/FakeBlockStore.h"
#include "blockstore/implementations/testfake/FakeBlock.h"
#include "blobstore/implementations/onblocks/BlobStoreOnBlocks.h"
#include "blobstore/implementations/onblocks/impl/DataNodeView.h"
#include "test/testutils/DataBlockFixture.h"
@ -14,7 +14,7 @@ using std::make_unique;
using std::string;
using blockstore::BlockStore;
using blockstore::inmemory::InMemoryBlockStore;
using blockstore::testfake::FakeBlockStore;
using namespace blobstore;
using namespace blobstore::onblocks;
@ -25,7 +25,7 @@ public:
// because the next block load will just give you the same data region (and the overflow data will most
// likely still be intact).
// So better write a FakeBlockStore class for test cases.
unique_ptr<BlockStore> blockStore = make_unique<InMemoryBlockStore>();
unique_ptr<BlockStore> blockStore = make_unique<FakeBlockStore>();
};
TEST_F(DataNodeViewTest, MagicNumberIsStored) {
@ -54,13 +54,13 @@ TEST_P(DataNodeViewSizeTest, SizeIsStored) {
TEST_F(DataNodeViewTest, DataIsStored) {
DataBlockFixture randomData(DataNodeView::DATASIZE_BYTES);
auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE);
auto block = blockStore->create(DataNodeView::BLOCKSIZE_BYTES);
{
DataNodeView view(std::move(block.block));
std::memcpy(view.DataBegin<uint8_t>(), randomData.data(), DataNodeView::DATASIZE_BYTES);
std::memcpy(view.DataBegin<uint8_t>(), randomData.data(), randomData.size());
}
DataNodeView view(blockStore->load(block.key));
EXPECT_EQ(0, std::memcmp(view.DataBegin<uint8_t>(), randomData.data(), DataNodeView::DATASIZE_BYTES));
EXPECT_EQ(0, std::memcmp(view.DataBegin<uint8_t>(), randomData.data(), randomData.size()));
}
TEST_F(DataNodeViewTest, HeaderAndBodyDontOverlap) {

View File

@ -20,6 +20,12 @@ void DataBlockFixture::fillFileWithRandomData(long long int IV) {
val += 1442695040888963407;
reinterpret_cast<long long int*>(_fileData)[i] = val;
}
//Fill remaining bytes
for(size_t i=(_size/sizeof(long long int))*sizeof(long long int); i<_size; ++i) {
val *= 6364136223846793005L;
val += 1442695040888963407;
reinterpret_cast<char*>(_fileData)[i] = val;
}
}
const char *DataBlockFixture::data() const {