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

Function TestCursor_First_EmptyPages

cursor_test.go:590–633  ·  cursor_test.go::TestCursor_First_EmptyPages

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

(t *testing.T)

Source from the content-addressed store, hash-verified

588
589// Ensure that a cursor can skip over empty pages that have been deleted.
590func TestCursor_First_EmptyPages(t *testing.T) {
591 db := btesting.MustCreateDB(t)
592
593 // Create 1000 keys in the "widgets" bucket.
594 if err := db.Update(func(tx *bolt.Tx) error {
595 b, err := tx.CreateBucket([]byte("widgets"))
596 if err != nil {
597 t.Fatal(err)
598 }
599
600 for i := 0; i < 1000; i++ {
601 if err := b.Put(u64tob(uint64(i)), []byte{}); err != nil {
602 t.Fatal(err)
603 }
604 }
605
606 return nil
607 }); err != nil {
608 t.Fatal(err)
609 }
610
611 // Delete half the keys and then try to iterate.
612 if err := db.Update(func(tx *bolt.Tx) error {
613 b := tx.Bucket([]byte("widgets"))
614 for i := 0; i < 600; i++ {
615 if err := b.Delete(u64tob(uint64(i))); err != nil {
616 t.Fatal(err)
617 }
618 }
619
620 c := b.Cursor()
621 var n int
622 for k, _ := c.First(); k != nil; k, _ = c.Next() {
623 n++
624 }
625 if n != 400 {
626 t.Fatalf("unexpected key count: %d", n)
627 }
628
629 return nil
630 }); err != nil {
631 t.Fatal(err)
632 }
633}
634
635// Ensure that a cursor can skip over empty pages that have been deleted.
636func TestCursor_Last_EmptyPages(t *testing.T) {

Callers

nothing calls this directly

Calls 12

MustCreateDBFunction · 0.92
u64tobFunction · 0.85
UpdateMethod · 0.80
FirstMethod · 0.80
NextMethod · 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