integrate boltdb engine.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package gorush
|
||||
|
||||
import (
|
||||
"github.com/appleboy/gorush/gorush/storage/boltdb"
|
||||
"github.com/appleboy/gorush/gorush/storage/memory"
|
||||
"github.com/appleboy/gorush/gorush/storage/redis"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -29,18 +30,27 @@ type IosStatus struct {
|
||||
}
|
||||
|
||||
// InitAppStatus for initialize app status
|
||||
func InitAppStatus() {
|
||||
func InitAppStatus() error {
|
||||
switch PushConf.Stat.Engine {
|
||||
case "memory":
|
||||
StatStorage = memory.New()
|
||||
case "redis":
|
||||
StatStorage = redis.New(PushConf)
|
||||
StatStorage.Init()
|
||||
// case "boltdb":
|
||||
// initBoltDB()
|
||||
err := StatStorage.Init()
|
||||
|
||||
if err != nil {
|
||||
LogError.Error("redis error: " + err.Error())
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
case "boltdb":
|
||||
StatStorage = boltdb.New(PushConf)
|
||||
default:
|
||||
StatStorage = memory.New()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func appStatusHandler(c *gin.Context) {
|
||||
|
||||
@@ -74,21 +74,23 @@ func TestStatForMemoryEngine(t *testing.T) {
|
||||
assert.Equal(t, int64(500), val)
|
||||
}
|
||||
|
||||
// func TestRedisServerSuccess(t *testing.T) {
|
||||
// PushConf.Stat.Redis.Addr = "localhost:6379"
|
||||
func TestRedisServerSuccess(t *testing.T) {
|
||||
PushConf.Stat.Engine = "redis"
|
||||
PushConf.Stat.Redis.Addr = "localhost:6379"
|
||||
|
||||
// err := initRedis()
|
||||
err := InitAppStatus()
|
||||
|
||||
// assert.NoError(t, err)
|
||||
// }
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
// func TestRedisServerError(t *testing.T) {
|
||||
// PushConf.Stat.Redis.Addr = "localhost:6370"
|
||||
func TestRedisServerError(t *testing.T) {
|
||||
PushConf.Stat.Engine = "redis"
|
||||
PushConf.Stat.Redis.Addr = "localhost:6370"
|
||||
|
||||
// err := initRedis()
|
||||
err := InitAppStatus()
|
||||
|
||||
// assert.Error(t, err)
|
||||
// }
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestStatForRedisEngine(t *testing.T) {
|
||||
var val int64
|
||||
@@ -117,48 +119,50 @@ func TestStatForRedisEngine(t *testing.T) {
|
||||
assert.Equal(t, int64(500), val)
|
||||
}
|
||||
|
||||
// func TestDefaultEngine(t *testing.T) {
|
||||
// var val int64
|
||||
// PushConf.Stat.Engine = "test"
|
||||
// InitAppStatus()
|
||||
func TestDefaultEngine(t *testing.T) {
|
||||
var val int64
|
||||
PushConf.Stat.Engine = "test"
|
||||
InitAppStatus()
|
||||
|
||||
// addTotalCount(1)
|
||||
// addIosSuccess(2)
|
||||
// addIosError(3)
|
||||
// addAndroidSuccess(4)
|
||||
// addAndroidError(5)
|
||||
StatStorage.AddTotalCount(100)
|
||||
StatStorage.AddIosSuccess(200)
|
||||
StatStorage.AddIosError(300)
|
||||
StatStorage.AddAndroidSuccess(400)
|
||||
StatStorage.AddAndroidError(500)
|
||||
|
||||
// val = getTotalCount()
|
||||
// assert.Equal(t, int64(1), val)
|
||||
// val = getIosSuccess()
|
||||
// assert.Equal(t, int64(2), val)
|
||||
// val = getIosError()
|
||||
// assert.Equal(t, int64(3), val)
|
||||
// val = getAndroidSuccess()
|
||||
// assert.Equal(t, int64(4), val)
|
||||
// val = getAndroidError()
|
||||
// assert.Equal(t, int64(5), val)
|
||||
// }
|
||||
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)
|
||||
}
|
||||
|
||||
// func TestStatForBoltDBEngine(t *testing.T) {
|
||||
// var val int64
|
||||
// PushConf.Stat.Engine = "boltdb"
|
||||
// InitAppStatus()
|
||||
func TestStatForBoltDBEngine(t *testing.T) {
|
||||
var val int64
|
||||
PushConf.Stat.Engine = "boltdb"
|
||||
InitAppStatus()
|
||||
|
||||
// addTotalCount(100)
|
||||
// addIosSuccess(200)
|
||||
// addIosError(300)
|
||||
// addAndroidSuccess(400)
|
||||
// addAndroidError(500)
|
||||
StatStorage.Reset()
|
||||
|
||||
// val = getTotalCount()
|
||||
// assert.Equal(t, int64(100), val)
|
||||
// val = getIosSuccess()
|
||||
// assert.Equal(t, int64(200), val)
|
||||
// val = getIosError()
|
||||
// assert.Equal(t, int64(300), val)
|
||||
// val = getAndroidSuccess()
|
||||
// assert.Equal(t, int64(400), val)
|
||||
// val = getAndroidError()
|
||||
// assert.Equal(t, int64(500), val)
|
||||
// }
|
||||
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