242 lines
6.6 KiB
Go
242 lines
6.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"samba/pkg/log"
|
|
"samba/pkg/servername"
|
|
"samba/proto"
|
|
. "samba/server/truco/service"
|
|
"samba/util/model"
|
|
"samba/util/routingKey"
|
|
"samba/util/util"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// 测试向网关发送数据
|
|
func TestSendGate(t *testing.T) {
|
|
initEnv()
|
|
defer releaseEnv()
|
|
|
|
user := int64(1008)
|
|
msg := fmt.Sprintf(`{"a":"user_transfer","p":{"u":"%v","d":{"t":0,"c":3,"p":[[413,113,301],[]],"d":1}}}`, user)
|
|
msg = fmt.Sprintf(`{"a":"user_transfer","p":{"u":"%v","d":{"c":0,"r":100001}}}`, user)
|
|
|
|
err := TrucoService.Publish(util.Direct(servername.User), routingKey.GateKey(user), []byte(msg))
|
|
if err != nil {
|
|
log.Error(fmt.Sprintf("send gate err: %v", err))
|
|
}
|
|
}
|
|
|
|
// 测试向clickhouse插入数据
|
|
func TestClickHouse(t *testing.T) {
|
|
initEnv()
|
|
defer releaseEnv()
|
|
sql := "INSERT INTO `samba`.`player_game_record` (uid,`game_no`,`room_type`,`start_time`,`end_time`,`take_coin`,`play_coin`,`favorite`) VALUES (11,'0cc95a5e-0cca-483d-b770-43af277bf60e',10000,1719289632,1719289632,0,0,0)"
|
|
req := proto.NtfClickHouseSql{Sql: sql}
|
|
|
|
var token = ""
|
|
uid := int64(0)
|
|
roomId := 0
|
|
SendMsg(util.Direct(servername.ClickHouse), routingKey.ClickHouseKey(uid), roomId, token, uid, proto.ReqInsertClickHouseId, &req)
|
|
}
|
|
|
|
// 测试加载机器人
|
|
func TestLoadRobot(t *testing.T) {
|
|
initEnv()
|
|
defer releaseEnv()
|
|
//if robots, err := model.NewRobotInfoOp().loadDb(1, 100); err != nil {
|
|
// log.Error(fmt.Sprintf("load robot err: %v", err))
|
|
//} else {
|
|
// for _, robot := range robots {
|
|
// log.Debug(fmt.Sprintf("robot:%+v", robot))
|
|
// }
|
|
//}
|
|
}
|
|
|
|
// 测试加载机器人的资源数据
|
|
func TestLoadRobotResource(t *testing.T) {
|
|
initEnv()
|
|
defer releaseEnv()
|
|
if takeCoin, err := model.NewUserResourceOp().GetTakeCoin(19384399); err != nil {
|
|
log.Error(fmt.Sprintf("load robot err: %v", err))
|
|
} else {
|
|
log.Debug(fmt.Sprintf("takeCoin:%v", takeCoin))
|
|
}
|
|
}
|
|
|
|
func testAddCoins(_ *testing.T, uid, coins int64) {
|
|
router := routingKey.DbKey(uid)
|
|
roomId := 0
|
|
var token = ""
|
|
SendMsg(util.Direct(servername.Money), router, roomId, token, uid, proto.ReqAddResourceId, &proto.ReqAddResource{
|
|
UserId: uid,
|
|
ResValue: coins,
|
|
Reason: "test",
|
|
Desc: "",
|
|
})
|
|
}
|
|
|
|
// 测试添加金币
|
|
func TestAddCoins(t *testing.T) {
|
|
initEnv()
|
|
testAddCoins(t, 12221008, 101)
|
|
releaseEnv()
|
|
}
|
|
|
|
// 测试加载金币
|
|
func TestLoadCoins(t *testing.T) {
|
|
initEnv()
|
|
uid1 := int64(12100215)
|
|
clubId := 1000013
|
|
router := routingKey.DbKey(uid1)
|
|
fmt.Println("router:", router)
|
|
var token = ""
|
|
SendMsg(util.Direct(servername.Money), router, 0, token, uid1, proto.ReqGetResourceId, &proto.ReqGetResource{
|
|
UserId: uid1,
|
|
ClubId: clubId,
|
|
ResType: model.ResClubScore,
|
|
})
|
|
SendMsg(util.Direct(servername.Money), router, 0, token, uid1, proto.ReqAddResourceId, &proto.ReqAddResource{
|
|
UserId: uid1,
|
|
ClubId: clubId,
|
|
ResType: model.ResClubScore,
|
|
ResValue: 1,
|
|
Reason: "test",
|
|
})
|
|
releaseEnv()
|
|
}
|
|
|
|
func testEnterMatch(_ *testing.T, roomType int, uid int64, token string) {
|
|
SendMsg(util.Direct(servername.Truco), routingKey.Truco, 0, token, uid, proto.ReqMatchRoomId, &proto.ReqMatchRoom{RoomType: roomType})
|
|
}
|
|
|
|
// 测试配牌
|
|
// {"a":"ReqSetPokersId","p":{"u":1010,"r":1111,"g":402,"p":[[211,112,111],[113,203,213]]}}
|
|
// e: truco.direct route_key:truco a:ReqSetPokers
|
|
func TestGmSetPoker(t *testing.T) {
|
|
initEnv()
|
|
uid1 := int64(13125360)
|
|
uid2 := int64(13126370)
|
|
var roomType = 10009
|
|
var token = ""
|
|
testEnterMatch(t, roomType, uid1, token)
|
|
testEnterMatch(t, roomType, uid2, token)
|
|
time.Sleep(4 * time.Second)
|
|
SendMsg(util.Direct(servername.Truco), routingKey.Truco, 0, token, uid1, proto.ReqSetPokersId, &proto.ReqSetPokers{
|
|
UserId: uid1,
|
|
GhostPoker: 103,
|
|
Pokers: [][]int{{112, 212, 312}, {411, 111, 211}},
|
|
RoomId: 190001,
|
|
})
|
|
releaseEnv()
|
|
}
|
|
|
|
// 测试更新配置
|
|
func TestUpdateConfig(t *testing.T) {
|
|
initEnv()
|
|
var token = ""
|
|
SendMsg(util.Direct(servername.Truco), routingKey.Truco, 0, token, 0, proto.NtfUpdateConfigId, &proto.NtfUpdateConfig{})
|
|
releaseEnv()
|
|
}
|
|
|
|
// 清理所有玩家的携带脏数据
|
|
func TestCleanTakeCoin(t *testing.T) {
|
|
initEnv()
|
|
model.CleanTakeCoin()
|
|
releaseEnv()
|
|
}
|
|
|
|
// 测试重连
|
|
func TestReconnect(t *testing.T) {
|
|
initEnv()
|
|
uid1 := int64(13125360)
|
|
uid2 := int64(13126370)
|
|
var roomType = 10009
|
|
var token = ""
|
|
testEnterMatch(t, roomType, uid1, token)
|
|
testEnterMatch(t, roomType, uid2, token)
|
|
|
|
SendMsg(util.Direct(servername.Truco), routingKey.Truco, 10000, token, 0, proto.ReqReconnectId, &proto.ReqReconnect{RoomId: 10000})
|
|
releaseEnv()
|
|
}
|
|
|
|
// 测试clickhouse消息置换成sql语句
|
|
func TestInsertClickHouse(t *testing.T) {
|
|
initEnv()
|
|
var token = ""
|
|
uid := int64(0)
|
|
roomId := 0
|
|
req := &proto.ReqInsertClickHouse{
|
|
TableName: "test",
|
|
Values: map[string]interface{}{"uid": uid + 1, "room_id": "roomId"},
|
|
}
|
|
b, _ := json.Marshal(req)
|
|
log.Debug(string(b))
|
|
SendMsg(util.Direct(servername.ClickHouse), routingKey.ClickHouseKey(uid), roomId, token, uid, proto.ReqInsertClickHouseId, req)
|
|
releaseEnv()
|
|
}
|
|
|
|
func testMatchClub(_ *testing.T, roomType int, uid int64, token string) {
|
|
SendMsg(util.Direct(servername.Hall), routingKey.Hall, 0, token, uid, proto.ReqMatchClubRoomId, &proto.ReqMatchClubRoom{RoomType: roomType, ClubId: 10000})
|
|
}
|
|
|
|
// 测试俱乐部匹配
|
|
func TestClubTruco(t *testing.T) {
|
|
initEnv()
|
|
uid1 := int64(13125360)
|
|
uid2 := int64(13126370)
|
|
var roomType = 10057
|
|
var token = ""
|
|
testMatchClub(t, roomType, uid1, token)
|
|
testMatchClub(t, roomType, uid2, token)
|
|
time.Sleep(10 * time.Minute)
|
|
releaseEnv()
|
|
}
|
|
|
|
func testEnterClubTruco(_ *testing.T, roomType, clubId int, uid int64) {
|
|
SendMsg(util.Direct(servername.Hall), routingKey.Hall, 0, "", uid, proto.ReqEnterClubRoomId, &proto.ReqEnterClubRoom{RoomType: roomType, ClubId: clubId})
|
|
}
|
|
|
|
func TestEnterClubTruco(t *testing.T) {
|
|
initEnv()
|
|
uid1 := int64(12100131)
|
|
//uid2 := int64(13126370)
|
|
var roomType = 22
|
|
var clubId = 10000029
|
|
testEnterClubTruco(t, roomType, clubId, uid1)
|
|
//testMatchClub(t, roomType, uid2, token)
|
|
time.Sleep(10 * time.Minute)
|
|
releaseEnv()
|
|
|
|
}
|
|
|
|
func TestClubLevel(t *testing.T) {
|
|
initEnv()
|
|
var clubId = 10000147
|
|
model.NewClubLevelOp().GetLevelByClubId(clubId)
|
|
releaseEnv()
|
|
}
|
|
|
|
func testAddClubResource(_ *testing.T, uid, coins int64, clubId int) {
|
|
router := routingKey.DbKey(uid)
|
|
roomId := 0
|
|
var token = ""
|
|
SendMsg(util.Direct(servername.Money), router, roomId, token, uid, proto.ReqAddClubResourceId, &proto.ReqAddClubResource{
|
|
UserId: uid,
|
|
ClubId: clubId,
|
|
ResValue: coins,
|
|
ResType: model.ResClubCoins,
|
|
Reason: "test",
|
|
Desc: "",
|
|
})
|
|
}
|
|
|
|
// 测试添加金币
|
|
func TestAddClubResource(t *testing.T) {
|
|
initEnv()
|
|
testAddClubResource(t, 12100131, 101, 10000029)
|
|
releaseEnv()
|
|
}
|