Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config enhance rpc dubbo integrate test #232

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* configcenter: uses of different config centers, including zookeeper, apollo and nacos at present.
* direct: A direct invocation example.
* filter: Some examples of different filter, including custom_filter and tpslimit
* general: A general example
* rpc: dubbo directory display dubbo protocol communication
* generic: A generic invocation example
* helloworld: A 101 example
* multi_registry: A multi-registry example
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* configcenter: 使用不同的配置中心,目前支持三种:zookeeper、apollo、和 nacos
* direct: 直连模式
* filter: 使用和扩展不同的 filter,目前包含了 custom_filter 和 tpslimit
* general: 通用例子,展示 zookeeper 注册中心的使用以及不同的配置项
* rpc: dubbo下展示dubbo协议通信调用
* generic: 泛化调用
* helloworld: 入门例子
* multi_registry: 多注册
Expand Down
12 changes: 5 additions & 7 deletions integrate_test/rpc/dubbo/tests/integration/main_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build integration

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand Down Expand Up @@ -119,12 +117,12 @@ func (User) JavaClassName() string {
}

type UserProvider struct {
GetUsers func(req []interface{}) ([]interface{}, error)
GetErr func(ctx context.Context, req []interface{}, rsp *User) error
GetUser func(ctx context.Context, req []interface{}, rsp *User) error
GetUsers func(req []string) ([]*User, error)
GetErr func(ctx context.Context, req *User) (*User, error)
GetUser func(ctx context.Context, req *User) (*User, error)
GetUser0 func(id string, name string) (User, error)
GetUser1 func(ctx context.Context, req []interface{}, rsp *User) error
GetUser2 func(ctx context.Context, req []interface{}, rsp *User) error `dubbo:"getUser"`
GetUser1 func(ctx context.Context, req *User) (*User, error)
GetUser2 func(ctx context.Context, req int32) (*User, error) `dubbo:"getUser"`
GetUser3 func() error
GetGender func(i int32) (Gender, error)
Echo func(ctx context.Context, req interface{}) (interface{}, error) // Echo represent EchoFilter will be used
Expand Down
48 changes: 23 additions & 25 deletions integrate_test/rpc/dubbo/tests/integration/userprovider_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build integration

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand Down Expand Up @@ -35,19 +33,21 @@ import (
)

func TestGetUserA000(t *testing.T) {
user := &User{}
err := userProvider.GetUser(context.TODO(), []interface{}{"A000"}, user)
reqUser := &User{}
reqUser.ID = "000"
user, err := userProvider.GetUser(context.TODO(), reqUser)
assert.Nil(t, err)
assert.Equal(t, "0", user.ID)
assert.Equal(t, "000", user.ID)
assert.Equal(t, "Alex Stocks", user.Name)
assert.Equal(t, int32(31), user.Age)
assert.Equal(t, Gender(pkg.MAN), user.Sex)
assert.NotNil(t, user.Time)
}

func TestGetUserA001(t *testing.T) {
user := &User{}
err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
reqUser := &User{}
reqUser.ID = "001"
user, err := userProvider.GetUser(context.TODO(), reqUser)
assert.Nil(t, err)
assert.Equal(t, "001", user.ID)
assert.Equal(t, "ZhangSheng", user.Name)
Expand All @@ -57,8 +57,9 @@ func TestGetUserA001(t *testing.T) {
}

func TestGetUserA002(t *testing.T) {
user := &User{}
err := userProvider.GetUser(context.TODO(), []interface{}{"A002"}, user)
reqUser := &User{}
reqUser.ID = "002"
user, err := userProvider.GetUser(context.TODO(), reqUser)
assert.Nil(t, err)
assert.Equal(t, "002", user.ID)
assert.Equal(t, "Lily", user.Name)
Expand All @@ -68,8 +69,9 @@ func TestGetUserA002(t *testing.T) {
}

func TestGetUserA003(t *testing.T) {
user := &User{}
err := userProvider.GetUser(context.TODO(), []interface{}{"A003"}, user)
reqUser := &User{}
reqUser.ID = "003"
user, err := userProvider.GetUser(context.TODO(), reqUser)
assert.Nil(t, err)
assert.Equal(t, "113", user.ID)
assert.Equal(t, "Moorse", user.Name)
Expand All @@ -79,37 +81,33 @@ func TestGetUserA003(t *testing.T) {
}

func TestGetUser0(t *testing.T) {
user, err := userProvider.GetUser0("A003", "Moorse")
user, err := userProvider.GetUser0("003", "Moorse")
assert.Nil(t, err)
assert.NotNil(t, user)

user, err = userProvider.GetUser0("A003", "MOORSE")
user, err = userProvider.GetUser0("003", "MOORSE")
assert.NotNil(t, err)
}

func TestGetUser2(t *testing.T) {
user := &User{}
err := userProvider.GetUser2(context.TODO(), []interface{}{int32(64)}, user)
user, err := userProvider.GetUser2(context.TODO(), int32(64))
assert.Nil(t, err)
assert.Equal(t, "64", user.ID)
}

func TestGetUser3(t *testing.T) {
err := userProvider.GetUser3()
assert.Nil(t, err)
}

func TestGetErr(t *testing.T) {
user := &User{}
err := userProvider.GetErr(context.TODO(), []interface{}{"A003"}, user)
reqUser := &User{}
reqUser.ID = "003"
_, err := userProvider.GetErr(context.TODO(), reqUser)
assert.IsType(t, &java_exception.Throwable{}, err)
}

func TestGetUsers(t *testing.T) {
users, err := userProvider.GetUsers([]interface{}{[]interface{}{"A002", "A003"}})
reqUsers := []string{"002", "003"}
users, err := userProvider.GetUsers(reqUsers)
assert.Nil(t, err)
assert.Equal(t, "Lily", users[0].(*User).Name)
assert.Equal(t, "Moorse", users[1].(*User).Name)
assert.Equal(t, "Lily", users[0].Name)
assert.Equal(t, "Moorse", users[1].Name)
}

func TestGetGender(t *testing.T) {
Expand Down
26 changes: 10 additions & 16 deletions rpc/dubbo/go-client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ func test() {
logger.Info("res: %v\n", res)

logger.Info("\n\n\nstart to test dubbo")
user := &pkg.User{}
user, err = userProvider.GetUser(context.TODO(), []interface{}{"A003"})
reqUser := &pkg.User{}
reqUser.ID = "003"
user, err := userProvider.GetUser(context.TODO(), reqUser)
if err != nil {
panic(err)
}
Expand All @@ -79,14 +80,14 @@ func test() {
}

logger.Info("\n\n\nstart to test dubbo - GetUser0")
ret, err := userProvider.GetUser0("A003", "Moorse")
ret, err := userProvider.GetUser0("003", "Moorse")
if err != nil {
panic(err)
}
logger.Info("response result: %v", ret)

logger.Info("\n\n\nstart to test dubbo - GetUsers")
ret1, err := userProvider.GetUsers([]interface{}{[]interface{}{"A002", "A003"}})
ret1, err := userProvider.GetUsers([]string{"002", "003"})
if err != nil {
panic(err)
}
Expand All @@ -95,30 +96,23 @@ func test() {
logger.Info("\n\n\nstart to test dubbo - getUser")
user = &pkg.User{}
var i int32 = 1
user, err = userProvider.GetUser2(context.TODO(), []interface{}{i})
if err != nil {
panic(err)
}
logger.Info("response result: %v", user)

logger.Info("\n\n\nstart to test dubbo - getUser - overload")
user = &pkg.User{}
user, err = userProvider.GetUser2(context.TODO(), []interface{}{i, "overload"})
user, err = userProvider.GetUser2(context.TODO(), i)
if err != nil {
panic(err)
}
logger.Info("response result: %v", user)

logger.Info("\n\n\nstart to test dubbo - getErr")
user = &pkg.User{}
user, err = userProvider.GetErr(context.TODO(), []interface{}{"A003"})
reqUser.ID = "003"
user, err = userProvider.GetErr(context.TODO(), reqUser)
if err == nil {
panic("err is nil")
}
logger.Info("getErr - error: %v", err)

logger.Info("\n\n\nstart to test dubbo illegal method")
user, err = userProvider.GetUser1(context.TODO(), []interface{}{"A003"})
reqUser.ID = "003"
user, err = userProvider.GetUser1(context.TODO(), reqUser)
if err == nil {
panic("err is nil")
}
Expand Down
68 changes: 34 additions & 34 deletions rpc/dubbo/go-client/pkg/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ func (User) JavaClassName() string {
}

type UserProvider struct {
GetUsers func(req []interface{}) ([]interface{}, error)
GetErr func(ctx context.Context, req []interface{}) (*User, error)
GetUsers func(req []string) ([]*User, error)
GetErr func(ctx context.Context, req *User) (*User, error)

GetUser func(ctx context.Context, req []interface{}) (*User, error)
GetUser func(ctx context.Context, req *User) (*User, error)

GetUserNew func(ctx context.Context, req1, req2 *User) (*User, error)

GetUser0 func(id string, name string) (User, error)
GetUser1 func(ctx context.Context, req []interface{}) (*User, error)
GetUser2 func(ctx context.Context, req []interface{}) (*User, error) `dubbo:"getUser"`
GetUser1 func(ctx context.Context, req *User) (*User, error)
GetUser2 func(ctx context.Context, req int32) (*User, error) `dubbo:"getUser"`
GetUser3 func() error
GetGender func(i int32) (Gender, error)
Echo func(ctx context.Context, req interface{}) (interface{}, error) // Echo represent EchoFilter will be used
Expand All @@ -107,32 +107,32 @@ func (u *UserProvider) Reference() string {
return "UserProvider"
}

type UserProvider1 struct {
GetUsers func(req []interface{}) ([]interface{}, error)
GetErr func(ctx context.Context, req []interface{}) (*User, error)
GetUser func(ctx context.Context, req []interface{}) (*User, error)
GetUser0 func(id string, name string) (User, error)
GetUser1 func(ctx context.Context, req []interface{}) (*User, error)
GetUser2 func(ctx context.Context, req []interface{}) (*User, error) `dubbo:"getUser"`
GetUser3 func() error
Echo func(ctx context.Context, req interface{}) (interface{}, error) // Echo represent EchoFilter will be used
}

func (u *UserProvider1) Reference() string {
return "UserProvider1"
}

type UserProvider2 struct {
GetUsers func(req []interface{}) ([]interface{}, error)
GetErr func(ctx context.Context, req []interface{}) (*User, error)
GetUser func(ctx context.Context, req []interface{}) (*User, error)
GetUser0 func(id string, name string) (User, error)
GetUser1 func(ctx context.Context, req []interface{}) (*User, error)
GetUser2 func(ctx context.Context, req []interface{}) (*User, error) `dubbo:"getUser"`
GetUser3 func() error
Echo func(ctx context.Context, req interface{}) (interface{}, error) // Echo represent EchoFilter will be used
}

func (u *UserProvider2) Reference() string {
return "UserProvider2"
}
//type UserProvider1 struct {
// GetUsers func(req []interface{}) ([]interface{}, error)
// GetErr func(ctx context.Context, req []interface{}) (*User, error)
// GetUser func(ctx context.Context, req []interface{}) (*User, error)
// GetUser0 func(id string, name string) (User, error)
// GetUser1 func(ctx context.Context, req []interface{}) (*User, error)
// GetUser2 func(ctx context.Context, req []interface{}) (*User, error) `dubbo:"getUser"`
// GetUser3 func() error
// Echo func(ctx context.Context, req interface{}) (interface{}, error) // Echo represent EchoFilter will be used
//}
//
//func (u *UserProvider1) Reference() string {
// return "UserProvider1"
//}
//
//type UserProvider2 struct {
// GetUsers func(req []interface{}) ([]interface{}, error)
// GetErr func(ctx context.Context, req []interface{}) (*User, error)
// GetUser func(ctx context.Context, req []interface{}) (*User, error)
// GetUser0 func(id string, name string) (User, error)
// GetUser1 func(ctx context.Context, req []interface{}) (*User, error)
// GetUser2 func(ctx context.Context, req []interface{}) (*User, error) `dubbo:"getUser"`
// GetUser3 func() error
// Echo func(ctx context.Context, req interface{}) (interface{}, error) // Echo represent EchoFilter will be used
//}
//
//func (u *UserProvider2) Reference() string {
// return "UserProvider2"
//}
10 changes: 5 additions & 5 deletions rpc/dubbo/go-server/pkg/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ type (

var (
DefaultUser = User{
ID: "0", Name: "Alex Stocks", Age: 31,
ID: "000", Name: "Alex Stocks", Age: 31,
Sex: Gender(MAN),
}

userMap = make(map[string]User)
)

func init() {
userMap["A000"] = DefaultUser
userMap["A001"] = User{ID: "001", Name: "ZhangSheng", Age: 18, Sex: Gender(MAN)}
userMap["A002"] = User{ID: "002", Name: "Lily", Age: 20, Sex: Gender(WOMAN)}
userMap["A003"] = User{ID: "113", Name: "Moorse", Age: 30, Sex: Gender(WOMAN)}
userMap["000"] = DefaultUser
userMap["001"] = User{ID: "001", Name: "ZhangSheng", Age: 18, Sex: Gender(MAN)}
userMap["002"] = User{ID: "002", Name: "Lily", Age: 20, Sex: Gender(WOMAN)}
userMap["003"] = User{ID: "113", Name: "Moorse", Age: 30, Sex: Gender(WOMAN)}
for k, v := range userMap {
v.Time = time.Now()
userMap[k] = v
Expand Down
19 changes: 9 additions & 10 deletions rpc/dubbo/go-server/pkg/user_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ func (u *UserProvider) getUser(userID string) (*User, error) {
return nil, fmt.Errorf("invalid user id:%s", userID)
}

func (u *UserProvider) GetUser(ctx context.Context, req []interface{}) (*User, error) {
func (u *UserProvider) GetUser(ctx context.Context, req *User) (*User, error) {
var (
err error
user *User
)

gxlog.CInfo("req:%#v", req)
user, err = u.getUser(req[0].(string))
user, err = u.getUser(req.ID)
if err == nil {
gxlog.CInfo("rsp:%#v", user)
}
Expand All @@ -77,40 +77,39 @@ func (u *UserProvider) GetUser0(id string, name string) (User, error) {
return *user, err
}

func (u *UserProvider) GetUser2(ctx context.Context, req []interface{}) (*User, error) {
func (u *UserProvider) GetUser2(ctx context.Context, req int32) (*User, error) {
var err error

gxlog.CInfo("req:%#v", req)
user := &User{}
user.ID = strconv.Itoa(int(req[0].(int32)))
user.ID = strconv.Itoa(int(req))
return user, err
}

func (u *UserProvider) GetUser3() error {
return nil
}

func (u *UserProvider) GetErr(ctx context.Context, req []interface{}) (*User, error) {
func (u *UserProvider) GetErr(ctx context.Context, req *User) (*User, error) {
return nil, java_exception.NewThrowable("exception")
}

func (u *UserProvider) GetUsers(req []interface{}) ([]interface{}, error) {
func (u *UserProvider) GetUsers(req []string) ([]*User, error) {
var err error

gxlog.CInfo("req:%s", req)
t := req[0].([]interface{})
user, err := u.getUser(t[0].(string))
user, err := u.getUser(req[0])
if err != nil {
return nil, err
}
gxlog.CInfo("user:%v", user)
user1, err := u.getUser(t[1].(string))
user1, err := u.getUser(req[1])
if err != nil {
return nil, err
}
gxlog.CInfo("user1:%v", user1)

return []interface{}{user, user1}, err
return []*User{user, user1}, err
}

func (s *UserProvider) GetGender(i int32) (hessian.JavaEnum, error) {
Expand Down
2 changes: 2 additions & 0 deletions start_integrate_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ array+=("rpc/triple/codec-extension")
array+=("rpc/triple/hessian2")
array+=("rpc/triple/pb/dubbogo-grpc")
array+=("rpc/grpc")
# dubbo
array+=("rpc/dubbo")


DOCKER_DIR=$(pwd)/integrate_test/dockercompose
Expand Down