From 3da04c52b991337e74c72f2c76bd1aa9df77eab2 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Fri, 7 Feb 2014 22:55:25 -0700 Subject: Rebalance after deletion. --- rwtransaction_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'rwtransaction_test.go') diff --git a/rwtransaction_test.go b/rwtransaction_test.go index f027e8b..5bf3f9f 100644 --- a/rwtransaction_test.go +++ b/rwtransaction_test.go @@ -136,3 +136,44 @@ func TestRWTransactionPutMultiple(t *testing.T) { } fmt.Fprint(os.Stderr, "\n") } + +// Ensure that a transaction can delete all key/value pairs and return to a single leaf page. +func TestRWTransactionDelete(t *testing.T) { + f := func(items testdata) bool { + withOpenDB(func(db *DB, path string) { + // Bulk insert all values. + db.CreateBucket("widgets") + rwtxn, _ := db.RWTransaction() + for _, item := range items { + assert.NoError(t, rwtxn.Put("widgets", item.Key, item.Value)) + } + assert.NoError(t, rwtxn.Commit()) + + // Remove items one at a time and check consistency. + for i, item := range items { + assert.NoError(t, db.Delete("widgets", item.Key)) + + // Anything before our deletion index should be nil. + txn, _ := db.Transaction() + for j, exp := range items { + if j > i { + if !assert.Equal(t, exp.Value, txn.Get("widgets", exp.Key)) { + t.FailNow() + } + } else { + if !assert.Nil(t, txn.Get("widgets", exp.Key)) { + t.FailNow() + } + } + } + txn.Close() + } + }) + fmt.Fprint(os.Stderr, ".") + return true + } + if err := quick.Check(f, qconfig()); err != nil { + t.Error(err) + } + fmt.Fprint(os.Stderr, "\n") +} -- cgit v1.2.3