You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/07/13 05:19:21 UTC
[dubbo-go-samples] branch 3.0 updated: Ftr: Add integration test
multi-server support (#161)
This is an automated email from the ASF dual-hosted git repository.
alexstocks 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 6ff8949 Ftr: Add integration test multi-server support (#161)
6ff8949 is described below
commit 6ff89499e980284822a213af23695ca9ea9138da
Author: EnableAsync <43...@users.noreply.github.com>
AuthorDate: Tue Jul 13 13:19:13 2021 +0800
Ftr: Add integration test multi-server support (#161)
Fix: add consumer config for middle
Ftr: add multi-zone to integration testing
Fix: start_integrate_test.sh
Fix: start_integrate_test.sh
Fix: test.sh
Tst: Add multi-zone tests
Fix: start_integrate_test.sh
---
chain/build/test.sh | 44 ++++++++++++++
integrate_test.sh | 20 ++++---
multi-zone/build/test.sh | 45 ++++++++++++++
multi-zone/go-server-hz/conf/client.yml | 61 +++++++++++++++++++
.../go-server-hz/tests/integration/main_test.go | 70 ++++++++++++++++++++++
.../tests/integration/userprovider_test.go | 38 ++++++++++++
multi-zone/go-server-sh/conf/client.yml | 61 +++++++++++++++++++
.../go-server-sh/tests/integration/main_test.go | 70 ++++++++++++++++++++++
.../tests/integration/userprovider_test.go | 38 ++++++++++++
start_integrate_test.sh | 6 +-
10 files changed, 445 insertions(+), 8 deletions(-)
diff --git a/chain/build/test.sh b/chain/build/test.sh
new file mode 100755
index 0000000..8cff497
--- /dev/null
+++ b/chain/build/test.sh
@@ -0,0 +1,44 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, softwarek
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This file is for integration testing only
+
+P_DIR="$1"
+
+# start zookeeper
+make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" BASE_DIR="$P_DIR"/dist -f build/Makefile docker-up
+
+# start server
+make PROJECT_DIR="$P_DIR"/backend PROJECT_NAME="$(basename "$P_DIR"/backend)" BASE_DIR="$P_DIR"/backend/dist -f build/Makefile start
+make PROJECT_DIR="$P_DIR"/middle PROJECT_NAME="$(basename "$P_DIR"/middle)" CONF_CONSUMER_FILE_PATH="$P_DIR"/middle/conf/client.yml BASE_DIR="$P_DIR"/middle/dist -f build/Makefile start
+
+# start integration testing
+make PROJECT_DIR="$P_DIR"/backend PROJECT_NAME="$(basename "$P_DIR"/backend)" BASE_DIR="$P_DIR"/backend/dist -f build/Makefile integration
+result=$?
+
+make PROJECT_DIR="$P_DIR"/middle PROJECT_NAME="$(basename "$P_DIR"/middle)" BASE_DIR="$P_DIR"/middle/dist CONF_CONSUMER_FILE_PATH="$P_DIR"/middle/conf/test.yml -f build/Makefile integration
+result2=$?
+
+if [ $result -eq 0 ]; then
+ result=$result2
+fi
+
+# stop server and clean
+make PROJECT_DIR="$P_DIR"/backend PROJECT_NAME="$(basename "$P_DIR"/backend)" BASE_DIR="$P_DIR"/backend/dist -f build/Makefile clean
+make PROJECT_DIR="$P_DIR"/middle PROJECT_NAME="$(basename "$P_DIR"/middle)" BASE_DIR="$P_DIR"/middle/dist -f build/Makefile clean
+
+make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" BASE_DIR="$P_DIR"/dist -f build/Makefile docker-down
+
+exit $result
diff --git a/integrate_test.sh b/integrate_test.sh
index 8ae516c..78eb52e 100755
--- a/integrate_test.sh
+++ b/integrate_test.sh
@@ -21,25 +21,31 @@ fi
P_DIR=$(pwd)/$1
-make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile docker-up
+if [ -f "$P_DIR"/build/test.sh ]; then
+ "$P_DIR"/build/test.sh "$P_DIR"
+ result=$?
+ exit $((result))
+fi
+
+make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" BASE_DIR="$P_DIR"/dist -f build/Makefile docker-up
# check docker health
-make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile docker-health-check
+make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" BASE_DIR="$P_DIR"/dist -f build/Makefile docker-health-check
# start server
-make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile start
+make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" BASE_DIR="$P_DIR"/dist -f build/Makefile start
# start integration
-make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile integration
+make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" BASE_DIR="$P_DIR"/dist -f build/Makefile integration
result=$?
# if fail print server log
if [ $result != 0 ];then
- make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile print-server-log
+ make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" BASE_DIR="$P_DIR"/dist -f build/Makefile print-server-log
fi
# stop server
-make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile clean
+make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" BASE_DIR="$P_DIR"/dist -f build/Makefile clean
-make PROJECT_DIR=$P_DIR PROJECT_NAME=$(basename $P_DIR) BASE_DIR=$P_DIR/dist -f build/Makefile docker-down
+make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" BASE_DIR="$P_DIR"/dist -f build/Makefile docker-down
exit $((result))
\ No newline at end of file
diff --git a/multi-zone/build/test.sh b/multi-zone/build/test.sh
new file mode 100755
index 0000000..836fea6
--- /dev/null
+++ b/multi-zone/build/test.sh
@@ -0,0 +1,45 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, softwarek
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This file is for integration testing only
+
+P_DIR="$1"
+
+# start zookeeper
+make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" BASE_DIR="$P_DIR"/dist -f build/Makefile docker-up
+
+# start server
+make PROJECT_DIR="$P_DIR"/go-server-hz PROJECT_NAME="$(basename "$P_DIR"/go-server-hz)" BASE_DIR="$P_DIR"/go-server-hz/dist -f build/Makefile start
+make PROJECT_DIR="$P_DIR"/go-server-sh PROJECT_NAME="$(basename "$P_DIR"/go-server-sh)" BASE_DIR="$P_DIR"/go-server-sh/dist -f build/Makefile start
+
+# start integration testing
+make PROJECT_DIR="$P_DIR"/go-server-hz PROJECT_NAME="$(basename "$P_DIR"/go-server-hz)" BASE_DIR="$P_DIR"/go-server-hz/dist -f build/Makefile integration
+result=$?
+
+make PROJECT_DIR="$P_DIR"/go-server-sh PROJECT_NAME="$(basename "$P_DIR"/go-server-sh)" BASE_DIR="$P_DIR"/go-server-sh/dist -f build/Makefile integration
+result2=$?
+
+if [ $result -eq 0 ]; then
+ result=$result2
+fi
+
+# stop server and clean
+make PROJECT_DIR="$P_DIR"/go-server-hz PROJECT_NAME="$(basename "$P_DIR"/go-server-hz)" BASE_DIR="$P_DIR"/go-server-hz/dist -f build/Makefile clean
+make PROJECT_DIR="$P_DIR"/go-server-sh PROJECT_NAME="$(basename "$P_DIR"/go-server-sh)" BASE_DIR="$P_DIR"/go-server-sh/dist -f build/Makefile clean
+
+# stop zookeeper
+make PROJECT_DIR="$P_DIR" PROJECT_NAME="$(basename "$P_DIR")" BASE_DIR="$P_DIR"/dist -f build/Makefile docker-down
+
+exit $result
\ No newline at end of file
diff --git a/multi-zone/go-server-hz/conf/client.yml b/multi-zone/go-server-hz/conf/client.yml
new file mode 100644
index 0000000..20ca150
--- /dev/null
+++ b/multi-zone/go-server-hz/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: "dubbo.io"
+ name: "UserInfoClient"
+ module: "dubbo-go user-info client"
+ version: "0.0.1"
+ environment: "dev"
+
+# registry config
+registries:
+ "demoZk":
+ protocol: "zookeeper"
+ timeout: "3s"
+ address: "127.0.0.1:2183"
+ username: ""
+ password: ""
+ zone: hangzhou
+ weight: 50
+
+# reference config
+references:
+ "UserProvider":
+ registry: "demoZk"
+ protocol: "dubbo"
+ interface: "org.apache.dubbo.UserProvider"
+ cluster: "failover"
+ methods:
+ - name: "GetUser"
+ retries: 3
+
+# protocol config
+protocol_conf:
+ dubbo:
+ reconnect_interval: 0
+ connection_number: 1
+ 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: 1024000
+ session_name: "client"
diff --git a/multi-zone/go-server-hz/tests/integration/main_test.go b/multi-zone/go-server-hz/tests/integration/main_test.go
new file mode 100644
index 0000000..b4a5139
--- /dev/null
+++ b/multi-zone/go-server-hz/tests/integration/main_test.go
@@ -0,0 +1,70 @@
+// +build integration
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package integration
+
+import (
+ "context"
+ "os"
+ "testing"
+ "time"
+)
+
+import (
+ 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/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/registry/zookeeper"
+)
+
+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
+ 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"
+}
+
+func (User) JavaClassName() string {
+ return "org.apache.dubbo.User"
+}
diff --git a/multi-zone/go-server-hz/tests/integration/userprovider_test.go b/multi-zone/go-server-hz/tests/integration/userprovider_test.go
new file mode 100644
index 0000000..89988b7
--- /dev/null
+++ b/multi-zone/go-server-hz/tests/integration/userprovider_test.go
@@ -0,0 +1,38 @@
+// +build integration
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package integration
+
+import (
+ "context"
+ "testing"
+)
+import (
+ "github.com/stretchr/testify/assert"
+)
+
+func TestGetUser(t *testing.T) {
+ user := &User{}
+ err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
+ assert.Nil(t, err)
+ assert.Equal(t, "dev-hz", user.ID)
+ assert.Equal(t, "Alex Stocks", user.Name)
+ assert.Equal(t, int32(18), user.Age)
+ assert.NotNil(t, user.Time)
+}
diff --git a/multi-zone/go-server-sh/conf/client.yml b/multi-zone/go-server-sh/conf/client.yml
new file mode 100644
index 0000000..9717e0c
--- /dev/null
+++ b/multi-zone/go-server-sh/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: "dubbo.io"
+ name: "UserInfoClient"
+ module: "dubbo-go user-info client"
+ version: "0.0.1"
+ environment: "dev"
+
+# registry config
+registries:
+ "demoZk":
+ protocol: "zookeeper"
+ timeout: "3s"
+ address: "127.0.0.1:2182"
+ username: ""
+ password: ""
+ zone: shanghai
+ weight: 50
+
+# reference config
+references:
+ "UserProvider":
+ registry: "demoZk"
+ protocol: "dubbo"
+ interface: "org.apache.dubbo.UserProvider"
+ cluster: "failover"
+ methods:
+ - name: "GetUser"
+ retries: 3
+
+# protocol config
+protocol_conf:
+ dubbo:
+ reconnect_interval: 0
+ connection_number: 1
+ 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: 1024000
+ session_name: "client"
diff --git a/multi-zone/go-server-sh/tests/integration/main_test.go b/multi-zone/go-server-sh/tests/integration/main_test.go
new file mode 100644
index 0000000..b4a5139
--- /dev/null
+++ b/multi-zone/go-server-sh/tests/integration/main_test.go
@@ -0,0 +1,70 @@
+// +build integration
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package integration
+
+import (
+ "context"
+ "os"
+ "testing"
+ "time"
+)
+
+import (
+ 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/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/registry/zookeeper"
+)
+
+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
+ 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"
+}
+
+func (User) JavaClassName() string {
+ return "org.apache.dubbo.User"
+}
diff --git a/multi-zone/go-server-sh/tests/integration/userprovider_test.go b/multi-zone/go-server-sh/tests/integration/userprovider_test.go
new file mode 100644
index 0000000..c8d3dd8
--- /dev/null
+++ b/multi-zone/go-server-sh/tests/integration/userprovider_test.go
@@ -0,0 +1,38 @@
+// +build integration
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package integration
+
+import (
+ "context"
+ "testing"
+)
+import (
+ "github.com/stretchr/testify/assert"
+)
+
+func TestGetUser(t *testing.T) {
+ user := &User{}
+ err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
+ assert.Nil(t, err)
+ assert.Equal(t, "dev-sh", user.ID)
+ assert.Equal(t, "Alex Stocks", user.Name)
+ assert.Equal(t, int32(18), user.Age)
+ assert.NotNil(t, user.Time)
+}
diff --git a/start_integrate_test.sh b/start_integrate_test.sh
index 6f2287c..14b1a03 100755
--- a/start_integrate_test.sh
+++ b/start_integrate_test.sh
@@ -18,6 +18,7 @@
array=("async/go-server")
array+=("attachment/go-server")
array+=("config-api/go-server")
+array+=("chain")
# config center
array+=("configcenter/apollo/go-server")
array+=("configcenter/nacos/go-server")
@@ -62,6 +63,9 @@ array+=("metric/go-server")
# multi-registry
array+=("multi-registry/go-server")
+# multi-zone
+array+=("multi-zone")
+
# registry
array+=("registry/zookeeper/go-server")
array+=("registry/etcd/go-server")
@@ -82,6 +86,6 @@ do
./integrate_test.sh "${array[i]}"
result=$?
if [ $result -gt 0 ]; then
- exit $result
+ exit $result
fi
done