2014-12-09 17:19:59 +01:00
|
|
|
#pragma once
|
2015-10-15 13:09:21 +02:00
|
|
|
#ifndef MESSMER_BLOCKSTORE_TEST_TESTUTILS_BLOCKSTOREWITHRANDOMKEYSTEST_H_
|
|
|
|
#define MESSMER_BLOCKSTORE_TEST_TESTUTILS_BLOCKSTOREWITHRANDOMKEYSTEST_H_
|
2014-12-09 17:19:59 +01:00
|
|
|
|
2016-02-11 15:19:58 +01:00
|
|
|
#include <gtest/gtest.h>
|
2014-12-09 17:19:59 +01:00
|
|
|
|
2016-02-11 15:19:58 +01:00
|
|
|
#include "blockstore/interface/BlockStore.h"
|
2014-12-09 17:19:59 +01:00
|
|
|
|
|
|
|
class BlockStoreWithRandomKeysTestFixture {
|
|
|
|
public:
|
2015-10-17 21:10:26 +02:00
|
|
|
virtual ~BlockStoreWithRandomKeysTestFixture() {}
|
2017-07-21 04:32:42 +02:00
|
|
|
virtual cpputils::unique_ref<blockstore::BlockStore> createBlockStore() = 0;
|
2014-12-09 17:19:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class ConcreteBlockStoreWithRandomKeysTestFixture>
|
|
|
|
class BlockStoreWithRandomKeysTest: public ::testing::Test {
|
|
|
|
public:
|
2015-10-17 21:10:26 +02:00
|
|
|
BlockStoreWithRandomKeysTest(): fixture() {}
|
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
BOOST_STATIC_ASSERT_MSG(
|
|
|
|
(std::is_base_of<BlockStoreWithRandomKeysTestFixture, ConcreteBlockStoreWithRandomKeysTestFixture>::value),
|
|
|
|
"Given test fixture for instantiating the (type parameterized) BlockStoreWithRandomKeysTest must inherit from BlockStoreWithRandomKeysTestFixture"
|
|
|
|
);
|
|
|
|
|
2014-12-09 20:57:10 +01:00
|
|
|
blockstore::Key key = blockstore::Key::FromString("1491BB4932A389EE14BC7090AC772972");
|
2014-12-09 20:36:32 +01:00
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
const std::vector<size_t> SIZES = {0, 1, 1024, 4096, 10*1024*1024};
|
|
|
|
|
|
|
|
ConcreteBlockStoreWithRandomKeysTestFixture fixture;
|
|
|
|
};
|
|
|
|
|
|
|
|
TYPED_TEST_CASE_P(BlockStoreWithRandomKeysTest);
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreWithRandomKeysTest, CreateTwoBlocksWithSameKeyAndSameSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block = blockStore->tryCreate(this->key, cpputils::Data(1024));
|
2015-07-20 18:57:48 +02:00
|
|
|
(*block)->flush(); //TODO Ideally, flush shouldn't be necessary here.
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block2 = blockStore->tryCreate(this->key, cpputils::Data(1024));
|
2015-07-20 18:57:48 +02:00
|
|
|
EXPECT_NE(boost::none, block);
|
|
|
|
EXPECT_EQ(boost::none, block2);
|
2014-12-09 17:19:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreWithRandomKeysTest, CreateTwoBlocksWithSameKeyAndDifferentSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block = blockStore->tryCreate(this->key, cpputils::Data(1024));
|
2015-07-20 18:57:48 +02:00
|
|
|
(*block)->flush(); //TODO Ideally, flush shouldn't be necessary here.
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block2 = blockStore->tryCreate(this->key, cpputils::Data(4096));
|
2015-07-20 18:57:48 +02:00
|
|
|
EXPECT_NE(boost::none, block);
|
|
|
|
EXPECT_EQ(boost::none, block2);
|
2014-12-09 17:19:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreWithRandomKeysTest, CreateTwoBlocksWithSameKeyAndFirstNullSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block = blockStore->tryCreate(this->key, cpputils::Data(0));
|
2015-07-20 18:57:48 +02:00
|
|
|
(*block)->flush(); //TODO Ideally, flush shouldn't be necessary here.
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block2 = blockStore->tryCreate(this->key, cpputils::Data(1024));
|
2015-07-20 18:57:48 +02:00
|
|
|
EXPECT_NE(boost::none, block);
|
|
|
|
EXPECT_EQ(boost::none, block2);
|
2014-12-09 17:19:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreWithRandomKeysTest, CreateTwoBlocksWithSameKeyAndSecondNullSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block = blockStore->tryCreate(this->key, cpputils::Data(1024));
|
2015-07-20 18:57:48 +02:00
|
|
|
(*block)->flush(); //TODO Ideally, flush shouldn't be necessary here.
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block2 = blockStore->tryCreate(this->key, cpputils::Data(0));
|
2015-07-20 18:57:48 +02:00
|
|
|
EXPECT_NE(boost::none, block);
|
|
|
|
EXPECT_EQ(boost::none, block2);
|
2014-12-09 17:19:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(BlockStoreWithRandomKeysTest, CreateTwoBlocksWithSameKeyAndBothNullSize) {
|
|
|
|
auto blockStore = this->fixture.createBlockStore();
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block = blockStore->tryCreate(this->key, cpputils::Data(0));
|
2015-07-20 18:57:48 +02:00
|
|
|
(*block)->flush(); //TODO Ideally, flush shouldn't be necessary here.
|
2015-04-25 02:48:41 +02:00
|
|
|
auto block2 = blockStore->tryCreate(this->key, cpputils::Data(0));
|
2015-07-20 18:57:48 +02:00
|
|
|
EXPECT_NE(boost::none, block);
|
|
|
|
EXPECT_EQ(boost::none, block2);
|
2014-12-09 17:19:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_TYPED_TEST_CASE_P(BlockStoreWithRandomKeysTest,
|
|
|
|
CreateTwoBlocksWithSameKeyAndSameSize,
|
|
|
|
CreateTwoBlocksWithSameKeyAndDifferentSize,
|
|
|
|
CreateTwoBlocksWithSameKeyAndFirstNullSize,
|
|
|
|
CreateTwoBlocksWithSameKeyAndSecondNullSize,
|
|
|
|
CreateTwoBlocksWithSameKeyAndBothNullSize
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|