Merge pull request #7 from aceld/feature/aceld

change some test param, add test init()
This commit is contained in:
刘丹冰 2024-03-20 18:10:57 +08:00 committed by GitHub
commit 171c7bb611
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 75 additions and 131 deletions

26
test/faas/faas_demo4.go Normal file
View File

@ -0,0 +1,26 @@
package faas
import (
"context"
"fmt"
"kis-flow/kis"
)
// type FaaS func(context.Context, Flow) error
func FuncDemo4Handler(ctx context.Context, flow kis.Flow) error {
fmt.Println("---> Call FuncDemo4Handler ----")
for index, row := range flow.Input() {
str := fmt.Sprintf("In FuncName = %s, FuncId = %s, row = %s", flow.GetThisFuncConf().FName, flow.GetThisFunction().GetId(), row)
fmt.Println(str)
// 计算结果数据
resultStr := fmt.Sprintf("data from funcName[%s], index = %d", flow.GetThisFuncConf().FName, index)
// 提交结果数据
_ = flow.CommitRow(resultStr)
}
return nil
}

25
test/init.go Normal file
View File

@ -0,0 +1,25 @@
package test
import (
"kis-flow/common"
"kis-flow/kis"
"kis-flow/test/caas"
"kis-flow/test/faas"
)
func init() {
// 0. 注册Function 回调业务
kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler)
kis.Pool().FaaS("funcName2", faas.FuncDemo2Handler)
kis.Pool().FaaS("funcName3", faas.FuncDemo3Handler)
kis.Pool().FaaS("funcName4", faas.FuncDemo4Handler)
kis.Pool().FaaS("abortFunc", faas.AbortFuncHandler) // abortFunc 业务
kis.Pool().FaaS("dataReuseFunc", faas.DataReuseFuncHandler) // dataReuseFunc 业务
kis.Pool().FaaS("noResultFunc", faas.NoResultFuncHandler) // noResultFunc 业务
kis.Pool().FaaS("jumpFunc", faas.JumpFuncHandler) // jumpFunc 业务
// 0. 注册ConnectorInit 和 Connector 回调业务
kis.Pool().CaaSInit("ConnName1", caas.InitConnDemo1)
kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1)
}

View File

@ -2,28 +2,18 @@ package test
import ( import (
"context" "context"
"kis-flow/common" "fmt"
"kis-flow/file" "kis-flow/file"
"kis-flow/kis" "kis-flow/kis"
"kis-flow/test/caas"
"kis-flow/test/faas"
"testing" "testing"
) )
func TestActionAbort(t *testing.T) { func TestActionAbort(t *testing.T) {
ctx := context.Background() ctx := context.Background()
// 0. 注册Function 回调业务
kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler)
kis.Pool().FaaS("abortFunc", faas.AbortFuncHandler) // 添加abortFunc 业务
kis.Pool().FaaS("funcName3", faas.FuncDemo3Handler)
// 0. 注册ConnectorInit 和 Connector 回调业务
kis.Pool().CaaSInit("ConnName1", caas.InitConnDemo1)
kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1)
// 1. 加载配置文件并构建Flow // 1. 加载配置文件并构建Flow
if err := file.ConfigImportYaml("/Users/aceld/gopath/src/kis-flow/test/load_conf/"); err != nil { if err := file.ConfigImportYaml("load_conf/"); err != nil {
fmt.Println("Wrong Config Yaml Path!")
panic(err) panic(err)
} }
@ -44,17 +34,9 @@ func TestActionAbort(t *testing.T) {
func TestActionDataReuse(t *testing.T) { func TestActionDataReuse(t *testing.T) {
ctx := context.Background() ctx := context.Background()
// 0. 注册Function 回调业务
kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler)
kis.Pool().FaaS("dataReuseFunc", faas.DataReuseFuncHandler) // 添加dataReuesFunc 业务
kis.Pool().FaaS("funcName3", faas.FuncDemo3Handler)
// 0. 注册ConnectorInit 和 Connector 回调业务
kis.Pool().CaaSInit("ConnName1", caas.InitConnDemo1)
kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1)
// 1. 加载配置文件并构建Flow // 1. 加载配置文件并构建Flow
if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { if err := file.ConfigImportYaml("load_conf/"); err != nil {
fmt.Println("Wrong Config Yaml Path!")
panic(err) panic(err)
} }
@ -75,17 +57,9 @@ func TestActionDataReuse(t *testing.T) {
func TestActionForceEntry(t *testing.T) { func TestActionForceEntry(t *testing.T) {
ctx := context.Background() ctx := context.Background()
// 0. 注册Function 回调业务
kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler)
kis.Pool().FaaS("noResultFunc", faas.NoResultFuncHandler) // 添加noResultFunc 业务
kis.Pool().FaaS("funcName3", faas.FuncDemo3Handler)
// 0. 注册ConnectorInit 和 Connector 回调业务
kis.Pool().CaaSInit("ConnName1", caas.InitConnDemo1)
kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1)
// 1. 加载配置文件并构建Flow // 1. 加载配置文件并构建Flow
if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { if err := file.ConfigImportYaml("load_conf/"); err != nil {
fmt.Println("Wrong Config Yaml Path!")
panic(err) panic(err)
} }
@ -106,17 +80,9 @@ func TestActionForceEntry(t *testing.T) {
func TestActionJumpFunc(t *testing.T) { func TestActionJumpFunc(t *testing.T) {
ctx := context.Background() ctx := context.Background()
// 0. 注册Function 回调业务
kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler)
kis.Pool().FaaS("funcName2", faas.FuncDemo2Handler)
kis.Pool().FaaS("jumpFunc", faas.JumpFuncHandler) // 添加jumpFunc 业务
// 0. 注册ConnectorInit 和 Connector 回调业务
kis.Pool().CaaSInit("ConnName1", caas.InitConnDemo1)
kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1)
// 1. 加载配置文件并构建Flow // 1. 加载配置文件并构建Flow
if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { if err := file.ConfigImportYaml("load_conf/"); err != nil {
fmt.Println("Wrong Config Yaml Path!")
panic(err) panic(err)
} }

View File

@ -1,33 +1,24 @@
package test package test
import ( import (
"kis-flow/common" "fmt"
"kis-flow/file" "kis-flow/file"
"kis-flow/kis" "kis-flow/kis"
"kis-flow/test/caas"
"kis-flow/test/faas"
"testing" "testing"
) )
func TestConfigExportYmal(t *testing.T) { func TestConfigExportYmal(t *testing.T) {
// 0. 注册Function 回调业务
kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler)
kis.Pool().FaaS("funcName2", faas.FuncDemo2Handler)
kis.Pool().FaaS("funcName3", faas.FuncDemo3Handler)
// 0. 注册ConnectorInit 和 Connector 回调业务
kis.Pool().CaaSInit("ConnName1", caas.InitConnDemo1)
kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1)
// 1. 加载配置文件并构建Flow // 1. 加载配置文件并构建Flow
if err := file.ConfigImportYaml("/Users/aceld/gopath/src/kis-flow/test/load_conf/"); err != nil { if err := file.ConfigImportYaml("load_conf/"); err != nil {
fmt.Println("Wrong Config Yaml Path!")
panic(err) panic(err)
} }
// 2. 讲构建的内存KisFlow结构配置导出的文件当中 // 2. 讲构建的内存KisFlow结构配置导出的文件当中
flows := kis.Pool().GetFlows() flows := kis.Pool().GetFlows()
for _, flow := range flows { for _, flow := range flows {
if err := file.ConfigExportYaml(flow, "/Users/aceld/gopath/src/kis-flow/test/export_conf/"); err != nil { if err := file.ConfigExportYaml(flow, "/Users/Aceld/go/src/kis-flow/test/export_conf/"); err != nil {
panic(err) panic(err)
} }
} }

View File

@ -2,28 +2,16 @@ package test
import ( import (
"context" "context"
"kis-flow/common"
"kis-flow/file" "kis-flow/file"
"kis-flow/kis" "kis-flow/kis"
"kis-flow/test/caas"
"kis-flow/test/faas"
"testing" "testing"
) )
func TestConfigImportYaml(t *testing.T) { func TestConfigImportYaml(t *testing.T) {
ctx := context.Background() ctx := context.Background()
// 0. 注册Function 回调业务
kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler)
kis.Pool().FaaS("funcName2", faas.FuncDemo2Handler)
kis.Pool().FaaS("funcName3", faas.FuncDemo3Handler)
// 0. 注册ConnectorInit 和 Connector 回调业务
kis.Pool().CaaSInit("ConnName1", caas.InitConnDemo1)
kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1)
// 1. 加载配置文件并构建Flow // 1. 加载配置文件并构建Flow
if err := file.ConfigImportYaml("/Users/aceld/gopath/src/kis-flow/test/load_conf/"); err != nil { if err := file.ConfigImportYaml("load_conf/"); err != nil {
panic(err) panic(err)
} }

View File

@ -5,9 +5,6 @@ import (
"kis-flow/common" "kis-flow/common"
"kis-flow/config" "kis-flow/config"
"kis-flow/flow" "kis-flow/flow"
"kis-flow/kis"
"kis-flow/test/caas"
"kis-flow/test/faas"
"testing" "testing"
) )
@ -15,15 +12,6 @@ func TestNewKisConnector(t *testing.T) {
ctx := context.Background() ctx := context.Background()
// 0. 注册Function 回调业务
kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler)
kis.Pool().FaaS("funcName2", faas.FuncDemo2Handler)
kis.Pool().FaaS("funcName3", faas.FuncDemo3Handler)
// 0. 注册ConnectorInit 和 Connector 回调业务
kis.Pool().CaaSInit("ConnName1", caas.InitConnDemo1)
kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1)
// 1. 创建3个KisFunction配置实例, 其中myFuncConfig2 有Connector配置 // 1. 创建3个KisFunction配置实例, 其中myFuncConfig2 有Connector配置
source1 := config.KisSource{ source1 := config.KisSource{
Name: "公众号抖音商城户订单数据", Name: "公众号抖音商城户订单数据",

View File

@ -71,9 +71,9 @@ func TestNewKisFlowData(t *testing.T) {
panic("myFuncConfig1 is nil") panic("myFuncConfig1 is nil")
} }
myFuncConfig2 := config.NewFuncConfig("funcName2", common.E, &source2, nil) myFuncConfig2 := config.NewFuncConfig("funcName4", common.E, &source2, nil)
if myFuncConfig2 == nil { if myFuncConfig2 == nil {
panic("myFuncConfig2 is nil") panic("myFuncConfig4 is nil")
} }
// 2. 创建一个 KisFlow 配置实例 // 2. 创建一个 KisFlow 配置实例
@ -82,7 +82,7 @@ func TestNewKisFlowData(t *testing.T) {
// 3. 创建一个KisFlow对象 // 3. 创建一个KisFlow对象
flow1 := flow.NewKisFlow(myFlowConfig1) flow1 := flow.NewKisFlow(myFlowConfig1)
// 4. 拼接Functioin 到 Flow 上 // 4. 拼接 Function 到 Flow 上
if err := flow1.Link(myFuncConfig1, nil); err != nil { if err := flow1.Link(myFuncConfig1, nil); err != nil {
panic(err) panic(err)
} }

View File

@ -2,28 +2,16 @@ package test
import ( import (
"context" "context"
"kis-flow/common"
"kis-flow/file" "kis-flow/file"
"kis-flow/kis" "kis-flow/kis"
"kis-flow/test/caas"
"kis-flow/test/faas"
"testing" "testing"
) )
func TestForkFlow(t *testing.T) { func TestForkFlow(t *testing.T) {
ctx := context.Background() ctx := context.Background()
// 0. 注册Function 回调业务
kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler)
kis.Pool().FaaS("funcName2", faas.FuncDemo2Handler)
kis.Pool().FaaS("funcName3", faas.FuncDemo3Handler)
// 0. 注册ConnectorInit 和 Connector 回调业务
kis.Pool().CaaSInit("ConnName1", caas.InitConnDemo1)
kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1)
// 1. 加载配置文件并构建Flow // 1. 加载配置文件并构建Flow
if err := file.ConfigImportYaml("/Users/aceld/gopath/src/kis-flow/test/load_conf/"); err != nil { if err := file.ConfigImportYaml("load_conf/"); err != nil {
panic(err) panic(err)
} }

View File

@ -2,11 +2,9 @@ package test
import ( import (
"context" "context"
"kis-flow/common" "fmt"
"kis-flow/file" "kis-flow/file"
"kis-flow/kis" "kis-flow/kis"
"kis-flow/test/caas"
"kis-flow/test/faas"
"testing" "testing"
"time" "time"
) )
@ -14,17 +12,9 @@ import (
func TestMetricsDataTotal(t *testing.T) { func TestMetricsDataTotal(t *testing.T) {
ctx := context.Background() ctx := context.Background()
// 0. 注册Function 回调业务
kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler)
kis.Pool().FaaS("funcName2", faas.FuncDemo2Handler)
kis.Pool().FaaS("funcName3", faas.FuncDemo3Handler)
// 0. 注册ConnectorInit 和 Connector 回调业务
kis.Pool().CaaSInit("ConnName1", caas.InitConnDemo1)
kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1)
// 1. 加载配置文件并构建Flow // 1. 加载配置文件并构建Flow
if err := file.ConfigImportYaml("/Users/aceld/gopath/src/kis-flow/test/load_conf/"); err != nil { if err := file.ConfigImportYaml("load_conf/"); err != nil {
fmt.Println("Wrong Config Yaml Path!")
panic(err) panic(err)
} }

View File

@ -2,28 +2,16 @@ package test
import ( import (
"context" "context"
"kis-flow/common"
"kis-flow/file" "kis-flow/file"
"kis-flow/kis" "kis-flow/kis"
"kis-flow/test/caas"
"kis-flow/test/faas"
"testing" "testing"
) )
func TestParams(t *testing.T) { func TestParams(t *testing.T) {
ctx := context.Background() ctx := context.Background()
// 0. 注册Function 回调业务
kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler)
kis.Pool().FaaS("funcName2", faas.FuncDemo2Handler)
kis.Pool().FaaS("funcName3", faas.FuncDemo3Handler)
// 0. 注册ConnectorInit 和 Connector 回调业务
kis.Pool().CaaSInit("ConnName1", caas.InitConnDemo1)
kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1)
// 1. 加载配置文件并构建Flow // 1. 加载配置文件并构建Flow
if err := file.ConfigImportYaml("/Users/aceld/gopath/src/kis-flow/test/load_conf/"); err != nil { if err := file.ConfigImportYaml("load_conf/"); err != nil {
panic(err) panic(err)
} }

View File

@ -5,8 +5,6 @@ import (
"kis-flow/common" "kis-flow/common"
"kis-flow/config" "kis-flow/config"
"kis-flow/flow" "kis-flow/flow"
"kis-flow/kis"
"kis-flow/test/faas"
"testing" "testing"
) )
@ -14,10 +12,6 @@ func TestNewKisPool(t *testing.T) {
ctx := context.Background() ctx := context.Background()
// 0. 注册Function
kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler)
kis.Pool().FaaS("funcName2", faas.FuncDemo2Handler)
// 1. 创建2个KisFunction配置实例 // 1. 创建2个KisFunction配置实例
source1 := config.KisSource{ source1 := config.KisSource{
Name: "公众号抖音商城户订单数据", Name: "公众号抖音商城户订单数据",
@ -34,9 +28,9 @@ func TestNewKisPool(t *testing.T) {
panic("myFuncConfig1 is nil") panic("myFuncConfig1 is nil")
} }
myFuncConfig2 := config.NewFuncConfig("funcName2", common.E, &source2, nil) myFuncConfig2 := config.NewFuncConfig("funcName4", common.E, &source2, nil)
if myFuncConfig2 == nil { if myFuncConfig2 == nil {
panic("myFuncConfig2 is nil") panic("myFuncConfig4 is nil")
} }
// 2. 创建一个 KisFlow 配置实例 // 2. 创建一个 KisFlow 配置实例