-
Notifications
You must be signed in to change notification settings - Fork 12
/
version_test.go
287 lines (256 loc) · 11 KB
/
version_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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// Copyright 2014-Present Couchbase, Inc.
//
// Use of this software is governed by the Business Source License included
// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
// in that file, in accordance with the Business Source License, use of this
// software will be governed by the Apache License, Version 2.0, included in
// the file licenses/APL2.txt.
package cbgt
import (
"testing"
)
func TestCheckVersion(t *testing.T) {
ok, err := CheckVersion(nil, "1.1.0")
if err != nil || ok {
t.Errorf("expect nil err and not ok on nil cfg")
}
cfg := NewCfgMem()
ok, err = CheckVersion(cfg, "1.0.0")
if err != nil || !ok {
t.Errorf("expected first version to win in brand new cfg")
}
v, _, err := cfg.Get(VERSION_KEY, 0)
if err != nil || string(v) != "1.0.0" {
t.Errorf("expected first version to persist in brand new cfg")
}
ok, err = CheckVersion(cfg, "1.1.0")
if err != nil || !ok {
t.Errorf("expected upgrade version to win")
}
v, _, err = cfg.Get(VERSION_KEY, 0)
if err != nil || string(v) != "1.1.0" {
t.Errorf("expected upgrade version to persist in brand new cfg")
}
ok, err = CheckVersion(cfg, "1.0.0")
if err != nil || ok {
t.Errorf("expected lower version to lose")
}
v, _, err = cfg.Get(VERSION_KEY, 0)
if err != nil || string(v) != "1.1.0" {
t.Errorf("expected version to remain stable on lower version check")
}
for i := 0; i < 3; i++ {
cfg = NewCfgMem()
eac := &ErrorAfterCfg{
inner: cfg,
errAfter: i,
}
ok, err = CheckVersion(eac, "1.0.0")
if err == nil || ok {
t.Errorf("expected err when cfg errors on %d'th op", i)
}
}
cfg = NewCfgMem()
eac := &ErrorAfterCfg{
inner: cfg,
errAfter: 3,
}
ok, err = CheckVersion(eac, "1.0.0")
if err != nil || !ok {
t.Errorf("expected ok when cfg doesn't error until 3rd op ")
}
cfg = NewCfgMem()
eac = &ErrorAfterCfg{
inner: cfg,
errAfter: 4,
}
ok, err = CheckVersion(eac, "1.0.0")
if err != nil || !ok {
t.Errorf("expected ok on first version init")
}
ok, err = CheckVersion(eac, "1.1.0")
if err == nil || ok {
t.Errorf("expected err when forcing cfg Set() error during version upgrade")
}
}
func TestCheckVersionForUpgrades(t *testing.T) {
cfg := NewCfgMem()
ok, err := CheckVersion(cfg, "5.0.0")
if err != nil || !ok {
t.Errorf("expected first version to win in brand new cfg")
}
v, _, err := cfg.Get(VERSION_KEY, 0)
if err != nil || string(v) != "5.0.0" {
t.Errorf("expected Cfg version 5.0.0")
}
// expect to fail as given lower version
ok, err = CheckVersion(cfg, "4.5.0")
if err != nil || ok {
t.Errorf("expected original version to win against given lower versions, err: %+v", err)
}
// case1 - with some old version 5.0.0 nodes
value := []byte(`{"uuid":"1530042671","nodeDefs":{"710948f76ea4f807dd4e41e44fe74c13":
{"hostPort":"127.0.0.1:9202","uuid":"710948f76ea4f807dd4e41e44fe74c13",
"implVersion":"5.0.0","tags":["feed","janitor","pindex","queryer","cbauth_service"],
"container":"","weight":1,"extras":"{\"features\":\"leanPlan\",\"nsHostPort\":` +
`\"127.0.0.1:9002\",\"version-cbft.app\":\"v0.5.0\",\"version-cbft.lib\": ` +
`\"v0.5.0\"}"},"7879038ec4529cc4815f5d927c3df476":{"hostPort":"192.168.1.3:9200",
"uuid":"7879038ec4529cc4815f5d927c3df476","implVersion":"5.0.0","tags":["feed",
"janitor","pindex","queryer","cbauth_service"],"container":"","weight":1,
"extras":"{\"features\":\"leanPlan\",\"nsHostPort\":\"192.168.1.3:9000\", ` +
`\"version-cbft.app\":\"v0.5.0\",\"version-cbft.lib\":\"v0.5.0\"}"},
"ecc1c3cad5a58523511e6ff2fd38f6be":{"hostPort":"127.0.0.1:9201",
"uuid":"ecc1c3cad5a58523511e6ff2fd38f6be","implVersion":"5.0.0",
"tags":["feed","janitor","pindex","queryer","cbauth_service"],"container":"",
"weight":1,"extras":"{\"features\":\"leanPlanNext\",\"nsHostPort\":\"127.0.0.1:9001\",` +
`\"version-cbft.app\":\"v0.5.0\",\"version-cbft.lib\":\"v0.5.0\"}"}},
"implVersion":"5.0.0"}`)
for _, k := range []string{NODE_DEFS_KNOWN, NODE_DEFS_WANTED} {
key := CfgNodeDefsKey(k)
_, err := cfg.Set(key, value, CFG_CAS_FORCE)
if err != nil {
t.Errorf("expected cfg Set to succeed")
}
}
// expected to pass though version bumping not happened with higher version 5.5.0
ok, err = CheckVersion(cfg, "5.5.0")
if err != nil || !ok {
t.Errorf("expected original version to win until all nodes are on given version, err: %+v", err)
}
// original 5.0.0 version retained
v, _, err = cfg.Get(VERSION_KEY, 0)
if err != nil || string(v) != "5.0.0" {
t.Errorf("expected Cfg version 5.0.0")
}
// case2 - with all cluster nodes on 5.5.0 version
value = []byte(`{"uuid":"1530042671","nodeDefs":{"710948f76ea4f807dd4e41e44fe74c13":
{"hostPort":"127.0.0.1:9202","uuid":"710948f76ea4f807dd4e41e44fe74c13",
"implVersion":"5.5.0","tags":["feed","janitor","pindex","queryer","cbauth_service"],
"container":"","weight":1,"extras":"{\"features\":\"leanPlan\",\"nsHostPort\":` +
`\"127.0.0.1:9002\",\"version-cbft.app\":\"v0.5.0\",\"version-cbft.lib\": ` +
`\"v0.5.0\"}"},"7879038ec4529cc4815f5d927c3df476":{"hostPort":"192.168.1.3:9200",
"uuid":"7879038ec4529cc4815f5d927c3df476","implVersion":"5.5.0","tags":["feed",
"janitor","pindex","queryer","cbauth_service"],"container":"","weight":1,
"extras":"{\"features\":\"leanPlan\",\"nsHostPort\":\"192.168.1.3:9000\", ` +
`\"version-cbft.app\":\"v0.5.0\",\"version-cbft.lib\":\"v0.5.0\"}"},
"ecc1c3cad5a58523511e6ff2fd38f6be":{"hostPort":"127.0.0.1:9201",
"uuid":"ecc1c3cad5a58523511e6ff2fd38f6be","implVersion":"5.5.0",
"tags":["feed","janitor","pindex","queryer","cbauth_service"],"container":"",
"weight":1,"extras":"{\"features\":\"leanPlanNext\",\"nsHostPort\":\"127.0.0.1:9001\",` +
`\"version-cbft.app\":\"v0.5.0\",\"version-cbft.lib\":\"v0.5.0\"}"}},
"implVersion":"5.5.0"}`)
for _, k := range []string{NODE_DEFS_KNOWN, NODE_DEFS_WANTED} {
key := CfgNodeDefsKey(k)
_, err := cfg.Set(key, value, CFG_CAS_FORCE)
if err != nil {
t.Errorf("expected cfg Set to succeed, err: %+v", err)
}
}
// expected to pass as all nodes are on same version 5.5.0
ok, err = CheckVersion(cfg, "5.5.0")
if err != nil || !ok {
t.Errorf("expected given version to win as all nodes are on given version, err: %+v", err)
}
// expect the 5.5.0 version
v, _, err = cfg.Get(VERSION_KEY, 0)
if err != nil || string(v) != "5.5.0" {
t.Errorf("expected Cfg version 5.5.0")
}
// expected to pass though version bumping not happened with higher 5.5.5 version
ok, err = CheckVersion(cfg, "5.5.5")
if err != nil || !ok {
t.Errorf("expected original version to win until all nodes are on given version, err: %+v", err)
}
// case3 - mixed node cluster with older 5.5.0 version & 5.5.5
value = []byte(`{"uuid":"1530042671","nodeDefs":{"710948f76ea4f807dd4e41e44fe74c13":
{"hostPort":"127.0.0.1:9202","uuid":"710948f76ea4f807dd4e41e44fe74c13",
"implVersion":"5.5.5","tags":["feed","janitor","pindex","queryer","cbauth_service"],
"container":"","weight":1,"extras":"{\"features\":\"leanPlan\",\"nsHostPort\":` +
`\"127.0.0.1:9002\",\"version-cbft.app\":\"v0.5.0\",\"version-cbft.lib\": ` +
`\"v0.5.0\"}"},"7879038ec4529cc4815f5d927c3df476":{"hostPort":"192.168.1.3:9200",
"uuid":"7879038ec4529cc4815f5d927c3df476","implVersion":"5.5.0","tags":["feed",
"janitor","pindex","queryer","cbauth_service"],"container":"","weight":1,
"extras":"{\"features\":\"leanPlan\",\"nsHostPort\":\"192.168.1.3:9000\", ` +
`\"version-cbft.app\":\"v0.5.0\",\"version-cbft.lib\":\"v0.5.0\"}"},
"ecc1c3cad5a58523511e6ff2fd38f6be":{"hostPort":"127.0.0.1:9201",
"uuid":"ecc1c3cad5a58523511e6ff2fd38f6be","implVersion":"5.5.5",
"tags":["feed","janitor","pindex","queryer","cbauth_service"],"container":"",
"weight":1,"extras":"{\"features\":\"leanPlanNext\",\"nsHostPort\":\"127.0.0.1:9001\",` +
`\"version-cbft.app\":\"v0.5.0\",\"version-cbft.lib\":\"v0.5.0\"}"}},
"implVersion":"5.5.5"}`)
for _, k := range []string{NODE_DEFS_KNOWN, NODE_DEFS_WANTED} {
key := CfgNodeDefsKey(k)
_, err := cfg.Set(key, value, CFG_CAS_FORCE)
if err != nil {
t.Errorf("expected cfg Set to succeed, err: %+v", err)
}
}
// expected to pass though version bumping not happened with higher 5.5.5 version
ok, err = CheckVersion(cfg, "5.5.5")
if err != nil || !ok {
t.Errorf("expected original version to win until all nodes are on given version, err: %+v", err)
}
// expected to pass with the same version as that of current
ok, err = CheckVersion(cfg, "5.5.0")
if err != nil || !ok {
t.Errorf("expected given version to win as few nodes are on given version, err: %+v", err)
}
// expect the 5.5.0 version
v, _, err = cfg.Get(VERSION_KEY, 0)
if err != nil || string(v) != "5.5.0" {
t.Errorf("expected Cfg version 5.5.0")
}
// case3 - all nodes in version 5.5.5
value = []byte(`{"uuid":"1530042671","nodeDefs":{"710948f76ea4f807dd4e41e44fe74c13":
{"hostPort":"127.0.0.1:9202","uuid":"710948f76ea4f807dd4e41e44fe74c13",
"implVersion":"5.5.5","tags":["feed","janitor","pindex","queryer","cbauth_service"],
"container":"","weight":1,"extras":"{\"features\":\"leanPlan\",\"nsHostPort\":` +
`\"127.0.0.1:9002\",\"version-cbft.app\":\"v0.5.0\",\"version-cbft.lib\": ` +
`\"v0.5.0\"}"},"7879038ec4529cc4815f5d927c3df476":{"hostPort":"192.168.1.3:9200",
"uuid":"7879038ec4529cc4815f5d927c3df476","implVersion":"5.5.5","tags":["feed",
"janitor","pindex","queryer","cbauth_service"],"container":"","weight":1,
"extras":"{\"features\":\"leanPlan\",\"nsHostPort\":\"192.168.1.3:9000\", ` +
`\"version-cbft.app\":\"v0.5.0\",\"version-cbft.lib\":\"v0.5.0\"}"},
"ecc1c3cad5a58523511e6ff2fd38f6be":{"hostPort":"127.0.0.1:9201",
"uuid":"ecc1c3cad5a58523511e6ff2fd38f6be","implVersion":"5.5.5",
"tags":["feed","janitor","pindex","queryer","cbauth_service"],"container":"",
"weight":1,"extras":"{\"features\":\"leanPlanNext\",\"nsHostPort\":\"127.0.0.1:9001\",` +
`\"version-cbft.app\":\"v0.5.0\",\"version-cbft.lib\":\"v0.5.0\"}"}},
"implVersion":"5.5.5"}`)
for _, k := range []string{NODE_DEFS_KNOWN, NODE_DEFS_WANTED} {
key := CfgNodeDefsKey(k)
_, err := cfg.Set(key, value, CFG_CAS_FORCE)
if err != nil {
t.Errorf("expected cfg Set to succeed, err: %+v", err)
}
}
// expected to pass as all nodes are on same version 5.5.5
ok, err = CheckVersion(cfg, "5.5.5")
if err != nil || !ok {
t.Errorf("expected given version to win as all nodes are on given version, err: %+v", err)
}
// expected to pass though no version bumping required with higher version
ok, err = CheckVersion(cfg, "5.5.9")
if err != nil || !ok {
t.Errorf("expected given version to fail until all nodes are on given version, err: %+v", err)
}
// expect the 5.5.5 version
v, _, err = cfg.Get(VERSION_KEY, 0)
if err != nil || string(v) != "5.5.5" {
t.Errorf("expected Cfg version 5.5.5")
}
}
func TestVerifyEffectiveClusterVersion(t *testing.T) {
cfg := NewCfgMem()
eac := &ErrorUntilCfg{
inner: cfg,
errUntil: 2,
}
rv, err := VerifyEffectiveClusterVersion(eac, LeanPlanVersion)
if err != nil {
t.Errorf("expected no err: %v", err)
}
if !rv {
t.Errorf("expected cluster version to match lean version %s", LeanPlanVersion)
}
}