From a58ac622ed70b9fb5450be725c850b50a0a2086a Mon Sep 17 00:00:00 2001 From: Steve Atherton Date: Tue, 18 May 2021 14:33:04 -0700 Subject: [PATCH] Bug fix in test data generation for IntIntPair DeltaTree unit test. --- fdbserver/VersionedBTree.actor.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/fdbserver/VersionedBTree.actor.cpp b/fdbserver/VersionedBTree.actor.cpp index f50d4368d0..223e712159 100644 --- a/fdbserver/VersionedBTree.actor.cpp +++ b/fdbserver/VersionedBTree.actor.cpp @@ -7024,12 +7024,19 @@ TEST_CASE("/redwood/correctness/unit/deltaTree/RedwoodRecordRef2") { TEST_CASE("/redwood/correctness/unit/deltaTree/IntIntPair") { const int N = 200; - IntIntPair prev = { 1, 0 }; - IntIntPair next = { 10000, 10000 }; + IntIntPair lowerBound = { 0, 0 }; + IntIntPair upperBound = { 1000, 1000 }; state std::function randomPair = [&]() { - return IntIntPair( - { deterministicRandom()->randomInt(prev.k, next.k), deterministicRandom()->randomInt(prev.v, next.v) }); + // Generate a pair >= lowerBound and < upperBound + int k = deterministicRandom()->randomInt(lowerBound.k, upperBound.k + 1); + int v = deterministicRandom()->randomInt(lowerBound.v, upperBound.v); + + // Only generate even values so the tests below can approach and find each + // key with a directional seek of the adjacent absent value on either side. + v -= v % 2; + + return IntIntPair(k, v); }; // Build a set of N unique items, where no consecutive items are in the set, a requirement of the seek behavior tests. @@ -7050,14 +7057,14 @@ TEST_CASE("/redwood/correctness/unit/deltaTree/IntIntPair") { int bufferSize = N * 2 * 30; DeltaTree* tree = (DeltaTree*)new uint8_t[bufferSize]; - int builtSize = tree->build(bufferSize, &items[0], &items[items.size()], &prev, &next); + int builtSize = tree->build(bufferSize, &items[0], &items[items.size()], &lowerBound, &upperBound); ASSERT(builtSize <= bufferSize); - DeltaTree::Mirror r(tree, &prev, &next); + DeltaTree::Mirror r(tree, &lowerBound, &upperBound); DeltaTree2* tree2 = (DeltaTree2*)new uint8_t[bufferSize]; - int builtSize2 = tree2->build(bufferSize, &items[0], &items[items.size()], &prev, &next); + int builtSize2 = tree2->build(bufferSize, &items[0], &items[items.size()], &lowerBound, &upperBound); ASSERT(builtSize2 <= bufferSize); - DeltaTree2::DecodeCache cache(prev, next); + DeltaTree2::DecodeCache cache(lowerBound, upperBound); DeltaTree2::Cursor cur2(&cache, tree2); auto printItems = [&] { @@ -7212,7 +7219,7 @@ TEST_CASE("/redwood/correctness/unit/deltaTree/IntIntPair") { scanAndVerify2(); // Create a new mirror, decoding the tree from scratch since insert() modified both the tree and the mirror - r = DeltaTree::Mirror(tree, &prev, &next); + r = DeltaTree::Mirror(tree, &lowerBound, &upperBound); cache.clear(); scanAndVerify(); scanAndVerify2();