2022-09-25 01:42:07 +03:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
2022-09-25 13:54:22 +03:00
|
|
|
"bytes"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2022-09-25 01:42:07 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func subTestAOF(t *testing.T, mc *mockServer) {
|
|
|
|
runStep(t, mc, "loading", aof_loading_test)
|
2022-09-25 13:54:22 +03:00
|
|
|
// runStep(t, mc, "AOFMD5", aof_AOFMD5_test)
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadAOFAndClose(aof any) error {
|
|
|
|
var aofb []byte
|
|
|
|
switch aof := aof.(type) {
|
|
|
|
case []byte:
|
|
|
|
aofb = []byte(aof)
|
|
|
|
case string:
|
|
|
|
aofb = []byte(aof)
|
|
|
|
default:
|
|
|
|
return errors.New("aof is not string or bytes")
|
|
|
|
}
|
|
|
|
mc, err := mockOpenServer(MockServerOptions{
|
|
|
|
Silent: true,
|
|
|
|
Metrics: false,
|
|
|
|
AOFData: aofb,
|
|
|
|
})
|
|
|
|
if mc != nil {
|
|
|
|
mc.Close()
|
|
|
|
}
|
|
|
|
return err
|
2022-09-25 01:42:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func aof_loading_test(mc *mockServer) error {
|
|
|
|
|
2022-09-25 13:54:22 +03:00
|
|
|
var err error
|
|
|
|
// invalid command
|
|
|
|
err = loadAOFAndClose("asdfasdf\r\n")
|
|
|
|
if err == nil || err.Error() != "unknown command 'asdfasdf'" {
|
|
|
|
return fmt.Errorf("expected '%v', got '%v'",
|
|
|
|
"unknown command 'asdfasdf'", err)
|
|
|
|
}
|
2022-09-25 01:42:07 +03:00
|
|
|
|
2022-09-25 13:54:22 +03:00
|
|
|
// incomplete command
|
|
|
|
err = loadAOFAndClose("set fleet truck point 10 10\r\nasdfasdf")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-25 01:42:07 +03:00
|
|
|
|
2022-09-25 13:54:22 +03:00
|
|
|
// big aof file
|
|
|
|
var aof string
|
|
|
|
for i := 0; i < 10000; i++ {
|
|
|
|
aof += fmt.Sprintf("SET fleet truck%d POINT 10 10\r\n", i)
|
|
|
|
}
|
|
|
|
err = loadAOFAndClose(aof)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-25 01:42:07 +03:00
|
|
|
|
2022-09-25 13:54:22 +03:00
|
|
|
// extra zeros at various places
|
|
|
|
aof = ""
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
|
|
if i%10 == 0 {
|
|
|
|
aof += string(bytes.Repeat([]byte{0}, 100))
|
|
|
|
}
|
|
|
|
aof += fmt.Sprintf("SET fleet truck%d POINT 10 10\r\n", i)
|
|
|
|
}
|
|
|
|
aof += string(bytes.Repeat([]byte{0}, 5000))
|
|
|
|
err = loadAOFAndClose(aof)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// bad protocol
|
|
|
|
aof = "*2\r\n$1\r\nh\r\n+OK\r\n"
|
|
|
|
err = loadAOFAndClose(aof)
|
|
|
|
if fmt.Sprintf("%v", err) != "Protocol error: expected '$', got '+'" {
|
|
|
|
return fmt.Errorf("expected '%v', got '%v'",
|
|
|
|
"Protocol error: expected '$', got '+'", err)
|
|
|
|
}
|
2022-09-25 01:42:07 +03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2022-09-25 13:54:22 +03:00
|
|
|
|
|
|
|
// func aof_AOFMD5_test(mc *mockServer) error {
|
|
|
|
// return nil
|
|
|
|
// }
|