Skip to content

Commit

Permalink
Corrected method name
Browse files Browse the repository at this point in the history
  • Loading branch information
chaocai committed Jul 31, 2018
1 parent 645b861 commit 248bf38
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Example() {

// 2. decorate the encapsulted function with decorators
// be careful of the order of the decorators
decFn := circuitBreakDec.Decorate(metricDec.Decorate(retryDec.Decorator(encapsulatedFn)))
decFn := circuitBreakDec.Decorate(metricDec.Decorate(retryDec.Decorate(encapsulatedFn)))
ret, err := decFn(encapsulatedReq{1, 2})
fmt.Println(ret, err)
//Output: 3 <nil>
Expand Down
2 changes: 1 addition & 1 deletion retry_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func CreateRetryDecorator(maxRetryTimes int, retryInterval time.Duration,
}

// Decorator function is to add the retry logic to the decorated method
func (dec *RetryDecorator) Decorator(innerFn ServiceFunc) ServiceFunc {
func (dec *RetryDecorator) Decorate(innerFn ServiceFunc) ServiceFunc {
return func(req Request) (Response, error) {
var (
res Response
Expand Down
9 changes: 4 additions & 5 deletions retry_decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestRetryWhenRetriableErrorOccurred(t *testing.T) {
}
retryDec, err := CreateRetryDecorator(maxRetryTimes, time.Second*1, time.Second*1, retriableChecker)
checkErr(err, t)
decFn := retryDec.Decorator(connectionErrFn)
decFn := retryDec.Decorate(connectionErrFn)
res, decErr := decFn(1)
if decErr != ErrorConnection {
t.Error("The connection exception is expected.")
Expand All @@ -45,7 +45,7 @@ func TestRetryWhenRetriableErrorOccurredAndRecovered(t *testing.T) {
}
retryDec, err := CreateRetryDecorator(maxRetryTimes, time.Second*1, time.Second*1, retriableChecker)
checkErr(err, t)
decFn := retryDec.Decorator(connectionErrFn)
decFn := retryDec.Decorate(connectionErrFn)
res, decErr := decFn(1)
checkErr(decErr, t)
if res.(int) != 2 {
Expand All @@ -62,7 +62,7 @@ func TestRetryWithoutError(t *testing.T) {
}
retryDec, err := CreateRetryDecorator(maxRetryTimes, time.Second*1, time.Second*1, retriableChecker)
checkErr(err, t)
decFn := retryDec.Decorator(connectionErrFn)
decFn := retryDec.Decorate(connectionErrFn)
res, decErr := decFn(1)
checkErr(decErr, t)
if res.(int) != 1 {
Expand All @@ -79,7 +79,7 @@ func TestRetryWhenUnretriableErrorOccurred(t *testing.T) {
}
retryDec, err := CreateRetryDecorator(maxRetryTimes, time.Second*1, time.Second*1, retriableChecker)
checkErr(err, t)
decFn := retryDec.Decorator(connectionErrFn)
decFn := retryDec.Decorate(connectionErrFn)
res, decErr := decFn(1)
if decErr == nil || decErr == ErrorConnection {
t.Error("The error is not expected.")
Expand All @@ -95,7 +95,6 @@ func TestCreateDecorateWithInvalidSettings(t *testing.T) {
if err1 == nil {
t.Error("Setting error is expected")
}

_, err2 = CreateRetryDecorator(3, 0, time.Second*1, retriableChecker)
if err2 == nil {
t.Error("Setting error is expected")
Expand Down

0 comments on commit 248bf38

Please sign in to comment.