2015-02-26 17:05:05 +01:00
|
|
|
#include "testutils/DataTreeTest.h"
|
2015-02-26 17:04:02 +01:00
|
|
|
#include <google/gmock/gmock.h>
|
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::WithParamInterface;
|
|
|
|
using ::testing::Values;
|
|
|
|
|
|
|
|
using blobstore::onblocks::datanodestore::DataLeafNode;
|
|
|
|
using blobstore::onblocks::datanodestore::DataInnerNode;
|
|
|
|
using blobstore::onblocks::datanodestore::DataNode;
|
|
|
|
using blobstore::onblocks::datanodestore::DataNodeLayout;
|
|
|
|
using blobstore::onblocks::datatreestore::DataTree;
|
|
|
|
using blockstore::Key;
|
|
|
|
|
|
|
|
class DataTreeTest_NumStoredBytes: public DataTreeTest {
|
|
|
|
public:
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(DataTreeTest_NumStoredBytes, CreatedTreeIsEmpty) {
|
|
|
|
auto tree = treeStore.createNewTree();
|
|
|
|
EXPECT_EQ(0, tree->numStoredBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
class DataTreeTest_NumStoredBytes_P: public DataTreeTest_NumStoredBytes, public WithParamInterface<uint32_t> {};
|
|
|
|
INSTANTIATE_TEST_CASE_P(EmptyLastLeaf, DataTreeTest_NumStoredBytes_P, Values(0u));
|
|
|
|
INSTANTIATE_TEST_CASE_P(HalfFullLastLeaf, DataTreeTest_NumStoredBytes_P, Values(5u, 10u));
|
|
|
|
INSTANTIATE_TEST_CASE_P(FullLastLeaf, DataTreeTest_NumStoredBytes_P, Values(DataNodeLayout(DataTreeTest_NumStoredBytes::BLOCKSIZE_BYTES).maxBytesPerLeaf()));
|
|
|
|
|
|
|
|
TEST_P(DataTreeTest_NumStoredBytes_P, SingleLeaf) {
|
|
|
|
Key key = CreateLeafWithSize(GetParam())->key();
|
2015-06-26 15:59:18 +02:00
|
|
|
auto tree = std::move(treeStore.load(key).get());
|
2015-02-26 17:04:02 +01:00
|
|
|
EXPECT_EQ(GetParam(), tree->numStoredBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(DataTreeTest_NumStoredBytes_P, TwoLeafTree) {
|
|
|
|
Key key = CreateTwoLeafWithSecondLeafSize(GetParam())->key();
|
2015-06-26 15:59:18 +02:00
|
|
|
auto tree = std::move(treeStore.load(key).get());
|
2015-02-26 17:04:02 +01:00
|
|
|
EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf() + GetParam(), tree->numStoredBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(DataTreeTest_NumStoredBytes_P, FullTwolevelTree) {
|
|
|
|
Key key = CreateFullTwoLevelWithLastLeafSize(GetParam())->key();
|
2015-06-26 15:59:18 +02:00
|
|
|
auto tree = std::move(treeStore.load(key).get());
|
2015-02-26 17:04:02 +01:00
|
|
|
EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf()*(nodeStore->layout().maxChildrenPerInnerNode()-1) + GetParam(), tree->numStoredBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(DataTreeTest_NumStoredBytes_P, ThreeLevelTreeWithOneChild) {
|
|
|
|
Key key = CreateThreeLevelWithOneChildAndLastLeafSize(GetParam())->key();
|
2015-06-26 15:59:18 +02:00
|
|
|
auto tree = std::move(treeStore.load(key).get());
|
2015-02-26 17:04:02 +01:00
|
|
|
EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf() + GetParam(), tree->numStoredBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(DataTreeTest_NumStoredBytes_P, ThreeLevelTreeWithTwoChildren) {
|
|
|
|
Key key = CreateThreeLevelWithTwoChildrenAndLastLeafSize(GetParam())->key();
|
2015-06-26 15:59:18 +02:00
|
|
|
auto tree = std::move(treeStore.load(key).get());
|
2015-02-26 17:04:02 +01:00
|
|
|
EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf()*nodeStore->layout().maxChildrenPerInnerNode() + nodeStore->layout().maxBytesPerLeaf() + GetParam(), tree->numStoredBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(DataTreeTest_NumStoredBytes_P, ThreeLevelTreeWithThreeChildren) {
|
|
|
|
Key key = CreateThreeLevelWithThreeChildrenAndLastLeafSize(GetParam())->key();
|
2015-06-26 15:59:18 +02:00
|
|
|
auto tree = std::move(treeStore.load(key).get());
|
2015-02-26 17:04:02 +01:00
|
|
|
EXPECT_EQ(2*nodeStore->layout().maxBytesPerLeaf()*nodeStore->layout().maxChildrenPerInnerNode() + nodeStore->layout().maxBytesPerLeaf() + GetParam(), tree->numStoredBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(DataTreeTest_NumStoredBytes_P, FullThreeLevelTree) {
|
|
|
|
Key key = CreateFullThreeLevelWithLastLeafSize(GetParam())->key();
|
2015-06-26 15:59:18 +02:00
|
|
|
auto tree = std::move(treeStore.load(key).get());
|
2015-02-26 17:04:02 +01:00
|
|
|
EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf()*nodeStore->layout().maxChildrenPerInnerNode()*(nodeStore->layout().maxChildrenPerInnerNode()-1) + nodeStore->layout().maxBytesPerLeaf()*(nodeStore->layout().maxChildrenPerInnerNode()-1) + GetParam(), tree->numStoredBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(DataTreeTest_NumStoredBytes_P, FourLevelMinDataTree) {
|
|
|
|
Key key = CreateFourLevelMinDataWithLastLeafSize(GetParam())->key();
|
2015-06-26 15:59:18 +02:00
|
|
|
auto tree = std::move(treeStore.load(key).get());
|
2015-02-26 17:04:02 +01:00
|
|
|
EXPECT_EQ(nodeStore->layout().maxBytesPerLeaf()*nodeStore->layout().maxChildrenPerInnerNode()*nodeStore->layout().maxChildrenPerInnerNode() + GetParam(), tree->numStoredBytes());
|
|
|
|
}
|