You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
250 lines
5.8 KiB
Go
250 lines
5.8 KiB
Go
package producer
|
|
|
|
import (
|
|
"context"
|
|
"joybuywork/internal/app"
|
|
"joybuywork/internal/config"
|
|
"joybuywork/internal/consts"
|
|
"joybuywork/internal/plugins/hashid"
|
|
"joybuywork/internal/repository/mtype"
|
|
"joybuywork/internal/service/queue/types"
|
|
"fmt"
|
|
"os"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/rs/xid"
|
|
"gits.branchcn.com/backend/microcode/plugins/kafka"
|
|
)
|
|
|
|
func conf() {
|
|
var filePath = config.FilePath{
|
|
ConfigName: "config-dev",
|
|
ConfigType: "yaml",
|
|
ConfigPath: os.Args[5] + "/etc",
|
|
}
|
|
|
|
err := config.LoadConfig(filePath)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
err = app.InitFeiShu()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
app.InitLogger()
|
|
|
|
app.InitRedis()
|
|
|
|
app.InitNode()
|
|
|
|
}
|
|
|
|
func TestCampaignLogic(t *testing.T) {
|
|
conf()
|
|
kafkaConfig := kafka.PluginConfig{
|
|
Brokers: []string{
|
|
"120.79.90.126:9093",
|
|
},
|
|
}
|
|
var err error
|
|
app.Kafka, err = kafka.NewPlugin(kafkaConfig)
|
|
if err != nil {
|
|
t.Log(err)
|
|
return
|
|
}
|
|
SetUp()
|
|
|
|
ctxId := xid.New().String()
|
|
//ctxId := "cslhe0rdervo4sb1lhng"
|
|
|
|
t.Log(ctxId)
|
|
|
|
ctx := context.WithValue(context.Background(), consts.TraceIdKey, ctxId)
|
|
|
|
p := NewStatCampaign(ctx)
|
|
|
|
for i := 0; i < 1; i++ {
|
|
//p.StatCampaign(types.StatCampaignValue{
|
|
// //BehaviorType: utils.Ternary[int32](i%2 == 0, mtype.FissionBehaviorTypeAppOpen, mtype.FissionBehaviorTypeAppInstall),
|
|
// //BehaviorType: mtype.FissionBehaviorTypeAppOpen,
|
|
// //BehaviorType: mtype.FissionBehaviorTypeAppRegister,
|
|
// BehaviorType: mtype.FissionBehaviorTypeAppInstall,
|
|
// //BehaviorType: mtype.FissionBehaviorTypeWebFirstOpen,
|
|
// //BehaviorType: mtype.FissionBehaviorTypePurchase,
|
|
// BehaviorTime: time.Now().Unix(),
|
|
// IpAddress: "13.214.120.1" + fmt.Sprintf("%d", i),
|
|
// Os: "ios",
|
|
// OsVersion: "16.2",
|
|
// DeviceModel: "iphone",
|
|
// DeviceID: xid.New().String(),
|
|
// //DeviceID: "d31tkujdervu1v302u3c",
|
|
// //UserID: xid.New().String(),
|
|
// //UserID: "zh_123457",
|
|
// WebId: "",
|
|
// //CampaignID: 3932,
|
|
// OwnerID: "123",
|
|
// Event: "",
|
|
// EventData: nil,
|
|
// ProjectID: 554,
|
|
// Channel: "",
|
|
// FromSrv: false,
|
|
// Hid: "d6rnbh6rdj7pn0gu1a1g",
|
|
// PurchasesData: &types.PurchaseData{
|
|
// TransactionId: "ffdd33",
|
|
// TransactionDesc: "交易描述",
|
|
// Amount: 2,
|
|
// Currency: "货币单位(如:USD CNY)",
|
|
// PurchaseCount: 1,
|
|
// ContentItems: []types.PurchaseItem{
|
|
// {
|
|
// ProductId: "123",
|
|
// ProductName: "产品名称",
|
|
// ProductPrice: 2,
|
|
// ProductQuantity: 1,
|
|
// },
|
|
// },
|
|
// },
|
|
//})
|
|
|
|
//p.StatCampaign(types.StatCampaignValue{
|
|
// //BehaviorType: utils.Ternary[int32](i%2 == 0, mtype.FissionBehaviorTypeAppOpen, mtype.FissionBehaviorTypeAppInstall),
|
|
// BehaviorType: mtype.FissionBehaviorTypeAppInstall,
|
|
// BehaviorTime: time.Now().Unix(),
|
|
// IpAddress: "13.224.212.22" + fmt.Sprintf("%d", i),
|
|
// Os: "ios",
|
|
// OsVersion: "16.3",
|
|
// DeviceModel: "iphone",
|
|
// DeviceID: xid.New().String(),
|
|
// //UserID: "123456",
|
|
// WebId: "",
|
|
// CampaignID: 3619,
|
|
// OwnerID: "zh_123",
|
|
// ProjectID: 143,
|
|
// Channel: "",
|
|
//})
|
|
|
|
p.StatCampaign(types.StatCampaignValue{
|
|
BehaviorType: mtype.FissionBehaviorTypeCustom,
|
|
BehaviorTime: time.Now().Unix(),
|
|
IpAddress: "127.268.24." + fmt.Sprintf("%d", i),
|
|
Os: "ios",
|
|
OsVersion: "16.3",
|
|
DeviceModel: "iphone",
|
|
//DeviceID: "123123",
|
|
//DeviceID: xid.New().String(),
|
|
//UserID: xid.New().String(),
|
|
UserID: "123",
|
|
WebId: "",
|
|
//CampaignID: 4376,
|
|
//OwnerID: "131",
|
|
Event: "product_detait_view",
|
|
EventData: []types.EventData{
|
|
{
|
|
EventKey: "is_success",
|
|
EventVal: "1",
|
|
},
|
|
},
|
|
ProjectID: 554,
|
|
Channel: "",
|
|
FromSrv: false,
|
|
//Hid: "d7fgfdmrdj7rdut0hhsg",
|
|
//Language: "zh",
|
|
//Tags: []string{"lv1", "lv2"},
|
|
})
|
|
}
|
|
|
|
time.Sleep(2 * time.Second)
|
|
}
|
|
|
|
func TestCampaignChildInvite(t *testing.T) {
|
|
conf()
|
|
kafkaConfig := kafka.PluginConfig{
|
|
Brokers: []string{
|
|
"120.79.90.126:9093",
|
|
},
|
|
}
|
|
var err error
|
|
app.Kafka, err = kafka.NewPlugin(kafkaConfig)
|
|
if err != nil {
|
|
t.Log(err)
|
|
return
|
|
}
|
|
SetUp()
|
|
|
|
ctxId := xid.New().String()
|
|
//ctxId := "cslhe0rdervo4sb1lhng"
|
|
|
|
t.Log(ctxId)
|
|
|
|
ctx := context.WithValue(context.Background(), consts.TraceIdKey, ctxId)
|
|
|
|
NewCampaignNotice(ctx).CampaignChildInvite(types.CampaignChildInvite{CampaignId: 4304})
|
|
|
|
time.Sleep(time.Second)
|
|
}
|
|
|
|
func TestRewardPushPub(t *testing.T) {
|
|
conf()
|
|
|
|
initCommonProducer()
|
|
|
|
RewardPushPub(context.Background(), 1, types.DelayCommonRewardPush{TaskId: 287660046502219776})
|
|
|
|
}
|
|
|
|
func TestBiFissionAction(t *testing.T) {
|
|
conf()
|
|
kafkaConfig := kafka.PluginConfig{
|
|
Brokers: []string{
|
|
"120.79.90.126:9093",
|
|
},
|
|
}
|
|
var err error
|
|
app.Kafka, err = kafka.NewPlugin(kafkaConfig)
|
|
if err != nil {
|
|
t.Log(err)
|
|
return
|
|
}
|
|
SetUp()
|
|
|
|
wg := sync.WaitGroup{}
|
|
defer wg.Wait()
|
|
ctxId := xid.New().String()
|
|
ctx := context.WithValue(context.Background(), consts.TraceIdKey, ctxId)
|
|
for i := 0; i < 100; i++ {
|
|
for j := 0; j < 1000; j++ {
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
NewFissionBiReceiver(ctx).FissionAction(types.FissionAction{
|
|
ID: hashid.IdBigint(),
|
|
CampaignID: 4929,
|
|
UserMark: xid.New().String(),
|
|
UserMarkSource: 4,
|
|
Type: 1,
|
|
ActionTime: time.Now().Unix(),
|
|
Dimension: mtype.Dimension{
|
|
Platform: "ios",
|
|
ChannelId: 287612651835895808,
|
|
ParentId: 0,
|
|
Lang: "zh",
|
|
LevelMark: "",
|
|
UserLv: 0,
|
|
Country: "",
|
|
FirstAction: true,
|
|
DimensionOption: mtype.DimensionOption{},
|
|
},
|
|
OtherData: "{\"ip\":\"223.74.148.216\",\"os\":\"macOS\",\"os_version\":\"10.15.7\"}",
|
|
})
|
|
}()
|
|
}
|
|
time.Sleep(time.Millisecond * 200)
|
|
}
|
|
|
|
time.Sleep(2 * time.Second)
|
|
}
|