Added some more test cases to BlobStore

This commit is contained in:
Sebastian Messmer 2015-03-06 16:39:40 +01:00
parent a9c44a40ed
commit df9a44eace
3 changed files with 80 additions and 9 deletions

View File

@ -0,0 +1,16 @@
#include "testutils/BlobStoreTest.h"
#include <messmer/blockstore/utils/Data.h>
//TODO Test read/write
//TODO Test read/write with loading inbetween
//TODO Test flushing isn't necessary (writing immediately flushes)
using std::unique_ptr;
using namespace blobstore;
using blockstore::Key;
using blockstore::Data;
class BlobReadWriteTest: public BlobStoreTest {
public:
};

View File

@ -1,18 +1,23 @@
#include "testutils/BlobStoreTest.h"
#include <messmer/blockstore/utils/Data.h>
#include "../../testutils/DataBlockFixture.h"
using std::unique_ptr;
using namespace blobstore;
using blockstore::Key;
using blockstore::Data;
class BlobSizeTest: public BlobStoreTest {
public:
BlobSizeTest(): blob(blobStore->create()) {}
static constexpr uint32_t MEDIUM_SIZE = 5 * 1024 * 1024;
static constexpr uint32_t LARGE_SIZE = 10 * 1024 * 1024;
unique_ptr<Blob> blob;
};
constexpr uint32_t BlobSizeTest::MEDIUM_SIZE;
constexpr uint32_t BlobSizeTest::LARGE_SIZE;
TEST_F(BlobSizeTest, CreatedBlobIsEmpty) {
@ -105,3 +110,62 @@ TEST_F(BlobSizeTest, WritingAfterEndOfBlobGrowsBlob_NonEmpty) {
blob->write(&value, 2, 4);
EXPECT_EQ(6, blob->size());
}
TEST_F(BlobSizeTest, ChangingSizeImmediatelyFlushes) {
blob->resize(LARGE_SIZE);
auto loaded = blobStore->load(blob->key());
EXPECT_EQ(LARGE_SIZE, loaded->size());
}
class BlobSizeDataTest: public BlobSizeTest {
public:
BlobSizeDataTest()
:ZEROES(LARGE_SIZE),
randomData(LARGE_SIZE) {
ZEROES.FillWithZeroes();
}
Data readBlob(const Blob &blob) {
Data data(blob.size());
blob.read(data.data(), 0, data.size());
return data;
}
Data ZEROES;
DataBlockFixture randomData;
};
TEST_F(BlobSizeDataTest, BlobIsZeroedOutAfterGrowing) {
blob->resize(LARGE_SIZE);
EXPECT_EQ(0, std::memcmp(readBlob(*blob).data(), ZEROES.data(), LARGE_SIZE));
}
TEST_F(BlobSizeDataTest, BlobIsZeroedOutAfterGrowingAndLoading) {
blob->resize(LARGE_SIZE);
auto loaded = blobStore->load(blob->key());
EXPECT_EQ(0, std::memcmp(readBlob(*loaded).data(), ZEROES.data(), LARGE_SIZE));
}
TEST_F(BlobSizeDataTest, DataStaysIntactWhenGrowing) {
blob->resize(MEDIUM_SIZE);
blob->write(randomData.data(), 0, MEDIUM_SIZE);
blob->resize(LARGE_SIZE);
EXPECT_EQ(0, std::memcmp(readBlob(*blob).data(), randomData.data(), MEDIUM_SIZE));
EXPECT_EQ(0, std::memcmp(readBlob(*blob).data() + MEDIUM_SIZE, ZEROES.data(), LARGE_SIZE-MEDIUM_SIZE));
}
TEST_F(BlobSizeDataTest, DataStaysIntactWhenShrinking) {
blob->resize(LARGE_SIZE);
blob->write(randomData.data(), 0, LARGE_SIZE);
blob->resize(MEDIUM_SIZE);
EXPECT_EQ(0, std::memcmp(readBlob(*blob).data(), randomData.data(), MEDIUM_SIZE));
}
TEST_F(BlobSizeDataTest, ChangedAreaIsZeroedOutWhenShrinkingAndRegrowing) {
blob->resize(LARGE_SIZE);
blob->write(randomData.data(), 0, LARGE_SIZE);
blob->resize(MEDIUM_SIZE);
blob->resize(LARGE_SIZE);
EXPECT_EQ(0, std::memcmp(readBlob(*blob).data(), randomData.data(), MEDIUM_SIZE));
EXPECT_EQ(0, std::memcmp(readBlob(*blob).data() + MEDIUM_SIZE, ZEROES.data(), LARGE_SIZE-MEDIUM_SIZE));
}

View File

@ -33,12 +33,3 @@ TEST_F(BlobStoreTest, BlobIsNotLoadableAfterDeletion_DeleteAfterLoading) {
blobStore->remove(blobStore->load(key));
EXPECT_EQ(nullptr, blobStore->load(key).get());
}
//TODO Test read/write
//TODO Test read/write with loading inbetween
//TODO Test flushing isn't necessary (changes do auto-flush)
//Taken from BlockStoreTest.h:
//TODO Blob is zeroed out after growing
//TODO Blob is zeroed out after growing and loading
//TODO Last blob part is zeroed out after shrinking and regrowing