|
1 | 1 | package replication
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "bytes" |
| 5 | + |
4 | 6 | . "github.com/pingcap/check"
|
5 | 7 | )
|
6 | 8 |
|
@@ -40,3 +42,37 @@ func (t *testSyncerSuite) TestIndexOutOfRange(c *C) {
|
40 | 42 |
|
41 | 43 | c.Assert(err, IsNil)
|
42 | 44 | }
|
| 45 | + |
| 46 | +func (t *testSyncerSuite) TestParseEvent(c *C) { |
| 47 | + parser := NewBinlogParser() |
| 48 | + parser.format = &FormatDescriptionEvent{ |
| 49 | + Version: 0x4, |
| 50 | + ServerVersion: []uint8{0x35, 0x2e, 0x36, 0x2e, 0x32, 0x30, 0x2d, 0x6c, 0x6f, 0x67, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, |
| 51 | + CreateTimestamp: 0x0, |
| 52 | + EventHeaderLength: 0x13, |
| 53 | + EventTypeHeaderLengths: []uint8{0x38, 0xd, 0x0, 0x8, 0x0, 0x12, 0x0, 0x4, 0x4, 0x4, 0x4, 0x12, 0x0, 0x0, 0x5c, 0x0, 0x4, 0x1a, 0x8, 0x0, 0x0, 0x0, 0x8, 0x8, 0x8, 0x2, 0x0, 0x0, 0x0, 0xa, 0xa, 0xa, 0x19, 0x19, 0x0}, |
| 54 | + ChecksumAlgorithm: 0x0, |
| 55 | + } |
| 56 | + testCases := []struct { |
| 57 | + byteData []byte |
| 58 | + eventSize uint32 |
| 59 | + }{ |
| 60 | + {[]byte{0x86, 0x4c, 0x9c, 0x5d, 0x03, 0x65, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x4d, 0x01, 0x00, 0x00, 0x00, 0x00}, uint32(19)}, |
| 61 | + {[]byte{0x15, 0x50, 0x9c, 0x5d, 0x03, 0x65, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x59, 0x01, 0x00, 0x00, 0x00, 0x00, 0x7d, 0x82, 0xa8, 0x50}, uint32(23)}, |
| 62 | + } |
| 63 | + |
| 64 | + for _, tc := range testCases { |
| 65 | + r := bytes.NewReader(tc.byteData) |
| 66 | + _, err := parser.ParseSingleEvent(r, func(e *BinlogEvent) error { |
| 67 | + c.Assert(e.Header.EventType, Equals, STOP_EVENT) |
| 68 | + c.Assert(e.Header.EventSize, Equals, tc.eventSize) |
| 69 | + return nil |
| 70 | + }) |
| 71 | + c.Assert(err, IsNil) |
| 72 | + |
| 73 | + e, err2 := parser.Parse(tc.byteData) |
| 74 | + c.Assert(e.Header.EventType, Equals, STOP_EVENT) |
| 75 | + c.Assert(e.Header.EventSize, Equals, tc.eventSize) |
| 76 | + c.Assert(err2, IsNil) |
| 77 | + } |
| 78 | +} |
0 commit comments