Fix traversal bug and add test case for it
This commit is contained in:
parent
d80b95514e
commit
ea349cf79b
@ -46,7 +46,7 @@ namespace blobstore {
|
||||
if (increaseTreeDepth && leaf->numBytes() != _nodeStore->layout().maxBytesPerLeaf()) {
|
||||
leaf->resize(_nodeStore->layout().maxBytesPerLeaf());
|
||||
}
|
||||
if (beginIndex == 0 && endIndex == 1) {
|
||||
if (beginIndex == 0 && endIndex >= 1) {
|
||||
onExistingLeaf(0, LeafHandle(_nodeStore, leaf));
|
||||
}
|
||||
} else {
|
||||
|
@ -109,9 +109,9 @@ public:
|
||||
GrowTree(tree.get().get());
|
||||
}
|
||||
|
||||
void GrowTree(DataTree *tree) {
|
||||
void GrowTree(DataTree *tree, std::function<void (int32_t)> traverse = [] (uint32_t){}) {
|
||||
uint64_t maxBytesPerLeaf = tree->maxBytesPerLeaf();
|
||||
tree->traverseLeaves(traversalBeginIndex, newNumberOfLeaves, [] (uint32_t, LeafHandle){}, [maxBytesPerLeaf] (uint32_t) -> Data { return Data(maxBytesPerLeaf).FillWithZeroes();});
|
||||
tree->traverseLeaves(traversalBeginIndex, newNumberOfLeaves, [&traverse] (uint32_t index, LeafHandle){traverse(index);}, [maxBytesPerLeaf, &traverse] (uint32_t index) -> Data { traverse(index); return Data(maxBytesPerLeaf).FillWithZeroes();});
|
||||
tree->flush();
|
||||
}
|
||||
|
||||
@ -218,3 +218,13 @@ TEST_P(DataTreeTest_ResizeByTraversing_P, DataStaysIntact) {
|
||||
|
||||
data.EXPECT_DATA_CORRECT(nodeStore->load(key).get().get(), oldNumberOfLeaves, oldLastLeafSize);
|
||||
}
|
||||
|
||||
TEST_P(DataTreeTest_ResizeByTraversing_P, AllLeavesAreTraversed) {
|
||||
std::vector<uint32_t> traversedLeaves;
|
||||
GrowTree(tree.get(), [&traversedLeaves] (uint32_t index) {traversedLeaves.push_back(index);});
|
||||
|
||||
EXPECT_EQ(newNumberOfLeaves-traversalBeginIndex, traversedLeaves.size());
|
||||
for (uint32_t i = traversalBeginIndex; i < newNumberOfLeaves; ++i) {
|
||||
EXPECT_NE(traversedLeaves.end(), std::find(traversedLeaves.begin(), traversedLeaves.end(), i));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user