153 lines
3.9 KiB
Go
153 lines
3.9 KiB
Go
package pagoda_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego"
|
|
"go_dreamfactory/lego/base/rpcx"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules/equipment"
|
|
"go_dreamfactory/modules/hero"
|
|
"go_dreamfactory/modules/items"
|
|
"go_dreamfactory/modules/pagoda"
|
|
"go_dreamfactory/modules/task"
|
|
"go_dreamfactory/modules/user"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/services"
|
|
"go_dreamfactory/sys/configure"
|
|
"go_dreamfactory/sys/db"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/golang/protobuf/ptypes"
|
|
)
|
|
|
|
var service core.IService
|
|
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
|
|
|
|
var module = new(hero.Hero)
|
|
|
|
type TestService struct {
|
|
rpcx.RPCXService
|
|
}
|
|
|
|
func newService(ops ...rpcx.Option) core.IService {
|
|
s := new(TestService)
|
|
s.Configure(ops...)
|
|
return s
|
|
}
|
|
|
|
//初始化相关系统
|
|
func (this *TestService) InitSys() {
|
|
this.RPCXService.InitSys()
|
|
if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil {
|
|
panic(fmt.Sprintf("init sys.db err: %s", err.Error()))
|
|
} else {
|
|
log.Infof("init sys.db success!")
|
|
}
|
|
if err := configure.OnInit(this.GetSettings().Sys["configure"], configure.SetConfigPath("F:/work/go/go_dreamfactory/bin/json")); err != nil {
|
|
panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
|
|
} else {
|
|
log.Infof("init sys.configure success!")
|
|
}
|
|
}
|
|
|
|
func Test_Main(t *testing.T) {
|
|
|
|
service = newService(
|
|
rpcx.SetConfPath("../../bin/conf/worker_1.yaml"),
|
|
)
|
|
service.OnInstallComp( //装备组件
|
|
s_gateComp, //此服务需要接受用户的消息 需要装备网关组件
|
|
)
|
|
go func() {
|
|
lego.Run(service, //运行模块
|
|
module,
|
|
items.NewModule(),
|
|
user.NewModule(),
|
|
equipment.NewModule(),
|
|
task.NewModule(),
|
|
pagoda.NewModule(),
|
|
)
|
|
}()
|
|
time.Sleep(time.Second * 2)
|
|
|
|
}
|
|
|
|
func GetMap() map[int32]int32 {
|
|
return nil
|
|
}
|
|
|
|
func Test_Modules(t *testing.T) {
|
|
|
|
data, _ := ptypes.MarshalAny(&pb.HeroListReq{})
|
|
reply := &pb.RPCMessageReply{}
|
|
s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62c79d66acc7aa239b07c21e", MainType: "hero", SubType: "list", Message: data}, reply)
|
|
log.Debugf("reply:%v", reply)
|
|
}
|
|
|
|
func TestXxx(t *testing.T) {
|
|
// uid := session.GetUserId()
|
|
// if !this.module.IsCross() {
|
|
// if conn, err := db.Cross(); err == nil {
|
|
// userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
// newData := &pb.DBPagodaRecord{
|
|
// Id: primitive.NewObjectID().Hex(),
|
|
// Uid: session.GetUserId(),
|
|
// PagodaId: 111,
|
|
// Type: 201,
|
|
// Nickname: userinfo.Name,
|
|
// Icon: "", // icon 暂无
|
|
// Lv: userinfo.Lv,
|
|
// CostTime: 1002,
|
|
// }
|
|
|
|
// conn.Mgo.InsertOne(comm.TablePagodaRecord, newData)
|
|
// users := make([]*pb.DBPagodaRecord, 0)
|
|
// users = append(users, newData)
|
|
// var (
|
|
// pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
|
// menbers []*redis.Z
|
|
// )
|
|
|
|
// menbers = make([]*redis.Z, 10)
|
|
// for i := 0; i < 10; i++ {
|
|
// uid += strconv.Itoa(i)
|
|
// menbers[i] = &redis.Z{Score: float64(i), Member: uid}
|
|
// }
|
|
|
|
// uid := session.GetUserId()
|
|
// if !this.module.IsCross() {
|
|
// if conn, err := db.Cross(); err == nil {
|
|
// var (
|
|
// pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
|
// menbers *redis.Z
|
|
// )
|
|
|
|
// menbers = &redis.Z{Score: float64(500), Member: uid}
|
|
|
|
// if cmd := pipe.ZAdd("pagodaList", menbers); cmd != nil {
|
|
// this.module.Errorln(err)
|
|
|
|
// dock, err1 := cmd.Result()
|
|
// this.module.Errorln(dock, err1)
|
|
// }
|
|
// if _, err = pipe.Exec(); err != nil {
|
|
// this.module.Errorln(err)
|
|
// return
|
|
// }
|
|
// //rd := pipe.ZRevRank("pagodaList", "dfmxf_6358f3f1375f6a340a12e2ab01234567")
|
|
// rd := pipe.ZRange("pagodaList", 1, 5)
|
|
// if _, err = pipe.Exec(); err != nil {
|
|
// this.module.Errorln(err)
|
|
// return
|
|
// }
|
|
// _data3 := rd.Val()
|
|
// _data, err2 := rd.Result()
|
|
// this.module.Errorln(_data, err2, _data3)
|
|
// }
|
|
// }
|
|
}
|