From adc3e3f5b9a1bd33f27f688f3113c12a0b6ebfc7 Mon Sep 17 00:00:00 2001
From: CodingSinger <ooczzoo@gmail.com>
Date: Thu, 5 Mar 2020 09:50:36 +0800
Subject: [PATCH] move healthcheck router to healthcheck dir

---
 cluster/router/condition/factory.go           | 14 +---
 cluster/router/condition/factory_test.go      |  7 +-
 .../default_health_check.go                   |  2 +-
 .../default_health_check_test.go              |  3 +-
 cluster/router/healthcheck/factory.go         | 44 ++++++++++++
 cluster/router/healthcheck/factory_test.go    | 67 +++++++++++++++++++
 .../health_check_route.go                     |  2 +-
 .../health_check_route_test.go                |  2 +-
 8 files changed, 118 insertions(+), 23 deletions(-)
 rename cluster/router/{condition => healthcheck}/default_health_check.go (99%)
 rename cluster/router/{condition => healthcheck}/default_health_check_test.go (99%)
 create mode 100644 cluster/router/healthcheck/factory.go
 create mode 100644 cluster/router/healthcheck/factory_test.go
 rename cluster/router/{condition => healthcheck}/health_check_route.go (99%)
 rename cluster/router/{condition => healthcheck}/health_check_route_test.go (99%)

diff --git a/cluster/router/condition/factory.go b/cluster/router/condition/factory.go
index 084903d34..68534aee4 100644
--- a/cluster/router/condition/factory.go
+++ b/cluster/router/condition/factory.go
@@ -27,7 +27,6 @@ import (
 func init() {
 	extension.SetRouterFactory(constant.ConditionRouterName, newConditionRouterFactory)
 	extension.SetRouterFactory(constant.ConditionAppRouterName, newAppRouterFactory)
-	extension.SetRouterFactory(constant.HealthCheckRouterName, newHealthCheckRouteFactory)
 }
 
 // ConditionRouterFactory Condition router factory
@@ -57,15 +56,4 @@ func newAppRouterFactory() router.RouterFactory {
 // NewRouter Create AppRouterFactory by URL
 func (c *AppRouterFactory) NewRouter(url *common.URL) (router.Router, error) {
 	return NewAppRouter(url)
-}
-
-type HealthCheckRouteFactory struct {
-}
-
-func newHealthCheckRouteFactory() router.RouterFactory {
-	return &HealthCheckRouteFactory{}
-}
-
-func (f *HealthCheckRouteFactory) NewRouter(url *common.URL) (router.Router, error) {
-	return NewHealthCheckRouter(url)
-}
+}
\ No newline at end of file
diff --git a/cluster/router/condition/factory_test.go b/cluster/router/condition/factory_test.go
index 97b4f7a40..54afcd424 100644
--- a/cluster/router/condition/factory_test.go
+++ b/cluster/router/condition/factory_test.go
@@ -365,9 +365,4 @@ func TestNewConditionRouterFactory(t *testing.T) {
 func TestNewAppRouterFactory(t *testing.T) {
 	factory := newAppRouterFactory()
 	assert.NotNil(t, factory)
-}
-
-func TestHealthCheckRouteFactory(t *testing.T) {
-	factory := newHealthCheckRouteFactory()
-	assert.NotNil(t, factory)
-}
+}
\ No newline at end of file
diff --git a/cluster/router/condition/default_health_check.go b/cluster/router/healthcheck/default_health_check.go
similarity index 99%
rename from cluster/router/condition/default_health_check.go
rename to cluster/router/healthcheck/default_health_check.go
index 70542feb4..44d5f0e95 100644
--- a/cluster/router/condition/default_health_check.go
+++ b/cluster/router/healthcheck/default_health_check.go
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package condition
+package healthcheck
 
 import (
 	"math"
diff --git a/cluster/router/condition/default_health_check_test.go b/cluster/router/healthcheck/default_health_check_test.go
similarity index 99%
rename from cluster/router/condition/default_health_check_test.go
rename to cluster/router/healthcheck/default_health_check_test.go
index 730e787ce..5ab2bfb47 100644
--- a/cluster/router/condition/default_health_check_test.go
+++ b/cluster/router/healthcheck/default_health_check_test.go
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package condition
+package healthcheck
 
 import (
 	"math"
@@ -32,6 +32,7 @@ import (
 )
 
 func TestDefaultHealthChecker_IsHealthy(t *testing.T) {
+
 	defer protocol.CleanAllStatus()
 	url, _ := common.NewURL("dubbo://192.168.10.10:20000/com.ikurento.user.UserProvider")
 	hc := NewDefaultHealthChecker(&url).(*DefaultHealthChecker)
diff --git a/cluster/router/healthcheck/factory.go b/cluster/router/healthcheck/factory.go
new file mode 100644
index 000000000..337013c9a
--- /dev/null
+++ b/cluster/router/healthcheck/factory.go
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package healthcheck
+
+import (
+	"github.com/apache/dubbo-go/cluster/router"
+	"github.com/apache/dubbo-go/common"
+	"github.com/apache/dubbo-go/common/constant"
+	"github.com/apache/dubbo-go/common/extension"
+)
+
+func init() {
+	extension.SetRouterFactory(constant.HealthCheckRouterName, newHealthCheckRouteFactory)
+}
+
+
+// HealthCheckRouteFactory
+type HealthCheckRouteFactory struct {
+}
+
+// newHealthCheckRouteFactory construct a new HealthCheckRouteFactory
+func newHealthCheckRouteFactory() router.RouterFactory {
+	return &HealthCheckRouteFactory{}
+}
+
+// NewRouter construct a new NewHealthCheckRouter via url
+func (f *HealthCheckRouteFactory) NewRouter(url *common.URL) (router.Router, error) {
+	return NewHealthCheckRouter(url)
+}
diff --git a/cluster/router/healthcheck/factory_test.go b/cluster/router/healthcheck/factory_test.go
new file mode 100644
index 000000000..824a44271
--- /dev/null
+++ b/cluster/router/healthcheck/factory_test.go
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package healthcheck
+
+import (
+	"context"
+	"testing"
+)
+
+import (
+	"github.com/stretchr/testify/assert"
+)
+
+import (
+	"github.com/apache/dubbo-go/common"
+	"github.com/apache/dubbo-go/protocol"
+)
+type MockInvoker struct {
+	url          common.URL
+}
+
+func NewMockInvoker(url common.URL, successCount int) *MockInvoker {
+	return &MockInvoker{
+		url:          url,
+	}
+}
+
+func (bi *MockInvoker) GetUrl() common.URL {
+	return bi.url
+}
+func (bi *MockInvoker) IsAvailable() bool {
+	return true
+}
+
+func (bi *MockInvoker) IsDestroyed() bool {
+	return true
+}
+
+
+
+func (bi *MockInvoker) Invoke(_ context.Context, _ protocol.Invocation) protocol.Result {
+	return nil
+}
+
+func (bi *MockInvoker) Destroy() {
+}
+
+
+func TestHealthCheckRouteFactory(t *testing.T) {
+	factory := newHealthCheckRouteFactory()
+	assert.NotNil(t, factory)
+}
diff --git a/cluster/router/condition/health_check_route.go b/cluster/router/healthcheck/health_check_route.go
similarity index 99%
rename from cluster/router/condition/health_check_route.go
rename to cluster/router/healthcheck/health_check_route.go
index e25baf3b5..7e66f9d0c 100644
--- a/cluster/router/condition/health_check_route.go
+++ b/cluster/router/healthcheck/health_check_route.go
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package condition
+package healthcheck
 
 import (
 	"github.com/apache/dubbo-go/cluster/router"
diff --git a/cluster/router/condition/health_check_route_test.go b/cluster/router/healthcheck/health_check_route_test.go
similarity index 99%
rename from cluster/router/condition/health_check_route_test.go
rename to cluster/router/healthcheck/health_check_route_test.go
index e2fe0856f..6ad5ce6b9 100644
--- a/cluster/router/condition/health_check_route_test.go
+++ b/cluster/router/healthcheck/health_check_route_test.go
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package condition
+package healthcheck
 
 import (
 	"math"
-- 
GitLab