vitess.io/vitess@v0.16.2/go/mysql/binlog_event_mariadb_test.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package mysql 18 19 import ( 20 "reflect" 21 "testing" 22 23 "github.com/stretchr/testify/assert" 24 "github.com/stretchr/testify/require" 25 ) 26 27 // sample event data 28 var ( 29 mariadbFormatEvent = []byte{0x87, 0x41, 0x9, 0x54, 0xf, 0x88, 0xf3, 0x0, 0x0, 0xf4, 0x0, 0x0, 0x0, 0xf8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x0, 0x31, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x33, 0x2d, 0x4d, 0x61, 0x72, 0x69, 0x61, 0x44, 0x42, 0x2d, 0x31, 0x7e, 0x70, 0x72, 0x65, 0x63, 0x69, 0x73, 0x65, 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, 0x87, 0x41, 0x9, 0x54, 0x13, 0x38, 0xd, 0x0, 0x8, 0x0, 0x12, 0x0, 0x4, 0x4, 0x4, 0x4, 0x12, 0x0, 0x0, 0xdc, 0x0, 0x4, 0x1a, 0x8, 0x0, 0x0, 0x0, 0x8, 0x8, 0x8, 0x2, 0x0, 0x0, 0x0, 0xa, 0xa, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,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0x0} 32 mariadbInsertEvent = []byte{0x88, 0x41, 0x9, 0x54, 0x2, 0x88, 0xf3, 0x0, 0x0, 0xa8, 0x0, 0x0, 0x0, 0x79, 0xa, 0x0, 0x0, 0x0, 0x0, 0x27, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x1a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x3, 0x73, 0x74, 0x64, 0x4, 0x21, 0x0, 0x21, 0x0, 0x21, 0x0, 0x76, 0x74, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x20, 0x76, 0x74, 0x5f, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x28, 0x6d, 0x73, 0x67, 0x29, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x20, 0x28, 0x27, 0x74, 0x65, 0x73, 0x74, 0x20, 0x30, 0x27, 0x29, 0x20, 0x2f, 0x2a, 0x20, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x20, 0x76, 0x74, 0x5f, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x20, 0x28, 0x69, 0x64, 0x20, 0x29, 0x20, 0x28, 0x6e, 0x75, 0x6c, 0x6c, 0x20, 0x29, 0x3b, 0x20, 0x2a, 0x2f} 33 34 mariadbChecksumFormatEvent = []byte{0x22, 0xe5, 0x3e, 0x54, 0xf, 0x8b, 0xf3, 0x0, 0x0, 0xf4, 0x0, 0x0, 0x0, 0xf8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x0, 0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 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x13, 0x4, 0x1, 0x14, 0x13, 0x32, 0xdc} 35 mariadbChecksumQueryEvent = []byte{0x22, 0xe5, 0x3e, 0x54, 0x2, 0x8a, 0xf3, 0x0, 0x0, 0xd9, 0x0, 0x0, 0x0, 0x69, 0x2, 0x0, 0x0, 0x0, 0x0, 0x1d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x1a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x3, 0x73, 0x74, 0x64, 0x4, 0x8, 0x0, 0x8, 0x0, 0x21, 0x0, 0x76, 0x74, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0, 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x20, 0x5f, 0x76, 0x74, 0x2e, 0x62, 0x6c, 0x70, 0x5f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x20, 0x53, 0x45, 0x54, 0x20, 0x70, 0x6f, 0x73, 0x3d, 0x27, 0x4d, 0x61, 0x72, 0x69, 0x61, 0x44, 0x42, 0x2f, 0x30, 0x2d, 0x36, 0x32, 0x33, 0x34, 0x34, 0x2d, 0x31, 0x34, 0x27, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x3d, 0x31, 0x34, 0x31, 0x33, 0x34, 0x30, 0x38, 0x30, 0x33, 0x34, 0x2c, 0x20, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x3d, 0x31, 0x34, 0x31, 0x33, 0x34, 0x30, 0x38, 0x30, 0x33, 0x34, 0x20, 0x57, 0x48, 0x45, 0x52, 0x45, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x64, 0x5f, 0x75, 0x69, 0x64, 0x3d, 0x30, 0xce, 0x49, 0x7a, 0x53} 36 mariadbChecksumStrippedQueryEvent = []byte{0x22, 0xe5, 0x3e, 0x54, 0x2, 0x8a, 0xf3, 0x0, 0x0, 0xd9, 0x0, 0x0, 0x0, 0x69, 0x2, 0x0, 0x0, 0x0, 0x0, 0x1d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x1a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x3, 0x73, 0x74, 0x64, 0x4, 0x8, 0x0, 0x8, 0x0, 0x21, 0x0, 0x76, 0x74, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0, 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x20, 0x5f, 0x76, 0x74, 0x2e, 0x62, 0x6c, 0x70, 0x5f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x20, 0x53, 0x45, 0x54, 0x20, 0x70, 0x6f, 0x73, 0x3d, 0x27, 0x4d, 0x61, 0x72, 0x69, 0x61, 0x44, 0x42, 0x2f, 0x30, 0x2d, 0x36, 0x32, 0x33, 0x34, 0x34, 0x2d, 0x31, 0x34, 0x27, 0x2c, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x3d, 0x31, 0x34, 0x31, 0x33, 0x34, 0x30, 0x38, 0x30, 0x33, 0x34, 0x2c, 0x20, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x3d, 0x31, 0x34, 0x31, 0x33, 0x34, 0x30, 0x38, 0x30, 0x33, 0x34, 0x20, 0x57, 0x48, 0x45, 0x52, 0x45, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x64, 0x5f, 0x75, 0x69, 0x64, 0x3d, 0x30} 37 38 mariadbSemiSyncNoAckInsertEvent = []byte{0xef, 0x00, 0x88, 0x41, 0x9, 0x54, 0x2, 0x88, 0xf3, 0x0, 0x0, 0xa8, 0x0, 0x0, 0x0, 0x79, 0xa, 0x0, 0x0, 0x0, 0x0, 0x27, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x1a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x3, 0x73, 0x74, 0x64, 0x4, 0x21, 0x0, 0x21, 0x0, 0x21, 0x0, 0x76, 0x74, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x20, 0x76, 0x74, 0x5f, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x28, 0x6d, 0x73, 0x67, 0x29, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x20, 0x28, 0x27, 0x74, 0x65, 0x73, 0x74, 0x20, 0x30, 0x27, 0x29, 0x20, 0x2f, 0x2a, 0x20, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x20, 0x76, 0x74, 0x5f, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x20, 0x28, 0x69, 0x64, 0x20, 0x29, 0x20, 0x28, 0x6e, 0x75, 0x6c, 0x6c, 0x20, 0x29, 0x3b, 0x20, 0x2a, 0x2f} 39 mariadbSemiSyncAckInsertEvent = []byte{0xef, 0x01, 0x88, 0x41, 0x9, 0x54, 0x2, 0x88, 0xf3, 0x0, 0x0, 0xa8, 0x0, 0x0, 0x0, 0x79, 0xa, 0x0, 0x0, 0x0, 0x0, 0x27, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x1a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x3, 0x73, 0x74, 0x64, 0x4, 0x21, 0x0, 0x21, 0x0, 0x21, 0x0, 0x76, 0x74, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x73, 0x70, 0x61, 0x63, 0x65, 0x0, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x20, 0x76, 0x74, 0x5f, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x28, 0x6d, 0x73, 0x67, 0x29, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x20, 0x28, 0x27, 0x74, 0x65, 0x73, 0x74, 0x20, 0x30, 0x27, 0x29, 0x20, 0x2f, 0x2a, 0x20, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x20, 0x76, 0x74, 0x5f, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x20, 0x28, 0x69, 0x64, 0x20, 0x29, 0x20, 0x28, 0x6e, 0x75, 0x6c, 0x6c, 0x20, 0x29, 0x3b, 0x20, 0x2a, 0x2f} 40 ) 41 42 func TestMariadbStandaloneGTIDEventIsGTID(t *testing.T) { 43 input := mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbStandaloneGTIDEvent)} 44 want := true 45 if got := input.IsGTID(); got != want { 46 t.Errorf("%#v.IsGTID() = %v, want %v", input, got, want) 47 } 48 } 49 50 func TestMariadbBeginGTIDEventIsGTID(t *testing.T) { 51 input := mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbBeginGTIDEvent)} 52 want := true 53 if got := input.IsGTID(); got != want { 54 t.Errorf("%#v.IsGTID() = %v, want %v", input, got, want) 55 } 56 } 57 58 func TestMariadbBinlogEventIsntGTID(t *testing.T) { 59 input := mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbInsertEvent)} 60 want := false 61 if got := input.IsGTID(); got != want { 62 t.Errorf("%#v.IsGTID() = %v, want %v", input, got, want) 63 } 64 } 65 66 func TestMariadbNotBeginGTID(t *testing.T) { 67 f, err := binlogEvent(mariadbFormatEvent).Format() 68 if err != nil { 69 t.Errorf("unexpected error: %v", err) 70 return 71 } 72 73 input := mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbStandaloneGTIDEvent)} 74 want := false 75 if _, got, err := input.GTID(f); got != want { 76 t.Errorf("%#v.GTID() = %v (%v), want %v", input, got, err, want) 77 } 78 } 79 80 func TestMariadbIsBeginGTID(t *testing.T) { 81 f, err := binlogEvent(mariadbFormatEvent).Format() 82 if err != nil { 83 t.Errorf("unexpected error: %v", err) 84 return 85 } 86 87 input := mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbBeginGTIDEvent)} 88 want := true 89 if _, got, err := input.GTID(f); got != want { 90 t.Errorf("%#v.IsBeginGTID() = %v (%v), want %v", input, got, err, want) 91 } 92 } 93 94 func TestMariadbStandaloneBinlogEventGTID(t *testing.T) { 95 f, err := binlogEvent(mariadbFormatEvent).Format() 96 if err != nil { 97 t.Errorf("unexpected error: %v", err) 98 return 99 } 100 101 input := mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbStandaloneGTIDEvent)} 102 want := MariadbGTID{Domain: 0, Server: 62344, Sequence: 9} 103 got, hasBegin, err := input.GTID(f) 104 assert.NoError(t, err, "unexpected error: %v", err) 105 assert.False(t, hasBegin, "unexpected hasBegin") 106 assert.True(t, reflect.DeepEqual(got, want), "%#v.GTID() = %#v, want %#v", input, got, want) 107 108 } 109 110 func TestMariadbBinlogEventGTID(t *testing.T) { 111 f, err := binlogEvent(mariadbFormatEvent).Format() 112 if err != nil { 113 t.Errorf("unexpected error: %v", err) 114 return 115 } 116 117 input := mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbBeginGTIDEvent)} 118 want := MariadbGTID{Domain: 0, Server: 62344, Sequence: 10} 119 got, hasBegin, err := input.GTID(f) 120 assert.NoError(t, err, "unexpected error: %v", err) 121 assert.True(t, hasBegin, "unexpected !hasBegin") 122 assert.True(t, reflect.DeepEqual(got, want), "%#v.GTID() = %#v, want %#v", input, got, want) 123 124 } 125 126 func TestMariadbBinlogEventFormat(t *testing.T) { 127 input := mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbFormatEvent)} 128 want := BinlogFormat{ 129 FormatVersion: 4, 130 ServerVersion: "10.0.13-MariaDB-1~precise-log", 131 HeaderLength: 19, 132 ChecksumAlgorithm: 0, 133 HeaderSizes: mariadbFormatEvent[76 : len(mariadbFormatEvent)-5], 134 } 135 got, err := input.Format() 136 assert.NoError(t, err, "unexpected error: %v", err) 137 assert.True(t, reflect.DeepEqual(got, want), "%#v.Format() = %v, want %v", input, got, want) 138 139 } 140 141 func TestMariadbBinlogEventChecksumFormat(t *testing.T) { 142 input := mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbChecksumFormatEvent)} 143 want := BinlogFormat{ 144 FormatVersion: 4, 145 ServerVersion: "10.0.13-MariaDB-1~precise-log", 146 HeaderLength: 19, 147 ChecksumAlgorithm: 1, 148 HeaderSizes: mariadbChecksumFormatEvent[76 : len(mariadbChecksumFormatEvent)-5], 149 } 150 got, err := input.Format() 151 assert.NoError(t, err, "unexpected error: %v", err) 152 assert.True(t, reflect.DeepEqual(got, want), "%#v.Format() = %v, want %v", input, got, want) 153 154 } 155 156 func TestMariadbBinlogEventStripChecksum(t *testing.T) { 157 f, err := (mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbChecksumFormatEvent)}).Format() 158 require.NoError(t, err, "unexpected error: %v", err) 159 160 input := mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbChecksumQueryEvent)} 161 wantEvent := mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbChecksumStrippedQueryEvent)} 162 wantChecksum := []byte{0xce, 0x49, 0x7a, 0x53} 163 gotEvent, gotChecksum, err := input.StripChecksum(f) 164 require.NoError(t, err, "unexpected error: %v", err) 165 166 if !reflect.DeepEqual(gotEvent, wantEvent) || !reflect.DeepEqual(gotChecksum, wantChecksum) { 167 t.Errorf("%#v.StripChecksum() = (%v, %v), want (%v, %v)", input, gotEvent, gotChecksum, wantEvent, wantChecksum) 168 } 169 } 170 171 func TestMariadbBinlogEventStripChecksumNone(t *testing.T) { 172 f, err := (mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbFormatEvent)}).Format() 173 require.NoError(t, err, "unexpected error: %v", err) 174 175 input := mariadbBinlogEvent{binlogEvent: binlogEvent(mariadbStandaloneGTIDEvent)} 176 want := input 177 gotEvent, gotChecksum, err := input.StripChecksum(f) 178 require.NoError(t, err, "unexpected error: %v", err) 179 180 if !reflect.DeepEqual(gotEvent, want) || gotChecksum != nil { 181 t.Errorf("%#v.StripChecksum() = (%v, %v), want (%v, nil)", input, gotEvent, gotChecksum, want) 182 } 183 } 184 185 func TestMariaDBSemiSyncAck(t *testing.T) { 186 { 187 c := Conn{ExpectSemiSyncIndicator: false} 188 buf, semiSyncAckRequested, err := c.AnalyzeSemiSyncAckRequest(mariadbInsertEvent) 189 assert.NoError(t, err) 190 e := NewMariadbBinlogEventWithSemiSyncInfo(buf, semiSyncAckRequested) 191 192 assert.False(t, e.IsSemiSyncAckRequested()) 193 assert.True(t, e.IsQuery()) 194 } 195 { 196 c := Conn{ExpectSemiSyncIndicator: true} 197 buf, semiSyncAckRequested, err := c.AnalyzeSemiSyncAckRequest(mariadbSemiSyncNoAckInsertEvent) 198 assert.NoError(t, err) 199 e := NewMariadbBinlogEventWithSemiSyncInfo(buf, semiSyncAckRequested) 200 201 assert.False(t, e.IsSemiSyncAckRequested()) 202 assert.True(t, e.IsQuery()) 203 } 204 { 205 c := Conn{ExpectSemiSyncIndicator: true} 206 buf, semiSyncAckRequested, err := c.AnalyzeSemiSyncAckRequest(mariadbSemiSyncAckInsertEvent) 207 assert.NoError(t, err) 208 e := NewMariadbBinlogEventWithSemiSyncInfo(buf, semiSyncAckRequested) 209 210 assert.True(t, e.IsSemiSyncAckRequested()) 211 assert.True(t, e.IsQuery()) 212 } 213 }