Skip to content

Commit

Permalink
frame test
Browse files Browse the repository at this point in the history
  • Loading branch information
venjiang committed May 18, 2022
1 parent e20bc73 commit b7950fc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions core/frame/data_frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ func TestDataFrameEncode(t *testing.T) {

tidbuf := []byte(d.TransactionID())
result := []byte{
0x80 | byte(TagOfDataFrame), byte(len(tidbuf) + 4 + 8 + 2),
0x80 | byte(TagOfMetaFrame), byte(len(tidbuf) + 2 + 2),
0x80 | byte(TagOfDataFrame), byte(len(tidbuf) + 4 + 8 + 2 + 3),
0x80 | byte(TagOfMetaFrame), byte(len(tidbuf) + 2 + 2 + 3),
byte(TagOfTransactionID), byte(len(tidbuf))}
result = append(result, tidbuf...)
result = append(result, byte(TagOfSourceID), 0x0)
result = append(result, byte(TagOfState), 0x1, 0x0)
result = append(result, 0x80|byte(TagOfPayloadFrame), 0x06,
userDataTag, 0x04, 0x79, 0x6F, 0x6D, 0x6F)
assert.Equal(t, result, d.Encode())
Expand Down
4 changes: 2 additions & 2 deletions core/frame/handshake_frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestHandshakeFrameEncode(t *testing.T) {
m.metaFrame.SetTransactionID("1234")
m.metaFrame.SetSourceID("1")
assert.Equal(t, []byte{
0x80 | byte(TagOfHandshakeFrame), 0x17 + 13,
0x80 | byte(TagOfHandshakeFrame), 0x17 + 13 + 3,
byte(TagOfHandshakeName), 0x04, 0x31, 0x32, 0x33, 0x34,
byte(TagOfHandshakeID), 0x0,
byte(TagOfHandshakeType), 0x01, 0xD3,
Expand All @@ -22,7 +22,7 @@ func TestHandshakeFrameEncode(t *testing.T) {
byte(TagOfHandshakeAuthName), 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e,
byte(TagOfHandshakeAuthPayload), 0x01, 0x61,
// metaframe, see meta_frame_test
0xaf, 0x09, 0x01, 0x04, 0x31, 0x32, 0x33, 0x34, 0x03, 0x01, 0x31,
0xaf, 0x0c, 0x01, 0x04, 0x31, 0x32, 0x33, 0x34, 0x03, 0x01, 0x31, 0x04, 0x01, 0x00,
},
m.Encode(),
)
Expand Down
6 changes: 4 additions & 2 deletions core/frame/meta_frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import (
func TestMetaFrameEncode(t *testing.T) {
m := NewMetaFrame()
tidbuf := []byte(m.tid)
result := []byte{0x80 | byte(TagOfMetaFrame), byte(1 + 1 + len(tidbuf) + 2), byte(TagOfTransactionID), byte(len(tidbuf))}
result := []byte{0x80 | byte(TagOfMetaFrame), byte(1 + 1 + len(tidbuf) + 5), byte(TagOfTransactionID), byte(len(tidbuf))}
result = append(result, tidbuf...)
result = append(result, byte(TagOfSourceID), 0x0)
result = append(result, byte(TagOfState), 0x1, 0x0)
assert.Equal(t, result, m.Encode())
}

func TestMetaFrameDecode(t *testing.T) {
buf := []byte{0x80 | byte(TagOfMetaFrame), 0x09, byte(TagOfTransactionID), 0x04, 0x31, 0x32, 0x33, 0x34, byte(TagOfSourceID), 0x01, 0x31}
buf := []byte{0x80 | byte(TagOfMetaFrame), 0x09 + 3, byte(TagOfTransactionID), 0x04, 0x31, 0x32, 0x33, 0x34, byte(TagOfSourceID), 0x01, 0x31, byte(TagOfState), 0x01, 0x0}
meta, err := DecodeToMetaFrame(buf)
assert.NoError(t, err)
assert.EqualValues(t, "1234", meta.TransactionID())
assert.EqualValues(t, "1", meta.SourceID())
assert.EqualValues(t, Normal, meta.State())
t.Logf("%# x", buf)
}

0 comments on commit b7950fc

Please sign in to comment.