Skip to content
Snippets Groups Projects
Commit a993531e authored by Ming Deng's avatar Ming Deng
Browse files

Fix UT

parent 5289c063
No related branches found
No related tags found
No related merge requests found
......@@ -71,8 +71,8 @@ const (
EXECUTE_LIMIT_KEY = "execute.limit"
DEFAULT_EXECUTE_LIMIT = "-1"
EXECUTE_REJECTED_EXECUTION_HANDLER_KEY = "execute.limit.rejected.handler"
PROVIDER_SHUTDOWN_FILTER = "pshutdown"
CONSUMER_SHUTDOWN_FILTER = "cshutdown"
PROVIDER_SHUTDOWN_FILTER = "pshutdown"
CONSUMER_SHUTDOWN_FILTER = "cshutdown"
)
const (
......
......@@ -22,7 +22,7 @@ import (
)
var (
customShutdownCallbacks = list.New()
customShutdownCallbacks = list.New()
)
/**
......@@ -44,7 +44,7 @@ var (
* the benefit of that mechanism is low.
* And it may introduce much complication for another users.
*/
func AddCustomShutdownCallback(callback func()) {
func AddCustomShutdownCallback(callback func()) {
customShutdownCallbacks.PushBack(callback)
}
......
......@@ -52,12 +52,12 @@ type ConsumerConfig struct {
ProxyFactory string `yaml:"proxy_factory" default:"default" json:"proxy_factory,omitempty" property:"proxy_factory"`
Check *bool `yaml:"check" json:"check,omitempty" property:"check"`
Registry *RegistryConfig `yaml:"registry" json:"registry,omitempty" property:"registry"`
Registries map[string]*RegistryConfig `yaml:"registries" json:"registries,omitempty" property:"registries"`
References map[string]*ReferenceConfig `yaml:"references" json:"references,omitempty" property:"references"`
ProtocolConf interface{} `yaml:"protocol_conf" json:"protocol_conf,omitempty" property:"protocol_conf"`
FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" `
ShutdownConfig *ShutdownConfig `yaml:"shutdown_conf" json:"shutdown_conf,omitempty" property:"shutdown_conf" `
Registry *RegistryConfig `yaml:"registry" json:"registry,omitempty" property:"registry"`
Registries map[string]*RegistryConfig `yaml:"registries" json:"registries,omitempty" property:"registries"`
References map[string]*ReferenceConfig `yaml:"references" json:"references,omitempty" property:"references"`
ProtocolConf interface{} `yaml:"protocol_conf" json:"protocol_conf,omitempty" property:"protocol_conf"`
FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" `
ShutdownConfig *ShutdownConfig `yaml:"shutdown_conf" json:"shutdown_conf,omitempty" property:"shutdown_conf" `
}
func (c *ConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
......
......@@ -18,16 +18,17 @@
package config
import (
"strconv"
"time"
)
import (
"github.com/apache/dubbo-go/common/logger"
)
const (
defaultTimeout = 60 * time.Second
defaultTimeout = 60 * time.Second
defaultStepTimeout = 10 * time.Second
)
type ShutdownConfig struct {
/*
* Total timeout. Even though we don't release all resources,
......@@ -35,7 +36,7 @@ type ShutdownConfig struct {
* default value is 60 * 1000 ms = 1 minutes
* In general, it should be bigger than 3 * StepTimeout.
*/
Timeout string `yaml:"timeout" json:"timeout,omitempty" property:"timeout"`
Timeout string `default:"60s" yaml:"timeout" json:"timeout,omitempty" property:"timeout"`
/*
* the timeout on each step. You should evaluate the response time of request
* and the time that client noticed that server shutdown.
......@@ -43,7 +44,7 @@ type ShutdownConfig struct {
* and the 99.9% requests will return response in 2s, so the StepTimeout will be bigger than(10+2) * 1000ms,
* maybe (10 + 2*3) * 1000ms is a good choice.
*/
StepTimeout string `yaml:"step_timeout" json:"step.timeout,omitempty" property:"step.timeout"`
StepTimeout string `default:"10s" yaml:"step_timeout" json:"step.timeout,omitempty" property:"step.timeout"`
// when we try to shutdown the application, we will reject the new requests. In most cases, you don't need to configure this.
RejectRequestHandler string `yaml:"reject_handler" json:"reject_handler,omitempty" property:"reject_handler"`
// true -> new request will be rejected.
......@@ -55,21 +56,21 @@ type ShutdownConfig struct {
}
func (config *ShutdownConfig) GetTimeout() time.Duration {
result, err := strconv.ParseInt(config.Timeout, 0, 0)
result, err := time.ParseDuration(config.Timeout)
if err != nil {
logger.Errorf("The Timeout configuration is invalid: %s, and we will use the default value: %s",
config.Timeout, defaultTimeout.String(), err)
return defaultTimeout
}
return time.Millisecond * time.Duration(result)
return result
}
func (config *ShutdownConfig) GetStepTimeout() time.Duration {
result, err := strconv.ParseInt(config.StepTimeout, 0, 0)
result, err := time.ParseDuration(config.StepTimeout)
if err != nil {
logger.Errorf("The StepTimeout configuration is invalid: %s, and we will use the default value: %s",
config.Timeout, defaultStepTimeout.String(), err)
return defaultStepTimeout
}
return time.Millisecond * time.Duration(result)
return result
}
......@@ -39,8 +39,8 @@ func TestShutdownConfig_GetTimeout(t *testing.T) {
assert.Equal(t, 10*time.Second, config.GetStepTimeout())
config = ShutdownConfig{
Timeout: "34",
StepTimeout: "79",
Timeout: "34ms",
StepTimeout: "79ms",
}
assert.Equal(t, 34*time.Millisecond, config.GetTimeout())
......
......@@ -42,8 +42,6 @@ func TestBeforeShutdown(t *testing.T) {
return &mockRegistryProtocol{}
})
protocolConfigs := make(map[interface{}]interface{})
protocolConfigs[constant.DUBBO] = "aaa"
......@@ -54,7 +52,7 @@ func TestBeforeShutdown(t *testing.T) {
ProtocolConf: protocolConfigs,
ShutdownConfig: &ShutdownConfig{
Timeout: "1",
StepTimeout: "1000",
StepTimeout: "1s",
},
}
......@@ -66,7 +64,7 @@ func TestBeforeShutdown(t *testing.T) {
providerConfig = &ProviderConfig{
ShutdownConfig: &ShutdownConfig{
Timeout: "1",
StepTimeout: "1000",
StepTimeout: "1s",
},
ProtocolConf: providerProtocols,
}
......@@ -76,7 +74,7 @@ func TestBeforeShutdown(t *testing.T) {
providerConfig = &ProviderConfig{
ShutdownConfig: &ShutdownConfig{
Timeout: "1",
StepTimeout: "-1",
StepTimeout: "-1s",
},
ProtocolConf: protocolConfigs,
}
......@@ -85,7 +83,7 @@ func TestBeforeShutdown(t *testing.T) {
ProtocolConf: protocolConfigs,
ShutdownConfig: &ShutdownConfig{
Timeout: "1",
StepTimeout: "-1",
StepTimeout: "-1s",
},
}
......
......@@ -44,12 +44,12 @@ type ProviderConfig struct {
ApplicationConfig *ApplicationConfig `yaml:"application" json:"application,omitempty" property:"application"`
Registry *RegistryConfig `yaml:"registry" json:"registry,omitempty" property:"registry"`
Registries map[string]*RegistryConfig `yaml:"registries" json:"registries,omitempty" property:"registries"`
Services map[string]*ServiceConfig `yaml:"services" json:"services,omitempty" property:"services"`
Protocols map[string]*ProtocolConfig `yaml:"protocols" json:"protocols,omitempty" property:"protocols"`
ProtocolConf interface{} `yaml:"protocol_conf" json:"protocol_conf,omitempty" property:"protocol_conf" `
FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" `
ShutdownConfig *ShutdownConfig `yaml:"shutdown_conf" json:"shutdown_conf,omitempty" property:"shutdown_conf" `
Registries map[string]*RegistryConfig `yaml:"registries" json:"registries,omitempty" property:"registries"`
Services map[string]*ServiceConfig `yaml:"services" json:"services,omitempty" property:"services"`
Protocols map[string]*ProtocolConfig `yaml:"protocols" json:"protocols,omitempty" property:"protocols"`
ProtocolConf interface{} `yaml:"protocol_conf" json:"protocol_conf,omitempty" property:"protocol_conf" `
FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" `
ShutdownConfig *ShutdownConfig `yaml:"shutdown_conf" json:"shutdown_conf,omitempty" property:"shutdown_conf" `
}
func (c *ProviderConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
......
......@@ -39,7 +39,7 @@ func TestGenericFilter_Invoke(t *testing.T) {
invoc := invocation.NewRPCInvocation("GetUser", []interface{}{"OK"}, make(map[string]string, 0))
invokeUrl := common.NewURLWithOptions(
common.WithParams(url.Values{}), )
common.WithParams(url.Values{}))
shutdownFilter := extension.GetFilter(constant.PROVIDER_SHUTDOWN_FILTER).(*gracefulShutdownFilter)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment