-
Notifications
You must be signed in to change notification settings - Fork 30
/
rocksdb_test.go
64 lines (49 loc) · 1.36 KB
/
rocksdb_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//go:build rocksdb
// +build rocksdb
package db
import (
"fmt"
"os"
"path/filepath"
"testing"
"github.com/spf13/cast"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRocksDBBackend(t *testing.T) {
name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()
db, err := NewDB(name, RocksDBBackend, dir)
require.NoError(t, err)
defer cleanupDBDir(dir, name)
_, ok := db.(*RocksDB)
assert.True(t, ok)
}
func TestWithRocksDB(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "rocksdb")
db, err := NewRocksDB(path, "", nil)
require.NoError(t, err)
t.Run("RocksDB", func(t *testing.T) { Run(t, db) })
}
func TestRocksDBStats(t *testing.T) {
name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()
db, err := NewDB(name, RocksDBBackend, dir)
require.NoError(t, err)
defer cleanupDBDir(dir, name)
assert.NotEmpty(t, db.Stats())
}
func TestRocksDBWithOptions(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "rocksdb")
opts := make(OptionsMap, 0)
opts["maxopenfiles"] = 1000
defaultOpts := defaultRocksdbOptions()
files := cast.ToInt(opts.Get("maxopenfiles"))
defaultOpts.SetMaxOpenFiles(files)
require.Equal(t, opts["maxopenfiles"], defaultOpts.GetMaxOpenFiles())
db, err := NewRocksDB(path, "", opts)
require.NoError(t, err)
t.Run("RocksDB", func(t *testing.T) { Run(t, db) })
}