2018-04-17 04:50:20 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-04-10 22:46:48 +01:00
|
|
|
package boltdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2018-09-05 17:10:35 +01:00
|
|
|
"path/filepath"
|
2018-04-10 22:46:48 +01:00
|
|
|
"testing"
|
2018-04-21 00:54:18 +01:00
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
"storj.io/storj/storage/testsuite"
|
2018-04-10 22:46:48 +01:00
|
|
|
)
|
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
func TestSuite(t *testing.T) {
|
2018-09-11 14:57:12 +01:00
|
|
|
tempdir, err := ioutil.TempDir("", "storj-bolt")
|
2018-05-07 18:01:53 +01:00
|
|
|
if err != nil {
|
2018-09-05 17:10:35 +01:00
|
|
|
t.Fatal(err)
|
2018-06-29 21:06:25 +01:00
|
|
|
}
|
2018-09-11 14:13:25 +01:00
|
|
|
defer func() { _ = os.RemoveAll(tempdir) }()
|
2018-06-29 21:06:25 +01:00
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
dbname := filepath.Join(tempdir, "bolt.db")
|
|
|
|
store, err := New(dbname, "bucket")
|
2018-04-10 22:46:48 +01:00
|
|
|
if err != nil {
|
2018-09-05 17:10:35 +01:00
|
|
|
t.Fatalf("failed to create db: %v", err)
|
2018-04-10 22:46:48 +01:00
|
|
|
}
|
2018-09-05 17:10:35 +01:00
|
|
|
defer func() {
|
|
|
|
if err := store.Close(); err != nil {
|
|
|
|
t.Fatalf("failed to close db: %v", err)
|
|
|
|
}
|
|
|
|
}()
|
2018-04-10 22:46:48 +01:00
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
testsuite.RunTests(t, store)
|
2018-06-29 21:06:25 +01:00
|
|
|
}
|
2018-04-10 22:46:48 +01:00
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
func BenchmarkSuite(b *testing.B) {
|
2018-09-11 14:57:12 +01:00
|
|
|
tempdir, err := ioutil.TempDir("", "storj-bolt")
|
2018-06-29 21:06:25 +01:00
|
|
|
if err != nil {
|
2018-09-05 17:10:35 +01:00
|
|
|
b.Fatal(err)
|
2018-04-10 22:46:48 +01:00
|
|
|
}
|
2018-09-11 14:13:25 +01:00
|
|
|
defer func() { _ = os.RemoveAll(tempdir) }()
|
2018-04-10 22:46:48 +01:00
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
dbname := filepath.Join(tempdir, "bolt.db")
|
|
|
|
store, err := New(dbname, "bucket")
|
2018-04-10 22:46:48 +01:00
|
|
|
if err != nil {
|
2018-09-05 17:10:35 +01:00
|
|
|
b.Fatalf("failed to create db: %v", err)
|
2018-04-10 22:46:48 +01:00
|
|
|
}
|
2018-09-05 17:10:35 +01:00
|
|
|
defer func() {
|
|
|
|
if err := store.Close(); err != nil {
|
|
|
|
b.Fatalf("failed to close db: %v", err)
|
2018-08-03 14:15:52 +01:00
|
|
|
}
|
2018-09-05 17:10:35 +01:00
|
|
|
}()
|
2018-08-03 14:15:52 +01:00
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
testsuite.RunBenchmarks(b, store)
|
2018-08-03 14:15:52 +01:00
|
|
|
}
|
2018-10-18 17:20:23 +01:00
|
|
|
|
|
|
|
func TestSuiteShared(t *testing.T) {
|
|
|
|
tempdir, err := ioutil.TempDir("", "storj-bolt")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer func() { _ = os.RemoveAll(tempdir) }()
|
|
|
|
|
|
|
|
dbname := filepath.Join(tempdir, "bolt.db")
|
|
|
|
stores, err := NewShared(dbname, "alpha", "beta")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create db: %v", err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
for _, store := range stores {
|
|
|
|
if err := store.Close(); err != nil {
|
|
|
|
t.Fatalf("failed to close db: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
for _, store := range stores {
|
|
|
|
testsuite.RunTests(t, store)
|
|
|
|
}
|
|
|
|
}
|