From 9abced434f459c20fd6629efa2be0b91e56de179 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Thu, 27 Feb 2014 11:55:44 -0700 Subject: Add bucket reclamation. After RWTransaction.DeleteBucket() is called, all pages related to the bucket are moved to the freelist for that transaction. --- rwtransaction_test.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'rwtransaction_test.go') diff --git a/rwtransaction_test.go b/rwtransaction_test.go index 83b2d1f..1635b45 100644 --- a/rwtransaction_test.go +++ b/rwtransaction_test.go @@ -66,6 +66,7 @@ func TestRWTransactionCreateBucketIfNotExists(t *testing.T) { withOpenDB(func(db *DB, path string) { assert.NoError(t, db.CreateBucketIfNotExists("widgets")) assert.NoError(t, db.CreateBucketIfNotExists("widgets")) + assert.Equal(t, db.CreateBucketIfNotExists(""), ErrBucketNameRequired) // Read the bucket through a separate transaction. b, err := db.Bucket("widgets") @@ -113,12 +114,17 @@ func TestRWTransactionDeleteBucket(t *testing.T) { db.CreateBucket("widgets") db.Put("widgets", []byte("foo"), []byte("bar")) + b, _ := db.Bucket("widgets") + // Delete the bucket and make sure we can't get the value. assert.NoError(t, db.DeleteBucket("widgets")) value, err := db.Get("widgets", []byte("foo")) assert.Equal(t, err, ErrBucketNotFound) assert.Nil(t, value) + // Verify that the bucket's page is free. + assert.Equal(t, db.freelist.all(), []pgid{b.root}) + // Create the bucket again and make sure there's not a phantom value. assert.NoError(t, db.CreateBucket("widgets")) value, err = db.Get("widgets", []byte("foo")) -- cgit v1.2.3