diff --git a/tests/ten_runtime/integration/go/access_property_go/BUILD.gn b/tests/ten_runtime/integration/go/access_property_go/BUILD.gn index 7ff8b3a997..88c9f7e988 100644 --- a/tests/ten_runtime/integration/go/access_property_go/BUILD.gn +++ b/tests/ten_runtime/integration/go/access_property_go/BUILD.gn @@ -15,10 +15,9 @@ ten_package_test_prepare_app("access_property_go_app") { replace_files_after_install_app = [ "access_property_go_app/manifest.json", "access_property_go_app/property.json", + "access_property_go_app/ten_packages", ] - replace_files_after_install_all = [ "access_property_go_app/ten_packages/extension/default_extension_go/extension.go" ] - deps = [ "//core/src/ten_manager", "//packages/core_apps/default_app_go:upload_default_app_go_to_server", diff --git a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/manifest.json b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/manifest.json index 54015e0959..fade8d5f5b 100644 --- a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/manifest.json +++ b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/manifest.json @@ -2,7 +2,7 @@ "dependencies": [ { "type": "extension", - "name": "default_extension_go", + "name": "extension_a", "version": "0.3.0-alpha" }, { @@ -11,4 +11,4 @@ "version": "0.3.0-alpha" } ] -} \ No newline at end of file +} diff --git a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/property.json b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/property.json index f809b7b370..094dab2645 100644 --- a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/property.json +++ b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/property.json @@ -18,4 +18,4 @@ } ] } -} \ No newline at end of file +} diff --git a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/default_extension_go/extension.go b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/extension.go similarity index 94% rename from tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/default_extension_go/extension.go rename to tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/extension.go index c1bf7e1563..bfbb346b22 100644 --- a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/default_extension_go/extension.go +++ b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/extension.go @@ -204,22 +204,6 @@ func (p *aExtension) OnCmd( } } -type nodeTestGroup struct { - ten.DefaultExtensionGroup -} - -func newNodeTestGroup(name string) ten.ExtensionGroup { - return &nodeTestGroup{} -} - -func (p *nodeTestGroup) OnCreateExtensions( - tenEnv ten.TenEnv, -) { - tenEnv.OnCreateExtensionsDone( - ten.WrapExtension(&aExtension{}, "A"), - ) -} - func init() { // Register addon err := ten.RegisterAddonAsExtension( diff --git a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/go.mod b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/go.mod new file mode 100644 index 0000000000..9c3192343b --- /dev/null +++ b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/go.mod @@ -0,0 +1,7 @@ +module extension_a + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/manifest.json b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/manifest.json new file mode 100644 index 0000000000..cd7f71e46e --- /dev/null +++ b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_a", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/property.json b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/expired_ten_go/BUILD.gn b/tests/ten_runtime/integration/go/expired_ten_go/BUILD.gn index 50b3b10df0..d9d7892ac9 100644 --- a/tests/ten_runtime/integration/go/expired_ten_go/BUILD.gn +++ b/tests/ten_runtime/integration/go/expired_ten_go/BUILD.gn @@ -15,10 +15,11 @@ ten_package_test_prepare_app("expired_ten_go_app") { replace_files_after_install_app = [ "expired_ten_go_app/manifest.json", "expired_ten_go_app/property.json", + "expired_ten_go_app/ten_packages", + "expired_ten_go_app/go_common_dep", + "expired_ten_go_app/go.mod", ] - replace_files_after_install_all = [ "expired_ten_go_app/ten_packages/extension/default_extension_go/extension.go" ] - if (ten_enable_package_manager) { deps = [ "//core/src/ten_manager", diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/go.mod b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/go.mod new file mode 100644 index 0000000000..e085ce3096 --- /dev/null +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/go.mod @@ -0,0 +1,11 @@ +module app + +go 1.20 + +replace ten_framework => ./ten_packages/system/ten_runtime_go/interface + +replace go_common_dep => ./go_common_dep + +require ten_framework v0.0.0-00010101000000-000000000000 + +require go_common_dep v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/go_common_dep/go.mod b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/go_common_dep/go.mod new file mode 100644 index 0000000000..a7d32e7d69 --- /dev/null +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/go_common_dep/go.mod @@ -0,0 +1,3 @@ +module go_common_dep + +go 1.18 diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/go_common_dep/types/data.go b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/go_common_dep/types/data.go new file mode 100644 index 0000000000..4f00185e30 --- /dev/null +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/go_common_dep/types/data.go @@ -0,0 +1,6 @@ +package types + +type UserData struct { + Uid int + Name string +} diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/manifest.json b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/manifest.json index 54015e0959..111dde5447 100644 --- a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/manifest.json +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/manifest.json @@ -2,7 +2,12 @@ "dependencies": [ { "type": "extension", - "name": "default_extension_go", + "name": "extension_a", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "extension_b", "version": "0.3.0-alpha" }, { diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/default_extension_go/extension.go b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/extension.go similarity index 64% rename from tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/default_extension_go/extension.go rename to tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/extension.go index 75eecd19dd..63f62f10e8 100644 --- a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/default_extension_go/extension.go +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/extension.go @@ -12,6 +12,7 @@ import ( "fmt" "time" + "go_common_dep/types" "ten_framework/ten" ) @@ -19,18 +20,10 @@ type extensionA struct { ten.DefaultExtension } -type extensionB struct { - ten.DefaultExtension -} - func newExtensionA(name string) ten.Extension { return &extensionA{} } -func newExtensionB(name string) ten.Extension { - return &extensionB{} -} - func (p *extensionA) OnCmd( tenEnv ten.TenEnv, cmd ten.Cmd, @@ -47,7 +40,7 @@ func (p *extensionA) OnCmd( tenEnv.ReturnResult(cmdResult, cmd) } else { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", detail.(*userData).name) + cmdResult.SetPropertyString("detail", detail.(*types.UserData).Name) tenEnv.ReturnResult(cmdResult, cmd) } }) @@ -63,31 +56,6 @@ func (p *extensionA) OnCmd( }() } -type userData struct { - uid int - name string -} - -func (p *extensionB) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - fmt.Println("extensionB OnCmd") - - cmdName, _ := cmd.GetName() - if cmdName == "B" { - data := userData{uid: 1, name: "ten"} - cs, _ := ten.NewCmdResult(ten.StatusCodeOk) - cs.SetProperty("data", &data) - err := tenEnv.ReturnResult(cs, cmd) - if err != nil { - panic(err) - } - } - }() -} - func init() { // Register addon err := ten.RegisterAddonAsExtension( @@ -97,12 +65,4 @@ func init() { if err != nil { fmt.Println("register addon failed", err) } - - err = ten.RegisterAddonAsExtension( - "extension_b", - ten.NewDefaultExtensionAddon(newExtensionB), - ) - if err != nil { - fmt.Println("register addon failed", err) - } } diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/go.mod b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/go.mod new file mode 100644 index 0000000000..d22e0ece5b --- /dev/null +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/go.mod @@ -0,0 +1,11 @@ +module extension_a + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +replace go_common_dep => ../../../go_common_dep + +require ten_framework v0.0.0-00010101000000-000000000000 + +require go_common_dep v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/manifest.json b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/manifest.json new file mode 100644 index 0000000000..cd7f71e46e --- /dev/null +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_a", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/property.json b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/extension.go new file mode 100644 index 0000000000..0e4c5139ef --- /dev/null +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/extension.go @@ -0,0 +1,55 @@ +// +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// + +package default_extension_go + +import ( + "fmt" + + "go_common_dep/types" + "ten_framework/ten" +) + +type extensionB struct { + ten.DefaultExtension +} + +func newExtensionB(name string) ten.Extension { + return &extensionB{} +} + +func (p *extensionB) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + fmt.Println("extensionB OnCmd") + + cmdName, _ := cmd.GetName() + if cmdName == "B" { + data := types.UserData{Uid: 1, Name: "ten"} + cs, _ := ten.NewCmdResult(ten.StatusCodeOk) + cs.SetProperty("data", &data) + err := tenEnv.ReturnResult(cs, cmd) + if err != nil { + panic(err) + } + } + }() +} + +func init() { + // Register addon + err := ten.RegisterAddonAsExtension( + "extension_b", + ten.NewDefaultExtensionAddon(newExtensionB), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/go.mod b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/go.mod new file mode 100644 index 0000000000..c11fa56f55 --- /dev/null +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/go.mod @@ -0,0 +1,11 @@ +module extension_b + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +replace go_common_dep => ../../../go_common_dep + +require ten_framework v0.0.0-00010101000000-000000000000 + +require go_common_dep v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/manifest.json b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/manifest.json new file mode 100644 index 0000000000..deb1721cda --- /dev/null +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_b", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/property.json b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/BUILD.gn b/tests/ten_runtime/integration/go/frequently_cgo_call_go/BUILD.gn index 596eea0a8f..0bbaadacc0 100644 --- a/tests/ten_runtime/integration/go/frequently_cgo_call_go/BUILD.gn +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/BUILD.gn @@ -15,10 +15,9 @@ ten_package_test_prepare_app("frequently_cgo_call_go_app") { replace_files_after_install_app = [ "frequently_cgo_call_go_app/manifest.json", "frequently_cgo_call_go_app/property.json", + "frequently_cgo_call_go_app/ten_packages", ] - replace_files_after_install_all = [ "frequently_cgo_call_go_app/ten_packages/extension/default_extension_go/extension.go" ] - if (ten_enable_package_manager) { deps = [ "//core/src/ten_manager", diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/manifest.json b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/manifest.json index 54015e0959..111dde5447 100644 --- a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/manifest.json +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/manifest.json @@ -2,7 +2,12 @@ "dependencies": [ { "type": "extension", - "name": "default_extension_go", + "name": "extension_a", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "extension_b", "version": "0.3.0-alpha" }, { diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/default_extension_go/extension.go b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/extension.go similarity index 61% rename from tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/default_extension_go/extension.go rename to tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/extension.go index 63105821e1..2543715cbc 100644 --- a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/default_extension_go/extension.go +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/extension.go @@ -21,18 +21,10 @@ type extensionA struct { ten.DefaultExtension } -type extensionB struct { - ten.DefaultExtension -} - func newExtensionA(name string) ten.Extension { return &extensionA{} } -func newExtensionB(name string) ten.Extension { - return &extensionB{} -} - func (p *extensionA) OnStart(tenEnv ten.TenEnv) { count := 0 for i := 0; i < concurrency; i++ { @@ -123,67 +115,6 @@ func (p *extensionA) OnCmd( }() } -func (p *extensionB) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - fmt.Println("extensionB OnCmd") - - connected, err := tenEnv.IsCmdConnected("cmd_not_exist") - if err != nil || connected { - panic("Should not happen.") - } - - cmdName, _ := cmd.GetName() - if cmdName == "B" { - var count uint32 = 0 - - done := make(chan struct{}, 1) - defer close(done) - - for i := 0; i < concurrency; i++ { - go func(i int) { - res, err := cmd.GetPropertyInt64( - fmt.Sprintf("prop_%d", i), - ) - if err != nil || int(res) != i { - panic("should not happen") - } - - cmdName, _ := cmd.GetName() - if cmdName != "B" { - panic("should not happen") - } - - if atomic.AddUint32(&count, 1) == concurrency { - done <- struct{}{} - } - }(i % 100) - } - <-done - - statusCmd, err := ten.NewCmdResult( - ten.StatusCodeOk, - ) - if err != nil { - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) - cmdResult.SetPropertyString("detail", err.Error()) - tenEnv.ReturnResult(cmdResult, cmd) - return - } - - statusCmd.SetProperty("detail", "this is extensionB.") - statusCmd.SetProperty("password", "password") - tenEnv.ReturnResult(statusCmd, cmd) - } else { - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) - cmdResult.SetPropertyString("detail", "wrong cmd name") - tenEnv.ReturnResult(cmdResult, cmd) - } - }() -} - func init() { // Register addon err := ten.RegisterAddonAsExtension( @@ -193,12 +124,4 @@ func init() { if err != nil { fmt.Println("register addon failed", err) } - - err = ten.RegisterAddonAsExtension( - "extension_b", - ten.NewDefaultExtensionAddon(newExtensionB), - ) - if err != nil { - fmt.Println("register addon failed", err) - } } diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/go.mod b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/go.mod new file mode 100644 index 0000000000..9c3192343b --- /dev/null +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/go.mod @@ -0,0 +1,7 @@ +module extension_a + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/manifest.json b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/manifest.json new file mode 100644 index 0000000000..cd7f71e46e --- /dev/null +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_a", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/property.json b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/extension.go new file mode 100644 index 0000000000..38c6981c70 --- /dev/null +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/extension.go @@ -0,0 +1,97 @@ +// +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to the "LICENSE" file in the root directory for more information. +// + +package default_extension_go + +import ( + "fmt" + "sync/atomic" + + "ten_framework/ten" +) + +const concurrency = 10000 + +type extensionB struct { + ten.DefaultExtension +} + +func newExtensionB(name string) ten.Extension { + return &extensionB{} +} + +func (p *extensionB) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + fmt.Println("extensionB OnCmd") + + connected, err := tenEnv.IsCmdConnected("cmd_not_exist") + if err != nil || connected { + panic("Should not happen.") + } + + cmdName, _ := cmd.GetName() + if cmdName == "B" { + var count uint32 = 0 + + done := make(chan struct{}, 1) + defer close(done) + + for i := 0; i < concurrency; i++ { + go func(i int) { + res, err := cmd.GetPropertyInt64( + fmt.Sprintf("prop_%d", i), + ) + if err != nil || int(res) != i { + panic("should not happen") + } + + cmdName, _ := cmd.GetName() + if cmdName != "B" { + panic("should not happen") + } + + if atomic.AddUint32(&count, 1) == concurrency { + done <- struct{}{} + } + }(i % 100) + } + <-done + + statusCmd, err := ten.NewCmdResult( + ten.StatusCodeOk, + ) + if err != nil { + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + cmdResult.SetPropertyString("detail", err.Error()) + tenEnv.ReturnResult(cmdResult, cmd) + return + } + + statusCmd.SetProperty("detail", "this is extensionB.") + statusCmd.SetProperty("password", "password") + tenEnv.ReturnResult(statusCmd, cmd) + } else { + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + cmdResult.SetPropertyString("detail", "wrong cmd name") + tenEnv.ReturnResult(cmdResult, cmd) + } + }() +} + +func init() { + // Register addon + err := ten.RegisterAddonAsExtension( + "extension_b", + ten.NewDefaultExtensionAddon(newExtensionB), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/go.mod b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/go.mod new file mode 100644 index 0000000000..8bfda874b6 --- /dev/null +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/go.mod @@ -0,0 +1,7 @@ +module extension_b + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/manifest.json b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/manifest.json new file mode 100644 index 0000000000..deb1721cda --- /dev/null +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_b", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/property.json b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/handle_error_go/BUILD.gn b/tests/ten_runtime/integration/go/handle_error_go/BUILD.gn index 7f88fe245b..af99fdd2a3 100644 --- a/tests/ten_runtime/integration/go/handle_error_go/BUILD.gn +++ b/tests/ten_runtime/integration/go/handle_error_go/BUILD.gn @@ -15,10 +15,9 @@ ten_package_test_prepare_app("handle_error_go_app") { replace_files_after_install_app = [ "handle_error_go_app/manifest.json", "handle_error_go_app/property.json", + "handle_error_go_app/ten_packages", ] - replace_files_after_install_all = [ "handle_error_go_app/ten_packages/extension/default_extension_go/extension.go" ] - if (ten_enable_package_manager) { deps = [ "//core/src/ten_manager", diff --git a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/manifest.json b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/manifest.json index 54015e0959..111dde5447 100644 --- a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/manifest.json +++ b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/manifest.json @@ -2,7 +2,12 @@ "dependencies": [ { "type": "extension", - "name": "default_extension_go", + "name": "extension_a", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "extension_b", "version": "0.3.0-alpha" }, { diff --git a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/default_extension_go/extension.go b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/extension.go similarity index 63% rename from tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/default_extension_go/extension.go rename to tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/extension.go index f4b9e0a03a..ddff0d482b 100644 --- a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/default_extension_go/extension.go +++ b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/extension.go @@ -18,18 +18,10 @@ type extensionA struct { ten.DefaultExtension } -type extensionB struct { - ten.DefaultExtension -} - func newExtensionA(name string) ten.Extension { return &extensionA{} } -func newExtensionB(name string) ten.Extension { - return &extensionB{} -} - func (p *extensionA) OnCmd( tenEnv ten.TenEnv, cmd ten.Cmd, @@ -67,32 +59,6 @@ func (p *extensionA) OnCmd( }() } -func (p *extensionB) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - fmt.Println("extensionB OnCmd") - - cmdName, _ := cmd.GetName() - if cmdName == "B" { - // Try to get nonexistent property. - res, err := cmd.GetPropertyString("agora") - if err != nil { - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) - cmdResult.SetPropertyString("detail", err.Error()) - tenEnv.ReturnResult(cmdResult, cmd) - } else { - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", res) - tenEnv.ReturnResult(cmdResult, cmd) - } - - } else { - } - }() -} - func init() { // Register addon err := ten.RegisterAddonAsExtension( @@ -102,12 +68,4 @@ func init() { if err != nil { fmt.Println("register addon failed", err) } - - err = ten.RegisterAddonAsExtension( - "extension_b", - ten.NewDefaultExtensionAddon(newExtensionB), - ) - if err != nil { - fmt.Println("register addon failed", err) - } } diff --git a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/go.mod b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/go.mod new file mode 100644 index 0000000000..9c3192343b --- /dev/null +++ b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/go.mod @@ -0,0 +1,7 @@ +module extension_a + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/manifest.json b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/manifest.json new file mode 100644 index 0000000000..cd7f71e46e --- /dev/null +++ b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_a", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/property.json b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/extension.go new file mode 100644 index 0000000000..212725954b --- /dev/null +++ b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/extension.go @@ -0,0 +1,60 @@ +// +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// + +package default_extension_go + +import ( + "fmt" + + "ten_framework/ten" +) + +type extensionB struct { + ten.DefaultExtension +} + +func newExtensionB(name string) ten.Extension { + return &extensionB{} +} + +func (p *extensionB) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + fmt.Println("extensionB OnCmd") + + cmdName, _ := cmd.GetName() + if cmdName == "B" { + // Try to get nonexistent property. + res, err := cmd.GetPropertyString("agora") + if err != nil { + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + cmdResult.SetPropertyString("detail", err.Error()) + tenEnv.ReturnResult(cmdResult, cmd) + } else { + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) + cmdResult.SetPropertyString("detail", res) + tenEnv.ReturnResult(cmdResult, cmd) + } + + } else { + } + }() +} + +func init() { + // Register addon + err := ten.RegisterAddonAsExtension( + "extension_b", + ten.NewDefaultExtensionAddon(newExtensionB), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/go.mod b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/go.mod new file mode 100644 index 0000000000..8bfda874b6 --- /dev/null +++ b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/go.mod @@ -0,0 +1,7 @@ +module extension_b + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/manifest.json b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/manifest.json new file mode 100644 index 0000000000..deb1721cda --- /dev/null +++ b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_b", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/property.json b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/BUILD.gn b/tests/ten_runtime/integration/go/prepare_to_stop_go/BUILD.gn index d2612df871..10cb85f473 100644 --- a/tests/ten_runtime/integration/go/prepare_to_stop_go/BUILD.gn +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/BUILD.gn @@ -15,10 +15,9 @@ ten_package_test_prepare_app("prepare_to_stop_go_app") { replace_files_after_install_app = [ "prepare_to_stop_go_app/manifest.json", "prepare_to_stop_go_app/property.json", + "prepare_to_stop_go_app/ten_packages", ] - replace_files_after_install_all = [ "prepare_to_stop_go_app/ten_packages/extension/default_extension_go/extension.go" ] - if (ten_enable_package_manager) { deps = [ "//core/src/ten_manager", diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/manifest.json b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/manifest.json index 54015e0959..cd99f2ac3f 100644 --- a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/manifest.json +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/manifest.json @@ -2,7 +2,17 @@ "dependencies": [ { "type": "extension", - "name": "default_extension_go", + "name": "extension_a", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "extension_b", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "extension_c", "version": "0.3.0-alpha" }, { diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/property.json b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/property.json index d6fd89c849..3c0db15d7c 100644 --- a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/property.json +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/property.json @@ -11,19 +11,19 @@ { "type": "extension", "name": "A", - "addon": "nodetest", + "addon": "extension_a", "extension_group": "nodetest_group" }, { "type": "extension", "name": "B", - "addon": "nodetest", + "addon": "extension_b", "extension_group": "nodetest_group" }, { "type": "extension", "name": "C", - "addon": "nodetest", + "addon": "extension_c", "extension_group": "nodetest_group" } ], diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/default_extension_go/extension.go b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/default_extension_go/extension.go deleted file mode 100644 index 46c084e453..0000000000 --- a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/default_extension_go/extension.go +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright © 2024 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more -// information. -// -// Note that this is just an example extension written in the GO programming -// language, so the package name does not equal to the containing directory -// name. However, it is not common in Go. -package default_extension_go - -import ( - "fmt" - "time" - - "ten_framework/ten" -) - -type addonImpl struct { - ten.DefaultAddon -} - -func (p *addonImpl) OnCreateInstance( - tenEnv ten.TenEnv, - name string, - context uintptr, -) { - switch name { - case "A": - ext := &aExtension{name: name, isStopped: false} - tenEnv.OnCreateInstanceDone(ten.WrapExtension(ext, "A"), context) - case "B": - ext := NewBExtension() - tenEnv.OnCreateInstanceDone(ten.WrapExtension(ext, "B"), context) - case "C": - ext := NewCExtension() - tenEnv.OnCreateInstanceDone(ten.WrapExtension(ext, "C"), context) - default: - panic("Should not happen.") - } -} - -type aExtension struct { - name string - isStopped bool - ten.DefaultExtension -} - -func (p *aExtension) OnDeinit(tenEnv ten.TenEnv) { - defer tenEnv.OnDeinitDone() - - tenEnv.LogDebug("onDeinit") - if !p.isStopped { - panic("should not happen.") - } -} - -func (p *aExtension) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - cmdName, _ := cmd.GetName() - tenEnv.LogInfo( - "receive command: " + cmdName, - ) - if cmdName == "start" { - tenEnv.SendCmd(cmd, func(r ten.TenEnv, cs ten.CmdResult) { - r.ReturnResultDirectly(cs) - }) - } - }() -} - -func (p *aExtension) OnStop(tenEnv ten.TenEnv) { - go func() { - tenEnv.LogDebug("onStop ") - - cmd, _ := ten.NewCmd("stop") - respChan := make(chan ten.CmdResult, 1) - - tenEnv.SendCmd(cmd, func(tenEnv ten.TenEnv, cmdStatus ten.CmdResult) { - respChan <- cmdStatus - }) - - select { - case resp := <-respChan: - statusCode, _ := resp.GetStatusCode() - if statusCode == ten.StatusCodeOk { - p.isStopped = true - tenEnv.OnStopDone() - } else { - panic("stop failed.") - } - } - }() -} - -type bExtension struct { - ten.DefaultExtension - stopChan chan struct{} -} - -func NewBExtension() *bExtension { - return &bExtension{ - stopChan: make(chan struct{}), - } -} - -func (p *bExtension) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - cmdName, _ := cmd.GetName() - tenEnv.LogInfo( - "receive command: " + - cmdName, - ) - if cmdName == "start" { - tenEnv.SendCmd(cmd, func(r ten.TenEnv, cs ten.CmdResult) { - r.ReturnResultDirectly(cs) - }) - } else if cmdName == "stop" { - tenEnv.SendCmd(cmd, func(r ten.TenEnv, cs ten.CmdResult) { - r.ReturnResultDirectly(cs) - - close(p.stopChan) - tenEnv.LogInfo("Stop command is processed.") - }) - } else { - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) - cmdResult.SetPropertyString("detail", "unknown cmd") - tenEnv.ReturnResult(cmdResult, cmd) - } - }() -} - -func (p *bExtension) OnStop(tenEnv ten.TenEnv) { - go func() { - tenEnv.LogDebug("OnStop") - - // Wait until the stop command is received and processed. - <-p.stopChan - - tenEnv.LogInfo("Stop command processed. Now calling OnStopDone.") - tenEnv.OnStopDone() - }() -} - -type cExtension struct { - ten.DefaultExtension - stopChan chan struct{} -} - -func NewCExtension() *cExtension { - return &cExtension{ - stopChan: make(chan struct{}), - } -} - -func (p *cExtension) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - cmdName, _ := cmd.GetName() - tenEnv.LogInfo( - "receive command: " + - cmdName, - ) - if cmdName == "start" { - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", "done") - tenEnv.ReturnResult(cmdResult, cmd) - } else if cmdName == "stop" { - go func() { - time.Sleep(time.Millisecond * 500) - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", "done") - tenEnv.ReturnResult(cmdResult, cmd) - - tenEnv.LogInfo("Stop command is processed.") - - close(p.stopChan) - }() - } else { - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) - cmdResult.SetPropertyString("detail", "unknown cmd") - tenEnv.ReturnResult(cmdResult, cmd) - } - }() -} - -func (p *cExtension) OnStop(tenEnv ten.TenEnv) { - go func() { - tenEnv.LogDebug("OnStop") - - // Wait until the stop command is received and processed. - <-p.stopChan - - tenEnv.LogInfo("Stop command processed. Now calling OnStopDone.") - tenEnv.OnStopDone() - }() -} - -func init() { - fmt.Println("call init") - - // Register addon - err := ten.RegisterAddonAsExtension("nodetest", &addonImpl{}) - if err != nil { - fmt.Println("register addon failed", err) - } -} diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/extension.go new file mode 100644 index 0000000000..db084ba057 --- /dev/null +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/extension.go @@ -0,0 +1,86 @@ +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// +// Note that this is just an example extension written in the GO programming +// language, so the package name does not equal to the containing directory +// name. However, it is not common in Go. +package default_extension_go + +import ( + "fmt" + + "ten_framework/ten" +) + +type aExtension struct { + name string + isStopped bool + ten.DefaultExtension +} + +func newAExtension(name string) ten.Extension { + return &aExtension{name: name, isStopped: false} +} + +func (p *aExtension) OnDeinit(tenEnv ten.TenEnv) { + defer tenEnv.OnDeinitDone() + + tenEnv.LogDebug("onDeinit") + if !p.isStopped { + panic("should not happen.") + } +} + +func (p *aExtension) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + cmdName, _ := cmd.GetName() + tenEnv.LogInfo( + "receive command: " + cmdName, + ) + if cmdName == "start" { + tenEnv.SendCmd(cmd, func(r ten.TenEnv, cs ten.CmdResult) { + r.ReturnResultDirectly(cs) + }) + } + }() +} + +func (p *aExtension) OnStop(tenEnv ten.TenEnv) { + go func() { + tenEnv.LogDebug("onStop ") + + cmd, _ := ten.NewCmd("stop") + respChan := make(chan ten.CmdResult, 1) + + tenEnv.SendCmd(cmd, func(tenEnv ten.TenEnv, cmdStatus ten.CmdResult) { + respChan <- cmdStatus + }) + + select { + case resp := <-respChan: + statusCode, _ := resp.GetStatusCode() + if statusCode == ten.StatusCodeOk { + p.isStopped = true + tenEnv.OnStopDone() + } else { + panic("stop failed.") + } + } + }() +} + +func init() { + fmt.Println("call init") + + // Register addon + err := ten.RegisterAddonAsExtension("extension_a", ten.NewDefaultExtensionAddon(newAExtension)) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/go.mod b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/go.mod new file mode 100644 index 0000000000..9c3192343b --- /dev/null +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/go.mod @@ -0,0 +1,7 @@ +module extension_a + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/manifest.json b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/manifest.json new file mode 100644 index 0000000000..cd7f71e46e --- /dev/null +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_a", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/property.json b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/extension.go new file mode 100644 index 0000000000..95e9cdfdea --- /dev/null +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/extension.go @@ -0,0 +1,78 @@ +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// +// Note that this is just an example extension written in the GO programming +// language, so the package name does not equal to the containing directory +// name. However, it is not common in Go. +package default_extension_go + +import ( + "fmt" + + "ten_framework/ten" +) + +type bExtension struct { + ten.DefaultExtension + stopChan chan struct{} +} + +func NewBExtension(name string) ten.Extension { + return &bExtension{ + stopChan: make(chan struct{}), + } +} + +func (p *bExtension) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + cmdName, _ := cmd.GetName() + tenEnv.LogInfo( + "receive command: " + + cmdName, + ) + if cmdName == "start" { + tenEnv.SendCmd(cmd, func(r ten.TenEnv, cs ten.CmdResult) { + r.ReturnResultDirectly(cs) + }) + } else if cmdName == "stop" { + tenEnv.SendCmd(cmd, func(r ten.TenEnv, cs ten.CmdResult) { + r.ReturnResultDirectly(cs) + + close(p.stopChan) + tenEnv.LogInfo("Stop command is processed.") + }) + } else { + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + cmdResult.SetPropertyString("detail", "unknown cmd") + tenEnv.ReturnResult(cmdResult, cmd) + } + }() +} + +func (p *bExtension) OnStop(tenEnv ten.TenEnv) { + go func() { + tenEnv.LogDebug("OnStop") + + // Wait until the stop command is received and processed. + <-p.stopChan + + tenEnv.LogInfo("Stop command processed. Now calling OnStopDone.") + tenEnv.OnStopDone() + }() +} + +func init() { + fmt.Println("call init") + + // Register addon + err := ten.RegisterAddonAsExtension("extension_b", ten.NewDefaultExtensionAddon(NewBExtension)) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/go.mod b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/go.mod new file mode 100644 index 0000000000..8bfda874b6 --- /dev/null +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/go.mod @@ -0,0 +1,7 @@ +module extension_b + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/manifest.json b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/manifest.json new file mode 100644 index 0000000000..deb1721cda --- /dev/null +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_b", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/property.json b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/extension.go b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/extension.go new file mode 100644 index 0000000000..2e665d0b1d --- /dev/null +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/extension.go @@ -0,0 +1,83 @@ +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// +// Note that this is just an example extension written in the GO programming +// language, so the package name does not equal to the containing directory +// name. However, it is not common in Go. +package default_extension_go + +import ( + "fmt" + "time" + + "ten_framework/ten" +) + +type cExtension struct { + ten.DefaultExtension + stopChan chan struct{} +} + +func NewCExtension(name string) ten.Extension { + return &cExtension{ + stopChan: make(chan struct{}), + } +} + +func (p *cExtension) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + cmdName, _ := cmd.GetName() + tenEnv.LogInfo( + "receive command: " + + cmdName, + ) + if cmdName == "start" { + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) + cmdResult.SetPropertyString("detail", "done") + tenEnv.ReturnResult(cmdResult, cmd) + } else if cmdName == "stop" { + go func() { + time.Sleep(time.Millisecond * 500) + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) + cmdResult.SetPropertyString("detail", "done") + tenEnv.ReturnResult(cmdResult, cmd) + + tenEnv.LogInfo("Stop command is processed.") + + close(p.stopChan) + }() + } else { + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + cmdResult.SetPropertyString("detail", "unknown cmd") + tenEnv.ReturnResult(cmdResult, cmd) + } + }() +} + +func (p *cExtension) OnStop(tenEnv ten.TenEnv) { + go func() { + tenEnv.LogDebug("OnStop") + + // Wait until the stop command is received and processed. + <-p.stopChan + + tenEnv.LogInfo("Stop command processed. Now calling OnStopDone.") + tenEnv.OnStopDone() + }() +} + +func init() { + fmt.Println("call init") + + // Register addon + err := ten.RegisterAddonAsExtension("extension_c", ten.NewDefaultExtensionAddon(NewCExtension)) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/go.mod b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/go.mod new file mode 100644 index 0000000000..78962b0f75 --- /dev/null +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/go.mod @@ -0,0 +1,7 @@ +module extension_c + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/manifest.json b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/manifest.json new file mode 100644 index 0000000000..f0d9742ba1 --- /dev/null +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_c", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/property.json b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/return_result_go/BUILD.gn b/tests/ten_runtime/integration/go/return_result_go/BUILD.gn index 8a79222a7e..7bdfa81f55 100644 --- a/tests/ten_runtime/integration/go/return_result_go/BUILD.gn +++ b/tests/ten_runtime/integration/go/return_result_go/BUILD.gn @@ -15,10 +15,9 @@ ten_package_test_prepare_app("return_result_go_app") { replace_files_after_install_app = [ "return_result_go_app/manifest.json", "return_result_go_app/property.json", + "return_result_go_app/ten_packages", ] - replace_files_after_install_all = [ "return_result_go_app/ten_packages/extension/default_extension_go/extension.go" ] - if (ten_enable_package_manager) { deps = [ "//core/src/ten_manager", diff --git a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/manifest.json b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/manifest.json index 54015e0959..111dde5447 100644 --- a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/manifest.json +++ b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/manifest.json @@ -2,7 +2,12 @@ "dependencies": [ { "type": "extension", - "name": "default_extension_go", + "name": "extension_a", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "extension_b", "version": "0.3.0-alpha" }, { diff --git a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/default_extension_go/extension.go b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/extension.go similarity index 68% rename from tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/default_extension_go/extension.go rename to tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/extension.go index f8677c5fa9..36758a93c0 100644 --- a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/default_extension_go/extension.go +++ b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/extension.go @@ -19,18 +19,10 @@ type extensionA struct { ten.DefaultExtension } -type extensionB struct { - ten.DefaultExtension -} - func newExtensionA(name string) ten.Extension { return &extensionA{} } -func newExtensionB(name string) ten.Extension { - return &extensionB{} -} - func (p *extensionA) OnCmd( tenEnv ten.TenEnv, cmd ten.Cmd, @@ -70,32 +62,6 @@ func (p *extensionA) OnCmd( }() } -func (p *extensionB) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - fmt.Println("extensionB OnCmd") - - cmdName, _ := cmd.GetName() - if cmdName == "B" { - statusCmd, err := ten.NewCmdResult( - ten.StatusCodeOk, - ) - if err != nil { - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) - cmdResult.SetPropertyString("detail", err.Error()) - tenEnv.ReturnResult(cmdResult, cmd) - return - } - - statusCmd.SetProperty("detail", "this is extensionB.") - statusCmd.SetProperty("password", "password") - tenEnv.ReturnResult(statusCmd, cmd) - } - }() -} - func init() { // Register addon err := ten.RegisterAddonAsExtension( @@ -105,12 +71,4 @@ func init() { if err != nil { fmt.Println("register addon failed", err) } - - err = ten.RegisterAddonAsExtension( - "extension_b", - ten.NewDefaultExtensionAddon(newExtensionB), - ) - if err != nil { - fmt.Println("register addon failed", err) - } } diff --git a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/go.mod b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/go.mod new file mode 100644 index 0000000000..9c3192343b --- /dev/null +++ b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/go.mod @@ -0,0 +1,7 @@ +module extension_a + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/manifest.json b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/manifest.json new file mode 100644 index 0000000000..cd7f71e46e --- /dev/null +++ b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_a", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/property.json b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/extension.go new file mode 100644 index 0000000000..ad6e94ece8 --- /dev/null +++ b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/extension.go @@ -0,0 +1,61 @@ +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// +// Note that this is just an example extension written in the GO programming +// language, so the package name does not equal to the containing directory +// name. However, it is not common in Go. +package default_extension_go + +import ( + "fmt" + + "ten_framework/ten" +) + +type extensionB struct { + ten.DefaultExtension +} + +func newExtensionB(name string) ten.Extension { + return &extensionB{} +} + +func (p *extensionB) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + fmt.Println("extensionB OnCmd") + + cmdName, _ := cmd.GetName() + if cmdName == "B" { + statusCmd, err := ten.NewCmdResult( + ten.StatusCodeOk, + ) + if err != nil { + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + cmdResult.SetPropertyString("detail", err.Error()) + tenEnv.ReturnResult(cmdResult, cmd) + return + } + + statusCmd.SetProperty("detail", "this is extensionB.") + statusCmd.SetProperty("password", "password") + tenEnv.ReturnResult(statusCmd, cmd) + } + }() +} + +func init() { + // Register addon + err := ten.RegisterAddonAsExtension( + "extension_b", + ten.NewDefaultExtensionAddon(newExtensionB), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/go.mod b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/go.mod new file mode 100644 index 0000000000..8bfda874b6 --- /dev/null +++ b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/go.mod @@ -0,0 +1,7 @@ +module extension_b + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/manifest.json b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/manifest.json new file mode 100644 index 0000000000..deb1721cda --- /dev/null +++ b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_b", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/property.json b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/return_value_go/BUILD.gn b/tests/ten_runtime/integration/go/return_value_go/BUILD.gn index 2e42603264..17920a3815 100644 --- a/tests/ten_runtime/integration/go/return_value_go/BUILD.gn +++ b/tests/ten_runtime/integration/go/return_value_go/BUILD.gn @@ -15,10 +15,11 @@ ten_package_test_prepare_app("return_value_go_app") { replace_files_after_install_app = [ "return_value_go_app/manifest.json", "return_value_go_app/property.json", + "return_value_go_app/ten_packages", + "return_value_go_app/go_common_dep", + "return_value_go_app/go.mod", ] - replace_files_after_install_all = [ "return_value_go_app/ten_packages/extension/default_extension_go/extension.go" ] - if (ten_enable_package_manager) { deps = [ "//core/src/ten_manager", diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/go.mod b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/go.mod new file mode 100644 index 0000000000..e085ce3096 --- /dev/null +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/go.mod @@ -0,0 +1,11 @@ +module app + +go 1.20 + +replace ten_framework => ./ten_packages/system/ten_runtime_go/interface + +replace go_common_dep => ./go_common_dep + +require ten_framework v0.0.0-00010101000000-000000000000 + +require go_common_dep v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/go_common_dep/go.mod b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/go_common_dep/go.mod new file mode 100644 index 0000000000..a7d32e7d69 --- /dev/null +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/go_common_dep/go.mod @@ -0,0 +1,3 @@ +module go_common_dep + +go 1.18 diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/go_common_dep/types/data.go b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/go_common_dep/types/data.go new file mode 100644 index 0000000000..4f00185e30 --- /dev/null +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/go_common_dep/types/data.go @@ -0,0 +1,6 @@ +package types + +type UserData struct { + Uid int + Name string +} diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/manifest.json b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/manifest.json index 54015e0959..111dde5447 100644 --- a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/manifest.json +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/manifest.json @@ -2,7 +2,12 @@ "dependencies": [ { "type": "extension", - "name": "default_extension_go", + "name": "extension_a", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "extension_b", "version": "0.3.0-alpha" }, { diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/default_extension_go/extension.go b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/extension.go similarity index 63% rename from tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/default_extension_go/extension.go rename to tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/extension.go index 9a171e05a2..23f34c6cdb 100644 --- a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/default_extension_go/extension.go +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/extension.go @@ -12,6 +12,7 @@ package default_extension_go import ( "fmt" + "go_common_dep/types" "ten_framework/ten" ) @@ -19,18 +20,10 @@ type extensionA struct { ten.DefaultExtension } -type extensionB struct { - ten.DefaultExtension -} - func newExtensionA(name string) ten.Extension { return &extensionA{} } -func newExtensionB(name string) ten.Extension { - return &extensionB{} -} - func (p *extensionA) OnCmd( tenEnv ten.TenEnv, cmd ten.Cmd, @@ -49,38 +42,12 @@ func (p *extensionA) OnCmd( } cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", detail.(*userData).name) + cmdResult.SetPropertyString("detail", detail.(*types.UserData).Name) tenEnv.ReturnResult(cmdResult, cmd) }) }() } -type userData struct { - uid int - name string -} - -func (p *extensionB) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - fmt.Println("extensionB OnCmd") - - cmdName, _ := cmd.GetName() - if cmdName == "B" { - data := userData{uid: 1, name: "ten"} - cs, _ := ten.NewCmdResult(ten.StatusCodeOk) - cs.SetProperty("data", &data) - err := tenEnv.ReturnResult(cs, cmd) - if err != nil { - panic(err) - } - } else { - } - }() -} - func init() { // Register addon err := ten.RegisterAddonAsExtension( @@ -90,12 +57,4 @@ func init() { if err != nil { fmt.Println("register addon failed", err) } - - err = ten.RegisterAddonAsExtension( - "extension_b", - ten.NewDefaultExtensionAddon(newExtensionB), - ) - if err != nil { - fmt.Println("register addon failed", err) - } } diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/go.mod b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/go.mod new file mode 100644 index 0000000000..d22e0ece5b --- /dev/null +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/go.mod @@ -0,0 +1,11 @@ +module extension_a + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +replace go_common_dep => ../../../go_common_dep + +require ten_framework v0.0.0-00010101000000-000000000000 + +require go_common_dep v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/manifest.json b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/manifest.json new file mode 100644 index 0000000000..cd7f71e46e --- /dev/null +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_a", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/property.json b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/extension.go new file mode 100644 index 0000000000..6f92de9c72 --- /dev/null +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/extension.go @@ -0,0 +1,57 @@ +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// +// Note that this is just an example extension written in the GO programming +// language, so the package name does not equal to the containing directory +// name. However, it is not common in Go. +package default_extension_go + +import ( + "fmt" + + "go_common_dep/types" + "ten_framework/ten" +) + +type extensionB struct { + ten.DefaultExtension +} + +func newExtensionB(name string) ten.Extension { + return &extensionB{} +} + +func (p *extensionB) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + fmt.Println("extensionB OnCmd") + + cmdName, _ := cmd.GetName() + if cmdName == "B" { + data := types.UserData{Uid: 1, Name: "ten"} + cs, _ := ten.NewCmdResult(ten.StatusCodeOk) + cs.SetProperty("data", &data) + err := tenEnv.ReturnResult(cs, cmd) + if err != nil { + panic(err) + } + } else { + } + }() +} + +func init() { + // Register addon + err := ten.RegisterAddonAsExtension( + "extension_b", + ten.NewDefaultExtensionAddon(newExtensionB), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/go.mod b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/go.mod new file mode 100644 index 0000000000..c11fa56f55 --- /dev/null +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/go.mod @@ -0,0 +1,11 @@ +module extension_b + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +replace go_common_dep => ../../../go_common_dep + +require ten_framework v0.0.0-00010101000000-000000000000 + +require go_common_dep v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/manifest.json b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/manifest.json new file mode 100644 index 0000000000..deb1721cda --- /dev/null +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_b", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/property.json b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/send_json_go/BUILD.gn b/tests/ten_runtime/integration/go/send_json_go/BUILD.gn index 3043f4cd99..b05ea6eaea 100644 --- a/tests/ten_runtime/integration/go/send_json_go/BUILD.gn +++ b/tests/ten_runtime/integration/go/send_json_go/BUILD.gn @@ -15,10 +15,7 @@ ten_package_test_prepare_app("send_json_go_app") { replace_files_after_install_app = [ "send_json_go_app/manifest.json", "send_json_go_app/property.json", - ] - - replace_files_after_install_all = [ - "send_json_go_app/ten_packages/extension/default_extension_go/extension.go", + "send_json_go_app/ten_packages", ] if (ten_enable_package_manager) { diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/manifest.json b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/manifest.json index 54015e0959..cd99f2ac3f 100644 --- a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/manifest.json +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/manifest.json @@ -2,7 +2,17 @@ "dependencies": [ { "type": "extension", - "name": "default_extension_go", + "name": "extension_a", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "extension_b", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "extension_c", "version": "0.3.0-alpha" }, { diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/property.json b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/property.json index 5ba7982861..178fd94f3a 100644 --- a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/property.json +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/property.json @@ -11,19 +11,19 @@ { "type": "extension", "name": "A", - "addon": "nodetest", + "addon": "extension_a", "extension_group": "nodetest_group" }, { "type": "extension", "name": "B", - "addon": "nodetest", + "addon": "extension_b", "extension_group": "nodetest_group" }, { "type": "extension", "name": "C", - "addon": "nodetest", + "addon": "extension_c", "extension_group": "nodetest_group" } ], diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/default_extension_go/extension.go b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/default_extension_go/extension.go deleted file mode 100644 index 6aeb48a2fc..0000000000 --- a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/default_extension_go/extension.go +++ /dev/null @@ -1,163 +0,0 @@ -// -// Copyright © 2024 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more -// information. -// - -package default_extension_go - -import ( - "fmt" - - "ten_framework/ten" -) - -type addonImpl struct { - ten.DefaultAddon -} - -func (p *addonImpl) OnCreateInstance( - tenEnv ten.TenEnv, name string, context uintptr) { - switch name { - case "A": - ext := &aExtension{name: name} - tenEnv.OnCreateInstanceDone(ten.WrapExtension(ext, "A"), context) - case "B": - ext := &bExtension{} - tenEnv.OnCreateInstanceDone(ten.WrapExtension(ext, "B"), context) - case "C": - ext := &cExtension{} - tenEnv.OnCreateInstanceDone(ten.WrapExtension(ext, "C"), context) - default: - panic("Should not happen.") - } -} - -type aExtension struct { - aCmd ten.Cmd - name string - ten.DefaultExtension -} - -func (p *aExtension) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - cmdName, _ := cmd.GetName() - fmt.Println( - "aExtension receive command: ", - cmdName, - ) - - if cmdName == "A" { - // Cache the cmd for returning it in the future. - p.aCmd = cmd - err := tenEnv.SendJSON(`{ - "_ten": { - "name": "B" - } - }`, func(tenEnv ten.TenEnv, cmdStatus ten.CmdResult) { - detail, err := cmdStatus.GetPropertyString("detail") - if err != nil { - panic("Should not happen.") - } - - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", detail) - err = tenEnv.ReturnResult(cmdResult, p.aCmd) - if err != nil { - panic("Should not happen.") - } - }) - if err != nil { - panic("aExtension sendCmd B failed") - } - - return - } - }() -} - -type bExtension struct { - ten.DefaultExtension -} - -func (p *bExtension) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - cmdName, _ := cmd.GetName() - fmt.Println( - "bExtension receive command: ", - cmdName, - ) - - if cmdName == "B" { - err := tenEnv.SendJSON(`{ - "_ten": { - "name": "C" - } - }`, func(tenEnv ten.TenEnv, cmdStatus ten.CmdResult) { - detail, err := cmdStatus.GetPropertyString("detail") - if err != nil { - panic("should not happen") - } - - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", detail) - err = tenEnv.ReturnResult(cmdResult, cmd) - if err != nil { - panic("should not happen") - } - }) - if err != nil { - panic("bExtension sendCmd C failed") - } - - return - } - }() -} - -type cExtension struct { - ten.DefaultExtension -} - -func (p *cExtension) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - cmdName, _ := cmd.GetName() - fmt.Println( - "cExtension receive command: ", - cmdName, - ) - - if cmdName == "C" { - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", "I am cExtension") - err := tenEnv.ReturnResult(cmdResult, cmd) - if err != nil { - panic("should not happen") - } - } - }() -} - -func init() { - fmt.Println("call init") - - // Register addon - err := ten.RegisterAddonAsExtension( - "nodetest", - &addonImpl{}, - ) - if err != nil { - fmt.Println("register addon failed", err) - } -} diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_a/extension.go new file mode 100644 index 0000000000..cb31bb16d0 --- /dev/null +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_a/extension.go @@ -0,0 +1,78 @@ +// +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// + +package default_extension_go + +import ( + "fmt" + + "ten_framework/ten" +) + +type aExtension struct { + aCmd ten.Cmd + name string + ten.DefaultExtension +} + +func newAExtension(name string) ten.Extension { + return &aExtension{name: name} +} + +func (p *aExtension) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + cmdName, _ := cmd.GetName() + fmt.Println( + "aExtension receive command: ", + cmdName, + ) + + if cmdName == "A" { + // Cache the cmd for returning it in the future. + p.aCmd = cmd + err := tenEnv.SendJSON(`{ + "_ten": { + "name": "B" + } + }`, func(tenEnv ten.TenEnv, cmdStatus ten.CmdResult) { + detail, err := cmdStatus.GetPropertyString("detail") + if err != nil { + panic("Should not happen.") + } + + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) + cmdResult.SetPropertyString("detail", detail) + err = tenEnv.ReturnResult(cmdResult, p.aCmd) + if err != nil { + panic("Should not happen.") + } + }) + if err != nil { + panic("aExtension sendCmd B failed") + } + + return + } + }() +} + +func init() { + fmt.Println("call init") + + // Register addon + err := ten.RegisterAddonAsExtension( + "extension_a", + ten.NewDefaultExtensionAddon(newAExtension), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_a/go.mod b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_a/go.mod new file mode 100644 index 0000000000..9c3192343b --- /dev/null +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_a/go.mod @@ -0,0 +1,7 @@ +module extension_a + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_a/manifest.json b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_a/manifest.json new file mode 100644 index 0000000000..cd7f71e46e --- /dev/null +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_a/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_a", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_a/property.json b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_a/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_a/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_b/extension.go new file mode 100644 index 0000000000..35dd88879c --- /dev/null +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_b/extension.go @@ -0,0 +1,74 @@ +// +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// + +package default_extension_go + +import ( + "fmt" + + "ten_framework/ten" +) + +type bExtension struct { + ten.DefaultExtension +} + +func newBExtension(name string) ten.Extension { + return &bExtension{} +} + +func (p *bExtension) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + cmdName, _ := cmd.GetName() + fmt.Println( + "bExtension receive command: ", + cmdName, + ) + + if cmdName == "B" { + err := tenEnv.SendJSON(`{ + "_ten": { + "name": "C" + } + }`, func(tenEnv ten.TenEnv, cmdStatus ten.CmdResult) { + detail, err := cmdStatus.GetPropertyString("detail") + if err != nil { + panic("should not happen") + } + + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) + cmdResult.SetPropertyString("detail", detail) + err = tenEnv.ReturnResult(cmdResult, cmd) + if err != nil { + panic("should not happen") + } + }) + if err != nil { + panic("bExtension sendCmd C failed") + } + + return + } + }() +} + +func init() { + fmt.Println("call init") + + // Register addon + err := ten.RegisterAddonAsExtension( + "extension_b", + ten.NewDefaultExtensionAddon(newBExtension), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_b/go.mod b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_b/go.mod new file mode 100644 index 0000000000..8bfda874b6 --- /dev/null +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_b/go.mod @@ -0,0 +1,7 @@ +module extension_b + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_b/manifest.json b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_b/manifest.json new file mode 100644 index 0000000000..deb1721cda --- /dev/null +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_b/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_b", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_b/property.json b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_b/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_b/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_c/extension.go b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_c/extension.go new file mode 100644 index 0000000000..c4db9a54bf --- /dev/null +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_c/extension.go @@ -0,0 +1,58 @@ +// +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// + +package default_extension_go + +import ( + "fmt" + + "ten_framework/ten" +) + +type cExtension struct { + ten.DefaultExtension +} + +func newCExtension(name string) ten.Extension { + return &cExtension{} +} + +func (p *cExtension) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + cmdName, _ := cmd.GetName() + fmt.Println( + "cExtension receive command: ", + cmdName, + ) + + if cmdName == "C" { + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) + cmdResult.SetPropertyString("detail", "I am cExtension") + err := tenEnv.ReturnResult(cmdResult, cmd) + if err != nil { + panic("should not happen") + } + } + }() +} + +func init() { + fmt.Println("call init") + + // Register addon + err := ten.RegisterAddonAsExtension( + "extension_c", + ten.NewDefaultExtensionAddon(newCExtension), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_c/go.mod b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_c/go.mod new file mode 100644 index 0000000000..78962b0f75 --- /dev/null +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_c/go.mod @@ -0,0 +1,7 @@ +module extension_c + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_c/manifest.json b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_c/manifest.json new file mode 100644 index 0000000000..f0d9742ba1 --- /dev/null +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_c/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_c", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_c/property.json b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_c/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/send_json_go/send_json_go_app/ten_packages/extension/extension_c/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/BUILD.gn b/tests/ten_runtime/integration/go/three_extension_cmd_go/BUILD.gn index 62fce54c6f..5f2649eaf1 100644 --- a/tests/ten_runtime/integration/go/three_extension_cmd_go/BUILD.gn +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/BUILD.gn @@ -15,10 +15,9 @@ ten_package_test_prepare_app("three_extension_cmd_go_app") { replace_files_after_install_app = [ "three_extension_cmd_go_app/manifest.json", "three_extension_cmd_go_app/property.json", + "three_extension_cmd_go_app/ten_packages", ] - replace_files_after_install_all = [ "three_extension_cmd_go_app/ten_packages/extension/default_extension_go/extension.go" ] - if (ten_enable_package_manager) { deps = [ "//core/src/ten_manager", diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/client/client.cc b/tests/ten_runtime/integration/go/three_extension_cmd_go/client/client.cc index 2c3d87f93a..d3f3669bbd 100644 --- a/tests/ten_runtime/integration/go/three_extension_cmd_go/client/client.cc +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/client/client.cc @@ -23,21 +23,21 @@ int main(TEN_UNUSED int argc, TEN_UNUSED char **argv) { "type": "extension", "app": "msgpack://127.0.0.1:8007/", "extension_group": "nodetest_group", - "addon": "nodetest", + "addon": "extension_a", "name": "A" }, { "type": "extension", "app": "msgpack://127.0.0.1:8007/", "extension_group": "nodetest_group", - "addon": "nodetest", + "addon": "extension_b", "name": "B" }, { "type": "extension", "app": "msgpack://127.0.0.1:8007/", "extension_group": "nodetest_group", - "addon": "nodetest", + "addon": "extension_c", "name": "C" } ], diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/manifest.json b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/manifest.json index 54015e0959..cd99f2ac3f 100644 --- a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/manifest.json +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/manifest.json @@ -2,7 +2,17 @@ "dependencies": [ { "type": "extension", - "name": "default_extension_go", + "name": "extension_a", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "extension_b", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "extension_c", "version": "0.3.0-alpha" }, { diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/default_extension_go/extension.go b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/default_extension_go/extension.go deleted file mode 100644 index 940f29fecd..0000000000 --- a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/default_extension_go/extension.go +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright © 2024 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more -// information. -// -// Note that this is just an example extension written in the GO programming -// language, so the package name does not equal to the containing directory -// name. However, it is not common in Go. -package default_extension_go - -import ( - "encoding/json" - "fmt" - - "ten_framework/ten" -) - -type userData struct { - Result int `json:"result"` -} - -type addonImpl struct { - ten.DefaultAddon -} - -func (p *addonImpl) OnCreateInstance( - tenEnv ten.TenEnv, - name string, - context uintptr, -) { - switch name { - case "A": - tenEnv.OnCreateInstanceDone( - ten.WrapExtension(&aExtension{name: name}, name), context, - ) - case "B": - tenEnv.OnCreateInstanceDone( - ten.WrapExtension(&bExtension{}, name), - context, - ) - case "C": - tenEnv.OnCreateInstanceDone( - ten.WrapExtension(&cExtension{}, name), - context, - ) - default: - fmt.Println("Bad name") - } -} - -type aExtension struct { - name string - ten.DefaultExtension -} - -func (p *aExtension) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - cmdName, _ := cmd.GetName() - fmt.Println( - "aExtension receive command: ", - cmdName, - ) - if cmd.GetType() != ten.MsgTypeCmdResult { - fmt.Println(p.name, "onCmd: ", cmdName) - } - - if cmdName == "A" { - cmdB, _ := ten.NewCmd("B") - err := cmdB.SetProperty("data", 2) - if err != nil { - panic("Should not happen.") - } - err = tenEnv.SendCmd( - cmdB, - func(tenEnv ten.TenEnv, cmdStatus ten.CmdResult) { - detail, err := cmdStatus.GetPropertyString("detail") - if err != nil { - panic("Should not happen.") - } - statusCode, _ := cmdStatus.GetStatusCode() - fmt.Println( - "statusCode:", - statusCode, - " detail: ", - detail, - ) - - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", detail) - err = tenEnv.ReturnResult(cmdResult, cmd) - if err != nil { - panic("Should not happen.") - } - }, - ) - if err != nil { - panic("sendCmd failed") - } - } else { - } - }() -} - -func (p *aExtension) OnData( - tenEnv ten.TenEnv, - data ten.Data, -) { - fmt.Println("aExtension onData") -} - -type bExtension struct { - ten.DefaultExtension -} - -func (p *bExtension) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - cmdName, _ := cmd.GetName() - fmt.Println( - "bExtension receive command: ", - cmdName, - ) - - if cmdName == "B" { - data, err := cmd.GetPropertyInt64("data") - if err != nil { - panic("Should not happen.") - } - - cmdC, _ := ten.NewCmd("C") - err = cmdC.SetProperty("data", data*3) - if err != nil { - panic("Should not happen.") - } - - err = tenEnv.SendCmd( - cmdC, - func(tenEnv ten.TenEnv, cmdStatus ten.CmdResult) { - detail, err := cmdStatus.GetPropertyString("detail") - if err != nil { - panic("Should not happen.") - } - statusCode, _ := cmdStatus.GetStatusCode() - fmt.Println( - "statusCode:", - statusCode, - " detail: ", - detail, - ) - - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", detail) - err = tenEnv.ReturnResult(cmdResult, cmd) - if err != nil { - panic("Should not happen.") - } - }, - ) - if err != nil { - panic("sendCmd failed") - } - } else { - } - }() -} - -type cExtension struct { - ten.DefaultExtension -} - -func (p *cExtension) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - cmdName, _ := cmd.GetName() - fmt.Println( - "bExtension receive command: ", - cmdName, - ) - - if cmdName == "C" { - data, err := cmd.GetPropertyInt64("data") - if err != nil { - panic("Should not happen.") - } - - result := int(data) * 5 - - res, _ := json.Marshal(userData{Result: result}) - - fmt.Println("return command C, res:", string(res)) - - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", string(res)) - err = tenEnv.ReturnResult(cmdResult, cmd) - if err != nil { - panic("Should not happen.") - } - - } else { - } - }() -} - -func init() { - fmt.Println("call init") - - // Register addon - err := ten.RegisterAddonAsExtension("nodetest", &addonImpl{}) - if err != nil { - fmt.Println("register addon failed", err) - } -} diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/extension.go new file mode 100644 index 0000000000..c200ce3e8e --- /dev/null +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/extension.go @@ -0,0 +1,96 @@ +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// +// Note that this is just an example extension written in the GO programming +// language, so the package name does not equal to the containing directory +// name. However, it is not common in Go. +package default_extension_go + +import ( + "fmt" + + "ten_framework/ten" +) + +type aExtension struct { + name string + ten.DefaultExtension +} + +func NewExtensionA(name string) ten.Extension { + return &aExtension{name: name} +} + +func (p *aExtension) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + cmdName, _ := cmd.GetName() + fmt.Println( + "aExtension receive command: ", + cmdName, + ) + if cmd.GetType() != ten.MsgTypeCmdResult { + fmt.Println(p.name, "onCmd: ", cmdName) + } + + if cmdName == "A" { + cmdB, _ := ten.NewCmd("B") + err := cmdB.SetProperty("data", 2) + if err != nil { + panic("Should not happen.") + } + err = tenEnv.SendCmd( + cmdB, + func(tenEnv ten.TenEnv, cmdStatus ten.CmdResult) { + detail, err := cmdStatus.GetPropertyString("detail") + if err != nil { + panic("Should not happen.") + } + statusCode, _ := cmdStatus.GetStatusCode() + fmt.Println( + "statusCode:", + statusCode, + " detail: ", + detail, + ) + + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) + cmdResult.SetPropertyString("detail", detail) + err = tenEnv.ReturnResult(cmdResult, cmd) + if err != nil { + panic("Should not happen.") + } + }, + ) + if err != nil { + panic("sendCmd failed") + } + } else { + } + }() +} + +func (p *aExtension) OnData( + tenEnv ten.TenEnv, + data ten.Data, +) { + fmt.Println("aExtension onData") +} + +func init() { + fmt.Println("call init") + + // Register addon + err := ten.RegisterAddonAsExtension( + "extension_a", + ten.NewDefaultExtensionAddon(NewExtensionA), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/go.mod b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/go.mod new file mode 100644 index 0000000000..9c3192343b --- /dev/null +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/go.mod @@ -0,0 +1,7 @@ +module extension_a + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/manifest.json b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/manifest.json new file mode 100644 index 0000000000..cd7f71e46e --- /dev/null +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_a", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/property.json b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/extension.go new file mode 100644 index 0000000000..f7a417c20d --- /dev/null +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/extension.go @@ -0,0 +1,91 @@ +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// +// Note that this is just an example extension written in the GO programming +// language, so the package name does not equal to the containing directory +// name. However, it is not common in Go. +package default_extension_go + +import ( + "fmt" + + "ten_framework/ten" +) + +type bExtension struct { + ten.DefaultExtension +} + +func NewExtensionB(name string) ten.Extension { + return &bExtension{} +} + +func (p *bExtension) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + cmdName, _ := cmd.GetName() + fmt.Println( + "bExtension receive command: ", + cmdName, + ) + + if cmdName == "B" { + data, err := cmd.GetPropertyInt64("data") + if err != nil { + panic("Should not happen.") + } + + cmdC, _ := ten.NewCmd("C") + err = cmdC.SetProperty("data", data*3) + if err != nil { + panic("Should not happen.") + } + + err = tenEnv.SendCmd( + cmdC, + func(tenEnv ten.TenEnv, cmdStatus ten.CmdResult) { + detail, err := cmdStatus.GetPropertyString("detail") + if err != nil { + panic("Should not happen.") + } + statusCode, _ := cmdStatus.GetStatusCode() + fmt.Println( + "statusCode:", + statusCode, + " detail: ", + detail, + ) + + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) + cmdResult.SetPropertyString("detail", detail) + err = tenEnv.ReturnResult(cmdResult, cmd) + if err != nil { + panic("Should not happen.") + } + }, + ) + if err != nil { + panic("sendCmd failed") + } + } else { + } + }() +} + +func init() { + fmt.Println("call init") + + // Register addon + err := ten.RegisterAddonAsExtension( + "extension_b", + ten.NewDefaultExtensionAddon(NewExtensionB), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/go.mod b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/go.mod new file mode 100644 index 0000000000..8bfda874b6 --- /dev/null +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/go.mod @@ -0,0 +1,7 @@ +module extension_b + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/manifest.json b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/manifest.json new file mode 100644 index 0000000000..deb1721cda --- /dev/null +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_b", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/property.json b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/extension.go b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/extension.go new file mode 100644 index 0000000000..b4e6a43a9e --- /dev/null +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/extension.go @@ -0,0 +1,77 @@ +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// +// Note that this is just an example extension written in the GO programming +// language, so the package name does not equal to the containing directory +// name. However, it is not common in Go. +package default_extension_go + +import ( + "encoding/json" + "fmt" + + "ten_framework/ten" +) + +type userData struct { + Result int `json:"result"` +} + +type cExtension struct { + ten.DefaultExtension +} + +func NewExtensionC(name string) ten.Extension { + return &cExtension{} +} + +func (p *cExtension) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + cmdName, _ := cmd.GetName() + fmt.Println( + "bExtension receive command: ", + cmdName, + ) + + if cmdName == "C" { + data, err := cmd.GetPropertyInt64("data") + if err != nil { + panic("Should not happen.") + } + + result := int(data) * 5 + + res, _ := json.Marshal(userData{Result: result}) + + fmt.Println("return command C, res:", string(res)) + + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) + cmdResult.SetPropertyString("detail", string(res)) + err = tenEnv.ReturnResult(cmdResult, cmd) + if err != nil { + panic("Should not happen.") + } + + } else { + } + }() +} + +func init() { + fmt.Println("call init") + + // Register addon + err := ten.RegisterAddonAsExtension( + "extension_c", + ten.NewDefaultExtensionAddon(NewExtensionC), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/go.mod b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/go.mod new file mode 100644 index 0000000000..78962b0f75 --- /dev/null +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/go.mod @@ -0,0 +1,7 @@ +module extension_c + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/manifest.json b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/manifest.json new file mode 100644 index 0000000000..f0d9742ba1 --- /dev/null +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_c", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/property.json b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/BUILD.gn b/tests/ten_runtime/integration/go/transfer_pointer_go/BUILD.gn index 29406a1447..34cc87f4b2 100644 --- a/tests/ten_runtime/integration/go/transfer_pointer_go/BUILD.gn +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/BUILD.gn @@ -15,10 +15,11 @@ ten_package_test_prepare_app("transfer_pointer_go_app") { replace_files_after_install_app = [ "transfer_pointer_go_app/manifest.json", "transfer_pointer_go_app/property.json", + "transfer_pointer_go_app/ten_packages", + "transfer_pointer_go_app/go_common_dep", + "transfer_pointer_go_app/go.mod", ] - replace_files_after_install_all = [ "transfer_pointer_go_app/ten_packages/extension/default_extension_go/extension.go" ] - if (ten_enable_package_manager) { deps = [ "//core/src/ten_manager", diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/go.mod b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/go.mod new file mode 100644 index 0000000000..e085ce3096 --- /dev/null +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/go.mod @@ -0,0 +1,11 @@ +module app + +go 1.20 + +replace ten_framework => ./ten_packages/system/ten_runtime_go/interface + +replace go_common_dep => ./go_common_dep + +require ten_framework v0.0.0-00010101000000-000000000000 + +require go_common_dep v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/go_common_dep/go.mod b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/go_common_dep/go.mod new file mode 100644 index 0000000000..a7d32e7d69 --- /dev/null +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/go_common_dep/go.mod @@ -0,0 +1,3 @@ +module go_common_dep + +go 1.18 diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/go_common_dep/types/data.go b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/go_common_dep/types/data.go new file mode 100644 index 0000000000..4f00185e30 --- /dev/null +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/go_common_dep/types/data.go @@ -0,0 +1,6 @@ +package types + +type UserData struct { + Uid int + Name string +} diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/manifest.json b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/manifest.json index 54015e0959..111dde5447 100644 --- a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/manifest.json +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/manifest.json @@ -2,7 +2,12 @@ "dependencies": [ { "type": "extension", - "name": "default_extension_go", + "name": "extension_a", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "extension_b", "version": "0.3.0-alpha" }, { diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/extension.go new file mode 100644 index 0000000000..b198e780f5 --- /dev/null +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/extension.go @@ -0,0 +1,72 @@ +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// +// Note that this is just an example extension written in the GO programming +// language, so the package name does not equal to the containing directory +// name. However, it is not common in Go. +package default_extension_go + +import ( + "fmt" + + "go_common_dep/types" + "ten_framework/ten" +) + +type extensionA struct { + ten.DefaultExtension +} + +func newExtensionA(name string) ten.Extension { + return &extensionA{} +} + +func (p *extensionA) OnCmd( + tenEnv ten.TenEnv, + cmd ten.Cmd, +) { + go func() { + fmt.Println("extensionA OnCmd") + + cmdB, _ := ten.NewCmd("B") + + strArray := []string{"hello", "world", "ten"} + cmdB.SetProperty("array", &strArray) + + propMap := make(map[string]interface{}) + propMap["paramA"] = "A" + cmdB.SetProperty("map", &propMap) + + data := &types.UserData{Uid: 2, Name: "str"} + cmdB.SetProperty("struct", data) + data.Uid = 3 + + tenEnv.SendCmd(cmdB, func(r ten.TenEnv, cs ten.CmdResult) { + detail, err := cs.GetPropertyString("detail") + if err != nil { + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + cmdResult.SetPropertyString("detail", err.Error()) + r.ReturnResult(cmdResult, cmd) + return + } + + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) + cmdResult.SetPropertyString("detail", detail) + r.ReturnResult(cmdResult, cmd) + }) + }() +} + +func init() { + // Register addon + err := ten.RegisterAddonAsExtension( + "extension_a", + ten.NewDefaultExtensionAddon(newExtensionA), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/go.mod b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/go.mod new file mode 100644 index 0000000000..d22e0ece5b --- /dev/null +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/go.mod @@ -0,0 +1,11 @@ +module extension_a + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +replace go_common_dep => ../../../go_common_dep + +require ten_framework v0.0.0-00010101000000-000000000000 + +require go_common_dep v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/manifest.json b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/manifest.json new file mode 100644 index 0000000000..cd7f71e46e --- /dev/null +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_a", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/property.json b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/default_extension_go/extension.go b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/extension.go similarity index 58% rename from tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/default_extension_go/extension.go rename to tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/extension.go index 537f4d724a..e68ed22414 100644 --- a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/default_extension_go/extension.go +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/extension.go @@ -12,66 +12,18 @@ package default_extension_go import ( "fmt" + "go_common_dep/types" "ten_framework/ten" ) -type extensionA struct { - ten.DefaultExtension -} - type extensionB struct { ten.DefaultExtension } -func newExtensionA(name string) ten.Extension { - return &extensionA{} -} - func newExtensionB(name string) ten.Extension { return &extensionB{} } -type userData struct { - num int - str string -} - -func (p *extensionA) OnCmd( - tenEnv ten.TenEnv, - cmd ten.Cmd, -) { - go func() { - fmt.Println("extensionA OnCmd") - - cmdB, _ := ten.NewCmd("B") - - strArray := []string{"hello", "world", "ten"} - cmdB.SetProperty("array", &strArray) - - propMap := make(map[string]interface{}) - propMap["paramA"] = "A" - cmdB.SetProperty("map", &propMap) - - data := &userData{num: 2, str: "str"} - cmdB.SetProperty("struct", data) - data.num = 3 - - tenEnv.SendCmd(cmdB, func(r ten.TenEnv, cs ten.CmdResult) { - detail, err := cs.GetPropertyString("detail") - if err != nil { - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) - cmdResult.SetPropertyString("detail", err.Error()) - r.ReturnResult(cmdResult, cmd) - return - } - - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", detail) - r.ReturnResult(cmdResult, cmd) - }) - }() -} - func (p *extensionB) OnCmd( tenEnv ten.TenEnv, cmd ten.Cmd, @@ -110,9 +62,9 @@ func (p *extensionB) OnCmd( panic("failed to get prop: struct") } - structData := structPtr.(*userData) + structData := structPtr.(*types.UserData) - if structData.num != 3 || structData.str != "str" { + if structData.Uid != 3 || structData.Name != "str" { panic("should not happen") } @@ -126,14 +78,6 @@ func (p *extensionB) OnCmd( func init() { // Register addon err := ten.RegisterAddonAsExtension( - "extension_a", - ten.NewDefaultExtensionAddon(newExtensionA), - ) - if err != nil { - fmt.Println("register addon failed", err) - } - - err = ten.RegisterAddonAsExtension( "extension_b", ten.NewDefaultExtensionAddon(newExtensionB), ) diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/go.mod b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/go.mod new file mode 100644 index 0000000000..c11fa56f55 --- /dev/null +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/go.mod @@ -0,0 +1,11 @@ +module extension_b + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +replace go_common_dep => ../../../go_common_dep + +require ten_framework v0.0.0-00010101000000-000000000000 + +require go_common_dep v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/manifest.json b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/manifest.json new file mode 100644 index 0000000000..deb1721cda --- /dev/null +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "extension_b", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/property.json b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/BUILD.gn b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/BUILD.gn index 1df7a578d0..03fa134a0b 100644 --- a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/BUILD.gn +++ b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/BUILD.gn @@ -15,10 +15,9 @@ ten_package_test_prepare_app("two_extension_one_group_cmd_go_app") { replace_files_after_install_app = [ "two_extension_one_group_cmd_go_app/manifest.json", "two_extension_one_group_cmd_go_app/property.json", + "two_extension_one_group_cmd_go_app/ten_packages", ] - replace_files_after_install_all = [ "two_extension_one_group_cmd_go_app/ten_packages/extension/default_extension_go/extension.go" ] - if (ten_enable_package_manager) { deps = [ "//core/src/ten_manager", diff --git a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/manifest.json b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/manifest.json index 54015e0959..1091ac2ac5 100644 --- a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/manifest.json +++ b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/manifest.json @@ -2,7 +2,12 @@ "dependencies": [ { "type": "extension", - "name": "default_extension_go", + "name": "addon_a", + "version": "0.3.0-alpha" + }, + { + "type": "extension", + "name": "addon_b", "version": "0.3.0-alpha" }, { diff --git a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/default_extension_go/extension.go b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/extension.go similarity index 53% rename from tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/default_extension_go/extension.go rename to tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/extension.go index e2f156599a..3044c46b23 100644 --- a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/default_extension_go/extension.go +++ b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/extension.go @@ -106,117 +106,13 @@ func (p *aExtension) OnCmd( }() } -type bExtension struct { - baseExtension - bName string -} - -func NewBExtension(name string) ten.Extension { - return &bExtension{ - baseExtension: baseExtension{baseCount: 1, baseName: "bBase"}, - bName: "before_start", - } -} - -func (p *bExtension) OnData( - tenEnv ten.TenEnv, - data ten.Data, -) { - fmt.Println( - "bExtension onData, bName: before_start = ", - p.bName, - " baseName: bBase = ", - p.baseName, - ) - - // The buffer in data is always copied to GO. - bytes, err := data.GetPropertyBytes("test_data_path") - if err != nil { - panic(err) - } - - defer ten.ReleaseBytes(bytes) - - res := string(bytes) - if res != "after start" { - panic("wrong in bExtension OnData") - } -} - -type nodeTestGroup struct { - ten.DefaultExtensionGroup -} - -func newNodeTestGroup(name string) ten.ExtensionGroup { - return &nodeTestGroup{} -} - -func (p *nodeTestGroup) OnCreateExtensions( - tenEnv ten.TenEnv, -) { - var extensionsArray []ten.Extension - - callback := func(tenEnv ten.TenEnv, p ten.Extension) { - extensionsArray = append(extensionsArray, p) - if len(extensionsArray) == 2 { - tenEnv.OnCreateExtensionsDone(extensionsArray...) - } - } - - err := tenEnv.AddonCreateExtensionAsync("addon_a", "A", callback) - if err != nil { - panic("should not happen") - } - - err = tenEnv.AddonCreateExtensionAsync("addon_b", "B", callback) - if err != nil { - panic("should not happen") - } -} - -func (p *nodeTestGroup) OnDestroyExtensions( - tenEnv ten.TenEnv, - extensions []ten.Extension, -) { - count := 0 - callback := func(tenEnv ten.TenEnv) { - count += 1 - if count == 2 { - tenEnv.OnDestroyExtensionsDone() - } - } - - for _, extension := range extensions { - err := tenEnv.AddonDestroyExtensionAsync(extension, callback) - if err != nil { - panic("should not happen") - } - } -} - func init() { // Register addon - err := ten.RegisterAddonAsExtensionGroup( - "nodetest", - ten.NewDefaultExtensionGroupAddon(newNodeTestGroup), - ) - if err != nil { - fmt.Println("register addon failed", err) - } - - err = ten.RegisterAddonAsExtension( + err := ten.RegisterAddonAsExtension( "addon_a", ten.NewDefaultExtensionAddon(NewAExtension), ) if err != nil { fmt.Println("register addon failed", err) } - - err = ten.RegisterAddonAsExtension( - "addon_b", - ten.NewDefaultExtensionAddon(NewBExtension), - ) - if err != nil { - fmt.Println("register addon failed", err) - } } diff --git a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/go.mod b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/go.mod new file mode 100644 index 0000000000..33c68e4a3c --- /dev/null +++ b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/go.mod @@ -0,0 +1,7 @@ +module addon_a + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/manifest.json b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/manifest.json new file mode 100644 index 0000000000..49af0f92b8 --- /dev/null +++ b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "addon_a", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/property.json b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_b/extension.go b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_b/extension.go new file mode 100644 index 0000000000..c969cfbfef --- /dev/null +++ b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_b/extension.go @@ -0,0 +1,82 @@ +// Copyright © 2024 Agora +// This file is part of TEN Framework, an open source project. +// Licensed under the Apache License, Version 2.0, with certain conditions. +// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more +// information. +// +// Note that this is just an example extension written in the GO programming +// language, so the package name does not equal to the containing directory +// name. However, it is not common in Go. +package default_extension_go + +import ( + "fmt" + + "ten_framework/ten" +) + +type baseExtension struct { + baseName string + baseCount int + ten.DefaultExtension +} + +func (p *baseExtension) OnStart(tenEnv ten.TenEnv) { + fmt.Println("baseExtension onStart, name:", p.baseName) + + tenEnv.OnStartDone() +} + +func (p *baseExtension) OnStop(tenEnv ten.TenEnv) { + fmt.Println("baseExtension OnStop name:", p.baseName) + + tenEnv.OnStopDone() +} + +type bExtension struct { + baseExtension + bName string +} + +func NewBExtension(name string) ten.Extension { + return &bExtension{ + baseExtension: baseExtension{baseCount: 1, baseName: "bBase"}, + bName: "before_start", + } +} + +func (p *bExtension) OnData( + tenEnv ten.TenEnv, + data ten.Data, +) { + fmt.Println( + "bExtension onData, bName: before_start = ", + p.bName, + " baseName: bBase = ", + p.baseName, + ) + + // The buffer in data is always copied to GO. + bytes, err := data.GetPropertyBytes("test_data_path") + if err != nil { + panic(err) + } + + defer ten.ReleaseBytes(bytes) + + res := string(bytes) + if res != "after start" { + panic("wrong in bExtension OnData") + } +} + +func init() { + // Register addon + err := ten.RegisterAddonAsExtension( + "addon_b", + ten.NewDefaultExtensionAddon(NewBExtension), + ) + if err != nil { + fmt.Println("register addon failed", err) + } +} diff --git a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_b/go.mod b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_b/go.mod new file mode 100644 index 0000000000..e42a08d211 --- /dev/null +++ b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_b/go.mod @@ -0,0 +1,7 @@ +module addon_b + +go 1.18 + +replace ten_framework => ../../../ten_packages/system/ten_runtime_go/interface + +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_b/manifest.json b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_b/manifest.json new file mode 100644 index 0000000000..1118bcec98 --- /dev/null +++ b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_b/manifest.json @@ -0,0 +1,18 @@ +{ + "type": "extension", + "name": "addon_b", + "version": "0.3.0-alpha", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.3.0-alpha" + } + ], + "package": { + "include": [ + "**" + ] + }, + "api": {} +} \ No newline at end of file diff --git a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_b/property.json b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_b/property.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_b/property.json @@ -0,0 +1 @@ +{} \ No newline at end of file