2015-02-24 22:44:10 +01:00
|
|
|
#include "testutils/DataTreeTest.h"
|
|
|
|
|
|
|
|
#include "../../../../implementations/onblocks/datanodestore/DataNodeStore.h"
|
|
|
|
#include "../../../../implementations/onblocks/datatreestore/DataTreeStore.h"
|
|
|
|
#include <messmer/blockstore/implementations/testfake/FakeBlockStore.h>
|
2015-06-26 15:59:18 +02:00
|
|
|
#include <messmer/cpp-utils/pointer/unique_ref_boost_optional_gtest_workaround.h>
|
2015-02-24 22:44:10 +01:00
|
|
|
|
|
|
|
using blockstore::testfake::FakeBlockStore;
|
|
|
|
using blockstore::Key;
|
|
|
|
using blobstore::onblocks::datanodestore::DataNodeStore;
|
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) {
|
|
|
|
Key key = treeStore.createNewTree()->key();
|
2015-06-26 15:59:18 +02:00
|
|
|
auto tree = std::move(treeStore.load(key).get());
|
2015-02-27 14:32:28 +01:00
|
|
|
EXPECT_EQ(key, tree->key());
|
|
|
|
}
|
|
|
|
|
2015-02-24 22:51:56 +01:00
|
|
|
TEST_F(DataTreeStoreTest, CreatedTreeIsLoadable) {
|
|
|
|
auto key = treeStore.createNewTree()->key();
|
|
|
|
auto loaded = treeStore.load(key);
|
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();
|
|
|
|
|
|
|
|
EXPECT_IS_LEAF_NODE(tree->key());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DataTreeStoreTest, TreeIsNotLoadableAfterRemove) {
|
|
|
|
Key key = treeStore.createNewTree()->key();
|
|
|
|
auto tree = treeStore.load(key);
|
2015-06-26 15:59:18 +02:00
|
|
|
EXPECT_NE(none, tree);
|
|
|
|
treeStore.remove(std::move(*tree));
|
|
|
|
EXPECT_EQ(none, treeStore.load(key));
|
2015-02-24 22:44:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DataTreeStoreTest, RemovingTreeRemovesAllNodesOfTheTree) {
|
2015-02-24 22:46:44 +01:00
|
|
|
auto key = CreateThreeLevelMinData()->key();
|
2015-06-26 15:59:18 +02:00
|
|
|
auto tree1 = std::move(treeStore.load(key).get());
|
2015-02-24 22:44:10 +01:00
|
|
|
auto tree2_key = treeStore.createNewTree()->key();
|
|
|
|
|
|
|
|
treeStore.remove(std::move(tree1));
|
|
|
|
|
|
|
|
//Check that the only remaining node is tree2
|
|
|
|
EXPECT_EQ(1, nodeStore->numNodes());
|
2015-06-26 15:59:18 +02:00
|
|
|
EXPECT_NE(none, treeStore.load(tree2_key));
|
2015-02-24 22:44:10 +01:00
|
|
|
}
|