Skip to content

Commit

Permalink
Merge pull request #5 from apache/develop
Browse files Browse the repository at this point in the history
Sync latest Develop
  • Loading branch information
sxllwx authored May 21, 2020
2 parents 7a256e4 + f07be5c commit 60ff0c4
Show file tree
Hide file tree
Showing 19 changed files with 969 additions and 6 deletions.
32 changes: 28 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
language: go
dist: trusty
sudo: required

# define the dependence env
language: go
os:
- linux

go:
- "1.13"

services:
- docker
env:
- GO111MODULE=on

install: true

# define ci-stage
script:
# license-check
- echo 'start license check'
- go fmt ./... && [[ -z `git status -s` ]]
- sh before_validate_license.sh
- chmod u+x /tmp/tools/license/license-header-checker
- /tmp/tools/license/license-header-checker -v -a -r -i vendor /tmp/tools/license/license.txt . go && [[ -z `git status -s` ]]
# unit-test
- echo 'start unit-test'
- chmod u+x before_ut.sh && ./before_ut.sh
- go mod vendor && go test ./... -coverprofile=coverage.txt -covermode=atomic
# integrate-test
- echo 'start integrate-test'
# start zookeeper registry insecure listen in [:]:2181
- docker run -d --network host zookeeper
- ROOTDIR=$(pwd)
- cd ./test/integrate/dubbo/go-client && docker build . -t ci-consumer --build-arg PR_ORIGIN_REPO=${TRAVIS_PULL_REQUEST_SLUG} --build-arg PR_ORIGIN_COMMITID=${TRAVIS_PULL_REQUEST_SHA} && cd $ROOTDIR
- cd ./test/integrate/dubbo/go-server && docker build . -t ci-provider --build-arg PR_ORIGIN_REPO=${TRAVIS_PULL_REQUEST_SLUG} --build-arg PR_ORIGIN_COMMITID=${TRAVIS_PULL_REQUEST_SHA} && cd $ROOTDIR
- docker run -d --network host ci-provider
- docker run -it --network host ci-consumer

# another registry instance, start it by dep
# start etcd registry insecure listen in [:]:2379
#- docker run -d --network host k8s.gcr.io/etcd:3.3.10 etcd
# start consul registry insecure listen in [:]:8500
#- docker run -d --network host consul
# start nacos registry insecure listen in [:]:8848
#- docker run -d --network host nacos/nacos-server:latest

after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ require (
github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
github.com/zouyx/agollo v0.0.0-20191114083447-dde9fc9f35b8
go.etcd.io/bbolt v1.3.4 // indirect
go.uber.org/atomic v1.4.0
go.uber.org/zap v1.10.0
google.golang.org/grpc v1.22.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/zouyx/agollo v0.0.0-20191114083447-dde9fc9f35b8 h1:k8TV7Gz7cpWpOw/dz71fx8cCZdWoPuckHJ/wkJl+meg=
github.com/zouyx/agollo v0.0.0-20191114083447-dde9fc9f35b8/go.mod h1:S1cAa98KMFv4Sa8SbJ6ZtvOmf0VlgH0QJ1gXI0lBfBY=
go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg=
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
Expand Down Expand Up @@ -548,6 +550,8 @@ golang.org/x/sys v0.0.0-20190508220229-2d0786266e9c/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 h1:4y9KwBHBgBNwDbtu44R5o1fdOCQUEXhbk/P4A9WmJq0=
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand Down
9 changes: 7 additions & 2 deletions registry/directory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type RegistryDirectory struct {
forbidden atomic.Bool
}

// NewRegistryDirectory ...
// NewRegistryDirectory will create a new RegistryDirectory
func NewRegistryDirectory(url *common.URL, registry registry.Registry) (cluster.Directory, error) {
if url.SubURL == nil {
return nil, perrors.Errorf("url is invalid, suburl can not be nil")
Expand All @@ -79,13 +79,14 @@ func NewRegistryDirectory(url *common.URL, registry registry.Registry) (cluster.
return dir, nil
}

//subscribe from registry
// subscribe from registry
func (dir *RegistryDirectory) subscribe(url *common.URL) {
dir.consumerConfigurationListener.addNotifyListener(dir)
dir.referenceConfigurationListener = newReferenceConfigurationListener(dir, url)
dir.registry.Subscribe(url, dir)
}

// Notify monitor changes from registry,and update the cacheServices
func (dir *RegistryDirectory) Notify(event *registry.ServiceEvent) {
go dir.update(event)
}
Expand Down Expand Up @@ -244,6 +245,7 @@ func (dir *RegistryDirectory) List(invocation protocol.Invocation) []protocol.In
return routerChain.Route(invokers, dir.cacheOriginUrl, invocation)
}

// IsAvailable whether the directory is available
func (dir *RegistryDirectory) IsAvailable() bool {
if !dir.BaseDirectory.IsAvailable() {
return dir.BaseDirectory.IsAvailable()
Expand All @@ -258,6 +260,7 @@ func (dir *RegistryDirectory) IsAvailable() bool {
return false
}

// Destroy method
func (dir *RegistryDirectory) Destroy() {
//TODO:unregister & unsubscribe
dir.BaseDirectory.Destroy(func() {
Expand Down Expand Up @@ -297,6 +300,7 @@ func newReferenceConfigurationListener(dir *RegistryDirectory, url *common.URL)
return listener
}

// Process handle events and update Invokers
func (l *referenceConfigurationListener) Process(event *config_center.ConfigChangeEvent) {
l.BaseConfigurationListener.Process(event)
l.directory.refreshInvokers(nil)
Expand All @@ -322,6 +326,7 @@ func (l *consumerConfigurationListener) addNotifyListener(listener registry.Noti
l.listeners = append(l.listeners, listener)
}

// Process handles events from Configuration Center and update Invokers
func (l *consumerConfigurationListener) Process(event *config_center.ConfigChangeEvent) {
l.BaseConfigurationListener.Process(event)
l.directory.refreshInvokers(nil)
Expand Down
36 changes: 36 additions & 0 deletions test/integrate/dubbo/go-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
#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.
#

FROM golang

WORKDIR /go/src/github.com/apache/dubbo-go/test/integrate/dubbo/go-client

ENV CONF_CONSUMER_FILE_PATH "client.yml"
ENV APP_LOG_CONF_FILE "log.yml"

ARG PR_ORIGIN_REPO
ARG PR_ORIGIN_COMMITID

ADD . /go/src/github.com/apache/dubbo-go/test/integrate/dubbo/go-client

# update dubbo-go to current commit id
RUN echo "github.com/apache/dubbo-go will be replace to github.com/${PR_ORIGIN_REPO}@${PR_ORIGIN_COMMITID}"
RUN go mod edit -replace=github.com/apache/dubbo-go=github.com/${PR_ORIGIN_REPO}@${PR_ORIGIN_COMMITID}

RUN go install github.com/apache/dubbo-go/test/integrate/dubbo/go-client

CMD go-client
70 changes: 70 additions & 0 deletions test/integrate/dubbo/go-client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 main

import (
"context"
"fmt"
"time"
)

import (
hessian "github.com/apache/dubbo-go-hessian2"
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config"
_ "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"
)

var (
survivalTimeout int = 10e9
)

func println(format string, args ...interface{}) {
fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...)
}

// they are necessary:
// export CONF_CONSUMER_FILE_PATH="xxx"
// export APP_LOG_CONF_FILE="xxx"
func main() {
hessian.RegisterPOJO(&User{})
config.Load()
time.Sleep(3e9)

println("\n\n\nstart to test dubbo")

go func() {
select {
case <-time.After(time.Minute):
panic("provider not start after client already running 1min")
}
}()
user := &User{}
err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
if err != nil {
panic(err)
}
println("response result: %v\n", user)
}
61 changes: 61 additions & 0 deletions test/integrate/dubbo/go-client/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 : "ikurento.com"
name : "BDTService"
module : "dubbogo user-info client"
version : "0.0.1"
owner : "ZX"
environment : "dev"

registries :
"demoZk":
protocol: "zookeeper"
timeout : "3s"
address: "127.0.0.1:2181"
username: ""
password: ""


references:
"UserProvider":
# 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
registry: "demoZk"
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: "20s"
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"
3 changes: 3 additions & 0 deletions test/integrate/dubbo/go-client/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/apache/dubbo-go/test/integrate/dubbo/go-client

go 1.13
Loading

0 comments on commit 60ff0c4

Please sign in to comment.