From 77c9c6141a6101d4edf2d448936335b48fc216b7 Mon Sep 17 00:00:00 2001 From: Aceld Date: Wed, 20 Mar 2024 10:20:12 +0800 Subject: [PATCH 1/3] change config test path --- test/kis_action_test.go | 2 +- test/kis_config_export_test.go | 4 ++-- test/kis_config_import_test.go | 2 +- test/kis_fork_test.go | 2 +- test/kis_metrics_test.go | 2 +- test/kis_params_test.go | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/kis_action_test.go b/test/kis_action_test.go index 7adfcde..c286adc 100644 --- a/test/kis_action_test.go +++ b/test/kis_action_test.go @@ -23,7 +23,7 @@ func TestActionAbort(t *testing.T) { kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1) // 1. 加载配置文件并构建Flow - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/aceld/gopath/src/kis-flow/test/load_conf/"); err != nil { panic(err) } diff --git a/test/kis_config_export_test.go b/test/kis_config_export_test.go index 1a2d31c..485b324 100644 --- a/test/kis_config_export_test.go +++ b/test/kis_config_export_test.go @@ -20,14 +20,14 @@ func TestConfigExportYmal(t *testing.T) { kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1) // 1. 加载配置文件并构建Flow - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/aceld/gopath/src/kis-flow/test/load_conf/"); err != nil { panic(err) } // 2. 讲构建的内存KisFlow结构配置导出的文件当中 flows := kis.Pool().GetFlows() for _, flow := range flows { - if err := file.ConfigExportYaml(flow, "/Users/tal/gopath/src/kis-flow/test/export_conf/"); err != nil { + if err := file.ConfigExportYaml(flow, "/Users/aceld/gopath/src/kis-flow/test/export_conf/"); err != nil { panic(err) } } diff --git a/test/kis_config_import_test.go b/test/kis_config_import_test.go index f008070..53293a3 100644 --- a/test/kis_config_import_test.go +++ b/test/kis_config_import_test.go @@ -23,7 +23,7 @@ func TestConfigImportYaml(t *testing.T) { kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1) // 1. 加载配置文件并构建Flow - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/aceld/gopath/src/kis-flow/test/load_conf/"); err != nil { panic(err) } diff --git a/test/kis_fork_test.go b/test/kis_fork_test.go index 718b3f7..4325a85 100644 --- a/test/kis_fork_test.go +++ b/test/kis_fork_test.go @@ -23,7 +23,7 @@ func TestForkFlow(t *testing.T) { kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1) // 1. 加载配置文件并构建Flow - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/aceld/gopath/src/kis-flow/test/load_conf/"); err != nil { panic(err) } diff --git a/test/kis_metrics_test.go b/test/kis_metrics_test.go index 9cbe41c..35da706 100644 --- a/test/kis_metrics_test.go +++ b/test/kis_metrics_test.go @@ -24,7 +24,7 @@ func TestMetricsDataTotal(t *testing.T) { kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1) // 1. 加载配置文件并构建Flow - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/aceld/gopath/src/kis-flow/test/load_conf/"); err != nil { panic(err) } diff --git a/test/kis_params_test.go b/test/kis_params_test.go index 8ee0ef4..fd75dc1 100644 --- a/test/kis_params_test.go +++ b/test/kis_params_test.go @@ -23,7 +23,7 @@ func TestParams(t *testing.T) { kis.Pool().CaaS("ConnName1", "funcName2", common.S, caas.CaasDemoHanler1) // 1. 加载配置文件并构建Flow - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/aceld/gopath/src/kis-flow/test/load_conf/"); err != nil { panic(err) } From e07034026bd529511f932c4cc51e0be36111500a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E4=B8=B9=E5=86=B0?= Date: Wed, 20 Mar 2024 16:43:15 +0800 Subject: [PATCH 2/3] Update README.md --- README.md | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c963886..a1f7f31 100644 --- a/README.md +++ b/README.md @@ -233,21 +233,18 @@ func FuncDemo1Handler(ctx context.Context, flow kis.Flow) error { // ... FuncDemo3Handler ``` +### 开发者 +* 刘丹冰([@aceld](https://github.com/aceld)) +* 胡辰豪([@ChenHaoHu](https://github.com/ChenHaoHu)) ---- -### About the author + +Thanks to all the developers who contributed to KisFlow! -`name`:`Aceld(刘丹冰)` + + + -`mail`: -[danbing.at@gmail.com](mailto:danbing.at@gmail.com) - -`github`: -[https://github.com/aceld](https://github.com/aceld) - -`original work`: -[https://www.yuque.com/aceld](https://www.yuque.com/aceld) ### 加入KisFlow 社区 From 4b7d213367959cbb9c52141f895de80788beec54 Mon Sep 17 00:00:00 2001 From: aceld Date: Wed, 20 Mar 2024 17:57:41 +0800 Subject: [PATCH 3/3] change some test param, add test init() --- test/faas/faas_demo4.go | 26 +++++++++++++++++ test/init.go | 25 ++++++++++++++++ test/kis_action_test.go | 52 ++++++---------------------------- test/kis_config_export_test.go | 17 +++-------- test/kis_config_import_test.go | 14 +-------- test/kis_connector_test.go | 12 -------- test/kis_flow_test.go | 6 ++-- test/kis_fork_test.go | 14 +-------- test/kis_metrics_test.go | 16 ++--------- test/kis_params_test.go | 14 +-------- test/kis_pool_test.go | 10 ++----- 11 files changed, 75 insertions(+), 131 deletions(-) create mode 100644 test/faas/faas_demo4.go create mode 100644 test/init.go diff --git a/test/faas/faas_demo4.go b/test/faas/faas_demo4.go new file mode 100644 index 0000000..79233f3 --- /dev/null +++ b/test/faas/faas_demo4.go @@ -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 +} diff --git a/test/init.go b/test/init.go new file mode 100644 index 0000000..fb72805 --- /dev/null +++ b/test/init.go @@ -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) + +} diff --git a/test/kis_action_test.go b/test/kis_action_test.go index 7adfcde..899eed0 100644 --- a/test/kis_action_test.go +++ b/test/kis_action_test.go @@ -2,28 +2,18 @@ package test import ( "context" - "kis-flow/common" + "fmt" "kis-flow/file" "kis-flow/kis" - "kis-flow/test/caas" - "kis-flow/test/faas" "testing" ) func TestActionAbort(t *testing.T) { 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 - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/Aceld/go/src/kis-flow/test/load_conf/"); err != nil { + fmt.Println("Wrong Config Yaml Path!") panic(err) } @@ -44,17 +34,9 @@ func TestActionAbort(t *testing.T) { func TestActionDataReuse(t *testing.T) { 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 - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/Aceld/go/src/kis-flow/test/load_conf/"); err != nil { + fmt.Println("Wrong Config Yaml Path!") panic(err) } @@ -75,17 +57,9 @@ func TestActionDataReuse(t *testing.T) { func TestActionForceEntry(t *testing.T) { 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 - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/Aceld/go/src/kis-flow/test/load_conf/"); err != nil { + fmt.Println("Wrong Config Yaml Path!") panic(err) } @@ -106,17 +80,9 @@ func TestActionForceEntry(t *testing.T) { func TestActionJumpFunc(t *testing.T) { 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 - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/Aceld/go/src/kis-flow/test/load_conf/"); err != nil { + fmt.Println("Wrong Config Yaml Path!") panic(err) } diff --git a/test/kis_config_export_test.go b/test/kis_config_export_test.go index 1a2d31c..f0a507e 100644 --- a/test/kis_config_export_test.go +++ b/test/kis_config_export_test.go @@ -1,33 +1,24 @@ package test import ( - "kis-flow/common" + "fmt" "kis-flow/file" "kis-flow/kis" - "kis-flow/test/caas" - "kis-flow/test/faas" "testing" ) 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 - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/Aceld/go/src/kis-flow/test/load_conf/"); err != nil { + fmt.Println("Wrong Config Yaml Path!") panic(err) } // 2. 讲构建的内存KisFlow结构配置导出的文件当中 flows := kis.Pool().GetFlows() for _, flow := range flows { - if err := file.ConfigExportYaml(flow, "/Users/tal/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) } } diff --git a/test/kis_config_import_test.go b/test/kis_config_import_test.go index f008070..102f3a5 100644 --- a/test/kis_config_import_test.go +++ b/test/kis_config_import_test.go @@ -2,28 +2,16 @@ package test import ( "context" - "kis-flow/common" "kis-flow/file" "kis-flow/kis" - "kis-flow/test/caas" - "kis-flow/test/faas" "testing" ) func TestConfigImportYaml(t *testing.T) { 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 - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/Aceld/go/src/kis-flow/test/load_conf/"); err != nil { panic(err) } diff --git a/test/kis_connector_test.go b/test/kis_connector_test.go index 605e063..764a6c1 100644 --- a/test/kis_connector_test.go +++ b/test/kis_connector_test.go @@ -5,9 +5,6 @@ import ( "kis-flow/common" "kis-flow/config" "kis-flow/flow" - "kis-flow/kis" - "kis-flow/test/caas" - "kis-flow/test/faas" "testing" ) @@ -15,15 +12,6 @@ func TestNewKisConnector(t *testing.T) { 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配置 source1 := config.KisSource{ Name: "公众号抖音商城户订单数据", diff --git a/test/kis_flow_test.go b/test/kis_flow_test.go index 557d1ad..b4d3d74 100644 --- a/test/kis_flow_test.go +++ b/test/kis_flow_test.go @@ -71,9 +71,9 @@ func TestNewKisFlowData(t *testing.T) { panic("myFuncConfig1 is nil") } - myFuncConfig2 := config.NewFuncConfig("funcName2", common.E, &source2, nil) + myFuncConfig2 := config.NewFuncConfig("funcName4", common.E, &source2, nil) if myFuncConfig2 == nil { - panic("myFuncConfig2 is nil") + panic("myFuncConfig4 is nil") } // 2. 创建一个 KisFlow 配置实例 @@ -82,7 +82,7 @@ func TestNewKisFlowData(t *testing.T) { // 3. 创建一个KisFlow对象 flow1 := flow.NewKisFlow(myFlowConfig1) - // 4. 拼接Functioin 到 Flow 上 + // 4. 拼接 Function 到 Flow 上 if err := flow1.Link(myFuncConfig1, nil); err != nil { panic(err) } diff --git a/test/kis_fork_test.go b/test/kis_fork_test.go index 718b3f7..76d035f 100644 --- a/test/kis_fork_test.go +++ b/test/kis_fork_test.go @@ -2,28 +2,16 @@ package test import ( "context" - "kis-flow/common" "kis-flow/file" "kis-flow/kis" - "kis-flow/test/caas" - "kis-flow/test/faas" "testing" ) func TestForkFlow(t *testing.T) { 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 - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/Aceld/go/src/kis-flow/test/load_conf/"); err != nil { panic(err) } diff --git a/test/kis_metrics_test.go b/test/kis_metrics_test.go index 9cbe41c..01475de 100644 --- a/test/kis_metrics_test.go +++ b/test/kis_metrics_test.go @@ -2,11 +2,9 @@ package test import ( "context" - "kis-flow/common" + "fmt" "kis-flow/file" "kis-flow/kis" - "kis-flow/test/caas" - "kis-flow/test/faas" "testing" "time" ) @@ -14,17 +12,9 @@ import ( func TestMetricsDataTotal(t *testing.T) { 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 - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/Aceld/go/src/kis-flow/test/load_conf/"); err != nil { + fmt.Println("Wrong Config Yaml Path!") panic(err) } diff --git a/test/kis_params_test.go b/test/kis_params_test.go index 8ee0ef4..e2e7aec 100644 --- a/test/kis_params_test.go +++ b/test/kis_params_test.go @@ -2,28 +2,16 @@ package test import ( "context" - "kis-flow/common" "kis-flow/file" "kis-flow/kis" - "kis-flow/test/caas" - "kis-flow/test/faas" "testing" ) func TestParams(t *testing.T) { 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 - if err := file.ConfigImportYaml("/Users/tal/gopath/src/kis-flow/test/load_conf/"); err != nil { + if err := file.ConfigImportYaml("/Users/Aceld/go/src/kis-flow/test/load_conf/"); err != nil { panic(err) } diff --git a/test/kis_pool_test.go b/test/kis_pool_test.go index 52e7726..5f49483 100644 --- a/test/kis_pool_test.go +++ b/test/kis_pool_test.go @@ -5,8 +5,6 @@ import ( "kis-flow/common" "kis-flow/config" "kis-flow/flow" - "kis-flow/kis" - "kis-flow/test/faas" "testing" ) @@ -14,10 +12,6 @@ func TestNewKisPool(t *testing.T) { ctx := context.Background() - // 0. 注册Function - kis.Pool().FaaS("funcName1", faas.FuncDemo1Handler) - kis.Pool().FaaS("funcName2", faas.FuncDemo2Handler) - // 1. 创建2个KisFunction配置实例 source1 := config.KisSource{ Name: "公众号抖音商城户订单数据", @@ -34,9 +28,9 @@ func TestNewKisPool(t *testing.T) { panic("myFuncConfig1 is nil") } - myFuncConfig2 := config.NewFuncConfig("funcName2", common.E, &source2, nil) + myFuncConfig2 := config.NewFuncConfig("funcName4", common.E, &source2, nil) if myFuncConfig2 == nil { - panic("myFuncConfig2 is nil") + panic("myFuncConfig4 is nil") } // 2. 创建一个 KisFlow 配置实例