diff --git a/cluster/router/condition/factory.go b/cluster/router/condition/factory.go index 084903d341d3c9f715076d3dde6aa123851ec45d..68534aee44f58821991509fd755417a1f755dc62 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 97b4f7a4081be681a7b8e45e726448e8a76d3853..54afcd42411b6599c8874b4f93cb171fb5adf53e 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 70542feb49de3eae702632c788decc32066413de..44d5f0e95c2f633df610b9adfd857b05d8868569 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 730e787ce44d6830556cb17e4d227f8972226e7d..5ab2bfb47d4569ea19f2376725c440f427c19cd2 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 0000000000000000000000000000000000000000..337013c9a4805898f137bf5d4eff07c501ec8d3e --- /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 0000000000000000000000000000000000000000..824a44271550523601aab1a571658220791b06a4 --- /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 e25baf3b5dd806ee91938b363127981556677f88..7e66f9d0c20342bf7b1bcbe72c0376fe37ea6da0 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 e2fe0856f93c1bba319b694beeb198ef8e530555..6ad5ce6b92ef5dfd2b7ac18982dfa708645c1e92 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"