@@ -24,6 +24,7 @@ import (
24
24
"github.com/stretchr/testify/assert"
25
25
"github.com/stretchr/testify/require"
26
26
27
+ "vitess.io/vitess/go/mysql/replication"
27
28
"vitess.io/vitess/go/test/utils"
28
29
29
30
binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
@@ -88,14 +89,50 @@ func TestComBinlogDumpGTID(t *testing.T) {
88
89
cConn .Close ()
89
90
}()
90
91
92
+ t .Run ("WriteComBinlogDumpGTIDEmptyGTID" , func (t * testing.T ) {
93
+ // Write ComBinlogDumpGTID packet, read it, compare.
94
+ var flags uint16 = 0x0d0e
95
+ err := cConn .WriteComBinlogDumpGTID (0x01020304 , "moofarm" , 0x05060708090a0b0c , flags , []byte {})
96
+ assert .NoError (t , err )
97
+ data , err := sConn .ReadPacket ()
98
+ require .NoError (t , err , "sConn.ReadPacket - ComBinlogDumpGTID failed: %v" , err )
99
+ require .NotEmpty (t , data )
100
+ require .EqualValues (t , data [0 ], ComBinlogDumpGTID )
101
+
102
+ expectedData := []byte {
103
+ ComBinlogDumpGTID ,
104
+ 0x0e , 0x0d , // flags
105
+ 0x04 , 0x03 , 0x02 , 0x01 , // server-id
106
+ 0x07 , 0x00 , 0x00 , 0x00 , // binlog-filename-len
107
+ 'm' , 'o' , 'o' , 'f' , 'a' , 'r' , 'm' , // bilog-filename
108
+ 0x0c , 0x0b , 0x0a , 0x09 , 0x08 , 0x07 , 0x06 , 0x05 , // binlog-pos
109
+ 0x00 , 0x00 , 0x00 , 0x00 , // data-size is zero, no GTID payload
110
+ }
111
+ assert .Equal (t , expectedData , data )
112
+ logFile , logPos , pos , err := sConn .parseComBinlogDumpGTID (data )
113
+ require .NoError (t , err , "parseComBinlogDumpGTID failed: %v" , err )
114
+ assert .Equal (t , "moofarm" , logFile )
115
+ assert .Equal (t , uint64 (0x05060708090a0b0c ), logPos )
116
+ assert .True (t , pos .IsZero ())
117
+ })
118
+
119
+ sConn .sequence = 0
120
+
91
121
t .Run ("WriteComBinlogDumpGTID" , func (t * testing.T ) {
92
122
// Write ComBinlogDumpGTID packet, read it, compare.
93
123
var flags uint16 = 0x0d0e
94
124
assert .Equal (t , flags , flags | BinlogThroughGTID )
95
- err := cConn .WriteComBinlogDumpGTID (0x01020304 , "moofarm" , 0x05060708090a0b0c , flags , []byte {0xfa , 0xfb })
125
+ gtidSet , err := replication .ParseMysql56GTIDSet ("16b1039f-22b6-11ed-b765-0a43f95f28a3:1-243" )
126
+ require .NoError (t , err )
127
+ sidBlock := gtidSet .SIDBlock ()
128
+ assert .Len (t , sidBlock , 48 )
129
+
130
+ err = cConn .WriteComBinlogDumpGTID (0x01020304 , "moofarm" , 0x05060708090a0b0c , flags , sidBlock )
96
131
assert .NoError (t , err )
97
132
data , err := sConn .ReadPacket ()
98
133
require .NoError (t , err , "sConn.ReadPacket - ComBinlogDumpGTID failed: %v" , err )
134
+ require .NotEmpty (t , data )
135
+ require .EqualValues (t , data [0 ], ComBinlogDumpGTID )
99
136
100
137
expectedData := []byte {
101
138
ComBinlogDumpGTID ,
@@ -104,10 +141,15 @@ func TestComBinlogDumpGTID(t *testing.T) {
104
141
0x07 , 0x00 , 0x00 , 0x00 , // binlog-filename-len
105
142
'm' , 'o' , 'o' , 'f' , 'a' , 'r' , 'm' , // bilog-filename
106
143
0x0c , 0x0b , 0x0a , 0x09 , 0x08 , 0x07 , 0x06 , 0x05 , // binlog-pos
107
- 0x02 , 0x00 , 0x00 , 0x00 , // data-size
108
- 0xfa , 0xfb , // data
144
+ 0x30 , 0x00 , 0x00 , 0x00 , // data-size
109
145
}
146
+ expectedData = append (expectedData , sidBlock ... ) // data
110
147
assert .Equal (t , expectedData , data )
148
+ logFile , logPos , pos , err := sConn .parseComBinlogDumpGTID (data )
149
+ require .NoError (t , err , "parseComBinlogDumpGTID failed: %v" , err )
150
+ assert .Equal (t , "moofarm" , logFile )
151
+ assert .Equal (t , uint64 (0x05060708090a0b0c ), logPos )
152
+ assert .Equal (t , gtidSet , pos .GTIDSet )
111
153
})
112
154
113
155
sConn .sequence = 0
0 commit comments