aboutsummaryrefslogtreecommitdiff
path: root/db_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-03-25 07:31:49 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-03-25 07:31:49 -0600
commit381d08dffdc123a32e4f8161dfc45dc2798e579c (patch)
treeedb3796d02f7b1db0cff564ff92be29c9448ea45 /db_test.go
parentREADME (diff)
parentFix bucket reclamation. (diff)
downloaddedo-381d08dffdc123a32e4f8161dfc45dc2798e579c.tar.gz
dedo-381d08dffdc123a32e4f8161dfc45dc2798e579c.tar.xz
Merge pull request #90 from benbjohnson/fix-bucket-reclamation
Fix bucket reclamation
Diffstat (limited to 'db_test.go')
-rw-r--r--db_test.go52
1 files changed, 47 insertions, 5 deletions
diff --git a/db_test.go b/db_test.go
index df17f94..a2df9d3 100644
--- a/db_test.go
+++ b/db_test.go
@@ -244,11 +244,11 @@ func TestDBStat(t *testing.T) {
// Obtain stats.
stat, err := db.Stat()
assert.NoError(t, err)
- assert.Equal(t, stat.PageCount, 128)
- assert.Equal(t, stat.FreePageCount, 2)
- assert.Equal(t, stat.PageSize, 4096)
- assert.Equal(t, stat.MmapSize, 4194304)
- assert.Equal(t, stat.TxCount, 2)
+ assert.Equal(t, 126, stat.PageCount)
+ assert.Equal(t, 3, stat.FreePageCount)
+ assert.Equal(t, 4096, stat.PageSize)
+ assert.Equal(t, 4194304, stat.MmapSize)
+ assert.Equal(t, 2, stat.TxCount)
// Close readers.
t0.Rollback()
@@ -282,6 +282,48 @@ func TestDBMmapSize(t *testing.T) {
assert.Equal(t, db.mmapSize(1<<30), 1<<31)
}
+// Ensure that database pages are in expected order and type.
+func TestDBConsistency(t *testing.T) {
+ withOpenDB(func(db *DB, path string) {
+ db.Update(func(tx *Tx) error {
+ return tx.CreateBucket("widgets")
+ })
+
+ for i := 0; i < 10; i++ {
+ db.Update(func(tx *Tx) error {
+ assert.NoError(t, tx.Bucket("widgets").Put([]byte("foo"), []byte("bar")))
+ return nil
+ })
+ }
+ db.Update(func(tx *Tx) error {
+ if p, _ := tx.Page(0); assert.NotNil(t, p) {
+ assert.Equal(t, "meta", p.Type)
+ }
+ if p, _ := tx.Page(1); assert.NotNil(t, p) {
+ assert.Equal(t, "meta", p.Type)
+ }
+ if p, _ := tx.Page(2); assert.NotNil(t, p) {
+ assert.Equal(t, "freelist", p.Type)
+ }
+ if p, _ := tx.Page(3); assert.NotNil(t, p) {
+ assert.Equal(t, "free", p.Type)
+ }
+ if p, _ := tx.Page(4); assert.NotNil(t, p) {
+ assert.Equal(t, "buckets", p.Type)
+ }
+ if p, _ := tx.Page(5); assert.NotNil(t, p) {
+ assert.Equal(t, "leaf", p.Type)
+ }
+ if p, _ := tx.Page(6); assert.NotNil(t, p) {
+ assert.Equal(t, "free", p.Type)
+ }
+ p, _ := tx.Page(7)
+ assert.Nil(t, p)
+ return nil
+ })
+ })
+}
+
// Ensure that a database can return a string representation of itself.
func TestDBString(t *testing.T) {
db := &DB{path: "/tmp/foo"}