refactor default engine as memory.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-12-20 09:34:25 +08:00
parent af1d4aecc2
commit 9595062bbf
2 changed files with 20 additions and 7 deletions

View File

@ -1,6 +1,9 @@
package gorush package gorush
import ( import (
"errors"
"net/http"
"github.com/appleboy/gorush/storage/boltdb" "github.com/appleboy/gorush/storage/boltdb"
"github.com/appleboy/gorush/storage/buntdb" "github.com/appleboy/gorush/storage/buntdb"
"github.com/appleboy/gorush/storage/leveldb" "github.com/appleboy/gorush/storage/leveldb"
@ -8,7 +11,6 @@ import (
"github.com/appleboy/gorush/storage/redis" "github.com/appleboy/gorush/storage/redis"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/thoas/stats" "github.com/thoas/stats"
"net/http"
) )
// Stats provide response time, status code count, etc. // Stats provide response time, status code count, etc.
@ -50,12 +52,14 @@ func InitAppStatus() error {
case "leveldb": case "leveldb":
StatStorage = leveldb.New(PushConf) StatStorage = leveldb.New(PushConf)
default: default:
StatStorage = memory.New() err := errors.New("can't find storage driver")
if err != nil {
LogError.Error("storage error: " + err.Error())
return err
}
} }
err := StatStorage.Init() if err := StatStorage.Init(); err != nil {
if err != nil {
LogError.Error("storage error: " + err.Error()) LogError.Error("storage error: " + err.Error())
return err return err

View File

@ -1,10 +1,17 @@
package gorush package gorush
import ( import (
"github.com/stretchr/testify/assert"
"testing" "testing"
"github.com/stretchr/testify/assert"
) )
func TestStorageDriverExist(t *testing.T) {
PushConf.Stat.Engine = "Test"
err := InitAppStatus()
assert.Error(t, err)
}
func TestStatForMemoryEngine(t *testing.T) { func TestStatForMemoryEngine(t *testing.T) {
var val int64 var val int64
PushConf.Stat.Engine = "memory" PushConf.Stat.Engine = "memory"
@ -75,9 +82,11 @@ func TestStatForRedisEngine(t *testing.T) {
func TestDefaultEngine(t *testing.T) { func TestDefaultEngine(t *testing.T) {
var val int64 var val int64
PushConf.Stat.Engine = "test" // defaul engine as memory
InitAppStatus() InitAppStatus()
StatStorage.Reset()
StatStorage.AddTotalCount(100) StatStorage.AddTotalCount(100)
StatStorage.AddIosSuccess(200) StatStorage.AddIosSuccess(200)
StatStorage.AddIosError(300) StatStorage.AddIosError(300)