Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Add ut for parsing lock value #9214

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions dbms/src/Storages/KVStore/tests/gtest_tikv_keyvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <IO/VarInt.h>
#include <Storages/KVStore/Decode/TiKVHelper.h>
#include <Storages/KVStore/Decode/TiKVRange.h>
#include <Storages/KVStore/Region.h>
#include <Storages/KVStore/TiKVHelpers/TiKVRecordFormat.h>
#include <Storages/KVStore/tests/region_helper.h>
#include <TestUtils/TiFlashTestBasic.h>

Expand Down Expand Up @@ -69,6 +71,13 @@ TiKVValue encode_lock_cf_value(
RecordKVFormat::encodeUInt64(12345678, res);
TiKV::writeVarUInt(87654321, res);
}
{
res.write(RecordKVFormat::TXN_SOURCE_PREFIX_FOR_LOCK);
TiKV::writeVarUInt(876543, res);
}
{
res.write(RecordKVFormat::PESSIMISTIC_LOCK_WITH_CONFLICT_PREFIX);
}
return TiKVValue(res.releaseStr());
}

Expand Down Expand Up @@ -442,7 +451,49 @@ TEST(TiKVKeyValueTest, PortedTests)
ASSERT_EQ(*tidb_pk, pk);
}
}

}

TEST(TiKVKeyValueTest, ParseLockValue)
try
{
// prepare
std::string shor_value = "value";
auto lock_for_update_ts = 7777, txn_size = 1;
const std::vector<std::string> & async_commit = {"s1", "s2"};
const std::vector<uint64_t> & rollback = {3, 4};
auto lock_value = encode_lock_cf_value(
Region::DelFlag,
"primary key",
421321,
std::numeric_limits<UInt64>::max(),
&shor_value,
66666,
lock_for_update_ts,
txn_size,
async_commit,
rollback);

// parse
auto ori_key = std::make_shared<const TiKVKey>(RecordKVFormat::genKey(1, 88888));
auto lock = RecordKVFormat::DecodedLockCFValue(ori_key, std::make_shared<TiKVValue>(std::move(lock_value)));

// check the parsed result
{
auto & lock_info = lock;
ASSERT_TRUE(kvrpcpb::Op::Del == lock_info.lock_type);
ASSERT_TRUE("primary key" == lock_info.primary_lock);
ASSERT_TRUE(421321 == lock_info.lock_version);
ASSERT_TRUE(std::numeric_limits<UInt64>::max() == lock_info.lock_ttl);
ASSERT_TRUE(66666 == lock_info.min_commit_ts);
ASSERT_TRUE(ori_key == lock_info.key);
ASSERT_EQ(lock_for_update_ts, lock_info.lock_for_update_ts);
ASSERT_EQ(txn_size, lock_info.txn_size);

ASSERT_EQ(true, lock_info.use_async_commit);
}
}
CATCH

TEST(TiKVKeyValueTest, Redact)
try
Expand Down