|
|
@ -1,55 +1,53 @@ |
|
|
|
package stages |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"gitea.anxinyun.cn/container/common_models" |
|
|
|
"log" |
|
|
|
"testing" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
func TestStageProcess(t *testing.T) { |
|
|
|
log.SetFlags(log.Lshortfile | log.Lmicroseconds) |
|
|
|
|
|
|
|
stage1 := NewStage("打印DeviceId") |
|
|
|
stage1.AddProcess(printDeviceId) |
|
|
|
stage2 := NewStage("打印DeviceName") |
|
|
|
stage2.AddProcess(printDeviceName) |
|
|
|
sm := NewStageManager() |
|
|
|
sm.AddStages(*stage1, *stage2) |
|
|
|
source := make(chan *common_models.ProcessData, 1) |
|
|
|
sm.AddSource(source) |
|
|
|
sm.Run() |
|
|
|
i := 0 |
|
|
|
go func() { |
|
|
|
for { |
|
|
|
i++ |
|
|
|
time.Sleep(time.Second * 2) |
|
|
|
deviceId := fmt.Sprintf("%d", i) |
|
|
|
pd := &common_models.ProcessData{ |
|
|
|
DeviceData: common_models.DeviceData{ |
|
|
|
DeviceId: deviceId, |
|
|
|
Name: "Name-" + deviceId, |
|
|
|
ThingId: "", |
|
|
|
StructId: 0, |
|
|
|
TaskId: "", |
|
|
|
AcqTime: time.Time{}, |
|
|
|
RealTime: time.Time{}, |
|
|
|
ErrCode: 0, |
|
|
|
Raw: nil, |
|
|
|
DeviceInfo: common_models.DeviceInfo{}, |
|
|
|
DimensionId: "", |
|
|
|
}, |
|
|
|
Stations: []common_models.Station{}, |
|
|
|
} |
|
|
|
source <- pd |
|
|
|
log.Printf("进入数据 %d", i) |
|
|
|
} |
|
|
|
}() |
|
|
|
for { |
|
|
|
sinkData := <-sm.out |
|
|
|
log.Printf("最终数据 %s", sinkData.DeviceData.Name) |
|
|
|
} |
|
|
|
//stage1 := NewStage("打印DeviceId")
|
|
|
|
//stage1.AddProcess(printDeviceId)
|
|
|
|
//stage2 := NewStage("打印DeviceName")
|
|
|
|
//stage2.AddProcess(printDeviceName)
|
|
|
|
//sm := NewStageManager()
|
|
|
|
//sm.AddStages(*stage1, *stage2)
|
|
|
|
//source := make(chan *common_models.ProcessData, 1)
|
|
|
|
//sm.AddSource(source)
|
|
|
|
//sm.Run()
|
|
|
|
//i := 0
|
|
|
|
//go func() {
|
|
|
|
// for {
|
|
|
|
// i++
|
|
|
|
// time.Sleep(time.Second * 2)
|
|
|
|
// deviceId := fmt.Sprintf("%d", i)
|
|
|
|
// pd := &common_models.ProcessData{
|
|
|
|
// DeviceData: common_models.DeviceData{
|
|
|
|
// DeviceId: deviceId,
|
|
|
|
// Name: "Name-" + deviceId,
|
|
|
|
// ThingId: "",
|
|
|
|
// StructId: 0,
|
|
|
|
// TaskId: "",
|
|
|
|
// AcqTime: time.Time{},
|
|
|
|
// RealTime: time.Time{},
|
|
|
|
// ErrCode: 0,
|
|
|
|
// Raw: nil,
|
|
|
|
// DeviceInfo: common_models.DeviceInfo{},
|
|
|
|
// DimensionId: "",
|
|
|
|
// },
|
|
|
|
// Stations: []common_models.Station{},
|
|
|
|
// }
|
|
|
|
// source <- pd
|
|
|
|
// log.Printf("进入数据 %d", i)
|
|
|
|
// }
|
|
|
|
//}()
|
|
|
|
//for {
|
|
|
|
// sinkData := <-sm.out
|
|
|
|
// log.Printf("最终数据 %s", sinkData.DeviceData.Name)
|
|
|
|
//}
|
|
|
|
|
|
|
|
} |
|
|
|
func printDeviceId(p *common_models.ProcessData) *common_models.ProcessData { |
|
|
|