This is an automated email from the ASF dual-hosted git repository.

laurence pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 7c8fc1c  add tracing integration test (#156)
7c8fc1c is described below

commit 7c8fc1c5642c6fca8aa97697f3895d89ef4c6956
Author: Mulavar <[email protected]>
AuthorDate: Wed Jul 7 23:28:11 2021 +0800

    add tracing integration test (#156)
---
 start_integrate_test.sh                            |  6 +-
 tracing/dubbo/go-client/{app => cmd}/client.go     | 11 +++-
 .../{go-server/app => go-client/cmd}/version.go    |  0
 tracing/dubbo/go-client/conf/client.yml            | 61 +++++++++++++++++++
 tracing/dubbo/go-client/conf/log.yml               | 28 +++++++++
 tracing/dubbo/go-client/{app => pkg}/user.go       | 16 +----
 tracing/dubbo/go-server/{app => cmd}/server.go     |  3 +-
 .../{go-client/app => go-server/cmd}/version.go    |  0
 tracing/dubbo/go-server/conf/client.yml            | 61 +++++++++++++++++++
 tracing/dubbo/go-server/conf/log.yml               | 28 +++++++++
 tracing/dubbo/go-server/conf/server.yml            | 62 +++++++++++++++++++
 tracing/dubbo/go-server/docker/docker-compose.yml  |  8 +++
 tracing/dubbo/go-server/{app => pkg}/user.go       |  2 +-
 .../tests/integration/main_test.go}                | 33 ++++++++--
 .../tests/integration/userprovider_test.go}        | 71 ++++------------------
 15 files changed, 304 insertions(+), 86 deletions(-)

diff --git a/start_integrate_test.sh b/start_integrate_test.sh
index 6f2287c..c04e977 100755
--- a/start_integrate_test.sh
+++ b/start_integrate_test.sh
@@ -14,8 +14,11 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
+# tracing integrate test
+array=("tracing/dubbo/go-server")
+
 # async
-array=("async/go-server")
+array+=("async/go-server")
 array+=("attachment/go-server")
 array+=("config-api/go-server")
 # config center
@@ -76,7 +79,6 @@ array+=("registry/servicediscovery/nacos/go-server")
 array+=("router/uniform-router/file/go-server")
 array+=("router/uniform-router/file/go-server2")
 
-
 for((i=0;i<${#array[*]};i++))
 do
        ./integrate_test.sh "${array[i]}"
diff --git a/tracing/dubbo/go-client/app/client.go 
b/tracing/dubbo/go-client/cmd/client.go
similarity index 92%
copy from tracing/dubbo/go-client/app/client.go
copy to tracing/dubbo/go-client/cmd/client.go
index 45bd478..7e23bce 100644
--- a/tracing/dubbo/go-client/app/client.go
+++ b/tracing/dubbo/go-client/cmd/client.go
@@ -20,6 +20,7 @@ package main
 import (
        "context"
        "fmt"
+       "github.com/apache/dubbo-go-samples/tracing/dubbo/go-client/pkg"
        "os"
        "os/signal"
        "syscall"
@@ -50,19 +51,25 @@ import (
 )
 
 var (
+       userProvider        = new(pkg.UserProvider)
        survivalTimeout int = 10e9
 )
 
+func init() {
+       config.SetConsumerService(userProvider)
+       hessian.RegisterPOJO(&pkg.User{})
+}
+
 // they are necessary:
 //             export CONF_CONSUMER_FILE_PATH="xxx"
 //             export APP_LOG_CONF_FILE="xxx"
 func main() {
-       hessian.RegisterPOJO(&User{})
+       hessian.RegisterPOJO(&pkg.User{})
        config.Load()
 
        initZipkin()
        gxlog.CInfo("\n\n\nstart to test dubbo")
-       user := &User{}
+       user := &pkg.User{}
        span, ctx := opentracing.StartSpanFromContext(context.Background(), 
"Test-Client-Service")
        err := userProvider.GetUser(ctx, []interface{}{"A001"}, user)
        span.Finish()
diff --git a/tracing/dubbo/go-server/app/version.go 
b/tracing/dubbo/go-client/cmd/version.go
similarity index 100%
rename from tracing/dubbo/go-server/app/version.go
rename to tracing/dubbo/go-client/cmd/version.go
diff --git a/tracing/dubbo/go-client/conf/client.yml 
b/tracing/dubbo/go-client/conf/client.yml
new file mode 100644
index 0000000..3bcc1cd
--- /dev/null
+++ b/tracing/dubbo/go-client/conf/client.yml
@@ -0,0 +1,61 @@
+# dubbo client yaml configure file
+
+
+check: true
+# client
+request_timeout : "3s"
+# connect timeout
+connect_timeout : "3s"
+
+# application config
+application:
+  organization : "ikurento.com"
+  name  : "BDTService"
+  module : "dubbogo user-info client"
+  version : "0.0.1"
+  owner : "ZX"
+  environment : "test"
+
+registries :
+  "hangzhouzk":
+    protocol: "zookeeper"
+    timeout    : "3s"
+    address: "127.0.0.1:2181"
+    username: ""
+    password: ""
+
+references:
+  "UserProvider":
+    # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
+    registry: "hangzhouzk"
+    protocol : "dubbo"
+    interface : "com.ikurento.user.UserProvider"
+    cluster: "failover"
+    methods :
+    - name: "GetUser"
+      retries: 3
+
+protocol_conf:
+  dubbo:
+    reconnect_interval: 0
+    connection_number: 2
+    heartbeat_period: "5s"
+    session_timeout: "180s"
+    pool_size: 64
+    pool_ttl: 600
+    getty_session_param:
+      compress_encoding: false
+      tcp_no_delay: true
+      tcp_keep_alive: true
+      keep_alive_period: "120s"
+      tcp_r_buf_size: 262144
+      tcp_w_buf_size: 65536
+      pkg_rq_size: 1024
+      pkg_wq_size: 512
+      tcp_read_timeout: "1s"
+      tcp_write_timeout: "5s"
+      wait_timeout: "1s"
+      max_msg_len: 10240
+      session_name: "client"
+
+filter: "tracing"
\ No newline at end of file
diff --git a/tracing/dubbo/go-client/conf/log.yml 
b/tracing/dubbo/go-client/conf/log.yml
new file mode 100644
index 0000000..baee0b7
--- /dev/null
+++ b/tracing/dubbo/go-client/conf/log.yml
@@ -0,0 +1,28 @@
+
+level: "info"
+development: false
+disableCaller: false
+disableStacktrace: true
+sampling:
+encoding: "console"
+
+# encoder
+encoderConfig:
+  messageKey: "message"
+  levelKey: "level"
+  timeKey: "time"
+  nameKey: "logger"
+  callerKey: "caller"
+  stacktraceKey: "stacktrace"
+  lineEnding: ""
+  levelEncoder: "capitalColor"
+  timeEncoder: "iso8601"
+  durationEncoder: "seconds"
+  callerEncoder: "short"
+  nameEncoder: ""
+
+outputPaths:
+  - "stderr"
+errorOutputPaths:
+  - "stderr"
+initialFields:
diff --git a/tracing/dubbo/go-client/app/user.go 
b/tracing/dubbo/go-client/pkg/user.go
similarity index 82%
copy from tracing/dubbo/go-client/app/user.go
copy to tracing/dubbo/go-client/pkg/user.go
index d144dd6..42c7eb9 100644
--- a/tracing/dubbo/go-client/app/user.go
+++ b/tracing/dubbo/go-client/pkg/user.go
@@ -15,27 +15,13 @@
  * limitations under the License.
  */
 
-package main
+package pkg
 
 import (
        "context"
        "time"
 )
 
-import (
-       "dubbo.apache.org/dubbo-go/v3/config"
-       hessian "github.com/apache/dubbo-go-hessian2"
-)
-
-var (
-       userProvider = &UserProvider{}
-)
-
-func init() {
-       config.SetConsumerService(userProvider)
-       hessian.RegisterPOJO(&User{})
-}
-
 type User struct {
        ID   string
        Name string
diff --git a/tracing/dubbo/go-server/app/server.go 
b/tracing/dubbo/go-server/cmd/server.go
similarity index 96%
rename from tracing/dubbo/go-server/app/server.go
rename to tracing/dubbo/go-server/cmd/server.go
index efcdbc9..5a08497 100644
--- a/tracing/dubbo/go-server/app/server.go
+++ b/tracing/dubbo/go-server/cmd/server.go
@@ -38,6 +38,7 @@ import (
        "dubbo.apache.org/dubbo-go/v3/config"
        _ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
        _ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
+       "github.com/apache/dubbo-go-samples/tracing/dubbo/go-server/pkg"
 
        _ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
        _ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
@@ -56,7 +57,7 @@ var (
 //             export APP_LOG_CONF_FILE="xxx"
 func main() {
 
-       hessian.RegisterPOJO(&User{})
+       hessian.RegisterPOJO(&pkg.User{})
        config.Load()
 
        initZipkin()
diff --git a/tracing/dubbo/go-client/app/version.go 
b/tracing/dubbo/go-server/cmd/version.go
similarity index 100%
rename from tracing/dubbo/go-client/app/version.go
rename to tracing/dubbo/go-server/cmd/version.go
diff --git a/tracing/dubbo/go-server/conf/client.yml 
b/tracing/dubbo/go-server/conf/client.yml
new file mode 100644
index 0000000..3bcc1cd
--- /dev/null
+++ b/tracing/dubbo/go-server/conf/client.yml
@@ -0,0 +1,61 @@
+# dubbo client yaml configure file
+
+
+check: true
+# client
+request_timeout : "3s"
+# connect timeout
+connect_timeout : "3s"
+
+# application config
+application:
+  organization : "ikurento.com"
+  name  : "BDTService"
+  module : "dubbogo user-info client"
+  version : "0.0.1"
+  owner : "ZX"
+  environment : "test"
+
+registries :
+  "hangzhouzk":
+    protocol: "zookeeper"
+    timeout    : "3s"
+    address: "127.0.0.1:2181"
+    username: ""
+    password: ""
+
+references:
+  "UserProvider":
+    # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
+    registry: "hangzhouzk"
+    protocol : "dubbo"
+    interface : "com.ikurento.user.UserProvider"
+    cluster: "failover"
+    methods :
+    - name: "GetUser"
+      retries: 3
+
+protocol_conf:
+  dubbo:
+    reconnect_interval: 0
+    connection_number: 2
+    heartbeat_period: "5s"
+    session_timeout: "180s"
+    pool_size: 64
+    pool_ttl: 600
+    getty_session_param:
+      compress_encoding: false
+      tcp_no_delay: true
+      tcp_keep_alive: true
+      keep_alive_period: "120s"
+      tcp_r_buf_size: 262144
+      tcp_w_buf_size: 65536
+      pkg_rq_size: 1024
+      pkg_wq_size: 512
+      tcp_read_timeout: "1s"
+      tcp_write_timeout: "5s"
+      wait_timeout: "1s"
+      max_msg_len: 10240
+      session_name: "client"
+
+filter: "tracing"
\ No newline at end of file
diff --git a/tracing/dubbo/go-server/conf/log.yml 
b/tracing/dubbo/go-server/conf/log.yml
new file mode 100644
index 0000000..baee0b7
--- /dev/null
+++ b/tracing/dubbo/go-server/conf/log.yml
@@ -0,0 +1,28 @@
+
+level: "info"
+development: false
+disableCaller: false
+disableStacktrace: true
+sampling:
+encoding: "console"
+
+# encoder
+encoderConfig:
+  messageKey: "message"
+  levelKey: "level"
+  timeKey: "time"
+  nameKey: "logger"
+  callerKey: "caller"
+  stacktraceKey: "stacktrace"
+  lineEnding: ""
+  levelEncoder: "capitalColor"
+  timeEncoder: "iso8601"
+  durationEncoder: "seconds"
+  callerEncoder: "short"
+  nameEncoder: ""
+
+outputPaths:
+  - "stderr"
+errorOutputPaths:
+  - "stderr"
+initialFields:
diff --git a/tracing/dubbo/go-server/conf/server.yml 
b/tracing/dubbo/go-server/conf/server.yml
new file mode 100644
index 0000000..4e101f5
--- /dev/null
+++ b/tracing/dubbo/go-server/conf/server.yml
@@ -0,0 +1,62 @@
+# dubbo server yaml configure file
+
+
+# application config
+application:
+  organization : "ikurento.com"
+  name : "BDTService"
+  module : "dubbogo user-info server"
+  version : "0.0.1"
+  owner : "ZX"
+  environment : "test"
+
+registries :
+  "hangzhouzk":
+    protocol: "zookeeper"
+    timeout    : "3s"
+    address: "127.0.0.1:2181"
+    username: ""
+    password: ""
+
+
+
+services:
+  "UserProvider":
+    # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
+    registry: "hangzhouzk"
+    protocol : "dubbo"
+    # 相当于dubbo.xml中的interface
+    interface : "com.ikurento.user.UserProvider"
+    loadbalance: "random"
+    warmup: "100"
+    cluster: "failover"
+    methods:
+    - name: "GetUser"
+      retries: 1
+      loadbalance: "random"
+
+protocols:
+  "dubbo":
+    name: "dubbo"
+    #    ip : "127.0.0.1"
+    port: 20000
+
+
+protocol_conf:
+  dubbo:
+    session_number: 700
+    session_timeout: "180s"
+    getty_session_param:
+      compress_encoding: false
+      tcp_no_delay: true
+      tcp_keep_alive: true
+      keep_alive_period: "120s"
+      tcp_r_buf_size: 262144
+      tcp_w_buf_size: 65536
+      pkg_rq_size: 1024
+      pkg_wq_size: 512
+      tcp_read_timeout: "1s"
+      tcp_write_timeout: "5s"
+      wait_timeout: "1s"
+      max_msg_len: 1024
+      session_name: "server"
diff --git a/tracing/dubbo/go-server/docker/docker-compose.yml 
b/tracing/dubbo/go-server/docker/docker-compose.yml
new file mode 100644
index 0000000..386a42e
--- /dev/null
+++ b/tracing/dubbo/go-server/docker/docker-compose.yml
@@ -0,0 +1,8 @@
+version: '3'
+
+services:
+  zookeeper:
+    image: zookeeper
+    ports:
+      - 2181:2181
+    restart: on-failure
\ No newline at end of file
diff --git a/tracing/dubbo/go-server/app/user.go 
b/tracing/dubbo/go-server/pkg/user.go
similarity index 99%
rename from tracing/dubbo/go-server/app/user.go
rename to tracing/dubbo/go-server/pkg/user.go
index 3166b1e..5e6fb21 100644
--- a/tracing/dubbo/go-server/app/user.go
+++ b/tracing/dubbo/go-server/pkg/user.go
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package main
+package pkg
 
 import (
        "context"
diff --git a/tracing/dubbo/go-client/app/user.go 
b/tracing/dubbo/go-server/tests/integration/main_test.go
similarity index 59%
rename from tracing/dubbo/go-client/app/user.go
rename to tracing/dubbo/go-server/tests/integration/main_test.go
index d144dd6..9c9dd34 100644
--- a/tracing/dubbo/go-client/app/user.go
+++ b/tracing/dubbo/go-server/tests/integration/main_test.go
@@ -1,3 +1,5 @@
+// +build integration
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -15,29 +17,48 @@
  * limitations under the License.
  */
 
-package main
+package integration
 
 import (
        "context"
+       "os"
+       "testing"
        "time"
 )
 
 import (
-       "dubbo.apache.org/dubbo-go/v3/config"
        hessian "github.com/apache/dubbo-go-hessian2"
 )
 
-var (
-       userProvider = &UserProvider{}
+import (
+       _ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
+       _ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
+       _ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
+       "dubbo.apache.org/dubbo-go/v3/config"
+       _ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
+       _ "dubbo.apache.org/dubbo-go/v3/metadata/mapping/memory"
+       _ "dubbo.apache.org/dubbo-go/v3/metadata/report/zookeeper"
+       _ "dubbo.apache.org/dubbo-go/v3/metadata/service/inmemory"
+       _ "dubbo.apache.org/dubbo-go/v3/metadata/service/remoting"
+       _ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
+       _ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
+       _ "dubbo.apache.org/dubbo-go/v3/registry/servicediscovery"
+       _ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper"
 )
 
-func init() {
+var userProvider = new(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
+       Id   string
        Name string
        Age  int32
        Time time.Time
diff --git a/tracing/dubbo/go-client/app/client.go 
b/tracing/dubbo/go-server/tests/integration/userprovider_test.go
similarity index 60%
rename from tracing/dubbo/go-client/app/client.go
rename to tracing/dubbo/go-server/tests/integration/userprovider_test.go
index 45bd478..d795eb9 100644
--- a/tracing/dubbo/go-client/app/client.go
+++ b/tracing/dubbo/go-server/tests/integration/userprovider_test.go
@@ -1,3 +1,5 @@
+// +build integration
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -15,86 +17,37 @@
  * limitations under the License.
  */
 
-package main
+package integration
 
 import (
        "context"
-       "fmt"
-       "os"
-       "os/signal"
-       "syscall"
-       "time"
+       "testing"
 )
-
 import (
-       hessian "github.com/apache/dubbo-go-hessian2"
        "github.com/dubbogo/gost/log"
        "github.com/opentracing/opentracing-go"
        zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing"
        "github.com/openzipkin/zipkin-go"
        zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
-)
+       "github.com/stretchr/testify/assert"
 
-import (
        "dubbo.apache.org/dubbo-go/v3/common/logger"
-       _ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
-       "dubbo.apache.org/dubbo-go/v3/config"
-       _ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
-       _ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
-
-       _ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
-
-       _ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
-       _ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
-       _ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper"
-)
-
-var (
-       survivalTimeout int = 10e9
 )
 
-// they are necessary:
-//             export CONF_CONSUMER_FILE_PATH="xxx"
-//             export APP_LOG_CONF_FILE="xxx"
-func main() {
-       hessian.RegisterPOJO(&User{})
-       config.Load()
-
+func TestGetUser(t *testing.T) {
        initZipkin()
        gxlog.CInfo("\n\n\nstart to test dubbo")
        user := &User{}
        span, ctx := opentracing.StartSpanFromContext(context.Background(), 
"Test-Client-Service")
        err := userProvider.GetUser(ctx, []interface{}{"A001"}, user)
        span.Finish()
-       if err != nil {
-               panic(err)
-       }
-       gxlog.CInfo("response result: %v\n", user)
-       initSignal()
-}
-
-func initSignal() {
-       signals := make(chan os.Signal, 1)
-       // It is not possible to block SIGKILL or syscall.SIGSTOP
-       signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP,
-               syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
-       for {
-               sig := <-signals
-               logger.Infof("get signal %s", sig.String())
-               switch sig {
-               case syscall.SIGHUP:
-                       // reload()
-               default:
-                       time.AfterFunc(time.Duration(survivalTimeout), func() {
-                               logger.Warnf("app exit now by force...")
-                               os.Exit(1)
-                       })
+       assert.Nil(t, err)
 
-                       // The program exits normally or timeout forcibly exits.
-                       fmt.Println("app exit now...")
-                       return
-               }
-       }
+       gxlog.CInfo("response result: %v\n", user)
+       //assert.Equal(t, "A001", user.Id)
+       assert.Equal(t, "Alex Stocks", user.Name)
+       assert.Equal(t, int32(18), user.Age)
+       assert.NotNil(t, user.Time)
 }
 
 func initZipkin() {

Reply via email to