feat: Add badgerDB support. (#353)
See https://github.com/dgraph-io/badger Slide: https://github.com/gopherchina/conference/blob/master/2018/1.5%20Badger_%20Fast%20Key-Value%20DB%20in%20Go.pdf
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/appleboy/gorush/storage/badger"
|
||||
"github.com/appleboy/gorush/storage/boltdb"
|
||||
"github.com/appleboy/gorush/storage/buntdb"
|
||||
"github.com/appleboy/gorush/storage/leveldb"
|
||||
@@ -52,6 +53,8 @@ func InitAppStatus() error {
|
||||
StatStorage = buntdb.New(PushConf)
|
||||
case "leveldb":
|
||||
StatStorage = leveldb.New(PushConf)
|
||||
case "badger":
|
||||
StatStorage = badger.New(PushConf)
|
||||
default:
|
||||
LogError.Error("storage error: can't find storage driver")
|
||||
return errors.New("can't find storage driver")
|
||||
|
||||
@@ -187,3 +187,29 @@ func TestStatForBuntDBEngine(t *testing.T) {
|
||||
// val = StatStorage.GetAndroidError()
|
||||
// assert.Equal(t, int64(500), val)
|
||||
// }
|
||||
|
||||
func TestStatForBadgerEngine(t *testing.T) {
|
||||
var val int64
|
||||
PushConf.Stat.Engine = "badger"
|
||||
err := InitAppStatus()
|
||||
assert.Nil(t, err)
|
||||
|
||||
StatStorage.Reset()
|
||||
|
||||
StatStorage.AddTotalCount(100)
|
||||
StatStorage.AddIosSuccess(200)
|
||||
StatStorage.AddIosError(300)
|
||||
StatStorage.AddAndroidSuccess(400)
|
||||
StatStorage.AddAndroidError(500)
|
||||
|
||||
val = StatStorage.GetTotalCount()
|
||||
assert.Equal(t, int64(100), val)
|
||||
val = StatStorage.GetIosSuccess()
|
||||
assert.Equal(t, int64(200), val)
|
||||
val = StatStorage.GetIosError()
|
||||
assert.Equal(t, int64(300), val)
|
||||
val = StatStorage.GetAndroidSuccess()
|
||||
assert.Equal(t, int64(400), val)
|
||||
val = StatStorage.GetAndroidError()
|
||||
assert.Equal(t, int64(500), val)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user