-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgtid_test.go
140 lines (126 loc) · 4.43 KB
/
gtid_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package gtid
import (
"testing"
)
func TestParseGtid_simple(t *testing.T) {
gtid, err := parseGtid("ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-11:13, ff92c4da-c5d7-11e3-8cf7-5e10e6a05cfb:1-5")
if nil != err {
t.Fatalf("unexpected error %v", err)
}
if gtid.String() != "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-11:13,ff92c4da-c5d7-11e3-8cf7-5e10e6a05cfb:1-5" {
t.Fatalf("wrong gtid %v", gtid.String())
}
}
func TestParseGtid_simple2(t *testing.T) {
gtid, err := parseGtid("CA8035EA-C5D5-11E3-8CE9-E66CCF50DB66:1-11:13, FF92C4DA-C5D7-11E3-8CF7-5E10E6A05CFB:1-5")
if nil != err {
t.Fatalf("unexpected error %v", err)
}
if gtid.String() != "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-11:13,ff92c4da-c5d7-11e3-8cf7-5e10e6a05cfb:1-5" {
t.Fatalf("wrong gtid %v", gtid.String())
}
}
func TestParseGtid_simple3(t *testing.T) {
gtid, err := parseGtid("CA8035EAC5D511E38CE9E66CCF50DB66:1-11:13, FF92C4DAC5D711E38CF75E10E6A05CFB:1-5")
if nil != err {
t.Fatalf("unexpected error %v", err)
}
if gtid.String() != "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-11:13,ff92c4da-c5d7-11e3-8cf7-5e10e6a05cfb:1-5" {
t.Fatalf("wrong gtid %v", gtid.String())
}
}
func TestParseGtid_simple4(t *testing.T) {
gtid, err := parseGtid("ca8035eac5d511e38ce9e66ccf50db66:1-11:13, ff92c4dac5d711e38cf75e10e6a05cfb:1-5")
if nil != err {
t.Fatalf("unexpected error %v", err)
}
if gtid.String() != "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-11:13,ff92c4da-c5d7-11e3-8cf7-5e10e6a05cfb:1-5" {
t.Fatalf("wrong gtid %v", gtid.String())
}
}
func TestParseGtid_interval_merge_left(t *testing.T) {
gtid, err := parseGtid("ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-10:13-14:15-20")
if nil != err {
t.Fatalf("unexpected error %v", err)
}
if gtid.String() != "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-10:13-20" {
t.Fatalf("wrong gtid %v", gtid.String())
}
}
func TestParseGtid_interval_merge_right(t *testing.T) {
gtid, err := parseGtid("ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-10:11-12:15-20")
if nil != err {
t.Fatalf("unexpected error %v", err)
}
if gtid.String() != "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-12:15-20" {
t.Fatalf("wrong gtid %v", gtid.String())
}
}
func TestParseGtid_interval_merge_cross(t *testing.T) {
gtid, err := parseGtid("ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:5-10:1-12:15-20")
if nil != err {
t.Fatalf("unexpected error %v", err)
}
if gtid.String() != "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-12:15-20" {
t.Fatalf("wrong gtid %v", gtid.String())
}
}
func TestParseGtid_uuid_merge_left(t *testing.T) {
gtid, err := parseGtid("ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:5-10, ff92c4da-c5d7-11e3-8cf7-5e10e6a05cfb:1-5, ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-4")
if nil != err {
t.Fatalf("unexpected error %v", err)
}
if gtid.String() != "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-10,ff92c4da-c5d7-11e3-8cf7-5e10e6a05cfb:1-5" {
t.Fatalf("wrong gtid %v", gtid.String())
}
}
func TestParseGtid_uuid_merge_right(t *testing.T) {
gtid, err := parseGtid("ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:5-10, ff92c4da-c5d7-11e3-8cf7-5e10e6a05cfb:1-5, ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-4")
if nil != err {
t.Fatalf("unexpected error %v", err)
}
if gtid.String() != "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-10,ff92c4da-c5d7-11e3-8cf7-5e10e6a05cfb:1-5" {
t.Fatalf("wrong gtid %v", gtid.String())
}
}
func TestGtidEventCount(t *testing.T) {
ret, err := GtidEventCount("ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-12:15-20, ff92c4da-c5d7-11e3-8cf7-5e10e6a05cfb:1-2")
if nil != err {
t.Fatalf("unexpected error %v", err)
}
if 20 != ret {
t.Fatalf("ret (%v) should == 20", ret)
}
}
func TestGtidEventList(t *testing.T) {
gtidString := "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1-3:5-6, ff92c4da-c5d7-11e3-8cf7-5e10e6a05cfb:1"
eventList, err := GtidEventList(gtidString)
if nil != err {
t.Fatalf("unexpected error %v", err)
}
if 6 != len(eventList) {
t.Fatalf("eventList length(%v) should == 6", len(eventList))
}
hasErr := false
if "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:1" != eventList[0] {
hasErr = true
}
if "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:2" != eventList[1] {
hasErr = true
}
if "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:3" != eventList[2] {
hasErr = true
}
if "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:5" != eventList[3] {
hasErr = true
}
if "ca8035ea-c5d5-11e3-8ce9-e66ccf50db66:6" != eventList[4] {
hasErr = true
}
if "ff92c4da-c5d7-11e3-8cf7-5e10e6a05cfb:1" != eventList[5] {
hasErr = true
}
if hasErr {
t.Fatalf("wrong eventList %v, gtid is %s", eventList, gtidString)
}
}