Skip to content

Commit

Permalink
add unit test for compatible
Browse files Browse the repository at this point in the history
Co-authored-by: Yaroslav <torwigua@gmail.com>
  • Loading branch information
PragmaTwice and torwig committed Mar 23, 2023
1 parent 00afbc5 commit 558bece
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/cppunit/types/metadata_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "storage/redis_metadata.h"
#include "test_base.h"
#include "time_util.h"
#include "types/redis_hash.h"

TEST(InternalKey, EncodeAndDecode) {
Expand Down Expand Up @@ -115,3 +116,18 @@ TEST_F(RedisTypeTest, Expire) {
ASSERT_TRUE(ttl >= 1000 && ttl <= 2000);
sleep(2);
}

TEST(Metadata, MetadataDecodingBackwardCompatibleSimpleKey) {
auto expire_at = (Util::GetTimeStamp() + 10) * 1000;
Metadata md_old(kRedisString, true, false);
EXPECT_FALSE(md_old.Is64BitEncoded());
md_old.expire = expire_at;
std::string encoded_bytes;
md_old.Encode(&encoded_bytes);

Metadata md_new(kRedisNone, false, true); // decoding existing metadata with 64-bit feature activated
md_new.Decode(encoded_bytes);
EXPECT_FALSE(md_new.Is64BitEncoded());
EXPECT_EQ(md_new.Type(), kRedisString);
EXPECT_EQ(md_new.expire, expire_at);
}

0 comments on commit 558bece

Please sign in to comment.