This is an automated email from the ASF dual-hosted git repository.
laurence pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
The following commit(s) were added to refs/heads/master by this push:
new 3545cb4 add custom filter sample pro 2 (#274)
3545cb4 is described below
commit 3545cb4c6c989428795ff3f9a1aa988bc841c5fb
Author: Jason Deng <[email protected]>
AuthorDate: Mon Oct 18 18:30:56 2021 +0800
add custom filter sample pro 2 (#274)
* filterer/custom
* Merge remote-tracking branch 'upstream/master'
# Conflicts:
# filter/custom/go-client/cmd/client.go
# filter/custom/go-client/pkg/user.go
# integrate_test/filter/custom/tests/integration/main_test.go
# integrate_test/filter/custom/tests/integration/userprovider_test.go
* Merge remote-tracking branch 'upstream/master'
# Conflicts:
# filter/custom/go-client/cmd/client.go
# filter/custom/go-client/pkg/user.go
# integrate_test/filter/custom/tests/integration/main_test.go
# integrate_test/filter/custom/tests/integration/userprovider_test.go
* Merge remote-tracking branch 'origin/master'
* Merge remote-tracking branch 'origin/master'
* Merge remote-tracking branch 'origin/master'
Co-authored-by: [email protected] <dzw19971017>
---
.../custom/go-client/cmd/client.go | 52 ++++++++++++----------
filter/custom/go-client/conf/dubbogo.yml | 18 ++++++++
.../custom/go-client/pkg/user.go | 28 ++----------
filter/custom/go-server/conf/dubbogo.yml | 20 +++++++++
.../custom}/tests/integration/main_test.go | 4 +-
.../custom/tests/integration/userprovider_test.go} | 39 ++++------------
.../registry/nacos/tests/integration/main_test.go | 2 +-
7 files changed, 81 insertions(+), 82 deletions(-)
diff --git a/integrate_test/registry/nacos/tests/integration/main_test.go
b/filter/custom/go-client/cmd/client.go
similarity index 59%
copy from integrate_test/registry/nacos/tests/integration/main_test.go
copy to filter/custom/go-client/cmd/client.go
index 9e0684c..95ae40f 100644
--- a/integrate_test/registry/nacos/tests/integration/main_test.go
+++ b/filter/custom/go-client/cmd/client.go
@@ -1,5 +1,3 @@
-// +build integration
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -17,44 +15,50 @@
* limitations under the License.
*/
-package integration
+package main
import (
"context"
- "os"
- "testing"
"time"
)
import (
+ "dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/config"
_ "dubbo.apache.org/dubbo-go/v3/imports"
hessian "github.com/apache/dubbo-go-hessian2"
)
-var userProvider = &UserProvider{}
-
-func TestMain(m *testing.M) {
- config.SetConsumerService(userProvider)
- hessian.RegisterPOJO(&User{})
- config.Load()
- time.Sleep(3 * time.Second)
+import (
+ "github.com/apache/dubbo-go-samples/filter/custom/go-client/pkg"
+)
- os.Exit(m.Run())
-}
+var userProvider = &pkg.UserProvider{}
-type User struct {
- ID string
- Name string
- Age int32
- Time time.Time
+func init() {
+ config.SetConsumerService(userProvider)
+ hessian.RegisterPOJO(&pkg.User{})
}
-type UserProvider struct {
- GetUser func(ctx context.Context, req *User) (rsp *User, err error)
-}
+func main() {
+ err := config.Load()
+ if err != nil {
+ panic(err)
+ }
-func (u*User) JavaClassName() string {
- return "org.apache.dubbo.User"
+ var successCount, failCount int64
+ logger.Infof("\n\n\nstart to test dubbo")
+ for i := 0; i < 60; i++ {
+ time.Sleep(200 * time.Millisecond)
+ user, err := userProvider.GetUser(context.TODO(), "A001")
+ if err != nil {
+ failCount++
+ logger.Infof("error: %v\n", err)
+ } else {
+ successCount++
+ }
+ logger.Infof("response: %v\n", user)
+ }
+ logger.Infof("failCount=%v, failCount=%v\n", successCount, failCount)
}
diff --git a/filter/custom/go-client/conf/dubbogo.yml
b/filter/custom/go-client/conf/dubbogo.yml
new file mode 100644
index 0000000..4617a7e
--- /dev/null
+++ b/filter/custom/go-client/conf/dubbogo.yml
@@ -0,0 +1,18 @@
+# dubbo client yaml configure file
+
+dubbo:
+ registries:
+ demoZK:
+ protocolIDs: zookeeper
+ timeout: 3s
+ address: 127.0.0.1:2181
+ consumer:
+ check: true
+ request_timeout: 3s
+ connect_timeout: 3s
+ registryIDs:
+ - demoZK
+ references:
+ UserProvider:
+ protocolIDs: dubbo
+ interface: org.apache.dubbo.UserProvider
\ No newline at end of file
diff --git a/integrate_test/registry/nacos/tests/integration/main_test.go
b/filter/custom/go-client/pkg/user.go
similarity index 65%
copy from integrate_test/registry/nacos/tests/integration/main_test.go
copy to filter/custom/go-client/pkg/user.go
index 9e0684c..505abac 100644
--- a/integrate_test/registry/nacos/tests/integration/main_test.go
+++ b/filter/custom/go-client/pkg/user.go
@@ -1,5 +1,3 @@
-// +build integration
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -17,33 +15,13 @@
* limitations under the License.
*/
-package integration
+package pkg
import (
"context"
- "os"
- "testing"
"time"
)
-import (
- "dubbo.apache.org/dubbo-go/v3/config"
- _ "dubbo.apache.org/dubbo-go/v3/imports"
-
- hessian "github.com/apache/dubbo-go-hessian2"
-)
-
-var userProvider = &UserProvider{}
-
-func TestMain(m *testing.M) {
- config.SetConsumerService(userProvider)
- hessian.RegisterPOJO(&User{})
- config.Load()
- time.Sleep(3 * time.Second)
-
- os.Exit(m.Run())
-}
-
type User struct {
ID string
Name string
@@ -52,9 +30,9 @@ type User struct {
}
type UserProvider struct {
- GetUser func(ctx context.Context, req *User) (rsp *User, err error)
+ GetUser func(ctx context.Context, req string) (*User, error)
}
-func (u*User) JavaClassName() string {
+func (u *User) JavaClassName() string {
return "org.apache.dubbo.User"
}
diff --git a/filter/custom/go-server/conf/dubbogo.yml
b/filter/custom/go-server/conf/dubbogo.yml
new file mode 100644
index 0000000..7dd1d1f
--- /dev/null
+++ b/filter/custom/go-server/conf/dubbogo.yml
@@ -0,0 +1,20 @@
+dubbo:
+ registries:
+ demoZK:
+ protocol: zookeeper
+ timeout: 3s
+ address: 127.0.0.1:2181
+ protocols:
+ dubbo:
+ name: dubbo
+ port: 20000
+ provider:
+ registryIDs:
+ - demoZK
+ services:
+ UserProvider:
+ protocolIDs: dubbo
+ interface: org.apache.dubbo.UserProvider
+ loadbalance: random
+ warmup: 100
+ cluster: failover
diff --git a/integrate_test/registry/nacos/tests/integration/main_test.go
b/integrate_test/filter/custom/tests/integration/main_test.go
similarity index 92%
copy from integrate_test/registry/nacos/tests/integration/main_test.go
copy to integrate_test/filter/custom/tests/integration/main_test.go
index 9e0684c..7dbd7f5 100644
--- a/integrate_test/registry/nacos/tests/integration/main_test.go
+++ b/integrate_test/filter/custom/tests/integration/main_test.go
@@ -52,9 +52,9 @@ type User struct {
}
type UserProvider struct {
- GetUser func(ctx context.Context, req *User) (rsp *User, err error)
+ GetUser func(ctx context.Context, req string) (*User, error)
}
-func (u*User) JavaClassName() string {
+func (u *User) JavaClassName() string {
return "org.apache.dubbo.User"
}
diff --git a/integrate_test/registry/nacos/tests/integration/main_test.go
b/integrate_test/filter/custom/tests/integration/userprovider_test.go
similarity index 60%
copy from integrate_test/registry/nacos/tests/integration/main_test.go
copy to integrate_test/filter/custom/tests/integration/userprovider_test.go
index 9e0684c..858b546 100644
--- a/integrate_test/registry/nacos/tests/integration/main_test.go
+++ b/integrate_test/filter/custom/tests/integration/userprovider_test.go
@@ -21,40 +21,19 @@ package integration
import (
"context"
- "os"
"testing"
- "time"
)
import (
- "dubbo.apache.org/dubbo-go/v3/config"
- _ "dubbo.apache.org/dubbo-go/v3/imports"
-
- hessian "github.com/apache/dubbo-go-hessian2"
+ "github.com/stretchr/testify/assert"
)
-var userProvider = &UserProvider{}
-
-func TestMain(m *testing.M) {
- config.SetConsumerService(userProvider)
- hessian.RegisterPOJO(&User{})
- config.Load()
- time.Sleep(3 * time.Second)
-
- os.Exit(m.Run())
-}
-
-type User struct {
- ID string
- Name string
- Age int32
- Time time.Time
-}
-
-type UserProvider struct {
- GetUser func(ctx context.Context, req *User) (rsp *User, err error)
-}
-
-func (u*User) JavaClassName() string {
- return "org.apache.dubbo.User"
+func TestGetUser(t *testing.T) {
+ user := &User{}
+ user, err := userProvider.GetUser(context.TODO(), "A001")
+ assert.Nil(t, err)
+ assert.Equal(t, "A001", user.ID)
+ assert.Equal(t, "ALEX STOCKS", user.Name)
+ assert.Equal(t, int32(28), user.Age)
+ assert.NotNil(t, user.Time)
}
diff --git a/integrate_test/registry/nacos/tests/integration/main_test.go
b/integrate_test/registry/nacos/tests/integration/main_test.go
index 9e0684c..2b98967 100644
--- a/integrate_test/registry/nacos/tests/integration/main_test.go
+++ b/integrate_test/registry/nacos/tests/integration/main_test.go
@@ -55,6 +55,6 @@ type UserProvider struct {
GetUser func(ctx context.Context, req *User) (rsp *User, err error)
}
-func (u*User) JavaClassName() string {
+func (u *User) JavaClassName() string {
return "org.apache.dubbo.User"
}