aboutsummaryrefslogtreecommitdiff
path: root/db_test.go
diff options
context:
space:
mode:
authorTommi Virtanen <tv@eagain.net>2014-08-24 15:42:55 -0700
committerTommi Virtanen <tv@eagain.net>2015-02-18 12:26:45 -0800
commitadbb1a19c1b93a95f17a4eb3c5524e5be8b0d10f (patch)
tree03bf30a873b68f7820dcb910b87eb639f22786ae /db_test.go
parentMerge pull request #309 from everdev/operation-go (diff)
downloaddedo-adbb1a19c1b93a95f17a4eb3c5524e5be8b0d10f.tar.gz
dedo-adbb1a19c1b93a95f17a4eb3c5524e5be8b0d10f.tar.xz
Add transaction batching
DB.Batch makes it easy to make lots of small transactions with significantly better performance. Batch combines multiple concurrent Update calls into a single disk transaction, managing errors smartly.
Diffstat (limited to 'db_test.go')
-rw-r--r--db_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/db_test.go b/db_test.go
index ecff7d8..ad17e87 100644
--- a/db_test.go
+++ b/db_test.go
@@ -618,6 +618,34 @@ func NewTestDB() *TestDB {
return &TestDB{db}
}
+// MustView executes a read-only function. Panic on error.
+func (db *TestDB) MustView(fn func(tx *bolt.Tx) error) {
+ if err := db.DB.View(func(tx *bolt.Tx) error {
+ return fn(tx)
+ }); err != nil {
+ panic(err.Error())
+ }
+}
+
+// MustUpdate executes a read-write function. Panic on error.
+func (db *TestDB) MustUpdate(fn func(tx *bolt.Tx) error) {
+ if err := db.DB.View(func(tx *bolt.Tx) error {
+ return fn(tx)
+ }); err != nil {
+ panic(err.Error())
+ }
+}
+
+// MustCreateBucket creates a new bucket. Panic on error.
+func (db *TestDB) MustCreateBucket(name []byte) {
+ if err := db.Update(func(tx *bolt.Tx) error {
+ _, err := tx.CreateBucket([]byte(name))
+ return err
+ }); err != nil {
+ panic(err.Error())
+ }
+}
+
// Close closes the database and deletes the underlying file.
func (db *TestDB) Close() {
// Log statistics.