diff --git a/storage/persisted/aof_test.go b/storage/persisted/aof_test.go new file mode 100644 index 0000000..7dbd997 --- /dev/null +++ b/storage/persisted/aof_test.go @@ -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) + } +} diff --git a/storage/persisted/codec.gen_test.go b/storage/persisted/codec.gen_test.go deleted file mode 100644 index da0e03c..0000000 --- a/storage/persisted/codec.gen_test.go +++ /dev/null @@ -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) -}