Skip to content

Commit

Permalink
fix remoting linter error
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks committed Jan 3, 2021
1 parent 971c854 commit 3e08d41
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 65 deletions.
9 changes: 7 additions & 2 deletions cluster/router/chain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ conditions:

zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, localIP, ts.Servers[0].Port))
configuration, err := extension.GetConfigCenterFactory(zk).GetDynamicConfiguration(zkUrl)
assert.NoError(t, err)
config.GetEnvInstance().SetDynamicConfiguration(configuration)

chain, err := NewRouterChain(getConditionRouteUrl(applicationKey))
Expand All @@ -154,11 +155,15 @@ conditions:

func TestRouterChainRoute(t *testing.T) {
ts, z, _, err := zookeeper.NewMockZookeeperClient("test", 15*time.Second)
defer ts.Stop()
defer z.Close()
defer func() {
err = ts.Stop()
assert.NoError(t, err)
z.Close()
}()

zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, localIP, ts.Servers[0].Port))
configuration, err := extension.GetConfigCenterFactory(zk).GetDynamicConfiguration(zkUrl)
assert.NoError(t, err)
config.GetEnvInstance().SetDynamicConfiguration(configuration)

chain, err := NewRouterChain(getConditionRouteUrl(applicationKey))
Expand Down
20 changes: 16 additions & 4 deletions config_center/zookeeper/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ func initZkData(group string, t *testing.T) (*zk.TestCluster, *zookeeperDynamicC

func TestGetConfig(t *testing.T) {
ts, reg := initZkData("dubbo", t)
defer ts.Stop()
defer func() {
err := ts.Stop()
assert.NoError(t, err)
}()
configs, err := reg.GetProperties(dubboPropertyFileName, config_center.WithGroup("dubbo"))
assert.NoError(t, err)
m, err := reg.Parser().Parse(configs)
Expand All @@ -118,7 +121,10 @@ func TestGetConfig(t *testing.T) {

func TestAddListener(t *testing.T) {
ts, reg := initZkData("", t)
defer ts.Stop()
defer func() {
err := ts.Stop()
assert.NoError(t, err)
}()
listener := &mockDataListener{}
reg.AddListener(dubboPropertyFileName, listener)
listener.wg.Add(1)
Expand Down Expand Up @@ -151,7 +157,10 @@ func TestAddListener(t *testing.T) {

func TestRemoveListener(t *testing.T) {
ts, reg := initZkData("", t)
defer ts.Stop()
defer func() {
err := ts.Stop()
assert.NoError(t, err)
}()
listener := &mockDataListener{}
reg.AddListener(dubboPropertyFileName, listener)
listener.wg.Add(1)
Expand Down Expand Up @@ -189,7 +198,10 @@ func TestZookeeperDynamicConfigurationPublishConfig(t *testing.T) {
customGroup := "Custom Group"
key := "myKey"
ts, zk := initZkData(config_center.DEFAULT_GROUP, t)
defer ts.Stop()
defer func() {
err := ts.Stop()
assert.NoError(t, err)
}()
err := zk.PublishConfig(key, customGroup, value)
assert.Nil(t, err)
result, err := zk.GetInternalProperty("myKey", config_center.WithGroup(customGroup))
Expand Down
19 changes: 16 additions & 3 deletions metadata/report/delegate/delegate_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ func (mr *MetadataReport) SaveServiceMetadata(identifier *identifier.ServiceMeta
if mr.syncReport {
return report.SaveServiceMetadata(identifier, url)
}
go report.SaveServiceMetadata(identifier, url)
go func() {
if err := report.SaveServiceMetadata(identifier, url); err != nil {
logger.Warnf("report.SaveServiceMetadata(identifier:%v, url:%v) = error:%v", identifier, url, err)
}
}()
return nil
}

Expand All @@ -230,7 +234,11 @@ func (mr *MetadataReport) RemoveServiceMetadata(identifier *identifier.ServiceMe
if mr.syncReport {
return report.RemoveServiceMetadata(identifier)
}
go report.RemoveServiceMetadata(identifier)
go func() {
if err := report.RemoveServiceMetadata(identifier); err != nil {
logger.Warnf("report.RemoveServiceMetadata(identifier:%v) = error:%v", identifier, err)
}
}()
return nil
}

Expand All @@ -255,7 +263,12 @@ func (mr *MetadataReport) SaveSubscribedData(identifier *identifier.SubscriberMe
if mr.syncReport {
return report.SaveSubscribedData(identifier, string(bytes))
}
go report.SaveSubscribedData(identifier, string(bytes))
go func() {
if err := report.SaveSubscribedData(identifier, string(bytes)); err != nil {
logger.Warnf("report.SaveSubscribedData(identifier:%v, string(bytes):%v) = error: %v",
identifier, string(bytes), err)
}
}()
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions metadata/report/etcd/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ func TestEtcdMetadataReport_CRUD(t *testing.T) {
assert.Nil(t, err)

serviceMi := newServiceMetadataIdentifier()
serviceUrl, _ := common.NewURL("registry://localhost:8848", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
metadataReport.SaveServiceMetadata(serviceMi, serviceUrl)
serviceUrl, err := common.NewURL("registry://localhost:8848", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
assert.Nil(t, err)
err = metadataReport.SaveServiceMetadata(serviceMi, serviceUrl)
assert.Nil(t, err)

subMi := newSubscribeMetadataIdentifier()
Expand Down
19 changes: 13 additions & 6 deletions metadata/service/inmemory/service_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,19 @@ func TestNewMetadataService(t *testing.T) {
assert.Nil(t, err)
_, err = pxy.GetServiceDefinitionByServiceKey("any")
assert.Nil(t, err)
pxy.ExportURL(&common.URL{})
pxy.SubscribeURL(&common.URL{})
pxy.MethodMapper()
pxy.UnexportURL(&common.URL{})
pxy.RefreshMetadata(constant.ANY_VALUE, constant.ANY_VALUE)

ok, err := pxy.ExportURL(&common.URL{})
assert.False(t, ok)
assert.NoError(t, err)
ok, err = pxy.SubscribeURL(&common.URL{})
assert.False(t, ok)
assert.NoError(t, err)
m := pxy.MethodMapper()
assert.True(t, len(m) == 0)
err = pxy.UnexportURL(&common.URL{})
assert.NoError(t, err)
ok, err = pxy.RefreshMetadata(constant.ANY_VALUE, constant.ANY_VALUE)
assert.False(t, ok)
assert.NoError(t, err)
}

func createPxy() service.MetadataService {
Expand Down
41 changes: 29 additions & 12 deletions metadata/service/inmemory/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func TestMetadataService(t *testing.T) {
"owner=ZX&pid=1447&revision=0.0.1&side=provider&timeout=3000&timestamp=1556509797245&group=%v&version=%v&bean.name=%v",
protocol, serviceName, group, version, beanName))
assert.NoError(t, err)
mts.ExportURL(u2)
ok, err := mts.ExportURL(u2)
assert.True(t, ok)
assert.NoError(t, err)

u3, err := common.NewURL(fmt.Sprintf(
"%v://127.0.0.1:20000/com.ikurento.user.UserProvider3?anyhost=true&"+
Expand All @@ -55,7 +57,9 @@ func TestMetadataService(t *testing.T) {
"owner=ZX&pid=1447&revision=0.0.1&side=provider&timeout=3000&timestamp=1556509797245&group=%v&version=%v&bean.name=%v",
protocol, serviceName, group, version, beanName))
assert.NoError(t, err)
mts.ExportURL(u3)
ok, err = mts.ExportURL(u3)
assert.True(t, ok)
assert.NoError(t, err)

u, err := common.NewURL(fmt.Sprintf(
"%v://127.0.0.1:20000/com.ikurento.user.UserProvider1?anyhost=true&"+
Expand All @@ -64,32 +68,45 @@ func TestMetadataService(t *testing.T) {
"owner=ZX&pid=1447&revision=0.0.1&side=provider&timeout=3000&timestamp=1556509797245&group=%v&version=%v&bean.name=%v",
protocol, serviceName, group, version, beanName))
assert.NoError(t, err)
mts.ExportURL(u)
ok, err = mts.ExportURL(u)
assert.True(t, ok)
assert.NoError(t, err)
list, _ := mts.GetExportedURLs(serviceName, group, version, protocol)
assert.Equal(t, 3, len(list))
mts.SubscribeURL(u)
ok, err = mts.SubscribeURL(u)
assert.True(t, ok)
assert.NoError(t, err)

mts.SubscribeURL(u)
list2, _ := mts.GetSubscribedURLs()
ok, err = mts.SubscribeURL(u)
assert.False(t, ok)
assert.NoError(t, err)
list2, err := mts.GetSubscribedURLs()
assert.Equal(t, 1, len(list2))
assert.NoError(t, err)

mts.UnexportURL(u)
err = mts.UnexportURL(u)
assert.NoError(t, err)
list3, _ := mts.GetExportedURLs(serviceName, group, version, protocol)
assert.Equal(t, 2, len(list3))

mts.UnsubscribeURL(u)
err = mts.UnsubscribeURL(u)
assert.NoError(t, err)
list4, _ := mts.GetSubscribedURLs()
assert.Equal(t, 0, len(list4))

userProvider := &definition.UserProvider{}
common.ServiceMap.Register(serviceName, protocol, group, version, userProvider)
mts.PublishServiceDefinition(u)
_, err = common.ServiceMap.Register(serviceName, protocol, group, version, userProvider)
assert.NoError(t, err)
err = mts.PublishServiceDefinition(u)
assert.NoError(t, err)
expected := "{\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," +
"\"Methods\":[{\"Name\":\"GetUser\",\"ParameterTypes\":[\"slice\"],\"ReturnType\":\"ptr\"," +
"\"Parameters\":null}],\"Types\":null}"
def1, _ := mts.GetServiceDefinition(serviceName, group, version)
def1, err := mts.GetServiceDefinition(serviceName, group, version)
assert.Equal(t, expected, def1)
assert.NoError(t, err)
serviceKey := definition.ServiceDescriperBuild(serviceName, group, version)
def2, _ := mts.GetServiceDefinitionByServiceKey(serviceKey)
def2, err := mts.GetServiceDefinitionByServiceKey(serviceKey)
assert.Equal(t, expected, def2)
assert.NoError(t, err)
}
34 changes: 22 additions & 12 deletions metadata/service/remote/service_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,28 @@ func TestMetadataServiceProxy_GetServiceDefinition(t *testing.T) {
// in fact, we don't use them
func TestMetadataServiceProxy(t *testing.T) {
pxy := createProxy()
pxy.ServiceName()
pxy.PublishServiceDefinition(&common.URL{})
pxy.Version()
pxy.GetSubscribedURLs()
pxy.UnsubscribeURL(&common.URL{})
pxy.GetServiceDefinitionByServiceKey("any")
pxy.ExportURL(&common.URL{})
pxy.SubscribeURL(&common.URL{})
pxy.MethodMapper()
pxy.UnexportURL(&common.URL{})
pxy.Reference()
pxy.RefreshMetadata(constant.ANY_VALUE, constant.ANY_VALUE)
_, err := pxy.ServiceName()
assert.NoError(t, err)
err = pxy.PublishServiceDefinition(&common.URL{})
assert.NoError(t, err)
_, err = pxy.Version()
assert.NoError(t, err)
_, err = pxy.GetSubscribedURLs()
assert.NoError(t, err)
err = pxy.UnsubscribeURL(&common.URL{})
assert.NoError(t, err)
_, err = pxy.GetServiceDefinitionByServiceKey("any")
assert.NoError(t, err)
_, err = pxy.ExportURL(&common.URL{})
assert.NoError(t, err)
_, err = pxy.SubscribeURL(&common.URL{})
assert.NoError(t, err)
_ = pxy.MethodMapper()
err = pxy.UnexportURL(&common.URL{})
assert.NoError(t, err)
_ = pxy.Reference()
_, err = pxy.RefreshMetadata(constant.ANY_VALUE, constant.ANY_VALUE)
assert.NoError(t, err)
}

func createProxy() service.MetadataService {
Expand Down
17 changes: 11 additions & 6 deletions protocol/dubbo/hessian2/hessian_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,29 +220,34 @@ func packRequest(service Service, header DubboHeader, req interface{}) ([]byte,
// body
//////////////////////////////////////////
if hb {
encoder.Encode(nil)
if err := encoder.Encode(nil); err != nil {
logger.Warnf("Encode(nil) = error: %v", err)
}
goto END
}

// dubbo version + path + version + method
if err := encoder.Encode(DEFAULT_DUBBO_PROTOCOL_VERSION); err != nil {
logger.Error("Encode(DEFAULT_DUBBO_PROTOCOL_VERSION) = error: %v", err)
logger.Warnf("Encode(DEFAULT_DUBBO_PROTOCOL_VERSION) = error: %v", err)
}
if err := encoder.Encode(service.Path); err != nil {
logger.Error("Encode(service.Path) = error: %v", err)
logger.Warnf("Encode(service.Path) = error: %v", err)
}
if err := encoder.Encode(service.Version); err != nil {
logger.Error("Encode(service.Version) = error: %v", err)
logger.Warnf("Encode(service.Version) = error: %v", err)
}
if err := encoder.Encode(service.Method); err != nil {
logger.Error("Encode(service.Method) = error: %v", err)
logger.Warnf("Encode(service.Method) = error: %v", err)
}

// args = args type list + args value list
if types, err = getArgsTypeList(args); err != nil {
return nil, perrors.Wrapf(err, " PackRequest(args:%+v)", args)
}
encoder.Encode(types)
if err := encoder.Encode(types); err != nil {
logger.Warnf("Encode(types:%v) = error: %v", types, err)
}

for _, v := range args {
encoder.Encode(v)
}
Expand Down
4 changes: 3 additions & 1 deletion registry/file/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ func newFileSystemServiceDiscovery(name string) (registry.ServiceDiscovery, erro
}

extension.AddCustomShutdownCallback(func() {
sd.Destroy()
if err := sd.Destroy(); err != nil {
logger.Warnf("sd.Destroy() = error:%v", err)
}
})

for _, v := range sd.GetServices().Values() {
Expand Down
12 changes: 9 additions & 3 deletions registry/file/service_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ func TestNewFileSystemServiceDiscoveryAndDestroy(t *testing.T) {
serviceDiscovery, err := newFileSystemServiceDiscovery(testName)
assert.NoError(t, err)
assert.NotNil(t, serviceDiscovery)
defer serviceDiscovery.Destroy()
defer func () {
err = serviceDiscovery.Destroy()
assert.Nil(t, err)
}()
}

func TestCURDFileSystemServiceDiscovery(t *testing.T) {
Expand Down Expand Up @@ -78,8 +81,11 @@ func TestCURDFileSystemServiceDiscovery(t *testing.T) {
assert.NoError(t, err)

err = serviceDiscovery.Register(r1)

defer serviceDiscovery.Destroy()
assert.NoError(t, err)
defer func () {
err = serviceDiscovery.Destroy()
assert.NoError(t, err)
}()
}

func prepareData() {
Expand Down
7 changes: 5 additions & 2 deletions remoting/getty/getty_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func getClient(url *common.URL) *Client {

exchangeClient := remoting.NewExchangeClient(url, client, 5*time.Second, false)
client.SetExchangeClient(exchangeClient)
client.Connect(url)
if err := client.Connect(url); err != nil {
return nil
}
return client
}

Expand Down Expand Up @@ -396,7 +398,8 @@ func InitTest(t *testing.T) (*Server, *common.URL) {
"side=provider&timeout=3000&timestamp=1556509797245&bean.name=UserProvider")
// init server
userProvider := &UserProvider{}
common.ServiceMap.Register("", url.Protocol, "", "0.0.1", userProvider)
_, err = common.ServiceMap.Register("", url.Protocol, "", "0.0.1", userProvider)
assert.NoError(t, err)
invoker := &proxy_factory.ProxyInvoker{
BaseInvoker: *protocol.NewBaseInvoker(url),
}
Expand Down
20 changes: 15 additions & 5 deletions remoting/getty/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,23 @@ func (c *gettyRPCClient) newSession(session getty.Session) error {
panic(fmt.Sprintf("%s, session.conn{%#v} is not tcp connection\n", session.Stat(), session.Conn()))
}

tcpConn.SetNoDelay(conf.GettySessionParam.TcpNoDelay)
tcpConn.SetKeepAlive(conf.GettySessionParam.TcpKeepAlive)
if err := tcpConn.SetNoDelay(conf.GettySessionParam.TcpNoDelay); err != nil {
logger.Error("tcpConn.SetNoDelay() = error:%v", err)
}
if err := tcpConn.SetKeepAlive(conf.GettySessionParam.TcpKeepAlive); err != nil {
logger.Error("tcpConn.SetKeepAlive() = error:%v", err)
}
if conf.GettySessionParam.TcpKeepAlive {
tcpConn.SetKeepAlivePeriod(conf.GettySessionParam.keepAlivePeriod)
if err := tcpConn.SetKeepAlivePeriod(conf.GettySessionParam.keepAlivePeriod); err != nil {
logger.Error("tcpConn.SetKeepAlivePeriod() = error:%v", err)
}
}
if err := tcpConn.SetReadBuffer(conf.GettySessionParam.TcpRBufSize); err != nil {
logger.Error("tcpConn.SetReadBuffer() = error:%v", err)
}
if err := tcpConn.SetWriteBuffer(conf.GettySessionParam.TcpWBufSize); err != nil {
logger.Error("tcpConn.SetWriteBuffer() = error:%v", err)
}
tcpConn.SetReadBuffer(conf.GettySessionParam.TcpRBufSize)
tcpConn.SetWriteBuffer(conf.GettySessionParam.TcpWBufSize)

session.SetName(conf.GettySessionParam.SessionName)
session.SetMaxMsgLen(conf.GettySessionParam.MaxMsgLen)
Expand Down
Loading

0 comments on commit 3e08d41

Please sign in to comment.