This is an automated email from the ASF dual-hosted git repository.
iluo 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 df067ac enhance tls examples (#91)
df067ac is described below
commit df067acd4475d94d4767c2b695a696799e4823ac
Author: Ian Luo <[email protected]>
AuthorDate: Tue Apr 13 16:29:44 2021 +0800
enhance tls examples (#91)
---
.run/tls/tls-client.run.xml | 15 ++++
.run/tls/tls-server.run.xml | 15 ++++
.run/tls/tls-test.run.xml | 17 ++++
tls/go-client/cmd/client.go | 9 +--
tls/go-client/conf/client.yml | 12 +--
tls/go-client/pkg/user.go | 2 +-
tls/go-server/cmd/server.go | 10 +--
tls/{go-client => go-server}/conf/client.yml | 12 +--
tls/go-server/conf/server.yml | 9 +--
tls/go-server/docker/docker-compose.yml | 9 +++
tls/go-server/pkg/user.go | 13 +---
.../tests/integration/main_test.go} | 90 ++++++++--------------
.../tests/integration/userprovider_test.go} | 33 ++++----
13 files changed, 125 insertions(+), 121 deletions(-)
diff --git a/.run/tls/tls-client.run.xml b/.run/tls/tls-client.run.xml
new file mode 100644
index 0000000..a529113
--- /dev/null
+++ b/.run/tls/tls-client.run.xml
@@ -0,0 +1,15 @@
+<component name="ProjectRunConfigurationManager">
+ <configuration default="false" name="tls-client"
type="GoApplicationRunConfiguration" factoryName="Go Application"
folderName="tls">
+ <module name="dubbo-go-samples" />
+ <working_directory value="$PROJECT_DIR$/tls/go-client" />
+ <envs>
+ <env name="APP_LOG_CONF_FILE"
value="$PROJECT_DIR$/tls/go-client/conf/log.yml" />
+ <env name="CONF_CONSUMER_FILE_PATH"
value="$PROJECT_DIR$/tls/go-client/conf/client.yml" />
+ </envs>
+ <kind value="PACKAGE" />
+ <filePath value="$PROJECT_DIR$/tls/go-client/cmd/client.go" />
+ <package value="github.com/apache/dubbo-go-samples/tls/go-client/cmd" />
+ <directory value="$PROJECT_DIR$" />
+ <method v="2" />
+ </configuration>
+</component>
diff --git a/.run/tls/tls-server.run.xml b/.run/tls/tls-server.run.xml
new file mode 100644
index 0000000..1674a9f
--- /dev/null
+++ b/.run/tls/tls-server.run.xml
@@ -0,0 +1,15 @@
+<component name="ProjectRunConfigurationManager">
+ <configuration default="false" name="tls-server"
type="GoApplicationRunConfiguration" factoryName="Go Application"
folderName="tls">
+ <module name="dubbo-go-samples" />
+ <working_directory value="$PROJECT_DIR$/tls/go-server" />
+ <envs>
+ <env name="CONF_PROVIDER_FILE_PATH"
value="$PROJECT_DIR$/tls/go-server/conf/server.yml" />
+ <env name="APP_LOG_CONF_FILE"
value="$PROJECT_DIR$/tls/go-server/conf/log.yml" />
+ </envs>
+ <kind value="PACKAGE" />
+ <filePath value="$PROJECT_DIR$/tls/go-server/cmd/server.go" />
+ <package value="github.com/apache/dubbo-go-samples/tls/go-server/cmd" />
+ <directory value="$PROJECT_DIR$" />
+ <method v="2" />
+ </configuration>
+</component>
diff --git a/.run/tls/tls-test.run.xml b/.run/tls/tls-test.run.xml
new file mode 100644
index 0000000..2e8744a
--- /dev/null
+++ b/.run/tls/tls-test.run.xml
@@ -0,0 +1,17 @@
+<component name="ProjectRunConfigurationManager">
+ <configuration default="false" name="tls-test" type="GoTestRunConfiguration"
factoryName="Go Test">
+ <module name="dubbo-go-samples" />
+ <working_directory value="$PROJECT_DIR$/tls/go-server" />
+ <useCustomBuildTags value="true" />
+ <envs>
+ <env name="CONF_CONSUMER_FILE_PATH" value="conf/client.yml" />
+ <env name="APP_LOG_CONF_FILE" value="conf/log.yml" />
+ </envs>
+ <framework value="gotest" />
+ <kind value="PACKAGE" />
+ <package
value="github.com/apache/dubbo-go-samples/tls/go-server/tests/integration" />
+ <directory value="$PROJECT_DIR$" />
+ <filePath value="$PROJECT_DIR$" />
+ <method v="2" />
+ </configuration>
+</component>
diff --git a/tls/go-client/cmd/client.go b/tls/go-client/cmd/client.go
index 8819129..9e97f6c 100755
--- a/tls/go-client/cmd/client.go
+++ b/tls/go-client/cmd/client.go
@@ -30,17 +30,16 @@ import (
import (
getty "github.com/apache/dubbo-getty"
hessian "github.com/apache/dubbo-go-hessian2"
- gxlog "github.com/dubbogo/gost/log"
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
"github.com/apache/dubbo-go/common/logger"
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
_ "github.com/apache/dubbo-go/protocol/dubbo"
_ "github.com/apache/dubbo-go/registry/protocol"
- _ "github.com/apache/dubbo-go/filter/filter_impl"
- _ "github.com/apache/dubbo-go/cluster/cluster_impl"
- _ "github.com/apache/dubbo-go/cluster/loadbalance"
_ "github.com/apache/dubbo-go/registry/zookeeper"
-
+ gxlog "github.com/dubbogo/gost/log"
)
import (
diff --git a/tls/go-client/conf/client.yml b/tls/go-client/conf/client.yml
index 2e5326a..35bdbc2 100644
--- a/tls/go-client/conf/client.yml
+++ b/tls/go-client/conf/client.yml
@@ -1,6 +1,5 @@
# dubbo client yaml configure file
-
check: true
# client
request_timeout : "3s"
@@ -9,11 +8,10 @@ connect_timeout : "3s"
# application config
application:
- organization : "ikurento.com"
- name : "BDTService"
+ organization : "dubbo.io"
+ name : "UserInfoClient"
module : "dubbogo user-info client"
version : "0.0.1"
- owner : "ZX"
environment : "dev"
registries :
@@ -24,19 +22,17 @@ registries :
usern ame: ""
password: ""
-
references:
"UserProvider":
# specify multiple registries separated by commas; if not specify to
register with all registries by default
registry: "demoZk"
protocol : "dubbo"
- interface : "com.ikurento.user.UserProvider"
+ interface : "org.apache.dubbo.UserProvider"
cluster: "failover"
methods :
- name: "GetUser"
retries: 3
-
protocol_conf:
dubbo:
reconnect_interval: 0
@@ -58,4 +54,4 @@ protocol_conf:
tcp_write_timeout: "5s"
wait_timeout: "1s"
max_msg_len: 1024000
- session_name: "client"
+ session_name: "client"
\ No newline at end of file
diff --git a/tls/go-client/pkg/user.go b/tls/go-client/pkg/user.go
index 42c7eb9..7733ea4 100755
--- a/tls/go-client/pkg/user.go
+++ b/tls/go-client/pkg/user.go
@@ -38,5 +38,5 @@ func (u *UserProvider) Reference() string {
}
func (User) JavaClassName() string {
- return "com.ikurento.user.User"
+ return "org.apache.dubbo.User"
}
diff --git a/tls/go-server/cmd/server.go b/tls/go-server/cmd/server.go
index 896fee6..9f59211 100755
--- a/tls/go-server/cmd/server.go
+++ b/tls/go-server/cmd/server.go
@@ -29,14 +29,14 @@ import (
import (
getty "github.com/apache/dubbo-getty"
hessian "github.com/apache/dubbo-go-hessian2"
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
"github.com/apache/dubbo-go/common/logger"
+ _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
_ "github.com/apache/dubbo-go/protocol/dubbo"
_ "github.com/apache/dubbo-go/registry/protocol"
- _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
- _ "github.com/apache/dubbo-go/filter/filter_impl"
- _ "github.com/apache/dubbo-go/cluster/cluster_impl"
- _ "github.com/apache/dubbo-go/cluster/loadbalance"
_ "github.com/apache/dubbo-go/registry/zookeeper"
)
@@ -66,8 +66,8 @@ func init(){
export CONF_PROVIDER_FILE_PATH="xx"
export APP_LOG_CONF_FILE="xx"
*/
-
func main() {
+ config.SetProviderService(new(pkg.UserProvider))
// serializing at run time
hessian.RegisterPOJO(&pkg.User{})
// load configuration
diff --git a/tls/go-client/conf/client.yml b/tls/go-server/conf/client.yml
similarity index 88%
copy from tls/go-client/conf/client.yml
copy to tls/go-server/conf/client.yml
index 2e5326a..35bdbc2 100644
--- a/tls/go-client/conf/client.yml
+++ b/tls/go-server/conf/client.yml
@@ -1,6 +1,5 @@
# dubbo client yaml configure file
-
check: true
# client
request_timeout : "3s"
@@ -9,11 +8,10 @@ connect_timeout : "3s"
# application config
application:
- organization : "ikurento.com"
- name : "BDTService"
+ organization : "dubbo.io"
+ name : "UserInfoClient"
module : "dubbogo user-info client"
version : "0.0.1"
- owner : "ZX"
environment : "dev"
registries :
@@ -24,19 +22,17 @@ registries :
usern ame: ""
password: ""
-
references:
"UserProvider":
# specify multiple registries separated by commas; if not specify to
register with all registries by default
registry: "demoZk"
protocol : "dubbo"
- interface : "com.ikurento.user.UserProvider"
+ interface : "org.apache.dubbo.UserProvider"
cluster: "failover"
methods :
- name: "GetUser"
retries: 3
-
protocol_conf:
dubbo:
reconnect_interval: 0
@@ -58,4 +54,4 @@ protocol_conf:
tcp_write_timeout: "5s"
wait_timeout: "1s"
max_msg_len: 1024000
- session_name: "client"
+ session_name: "client"
\ No newline at end of file
diff --git a/tls/go-server/conf/server.yml b/tls/go-server/conf/server.yml
index e225b7c..e982d7e 100644
--- a/tls/go-server/conf/server.yml
+++ b/tls/go-server/conf/server.yml
@@ -3,11 +3,10 @@
# application config
application:
- organization : "ikurento.com"
- name : "BDTService"
- module : "dubbogo user-info server"
+ organization : "dubbo.io"
+ name : "UserInfoServer"
+ module : "dubbo-go user-info server"
version : "0.0.1"
- owner : "ZX"
environment : "dev"
registries :
@@ -22,7 +21,7 @@ services:
registry: "demoZk"
protocol : "dubbo"
# equal to the interface in dubbo.xml
- interface : "com.ikurento.user.UserProvider"
+ interface : "org.apache.dubbo.UserProvider"
loadbalance: "random"
warmup: "100"
cluster: "failover"
diff --git a/tls/go-server/docker/docker-compose.yml
b/tls/go-server/docker/docker-compose.yml
new file mode 100644
index 0000000..8724179
--- /dev/null
+++ b/tls/go-server/docker/docker-compose.yml
@@ -0,0 +1,9 @@
+version: '3'
+
+services:
+ zookeeper:
+ image: zookeeper
+ ports:
+ - 2181:2181
+ restart: on-failure
+
diff --git a/tls/go-server/pkg/user.go b/tls/go-server/pkg/user.go
index 3a64ca1..e295a11 100755
--- a/tls/go-server/pkg/user.go
+++ b/tls/go-server/pkg/user.go
@@ -24,19 +24,8 @@ import (
import (
"github.com/dubbogo/gost/log"
- hessian "github.com/apache/dubbo-go-hessian2"
)
-import (
- "github.com/apache/dubbo-go/config"
-)
-
-func init() {
- config.SetProviderService(new(UserProvider))
- // ------for hessian2------
- hessian.RegisterPOJO(&User{})
-}
-
type User struct {
ID string
Name string
@@ -59,5 +48,5 @@ func (u *UserProvider) Reference() string {
}
func (u User) JavaClassName() string {
- return "com.ikurento.user.User"
+ return "org.apache.dubbo.User"
}
\ No newline at end of file
diff --git a/tls/go-client/cmd/client.go
b/tls/go-server/tests/integration/main_test.go
old mode 100755
new mode 100644
similarity index 56%
copy from tls/go-client/cmd/client.go
copy to tls/go-server/tests/integration/main_test.go
index 8819129..5abb8f7
--- a/tls/go-client/cmd/client.go
+++ b/tls/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,46 +17,35 @@
* limitations under the License.
*/
-package main
+package integration
import (
"context"
- "fmt"
"os"
- "os/signal"
"path/filepath"
- "syscall"
+ "testing"
"time"
)
import (
getty "github.com/apache/dubbo-getty"
hessian "github.com/apache/dubbo-go-hessian2"
- gxlog "github.com/dubbogo/gost/log"
- "github.com/apache/dubbo-go/common/logger"
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
+ _ "github.com/apache/dubbo-go/metadata/service/inmemory"
_ "github.com/apache/dubbo-go/protocol/dubbo"
_ "github.com/apache/dubbo-go/registry/protocol"
- _ "github.com/apache/dubbo-go/filter/filter_impl"
- _ "github.com/apache/dubbo-go/cluster/cluster_impl"
- _ "github.com/apache/dubbo-go/cluster/loadbalance"
_ "github.com/apache/dubbo-go/registry/zookeeper"
-
-)
-
-import (
- "github.com/apache/dubbo-go-samples/tls/go-client/pkg"
)
-var (
- survivalTimeout int = 10e9
- userProvider = new(pkg.UserProvider)
-)
+var userProvider = new(UserProvider)
-func init(){
+func TestMain(m *testing.M) {
config.SetConsumerService(userProvider)
- hessian.RegisterPOJO(&pkg.User{})
+ hessian.RegisterPOJO(&User{})
clientKeyPath, _ := filepath.Abs("../certs/ca.key")
caPemPath, _ := filepath.Abs("../certs/ca.pem")
config.SetSslEnabled(true)
@@ -62,46 +53,27 @@ func init(){
ClientPrivateKeyPath: clientKeyPath,
ClientTrustCertCollectionPath: caPemPath,
})
-}
-// they are necessary:
-// export CONF_CONSUMER_FILE_PATH="xxx"
-// export APP_LOG_CONF_FILE="xxx"
-func main() {
config.Load()
- time.Sleep(3e9)
+ time.Sleep(3 * time.Second)
+
+ os.Exit(m.Run())
+}
- gxlog.CInfo("\n\n\nstart to test dubbo")
- user := &pkg.User{}
- for i := 0;i < 10 ;i ++{
- err := userProvider.GetUser(context.TODO(),
[]interface{}{"A001"}, user)
- if err != nil {
- panic(err)
- }
- time.Sleep(time.Second * 5)
- }
+type User struct {
+ ID string
+ Name string
+ Age int32
+ Time time.Time
+}
+
+type UserProvider struct {
+ GetUser func(ctx context.Context, req []interface{}, rsp *User) error
+}
+
+func (u *UserProvider) Reference() string {
+ return "UserProvider"
+}
- gxlog.CInfo("response result: %v\n", user)
- initSignal()
+func (User) JavaClassName() string {
+ return "org.apache.dubbo.User"
}
-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)
- })
- // The program exits normally or timeout forcibly exits.
- fmt.Println("app exit now...")
- return
- }
- }
-}
\ No newline at end of file
diff --git a/tls/go-client/pkg/user.go
b/tls/go-server/tests/integration/userprovider_test.go
old mode 100755
new mode 100644
similarity index 68%
copy from tls/go-client/pkg/user.go
copy to tls/go-server/tests/integration/userprovider_test.go
index 42c7eb9..58cc595
--- a/tls/go-client/pkg/user.go
+++ b/tls/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,28 +17,23 @@
* limitations under the License.
*/
-package pkg
+package integration
import (
"context"
- "time"
+ "testing"
)
-type User struct {
- ID string
- Name string
- Age int32
- Time time.Time
-}
-
-type UserProvider struct {
- GetUser func(ctx context.Context, req []interface{}, rsp *User) error
-}
-
-func (u *UserProvider) Reference() string {
- return "UserProvider"
-}
+import (
+ "github.com/stretchr/testify/assert"
+)
-func (User) JavaClassName() string {
- return "com.ikurento.user.User"
+func TestGetUser(t *testing.T) {
+ user := &User{}
+ err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
+ assert.Nil(t, err)
+ assert.Equal(t, "A001", user.ID)
+ assert.Equal(t, "CJP", user.Name)
+ assert.Equal(t, int32(21), user.Age)
+ assert.NotNil(t, user.Time)
}