et-go 20240919重建
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

53 lines
1.3 KiB

package main
import (
"encoding/json"
"gitea.anxinyun.cn/container/common_models"
"log"
"node/agg_worker"
"strings"
"testing"
"time"
)
func Test_AggNodeHandler(t *testing.T) {
// 2024-04-08T11:01:48.001+08:00
// TODO 聚集数据中时间:"date": "2024-04-19T01:01:59.999+0000"
aggDataMSG := `{
"date": "2024-04-19T01:01:59.999+0000",
"sensorId": 106,
"structId": 1,
"factorId": 11,
"aggTypeId": 2006,
"aggMethodId": 3004,
"agg": {
"strain": -16.399999618530273
},
"changed": {
"strain": -0.7999992370605469
}
}`
// aggData 中的时间为UTC格式 2024-04-19T01:10:59.999+0000,
// 在进行 json.Unmarshal() 时报错
// 解决方案:先将 +0000 -> +00:00,然后再将 UTC 时间转换为 +08:00 时区时间
// 将 "+0000" 替换为 "+00:00"
replacedStr := strings.Replace(aggDataMSG, "+0000", "+00:00", 1)
aggData := &common_models.AggData{}
err := json.Unmarshal([]byte(replacedStr), &aggData)
if err != nil {
log.Panicf("测试异常%s", err.Error())
}
// 将 UTC 时间加上8小时得到中国的本地时间
aggData.Date = aggData.Date.Add(8 * time.Hour)
nodeWorker := agg_worker.NewAggWorker()
//nodeWorker.RegisterToMaster() 需要启动 master
log.Println("测试开始")
nodeWorker.ConsumerProcess(aggData)
time.Sleep(time.Second * 10)
log.Println("测试结束")
}