- all db orm use beego orm, don't use gorm anymore.
This commit is contained in:
100
business/jxutils/dtask/dtask_test.go
Normal file
100
business/jxutils/dtask/dtask_test.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package dtask
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
_ "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
func init() {
|
||||
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
||||
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
||||
|
||||
globals.Init()
|
||||
beegodb.Init()
|
||||
api.Init()
|
||||
}
|
||||
|
||||
func TestScope(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIt(t *testing.T) {
|
||||
Init(myObjCreator, []*model.Store{})
|
||||
var err error
|
||||
// taskID, err := CurMan.AddTask("testtask", "xjh")
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// tt := []*model.Store{
|
||||
// &model.Store{
|
||||
// Name: "storename",
|
||||
// },
|
||||
// }
|
||||
// pp := "asdfsafs"
|
||||
// err = CurMan.AddItem(taskID, "0", "DurableTaskTestFunc", 1, "str", map[string]interface{}{
|
||||
// "key1": "value1",
|
||||
// "key2": 100,
|
||||
// "key3": &pp,
|
||||
// }, []interface{}{1, "hello"}, tt)
|
||||
// err = CurMan.AddItem(taskID, "0", "DurableTaskTestFunc", 1, "str", map[string]interface{}{
|
||||
// "key1": "value1",
|
||||
// "key2": 100,
|
||||
// "key3": &pp,
|
||||
// }, []interface{}{1, "hello"}, tt)
|
||||
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// err = CurMan.StartTask(taskID)
|
||||
err = CurMan.LoadPendingTask()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = CurMan.Start()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// CurMan.LoadPendingTask()
|
||||
// CurMan.Start()
|
||||
time.Sleep(3 * time.Second)
|
||||
}
|
||||
|
||||
func TestEncode(t *testing.T) {
|
||||
data := []interface{}{
|
||||
3,
|
||||
"abc",
|
||||
float32(3.4),
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
enc := gob.NewEncoder(&buf)
|
||||
dec := gob.NewDecoder(&buf)
|
||||
enc.Encode(data)
|
||||
// t.Log(string(buf.Bytes()))
|
||||
var kk []interface{}
|
||||
dec.Decode(&kk)
|
||||
t.Log(kk)
|
||||
}
|
||||
|
||||
type tTest struct {
|
||||
}
|
||||
|
||||
func (p *tTest) DurableTaskTestFunc(intParam int, strParam string, mapParam map[string]interface{}, sliceParam []interface{}, tt []*model.Store) error {
|
||||
globals.SugarLogger.Debug(intParam, strParam, mapParam, sliceParam)
|
||||
globals.SugarLogger.Debug(utils.Format4Output(tt, false))
|
||||
time.Sleep(1 * time.Second)
|
||||
return nil // errors.New("hello")
|
||||
}
|
||||
|
||||
func myObjCreator(objHint string) interface{} {
|
||||
return new(tTest)
|
||||
}
|
||||
Reference in New Issue
Block a user