MCPcopy
hub / github.com/etcd-io/bbolt / TestCursor_Last_EmptyPages

Function TestCursor_Last_EmptyPages

cursor_test.go:636–679  ·  view source on GitHub ↗

Ensure that a cursor can skip over empty pages that have been deleted.

(t *testing.T)

Source from the content-addressed store, hash-verified

634
635// Ensure that a cursor can skip over empty pages that have been deleted.
636func TestCursor_Last_EmptyPages(t *testing.T) {
637 db := btesting.MustCreateDB(t)
638
639 // Create 1000 keys in the "widgets" bucket.
640 if err := db.Update(func(tx *bolt.Tx) error {
641 b, err := tx.CreateBucket([]byte("widgets"))
642 if err != nil {
643 t.Fatal(err)
644 }
645
646 for i := 0; i < 1000; i++ {
647 if err := b.Put(u64tob(uint64(i)), []byte{}); err != nil {
648 t.Fatal(err)
649 }
650 }
651
652 return nil
653 }); err != nil {
654 t.Fatal(err)
655 }
656
657 // Delete last 800 elements to ensure last page is empty
658 if err := db.Update(func(tx *bolt.Tx) error {
659 b := tx.Bucket([]byte("widgets"))
660 for i := 200; i < 1000; i++ {
661 if err := b.Delete(u64tob(uint64(i))); err != nil {
662 t.Fatal(err)
663 }
664 }
665
666 c := b.Cursor()
667 var n int
668 for k, _ := c.Last(); k != nil; k, _ = c.Prev() {
669 n++
670 }
671 if n != 200 {
672 t.Fatalf("unexpected key count: %d", n)
673 }
674
675 return nil
676 }); err != nil {
677 t.Fatal(err)
678 }
679}
680
681// Ensure that a Tx can iterate over all elements in a bucket.
682func TestCursor_QuickCheck(t *testing.T) {

Callers

nothing calls this directly

Calls 12

MustCreateDBFunction · 0.92
u64tobFunction · 0.85
UpdateMethod · 0.80
LastMethod · 0.80
PrevMethod · 0.80
FatalMethod · 0.65
FatalfMethod · 0.65
CreateBucketMethod · 0.45
PutMethod · 0.45
BucketMethod · 0.45
DeleteMethod · 0.45
CursorMethod · 0.45

Tested by

no test coverage detected