OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
| 9 "strings" |
9 "testing" | 10 "testing" |
10 "time" | 11 "time" |
11 | 12 |
12 ds "github.com/luci/gae/service/datastore" | 13 ds "github.com/luci/gae/service/datastore" |
13 "github.com/luci/gae/service/info" | 14 "github.com/luci/gae/service/info" |
14 . "github.com/luci/luci-go/common/testing/assertions" | 15 . "github.com/luci/luci-go/common/testing/assertions" |
15 . "github.com/smartystreets/goconvey/convey" | 16 . "github.com/smartystreets/goconvey/convey" |
16 "golang.org/x/net/context" | 17 "golang.org/x/net/context" |
17 ) | 18 ) |
18 | 19 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 }, | 104 }, |
104 }, | 105 }, |
105 | 106 |
106 { | 107 { |
107 putEnts: stage1Data, | 108 putEnts: stage1Data, |
108 expect: []qExpect{ | 109 expect: []qExpect{ |
109 {q: nq("Kind"), get: []ds.PropertyMap{}}, | 110 {q: nq("Kind"), get: []ds.PropertyMap{}}, |
110 {q: nq("Child").Ancestor(key("Kind", 3)), keys:
[]*ds.Key{ | 111 {q: nq("Child").Ancestor(key("Kind", 3)), keys:
[]*ds.Key{ |
111 key("Kind", 3, "Child", "seven"), | 112 key("Kind", 3, "Child", "seven"), |
112 }}, | 113 }}, |
| 114 {q: nq("Child").Ancestor(key("Kind", 3)).Eventua
lConsistency(true), keys: []*ds.Key{}}, |
| 115 {q: nq("Child").Ancestor(key("Kind", 3)).Eventua
lConsistency(true), keys: []*ds.Key{ |
| 116 key("Kind", 3, "Child", "seven"), |
| 117 }, inTxn: true}, |
| 118 {q: nq("Child").Ancestor(key("Kind", 3)), keys:
[]*ds.Key{ |
| 119 key("Kind", 3, "Child", "seven"), |
| 120 }, inTxn: true}, |
113 }, | 121 }, |
114 }, | 122 }, |
115 | 123 |
116 { | 124 { |
117 putEnts: stage2Data, | 125 putEnts: stage2Data, |
118 delEnts: []*ds.Key{key("Unique", 1)}, | 126 delEnts: []*ds.Key{key("Unique", 1)}, |
119 addIdxs: []*ds.IndexDefinition{ | 127 addIdxs: []*ds.IndexDefinition{ |
120 indx("Kind!", "-Extra", "-Val"), | 128 indx("Kind!", "-Extra", "-Val"), |
121 indx("Kind!", "-Extra", "-Val", "-__key__"), | 129 indx("Kind!", "-Extra", "-Val", "-__key__"), |
122 indx("Kind!", "Bogus", "Extra", "-Val"), | 130 indx("Kind!", "Bogus", "Extra", "-Val"), |
(...skipping 22 matching lines...) Expand all Loading... |
145 | 153 |
146 {q: nq("Child").Eq("Interesting", 28).Eq("Extra"
, "hello"), get: []ds.PropertyMap{ | 154 {q: nq("Child").Eq("Interesting", 28).Eq("Extra"
, "hello"), get: []ds.PropertyMap{ |
147 stage1Data[4], | 155 stage1Data[4], |
148 }}, | 156 }}, |
149 | 157 |
150 {q: (nq("Kind").Ancestor(key("Kind", 3)).Order("
Val"). | 158 {q: (nq("Kind").Ancestor(key("Kind", 3)).Order("
Val"). |
151 Start(curs("Val", 1, "__key__", key("Kin
d", 3))). | 159 Start(curs("Val", 1, "__key__", key("Kin
d", 3))). |
152 End(curs("Val", 90, "__key__", key("Kind
", 3, "Zeta", "woot")))), keys: []*ds.Key{}, | 160 End(curs("Val", 90, "__key__", key("Kind
", 3, "Zeta", "woot")))), keys: []*ds.Key{}, |
153 }, | 161 }, |
154 | 162 |
| 163 {q: (nq("Kind").Ancestor(key("Kind", 3)).Order("
Val"). |
| 164 Start(curs("Val", 1, "__key__", key("Kin
d", 3))). |
| 165 End(curs("Val", 90, "__key__", key("Kind
", 3, "Zeta", "woot")))), |
| 166 keys: []*ds.Key{}, |
| 167 inTxn: true}, |
| 168 |
155 {q: nq("Kind").Gt("Val", 2).Lte("Val", 5), get:
[]ds.PropertyMap{ | 169 {q: nq("Kind").Gt("Val", 2).Lte("Val", 5), get:
[]ds.PropertyMap{ |
156 stage1Data[0], stage1Data[3], | 170 stage1Data[0], stage1Data[3], |
157 }}, | 171 }}, |
158 | 172 |
159 {q: nq("Kind").Gt("Val", 2).Lte("Val", 5).Order(
"-Val"), get: []ds.PropertyMap{ | 173 {q: nq("Kind").Gt("Val", 2).Lte("Val", 5).Order(
"-Val"), get: []ds.PropertyMap{ |
160 stage1Data[3], stage1Data[0], | 174 stage1Data[3], stage1Data[0], |
161 }}, | 175 }}, |
162 | 176 |
163 {q: nq("").Gt("__key__", key("Kind", 2)), | 177 {q: nq("").Gt("__key__", key("Kind", 2)), |
164 // count counts from the index with Keys
Only and so counts the deleted | 178 // count counts from the index with Keys
Only and so counts the deleted |
(...skipping 23 matching lines...) Expand all Loading... |
188 Order("-Val"). | 202 Order("-Val"). |
189 Ancestor(key("Kind", 3))), | 203 Ancestor(key("Kind", 3))), |
190 get: []ds.PropertyMap{ | 204 get: []ds.PropertyMap{ |
191 stage1Data[2], | 205 stage1Data[2], |
192 stage2Data[0], | 206 stage2Data[0], |
193 stage2Data[1], | 207 stage2Data[1], |
194 }}, | 208 }}, |
195 | 209 |
196 {q: (nq("Kind"). | 210 {q: (nq("Kind"). |
197 Gt("Val", 2).Eq("Extra", "waffle"). | 211 Gt("Val", 2).Eq("Extra", "waffle"). |
| 212 Order("-Val"). |
| 213 Ancestor(key("Kind", 3))), |
| 214 get: []ds.PropertyMap{ |
| 215 stage1Data[2], |
| 216 stage2Data[0], |
| 217 stage2Data[1], |
| 218 }, inTxn: true}, |
| 219 |
| 220 {q: (nq("Kind"). |
| 221 Gt("Val", 2).Eq("Extra", "waffle"). |
198 Order("-Val", "-__key__"). | 222 Order("-Val", "-__key__"). |
199 Ancestor(key("Kind", 3))), | 223 Ancestor(key("Kind", 3))), |
200 get: []ds.PropertyMap{ | 224 get: []ds.PropertyMap{ |
201 stage1Data[2], | 225 stage1Data[2], |
202 stage2Data[0], | 226 stage2Data[0], |
203 stage2Data[1], | 227 stage2Data[1], |
204 }}, | 228 }}, |
205 | 229 |
206 {q: (nq("Kind"). | 230 {q: (nq("Kind"). |
207 Gt("Val", 2).Eq("Extra", "waffle"). | 231 Gt("Val", 2).Eq("Extra", "waffle"). |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 300 |
277 err = data.Run(q.Start(curs), func(pm ds
.PropertyMap, gc ds.CursorCB) bool { | 301 err = data.Run(q.Start(curs), func(pm ds
.PropertyMap, gc ds.CursorCB) bool { |
278 So(pm, ShouldResemble, stage1Dat
a[2]) | 302 So(pm, ShouldResemble, stage1Dat
a[2]) |
279 return false | 303 return false |
280 }) | 304 }) |
281 So(err, ShouldBeNil) | 305 So(err, ShouldBeNil) |
282 }, | 306 }, |
283 | 307 |
284 func(c context.Context) { | 308 func(c context.Context) { |
285 data := ds.Get(c) | 309 data := ds.Get(c) |
286 » » » » » q := nq("Something").Eq("Does", 2).Order
("Not", "Work") | 310 » » » » » q := nq("Something").Eq("Does", 2).Order
("Not", "-Work") |
287 So(data.Run(q, func(ds.Key, ds.CursorCB)
bool { | 311 So(data.Run(q, func(ds.Key, ds.CursorCB)
bool { |
288 return true | 312 return true |
289 » » » » » }), ShouldErrLike, "Try adding:\n C:Som
ething/Does/Not/Work") | 313 » » » » » }), ShouldErrLike, strings.Join([]string
{ |
| 314 » » » » » » "Consider adding:", |
| 315 » » » » » » "- kind: Something", |
| 316 » » » » » » " properties:", |
| 317 » » » » » » " - name: Does", |
| 318 » » » » » » " - name: Not", |
| 319 » » » » » » " - name: Work", |
| 320 » » » » » » " direction: desc", |
| 321 » » » » » }, "\n")) |
290 }, | 322 }, |
291 }, | 323 }, |
292 }, | 324 }, |
293 | 325 |
294 { | 326 { |
295 expect: []qExpect{ | 327 expect: []qExpect{ |
296 // eventual consistency; Unique/1 is deleted at
HEAD. Keysonly finds it, | 328 // eventual consistency; Unique/1 is deleted at
HEAD. Keysonly finds it, |
297 // but 'normal' doesn't. | 329 // but 'normal' doesn't. |
298 {q: nq("Unique").Gt("__key__", key("AKind", 5)).
Lte("__key__", key("Zeta", "prime")), | 330 {q: nq("Unique").Gt("__key__", key("AKind", 5)).
Lte("__key__", key("Zeta", "prime")), |
299 keys: []*ds.Key{key("Unique", 1)}, | 331 keys: []*ds.Key{key("Unique", 1)}, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 for j, fn := range stage.extraFn
s { | 432 for j, fn := range stage.extraFn
s { |
401 Convey(fmt.Sprintf("extr
aFn %d", j), func() { | 433 Convey(fmt.Sprintf("extr
aFn %d", j), func() { |
402 fn(c) | 434 fn(c) |
403 }) | 435 }) |
404 } | 436 } |
405 }) | 437 }) |
406 } | 438 } |
407 }) | 439 }) |
408 } | 440 } |
409 }) | 441 }) |
| 442 |
| 443 Convey("Test AutoIndex", t, func() { |
| 444 c, err := info.Get(Use(context.Background())).Namespace("ns") |
| 445 if err != nil { |
| 446 panic(err) |
| 447 } |
| 448 |
| 449 data := ds.Get(c) |
| 450 testing := data.Testable() |
| 451 testing.Consistent(true) |
| 452 |
| 453 So(data.Put(pmap("$key", key("Kind", 1), Next, |
| 454 "Val", 1, 2, 3, Next, |
| 455 "Extra", "hello", |
| 456 )), ShouldBeNil) |
| 457 |
| 458 So(data.Put(pmap("$key", key("Kind", 2), Next, |
| 459 "Val", 2, 3, 9, Next, |
| 460 "Extra", "ace", "hello", "there", |
| 461 )), ShouldBeNil) |
| 462 |
| 463 q := nq("Kind").Gt("Val", 2).Order("Val", "Extra") |
| 464 |
| 465 count, err := data.Count(q) |
| 466 So(err, ShouldErrLike, "Insufficient indexes") |
| 467 |
| 468 testing.AutoIndex(true) |
| 469 |
| 470 count, err = data.Count(q) |
| 471 So(err, ShouldBeNil) |
| 472 So(count, ShouldEqual, 2) |
| 473 }) |
410 } | 474 } |
OLD | NEW |