Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be 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 "strings" |
| 10 "testing" | 10 "testing" |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 pmap("$key", mkKey("dev~app", "", "__nam espace__", "bob")), | 359 pmap("$key", mkKey("dev~app", "", "__nam espace__", "bob")), |
| 360 pmap("$key", mkKey("dev~app", "", "__nam espace__", "ns")), | 360 pmap("$key", mkKey("dev~app", "", "__nam espace__", "ns")), |
| 361 }}, | 361 }}, |
| 362 {q: nq("__namespace__").Offset(1), get: []ds.Pro pertyMap{ | 362 {q: nq("__namespace__").Offset(1), get: []ds.Pro pertyMap{ |
| 363 pmap("$key", mkKey("dev~app", "", "__nam espace__", "bob")), | 363 pmap("$key", mkKey("dev~app", "", "__nam espace__", "bob")), |
| 364 pmap("$key", mkKey("dev~app", "", "__nam espace__", "ns")), | 364 pmap("$key", mkKey("dev~app", "", "__nam espace__", "ns")), |
| 365 }}, | 365 }}, |
| 366 {q: nq("__namespace__").Offset(1).Limit(1), get: []ds.PropertyMap{ | 366 {q: nq("__namespace__").Offset(1).Limit(1), get: []ds.PropertyMap{ |
| 367 pmap("$key", mkKey("dev~app", "", "__nam espace__", "bob")), | 367 pmap("$key", mkKey("dev~app", "", "__nam espace__", "bob")), |
| 368 }}, | 368 }}, |
| 369 // | |
| 370 // eventual consistency; Unique/1 is deleted at HEAD. Keysonly finds it, | |
| 371 // but 'normal' doesn't. | |
| 372 {q: nq("Unique").Gt("__key__", key("AKind", 5)). Lte("__key__", key("Zeta", "prime")), | |
| 373 keys: []*ds.Key{key("Unique", 1)}, | |
| 374 get: []ds.PropertyMap{}}, | |
| 369 }, | 375 }, |
| 370 | 376 |
| 371 extraFns: []func(context.Context){ | 377 extraFns: []func(context.Context){ |
| 372 func(c context.Context) { | 378 func(c context.Context) { |
| 373 curs := ds.Cursor(nil) | 379 curs := ds.Cursor(nil) |
| 374 | 380 |
| 375 q := nq("").Gt("__key__", key("Kind", 2) ) | 381 q := nq("").Gt("__key__", key("Kind", 2) ) |
| 376 | 382 |
| 377 err := ds.Run(c, q, func(pm ds.PropertyM ap, gc ds.CursorCB) error { | 383 err := ds.Run(c, q, func(pm ds.PropertyM ap, gc ds.CursorCB) error { |
| 378 So(pm, ShouldResemble, pmap( | 384 So(pm, ShouldResemble, pmap( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 " ancestor: yes", | 420 " ancestor: yes", |
| 415 " properties:", | 421 " properties:", |
| 416 " - name: Val", | 422 " - name: Val", |
| 417 }, "\n")) | 423 }, "\n")) |
| 418 }, | 424 }, |
| 419 }, | 425 }, |
| 420 }, | 426 }, |
| 421 | 427 |
| 422 { | 428 { |
| 423 expect: []qExpect{ | 429 expect: []qExpect{ |
| 424 // eventual consistency; Unique/1 is deleted at HEAD. Keysonly finds it, | |
| 425 // but 'normal' doesn't. | |
| 426 {q: nq("Unique").Gt("__key__", key("AKind", 5)). Lte("__key__", key("Zeta", "prime")), | |
| 427 keys: []*ds.Key{key("Unique", 1)}, | |
| 428 get: []ds.PropertyMap{}}, | |
| 429 | |
| 430 {q: nq("Kind").Eq("Val", 1, 3), get: []ds.Proper tyMap{ | 430 {q: nq("Kind").Eq("Val", 1, 3), get: []ds.Proper tyMap{ |
| 431 stage1Data[0], stage2Data[2], | 431 stage1Data[0], stage2Data[2], |
| 432 }}, | 432 }}, |
| 433 }, | 433 }, |
| 434 }, | 434 }, |
| 435 }}, | 435 }}, |
| 436 | |
| 436 {"collapsed types", []qExStage{ | 437 {"collapsed types", []qExStage{ |
| 437 { | 438 { |
| 438 putEnts: collapsedData, | 439 putEnts: collapsedData, |
| 439 }, | 440 }, |
| 440 { | 441 { |
| 441 expect: []qExpect{ | 442 expect: []qExpect{ |
| 442 // PTTime | 443 // PTTime |
| 443 { | 444 { |
| 444 q: nq("Kind").Lte("Date", time.Date(2000 , time.February, 1, 1, 1, 1, 1, time.UTC)), | 445 q: nq("Kind").Lte("Date", time.Date(2000 , time.February, 1, 1, 1, 1, 1, time.UTC)), |
| 445 get: []ds.PropertyMap{ | 446 get: []ds.PropertyMap{ |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 476 }, | 477 }, |
| 477 { | 478 { |
| 478 q: nq("Kind").Eq("Val", []byte("uwutm8") ), | 479 q: nq("Kind").Eq("Val", []byte("uwutm8") ), |
| 479 get: []ds.PropertyMap{ | 480 get: []ds.PropertyMap{ |
| 480 collapsedData[5], | 481 collapsedData[5], |
| 481 }, | 482 }, |
| 482 }, | 483 }, |
| 483 }, | 484 }, |
| 484 }, | 485 }, |
| 485 }}, | 486 }}, |
| 487 | |
| 488 {"regression: tombstones and limit/offset queries", []qExStage{ | |
| 489 { | |
| 490 putEnts: []ds.PropertyMap{ | |
| 491 pmap("$key", key("Kind", 1)), | |
| 492 pmap("$key", key("Kind", 2)), | |
| 493 pmap("$key", key("Kind", 3)), | |
| 494 }, | |
| 495 delEnts: []*ds.Key{key("Kind", 2)}, | |
| 496 }, | |
| 497 { | |
| 498 expect: []qExpect{ | |
| 499 { | |
| 500 q: nq("Kind").Limit(2), | |
| 501 get: []ds.PropertyMap{ | |
| 502 pmap("$key", key("Kind", 1)), | |
| 503 pmap("$key", key("Kind", 3)), | |
| 504 }, | |
| 505 }, | |
| 506 | |
| 507 { | |
| 508 q: nq("Kind").Offset(2), | |
| 509 get: []ds.PropertyMap{}, | |
| 510 }, | |
| 511 }, | |
| 512 }, | |
| 513 }}, | |
| 486 } | 514 } |
| 487 | 515 |
| 488 func TestQueryExecution(t *testing.T) { | 516 func TestQueryExecution(t *testing.T) { |
| 489 t.Parallel() | 517 t.Parallel() |
| 490 | 518 |
| 491 Convey("Test query execution", t, func() { | 519 Convey("Test query execution", t, func() { |
| 492 c, err := info.Namespace(Use(context.Background()), "ns") | 520 c, err := info.Namespace(Use(context.Background()), "ns") |
| 493 if err != nil { | 521 if err != nil { |
| 494 panic(err) | 522 panic(err) |
| 495 } | 523 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 513 } | 541 } |
| 514 for ns, ents := range byNs { | 542 for ns, ents := range byNs { |
| 515 c := info.MustNamespace(c, ns) | 543 c := info.MustNamespace(c, ns) |
| 516 if err := ds.Put(c, ents); err ! = nil { | 544 if err := ds.Put(c, ents); err ! = nil { |
| 517 // prevent Convey from t hinking this assertion should show up in | 545 // prevent Convey from t hinking this assertion should show up in |
| 518 // every test loop. | 546 // every test loop. |
| 519 panic(err) | 547 panic(err) |
| 520 } | 548 } |
| 521 } | 549 } |
| 522 | 550 |
| 551 if len(stage.delEnts) > 0 { | |
| 552 //fmt.Println("DELETING", stage. delEnts) | |
| 553 } | |
|
iannucci
2016/11/12 00:05:47
derp
| |
| 523 if err := ds.Delete(c, stage.delEnts); e rr != nil { | 554 if err := ds.Delete(c, stage.delEnts); e rr != nil { |
| 524 panic(err) | 555 panic(err) |
| 525 } | 556 } |
| 526 | 557 |
| 527 Convey(fmt.Sprintf("stage %d", i), func( ) { | 558 Convey(fmt.Sprintf("stage %d", i), func( ) { |
| 528 for j, expect := range stage.exp ect { | 559 for j, expect := range stage.exp ect { |
| 529 runner := func(c context .Context, f func(ic context.Context) error, _ *ds.TransactionOptions) error { | 560 runner := func(c context .Context, f func(ic context.Context) error, _ *ds.TransactionOptions) error { |
| 530 return f(c) | 561 return f(c) |
| 531 } | 562 } |
| 532 if expect.inTxn { | 563 if expect.inTxn { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 | 664 |
| 634 v, ok := actual.(error) | 665 v, ok := actual.(error) |
| 635 if !ok { | 666 if !ok { |
| 636 return fmt.Sprintf("type of 'actual' must be error, not %T", act ual) | 667 return fmt.Sprintf("type of 'actual' must be error, not %T", act ual) |
| 637 } | 668 } |
| 638 if v == nil || v == ds.Stop { | 669 if v == nil || v == ds.Stop { |
| 639 return "" | 670 return "" |
| 640 } | 671 } |
| 641 return fmt.Sprintf("expected success value, not %v", v) | 672 return fmt.Sprintf("expected success value, not %v", v) |
| 642 } | 673 } |
| OLD | NEW |