From d7b5f50999ef7f47bd7200c377202eff2956f981 Mon Sep 17 00:00:00 2001
From: Ming Deng <mindeng@ebay.com>
Date: Fri, 22 Nov 2019 10:02:46 +0800
Subject: [PATCH] fix review comment

---
 config/graceful_shutdown.go      |  9 ++++-----
 config/graceful_shutdown_test.go | 28 +++++++++++++++++-----------
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/config/graceful_shutdown.go b/config/graceful_shutdown.go
index d12c8dfb1..0b39d1115 100644
--- a/config/graceful_shutdown.go
+++ b/config/graceful_shutdown.go
@@ -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()
 	}
 }
 
diff --git a/config/graceful_shutdown_test.go b/config/graceful_shutdown_test.go
index 0c4960152..de203572c 100644
--- a/config/graceful_shutdown_test.go
+++ b/config/graceful_shutdown_test.go
@@ -43,31 +43,37 @@ 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 := map[string]*ProtocolConfig{}
+	providerProtocols[constant.DUBBO] = &ProtocolConfig{
+		Name: constant.DUBBO,
+	}
 
-	providerProtocols["mock"] = "aaa"
+	providerProtocols["mock"] = &ProtocolConfig{
+		Name: "mock",
+	}
 
 	providerConfig = &ProviderConfig{
 		ShutdownConfig: &ShutdownConfig{
 			Timeout:     "1",
 			StepTimeout: "1s",
 		},
-		ProtocolConf: providerProtocols,
+		Protocols: providerProtocols,
 	}
 	// test destroy protocol
 	BeforeShutdown()
@@ -77,11 +83,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",
-- 
GitLab