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

Fix: ineffassign #127

Merged
merged 3 commits into from
Jul 11, 2019
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
9 changes: 5 additions & 4 deletions common/rpc_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,23 @@ func (s *TestService1) Version() string {
func TestServiceMap_Register(t *testing.T) {
// lowercase
s0 := &testService{}
methods, err := ServiceMap.Register("testporotocol", s0)
// methods, err := ServiceMap.Register("testporotocol", s0)
_, err := ServiceMap.Register("testporotocol", s0)
AlexStocks marked this conversation as resolved.
Show resolved Hide resolved
assert.EqualError(t, err, "type testService is not exported")

// succ
s := &TestService{}
methods, err = ServiceMap.Register("testporotocol", s)
methods, err := ServiceMap.Register("testporotocol", s)
assert.NoError(t, err)
assert.Equal(t, "MethodOne,MethodThree,methodTwo", methods)

// repeat
methods, err = ServiceMap.Register("testporotocol", s)
_, err = ServiceMap.Register("testporotocol", s)
assert.EqualError(t, err, "service already defined: com.test.Path")

// no method
s1 := &TestService1{}
methods, err = ServiceMap.Register("testporotocol", s1)
_, err = ServiceMap.Register("testporotocol", s1)
assert.EqualError(t, err, "type com.test.Path1 has no exported methods of suitable type")

ServiceMap = &serviceMap{
Expand Down
4 changes: 2 additions & 2 deletions config_center/zookeeper/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func newZookeeperDynamicConfiguration(url *common.URL) (*zookeeperDynamicConfigu

err = c.client.Create(c.rootPath)
c.listener.ListenServiceEvent(c.rootPath, c.cacheListener)
return c, nil
return c, err

}

Expand All @@ -95,7 +95,7 @@ func newMockZookeeperDynamicConfiguration(url *common.URL, opts ...zookeeper.Opt

err = c.client.Create(c.rootPath)
go c.listener.ListenServiceEvent(c.rootPath, c.cacheListener)
return tc, c, nil
return tc, c, err

}

Expand Down
4 changes: 2 additions & 2 deletions protocol/dubbo/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ func TestClient_Call(t *testing.T) {
}
c.pool = newGettyRPCClientConnPool(c, clientConf.PoolSize, time.Duration(int(time.Second)*clientConf.PoolTTL))

user := &User{}
// user := &User{}
//err := c.Call("127.0.0.1:20000", url, "GetBigPkg", []interface{}{nil}, user)
//assert.NoError(t, err)
//assert.NotEqual(t, "", user.Id)
//assert.NotEqual(t, "", user.Name)

user = &User{}
user := &User{}
err := c.Call("127.0.0.1:20000", url, "GetUser", []interface{}{"1", "username"}, user)
assert.NoError(t, err)
assert.Equal(t, User{Id: "1", Name: "username"}, *user)
Expand Down
2 changes: 1 addition & 1 deletion protocol/jsonrpc/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestJsonClientCodec_Write(t *testing.T) {
assert.Equal(t, "{\"jsonrpc\":\"2.0\",\"method\":\"GetUser\",\"params\":[\"args\",2],\"id\":1}\n", string(data))

cd.Args = 1
data, err = codec.Write(cd)
_, err = codec.Write(cd)
assert.EqualError(t, err, "unsupported param type: int")
}

Expand Down
2 changes: 0 additions & 2 deletions registry/zookeeper/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ func (r *zkRegistry) Register(conf common.URL) error {
role, _ := strconv.Atoi(r.URL.GetParam(constant.ROLE_KEY, ""))
switch role {
case common.CONSUMER:
ok = false
r.cltLock.Lock()
_, ok = r.services[conf.Key()]
r.cltLock.Unlock()
Expand All @@ -232,7 +231,6 @@ func (r *zkRegistry) Register(conf common.URL) error {
case common.PROVIDER:

// 检验服务是否已经注册过
ok = false
r.cltLock.Lock()
// 注意此处与consumerZookeeperRegistry的差异,consumer用的是conf.Path,
// 因为consumer要提供watch功能给selector使用, provider允许注册同一个service的多个group or version
Expand Down
18 changes: 9 additions & 9 deletions registry/zookeeper/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func Test_Register(t *testing.T) {
regurl, _ := common.NewURL(context.TODO(), "registry://127.0.0.1:1111", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"}))

ts, reg, err := newMockZkRegistry(&regurl)
ts, reg, _ := newMockZkRegistry(&regurl)
defer ts.Stop()
err = reg.Register(url)
err := reg.Register(url)
children, _ := reg.client.GetChildren("/dubbo/com.ikurento.user.UserProvider/providers")
assert.Regexp(t, ".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26category%3Dproviders%26cluster%3Dmock%26dubbo%3Ddubbo-provider-golang-2.6.0%26.*provider", children)
assert.NoError(t, err)
Expand All @@ -49,10 +49,10 @@ func Test_Register(t *testing.T) {
func Test_Subscribe(t *testing.T) {
regurl, _ := common.NewURL(context.TODO(), "registry://127.0.0.1:1111", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"}))
ts, reg, err := newMockZkRegistry(&regurl)
ts, reg, _ := newMockZkRegistry(&regurl)

//provider register
err = reg.Register(url)
err := reg.Register(url)
assert.NoError(t, err)

if err != nil {
Expand All @@ -61,12 +61,12 @@ func Test_Subscribe(t *testing.T) {

//consumer register
regurl.Params.Set(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))
_, reg2, err := newMockZkRegistry(&regurl, zookeeper.WithTestCluster(ts))
_, reg2, _ := newMockZkRegistry(&regurl, zookeeper.WithTestCluster(ts))

err = reg2.Register(url)
listener, err := reg2.Subscribe(url)
reg2.Register(url)
listener, _ := reg2.Subscribe(url)

serviceEvent, err := listener.Next()
serviceEvent, _ := listener.Next()
assert.NoError(t, err)
if err != nil {
return
Expand Down Expand Up @@ -103,7 +103,7 @@ func Test_ProviderDestory(t *testing.T) {
defer ts.Stop()

assert.NoError(t, err)
err = reg.Register(url)
reg.Register(url)

//listener.Close()
time.Sleep(1e9)
Expand Down