2015-02-24 22:44:10 +01:00
|
|
|
#include "testutils/DataTreeTest.h"
|
|
|
|
|
2016-02-11 15:19:58 +01:00
|
|
|
#include "blobstore/implementations/onblocks/datanodestore/DataNodeStore.h"
|
|
|
|
#include "blobstore/implementations/onblocks/datatreestore/DataTreeStore.h"
|
|
|
|
#include <blockstore/implementations/testfake/FakeBlockStore.h>
|
|
|
|
#include <cpp-utils/pointer/unique_ref_boost_optional_gtest_workaround.h>
|
2015-02-24 22:44:10 +01:00
|
|
|
|
2017-09-17 03:07:27 +02:00
|
|
|
using blockstore::BlockId;
|
2015-06-26 15:59:18 +02:00
|
|
|
using boost::none;
|
2015-02-24 22:44:10 +01:00
|
|
|
|
|
|
|
using namespace blobstore::onblocks::datatreestore;
|
|
|
|
|
|
|
|
class DataTreeStoreTest: public DataTreeTest {
|
|
|
|
};
|
|
|
|
|
2015-02-27 14:32:28 +01:00
|
|
|
TEST_F(DataTreeStoreTest, CorrectKeyReturned) {
|
2017-09-17 03:07:27 +02:00
|
|
|
BlockId blockId = treeStore.createNewTree()->blockId();
|
|
|
|
auto tree = treeStore.load(blockId).value();
|
|
|
|
EXPECT_EQ(blockId, tree->blockId());
|
2015-02-27 14:32:28 +01:00
|
|
|
}
|
|
|
|
|
2015-02-24 22:51:56 +01:00
|
|
|
TEST_F(DataTreeStoreTest, CreatedTreeIsLoadable) {
|
2017-09-17 03:07:27 +02:00
|
|
|
auto blockId = treeStore.createNewTree()->blockId();
|
|
|
|
auto loaded = treeStore.load(blockId);
|
2015-06-26 15:59:18 +02:00
|
|
|
EXPECT_NE(none, loaded);
|
2015-02-24 22:51:56 +01:00
|
|
|
}
|
|
|
|
|
2015-02-24 22:44:10 +01:00
|
|
|
TEST_F(DataTreeStoreTest, NewTreeIsLeafOnly) {
|
|
|
|
auto tree = treeStore.createNewTree();
|
|
|
|
|
2017-09-17 03:07:27 +02:00
|
|
|
EXPECT_IS_LEAF_NODE(tree->blockId());
|
2015-02-24 22:44:10 +01:00
|
|
|
}
|
|
|
|
|
2016-07-13 11:06:37 +02:00
|
|
|
TEST_F(DataTreeStoreTest, TreeIsNotLoadableAfterRemove_DeleteByTree) {
|
2017-09-17 03:07:27 +02:00
|
|
|
BlockId blockId = treeStore.createNewTree()->blockId();
|
|
|
|
auto tree = treeStore.load(blockId);
|
2015-06-26 15:59:18 +02:00
|
|
|
EXPECT_NE(none, tree);
|
|
|
|
treeStore.remove(std::move(*tree));
|
2017-09-17 03:07:27 +02:00
|
|
|
EXPECT_EQ(none, treeStore.load(blockId));
|
2015-02-24 22:44:10 +01:00
|
|
|
}
|
|
|
|
|
2016-07-13 11:06:37 +02:00
|
|
|
TEST_F(DataTreeStoreTest, TreeIsNotLoadableAfterRemove_DeleteByKey) {
|
2017-09-17 03:07:27 +02:00
|
|
|
BlockId blockId = treeStore.createNewTree()->blockId();
|
|
|
|
treeStore.remove(blockId);
|
|
|
|
EXPECT_EQ(none, treeStore.load(blockId));
|
2016-07-13 11:06:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DataTreeStoreTest, RemovingTreeRemovesAllNodesOfTheTree_DeleteByTree) {
|
2017-09-17 03:07:27 +02:00
|
|
|
auto tree1_blockId = CreateThreeLevelMinData()->blockId();
|
|
|
|
auto tree2_blockId = treeStore.createNewTree()->blockId();
|
2015-02-24 22:44:10 +01:00
|
|
|
|
2017-09-17 03:07:27 +02:00
|
|
|
auto tree1 = treeStore.load(tree1_blockId).value();
|
2015-02-24 22:44:10 +01:00
|
|
|
treeStore.remove(std::move(tree1));
|
|
|
|
|
|
|
|
//Check that the only remaining node is tree2
|
2016-02-11 15:19:58 +01:00
|
|
|
EXPECT_EQ(1u, nodeStore->numNodes());
|
2017-09-17 03:07:27 +02:00
|
|
|
EXPECT_NE(none, treeStore.load(tree2_blockId));
|
2015-02-24 22:44:10 +01:00
|
|
|
}
|
2016-07-13 11:06:37 +02:00
|
|
|
|
|
|
|
TEST_F(DataTreeStoreTest, RemovingTreeRemovesAllNodesOfTheTree_DeleteByKey) {
|
2017-09-17 03:07:27 +02:00
|
|
|
auto tree1_blockId = CreateThreeLevelMinData()->blockId();
|
|
|
|
auto tree2_blockId = treeStore.createNewTree()->blockId();
|
2016-07-13 11:06:37 +02:00
|
|
|
|
2017-09-17 03:07:27 +02:00
|
|
|
treeStore.remove(tree1_blockId);
|
2016-07-13 11:06:37 +02:00
|
|
|
|
|
|
|
//Check that the only remaining node is tree2
|
|
|
|
EXPECT_EQ(1u, nodeStore->numNodes());
|
2017-09-17 03:07:27 +02:00
|
|
|
EXPECT_NE(none, treeStore.load(tree2_blockId));
|
2016-07-13 11:06:37 +02:00
|
|
|
}
|