Skip to content

Commit

Permalink
fix review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
flycash committed Nov 22, 2019
1 parent a17a95a commit 14dec2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
9 changes: 4 additions & 5 deletions config/graceful_shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,17 @@ func destroyProviderProtocols(consumerProtocols *gxset.HashSet) {

logger.Info("Graceful shutdown --- Destroy provider's protocols. ")

if providerConfig == nil || providerConfig.ProtocolConf == nil {
if providerConfig == nil || providerConfig.Protocols == nil {
return
}

protocols := providerConfig.ProtocolConf.(map[interface{}]interface{})
for name := range protocols {
for _, protocol := range providerConfig.Protocols {

// the protocol is the consumer's protocol too, we can not destroy it.
if consumerProtocols.Contains(name) {
if consumerProtocols.Contains(protocol.Name) {
continue
}
extension.GetProtocol(name.(string)).Destroy()
extension.GetProtocol(protocol.Name).Destroy()
}
}

Expand Down
29 changes: 18 additions & 11 deletions config/graceful_shutdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,38 @@ func TestBeforeShutdown(t *testing.T) {
return &mockRegistryProtocol{}
})

protocolConfigs := make(map[interface{}]interface{}, 16)
protocolConfigs[constant.DUBBO] = "aaa"
// protocolConfigs := make(map[interface{}]interface{}, 16)
consumerReferences := map[string]*ReferenceConfig{}
consumerReferences[constant.DUBBO] = &ReferenceConfig{
Protocol: constant.DUBBO,
}

// without configuration
BeforeShutdown()

consumerConfig = &ConsumerConfig{
ProtocolConf: protocolConfigs,
References: consumerReferences,
ShutdownConfig: &ShutdownConfig{
Timeout: "1",
StepTimeout: "1s",
},
}
},}

providerProtocols := make(map[interface{}]interface{}, 16)
providerProtocols[constant.DUBBO] = "aaa"

providerProtocols["mock"] = "aaa"
providerProtocols := map[string]*ProtocolConfig{}
providerProtocols[constant.DUBBO] = &ProtocolConfig{
Name: constant.DUBBO,
}

providerProtocols["mock"] = &ProtocolConfig{
Name: "mock",
}

providerConfig = &ProviderConfig{
ShutdownConfig: &ShutdownConfig{
Timeout: "1",
StepTimeout: "1s",
},
ProtocolConf: providerProtocols,
Protocols: providerProtocols,
}
// test destroy protocol
BeforeShutdown()
Expand All @@ -77,11 +84,11 @@ func TestBeforeShutdown(t *testing.T) {
Timeout: "1",
StepTimeout: "-1s",
},
ProtocolConf: protocolConfigs,
Protocols: providerProtocols,
}

consumerConfig = &ConsumerConfig{
ProtocolConf: protocolConfigs,
References:consumerReferences,
ShutdownConfig: &ShutdownConfig{
Timeout: "1",
StepTimeout: "-1s",
Expand Down

0 comments on commit 14dec2f

Please sign in to comment.