test(aof): update test

This commit is contained in:
bandl 2021-11-01 22:51:26 +08:00
parent 4ffa91ac6a
commit 7aa39979f0
2 changed files with 51 additions and 21 deletions

View File

@ -0,0 +1,51 @@
package persisted
import (
"bufio"
"fmt"
"io"
"os"
"strconv"
"testing"
"time"
"gitee.com/timedb/wheatCache/pkg/proto"
"github.com/stretchr/testify/require"
)
func TestAOF_SendRequest(t *testing.T) {
aof := NewAOF(nil, "./test.aof", time.Second*3, 5, time.Second*1)
for i := 0; i < 100; i++ {
req := &proto.ReduceRequest{
Key: proto.NewBaseKey(strconv.Itoa(i), int64(i)),
Renewal: int32(i),
}
aof.SendRequest("Reduce", req)
}
time.Sleep(4 * time.Second)
fmt.Println(len(aof.byteIO))
}
func TestAOF_ReadRequest(t *testing.T) {
aof := NewAOF(nil, "./test.aof", time.Second*2, 5, time.Second*1)
f, _ := os.Open("test.aof")
defer f.Close()
rd := bufio.NewReader(f)
for {
line, err := rd.ReadBytes('\n')
if err != nil {
if err != io.EOF {
require.NoError(t, err)
}
break
}
msg, err := aof.DecodeAOF(line[:len(line)-1])
require.NoError(t, err)
fmt.Println(msg)
}
}

View File

@ -1,21 +0,0 @@
package persisted
import (
"testing"
"gitee.com/timedb/wheatCache/pkg/proto"
"github.com/stretchr/testify/require"
)
func Test_codec_Encode(t *testing.T) {
c := codec{}
req := &proto.LIndexRequest{
Key: proto.NewBaseKey("123"),
Index: 11,
}
b, err := c.Encode("LIndex", req)
require.NoError(t, err)
res, err := c.Decode(b)
require.NoError(t, err)
require.Equal(t, req.Index, res.(*proto.LIndexRequest).Index)
}