Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 8 additions & 8 deletions cases/hash_as_listpack_with_hfe.aof
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ F1
$2
V1
$2
F3
$2
V3
$2
F2
$2
V2
$2
F3
$2
V3
*6
$10
HPEXPIREAT
$12
listpack-hfe
$13
2755484483878
2755482478325
$6
FIELDS
$1
1
$2
F3
F1
*5
$8
HPERSIST
Expand All @@ -45,10 +45,10 @@ HPEXPIREAT
$12
listpack-hfe
$13
2755482478325
2755484483878
$6
FIELDS
$1
1
$2
F1
F3
72 changes: 36 additions & 36 deletions cases/hash_with_hfe.aof
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,50 @@ HMSET
$8
hash-hfe
$2
F4
F1
$2
V4
V1
$2
F7
F2
$2
V7
V2
$2
F8
F3
$2
V8
V3
$2
F2
F4
$2
V2
V4
$2
F5
$2
V5
$2
F3
F6
$2
V3
V6
$2
F1
F7
$2
V1
V7
$2
F6
F8
$2
V6
*5
$8
HPERSIST
V8
*6
$10
HPEXPIREAT
$8
hash-hfe
$13
2755482424661
$6
FIELDS
$1
1
$2
F8
F1
*6
$10
HPEXPIREAT
Expand All @@ -59,43 +61,41 @@ $1
1
$2
F2
*5
$8
HPERSIST
*6
$10
HPEXPIREAT
$8
hash-hfe
$13
2755484433842
$6
FIELDS
$1
1
$2
F5
*6
$10
HPEXPIREAT
F3
*5
$8
HPERSIST
$8
hash-hfe
$13
2755484433842
$6
FIELDS
$1
1
$2
F3
*6
$10
HPEXPIREAT
F4
*5
$8
HPERSIST
$8
hash-hfe
$13
2755482424661
$6
FIELDS
$1
1
$2
F1
F5
*5
$8
HPERSIST
Expand All @@ -117,7 +117,7 @@ FIELDS
$1
1
$2
F4
F7
*5
$8
HPERSIST
Expand All @@ -128,4 +128,4 @@ FIELDS
$1
1
$2
F7
F8
Empty file.
3 changes: 3 additions & 0 deletions cases/valkey_cluster_slot_import.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[

]
Binary file added cases/valkey_cluster_slot_import.rdb
Binary file not shown.
7 changes: 7 additions & 0 deletions cases/valkey_cluster_slot_info.aof
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*3
$3
SET
$13
{6ZJ}:fixture
$5
value
3 changes: 3 additions & 0 deletions cases/valkey_cluster_slot_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"db":0,"key":"{6ZJ}:fixture","size":64,"type":"string","encoding":"string","value":"value"}
]
Binary file added cases/valkey_cluster_slot_info.rdb
Binary file not shown.
155 changes: 154 additions & 1 deletion helper/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,86 @@ func TestToJson(t *testing.T) {
}
}

func TestToJsonWithHashFieldExpiration(t *testing.T) {
jsonEncoder = sonic.ConfigStd
var cstZone = time.FixedZone("CST", 8*3600)
time.Local = cstZone

err := os.MkdirAll("tmp", os.ModePerm)
if err != nil {
return
}
defer func() {
err := os.RemoveAll("tmp")
if err != nil {
t.Logf("remove tmp directory failed: %v", err)
}
}()

testCases := []string{
"hash_with_hfe",
"hash_as_listpack_with_hfe",
"valkey_hash2_with_hfe",
}
for _, filename := range testCases {
srcRdb := filepath.Join("../cases", filename+".rdb")
actualJSON := filepath.Join("tmp", filename+".json")
expectJSON := filepath.Join("../cases", filename+".json")
err = ToJsons(srcRdb, actualJSON, WithConcurrent(1))
if err != nil {
t.Errorf("error occurs during parse %s, err: %v", filename, err)
continue
}
equals, err := compareFileByLine(t, actualJSON, expectJSON)
if err != nil {
t.Errorf("error occurs during compare %s, err: %v", filename, err)
continue
}
if !equals {
t.Errorf("result is not equal of %s", filename)
}
}
}

func TestToJsonWithValkeyClusterMetadata(t *testing.T) {
jsonEncoder = sonic.ConfigStd
var cstZone = time.FixedZone("CST", 8*3600)
time.Local = cstZone

err := os.MkdirAll("tmp", os.ModePerm)
if err != nil {
return
}
defer func() {
err := os.RemoveAll("tmp")
if err != nil {
t.Logf("remove tmp directory failed: %v", err)
}
}()

testCases := []string{
"valkey_cluster_slot_info",
"valkey_cluster_slot_import",
}
for _, filename := range testCases {
srcRdb := filepath.Join("../cases", filename+".rdb")
actualJSON := filepath.Join("tmp", filename+".json")
expectJSON := filepath.Join("../cases", filename+".json")
err = ToJsons(srcRdb, actualJSON, WithConcurrent(1))
if err != nil {
t.Errorf("error occurs during parse %s, err: %v", filename, err)
continue
}
equals, err := compareFileByLine(t, actualJSON, expectJSON)
if err != nil {
t.Errorf("error occurs during compare %s, err: %v", filename, err)
continue
}
if !equals {
t.Errorf("result is not equal of %s", filename)
}
}
}

func TestToJsonWithGlobalMeta(t *testing.T) {
// SortMapKeys will cause performance losses, only enabled during test
Expand Down Expand Up @@ -195,7 +275,7 @@ func TestToJsonWithRegex(t *testing.T) {
srcRdb := filepath.Join("../cases", "memory.rdb")
actualJSON := filepath.Join("tmp", "memory_regex.json")
expectJSON := filepath.Join("../cases", "memory_regex.json")
err = ToJsons(srcRdb, actualJSON, WithRegexOption("^l.*"))
err = ToJsons(srcRdb, actualJSON, WithRegexOption("^l.*"), WithConcurrent(1))
if err != nil {
t.Errorf("error occurs during parse, err: %v", err)
return
Expand Down Expand Up @@ -254,6 +334,79 @@ func TestToAof(t *testing.T) {
}
}

func TestToAofWithHashFieldExpiration(t *testing.T) {
err := os.MkdirAll("tmp", os.ModePerm)
if err != nil {
return
}
defer func() {
err := os.RemoveAll("tmp")
if err != nil {
t.Logf("remove tmp directory failed: %v", err)
}
}()

testCases := []string{
"hash_with_hfe",
"hash_as_listpack_with_hfe",
"valkey_hash2_with_hfe",
}
for _, filename := range testCases {
srcRdb := filepath.Join("../cases", filename+".rdb")
actualFile := filepath.Join("tmp", filename+".aof")
expectFile := filepath.Join("../cases", filename+".aof")
err = ToAOF(srcRdb, actualFile, lexOrder{})
if err != nil {
t.Errorf("error occurs during parse %s, err: %v", filename, err)
continue
}
equals, err := compareFileByLine(t, actualFile, expectFile)
if err != nil {
t.Errorf("error occurs during compare %s, err: %v", filename, err)
continue
}
if !equals {
t.Errorf("result is not equal of %s", filename)
}
}
}

func TestToAofWithValkeyClusterMetadata(t *testing.T) {
err := os.MkdirAll("tmp", os.ModePerm)
if err != nil {
return
}
defer func() {
err := os.RemoveAll("tmp")
if err != nil {
t.Logf("remove tmp directory failed: %v", err)
}
}()

testCases := []string{
"valkey_cluster_slot_info",
"valkey_cluster_slot_import",
}
for _, filename := range testCases {
srcRdb := filepath.Join("../cases", filename+".rdb")
actualFile := filepath.Join("tmp", filename+".aof")
expectFile := filepath.Join("../cases", filename+".aof")
err = ToAOF(srcRdb, actualFile, lexOrder{})
if err != nil {
t.Errorf("error occurs during parse %s, err: %v", filename, err)
continue
}
equals, err := compareFileByLine(t, actualFile, expectFile)
if err != nil {
t.Errorf("error occurs during compare %s, err: %v", filename, err)
continue
}
if !equals {
t.Errorf("result is not equal of %s", filename)
}
}
}

func TestToAofWithRegex(t *testing.T) {
err := os.MkdirAll("tmp", os.ModePerm)
if err != nil {
Expand Down
Loading