Skip to content

Commit

Permalink
Ftr: Add integration test multi-server support (apache#161)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
EnableAsync authored Jul 13, 2021
1 parent c875ae7 commit 6ff8949
Show file tree
Hide file tree
Showing 10 changed files with 445 additions and 8 deletions.
44 changes: 44 additions & 0 deletions chain/build/test.sh
Original file line number Diff line number Diff line change
@@ -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
20 changes: 13 additions & 7 deletions integrate_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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))
45 changes: 45 additions & 0 deletions multi-zone/build/test.sh
Original file line number Diff line number Diff line change
@@ -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
61 changes: 61 additions & 0 deletions multi-zone/go-server-hz/conf/client.yml
Original file line number Diff line number Diff line change
@@ -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"
70 changes: 70 additions & 0 deletions multi-zone/go-server-hz/tests/integration/main_test.go
Original file line number Diff line number Diff line change
@@ -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"
}
38 changes: 38 additions & 0 deletions multi-zone/go-server-hz/tests/integration/userprovider_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
61 changes: 61 additions & 0 deletions multi-zone/go-server-sh/conf/client.yml
Original file line number Diff line number Diff line change
@@ -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"
Loading

0 comments on commit 6ff8949

Please sign in to comment.