diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2015-11-09 09:36:12 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2015-11-09 09:36:12 -0700 |
commit | d359c78f40cc01fa12b65c3d30210dc9c529dd87 (patch) | |
tree | 92503156c2676df14855ecbf6cfc014eb9cb7e73 /cursor_test.go | |
parent | Merge branch 'xiang90-tx_write' (diff) | |
parent | skip empty pages during cursor seek (diff) | |
download | dedo-d359c78f40cc01fa12b65c3d30210dc9c529dd87.tar.gz dedo-d359c78f40cc01fa12b65c3d30210dc9c529dd87.tar.xz |
Merge pull request #452 from benbjohnson/empty-seek
Skip empty pages during cursor seek
Diffstat (limited to 'cursor_test.go')
-rw-r--r-- | cursor_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/cursor_test.go b/cursor_test.go index b12e1f9..d748852 100644 --- a/cursor_test.go +++ b/cursor_test.go @@ -303,6 +303,49 @@ func TestCursor_Restart(t *testing.T) { tx.Rollback() } +// Ensure that a cursor can skip over empty pages that have been deleted. +func TestCursor_First_EmptyPages(t *testing.T) { + db := NewTestDB() + defer db.Close() + + // Create 1000 keys in the "widgets" bucket. + db.Update(func(tx *bolt.Tx) error { + b, err := tx.CreateBucket([]byte("widgets")) + if err != nil { + t.Fatal(err) + } + + for i := 0; i < 1000; i++ { + if err := b.Put(u64tob(uint64(i)), []byte{}); err != nil { + t.Fatal(err) + } + } + + return nil + }) + + // Delete half the keys and then try to iterate. + db.Update(func(tx *bolt.Tx) error { + b := tx.Bucket([]byte("widgets")) + for i := 0; i < 600; i++ { + if err := b.Delete(u64tob(uint64(i))); err != nil { + t.Fatal(err) + } + } + + c := b.Cursor() + var n int + for k, _ := c.First(); k != nil; k, _ = c.Next() { + n++ + } + if n != 400 { + t.Fatalf("unexpected key count: %d", n) + } + + return nil + }) +} + // Ensure that a Tx can iterate over all elements in a bucket. func TestCursor_QuickCheck(t *testing.T) { f := func(items testdata) bool { |