talent-plan-tinykv/kv/raftstore/util/test_util.go
Connor 5e089a2cd1 init course framework
Signed-off-by: Connor <zbk602423539@gmail.com>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: linning <linningde25@gmail.com>
Co-authored-by: YangKeao <keao.yang@yahoo.com>
Co-authored-by: andylokandy <andylokandy@hotmail.com>
Co-authored-by: Iosmanthus Teng <myosmanthustree@gmail.com>
2020-04-30 15:25:07 +08:00

39 lines
910 B
Go

package util
import (
"io/ioutil"
"github.com/Connor1996/badger"
"github.com/pingcap-incubator/tinykv/kv/util/engine_util"
)
func NewTestEngines() *engine_util.Engines {
engines := new(engine_util.Engines)
var err error
engines.KvPath, err = ioutil.TempDir("", "tinykv_kv")
if err != nil {
panic("create kv dir failed")
}
kvOpts := badger.DefaultOptions
kvOpts.Dir = engines.KvPath
kvOpts.ValueDir = engines.KvPath
kvOpts.ValueThreshold = 256
engines.Kv, err = badger.Open(kvOpts)
if err != nil {
panic("open kv db failed")
}
engines.RaftPath, err = ioutil.TempDir("", "tinykv_raft")
if err != nil {
panic("create raft dir failed")
}
raftOpts := badger.DefaultOptions
raftOpts.Dir = engines.RaftPath
raftOpts.ValueDir = engines.RaftPath
raftOpts.ValueThreshold = 256
engines.Raft, err = badger.Open(raftOpts)
if err != nil {
panic("open raft db failed")
}
return engines
}