You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

93 lines
1.7 KiB

package shock
import (
"fmt"
"os"
"path"
"testing"
"go.etcd.io/bbolt"
)
func TestGob(t *testing.T) {
dbPath := path.Join(tmpDir, "gob.db")
gobDB, err := Open(dbPath, os.ModePerm, &Options{
Bolt: bbolt.DefaultOptions,
Serializer: GobSerializer{},
})
if err != nil {
panic(err)
}
bucket := gobDB.Bucket("gob")
if err := bucket.Init(); err != nil {
t.Log(err)
t.FailNow()
}
testCases(t, bucket, true)
if err := gobDB.Bolt.Close(); err != nil {
fmt.Printf("Could not close DB %s: %v\n", dbPath, err)
}
}
func BenchmarkJSON(b *testing.B) {
b.StopTimer()
dbPath := path.Join(tmpDir, "json.db")
jsonDB, err := Open(dbPath, os.ModePerm, &Options{
Bolt: bbolt.DefaultOptions,
Serializer: JSONSerializer{},
})
if err != nil {
panic(err)
}
bucket := jsonDB.Bucket("json")
if err := bucket.Init(); err != nil {
b.Log(err)
b.FailNow()
}
b.StartTimer()
for idx := 0; idx < b.N; idx++ {
for _, tc := range tt {
testStore(b, tc, bucket, true)
}
}
b.StopTimer()
if err := jsonDB.Bolt.Close(); err != nil {
fmt.Printf("Could not close DB %s: %v\n", dbPath, err)
}
}
func BenchmarkGob(b *testing.B) {
b.StopTimer()
dbPath := path.Join(tmpDir, "gob.db")
gobDB, err := Open(dbPath, os.ModePerm, &Options{
Bolt: bbolt.DefaultOptions,
Serializer: GobSerializer{},
})
if err != nil {
panic(err)
}
bucket := gobDB.Bucket("gob")
if err := bucket.Init(); err != nil {
b.Log(err)
b.FailNow()
}
b.StartTimer()
for idx := 0; idx < b.N; idx++ {
for _, tc := range tt {
testStore(b, tc, bucket, true)
}
}
b.StopTimer()
if err := gobDB.Bolt.Close(); err != nil {
fmt.Printf("Could not close DB %s: %v\n", dbPath, err)
}
}