-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package backoff | ||
|
||
// A Factory creates and returns a new backoff policy | ||
type Factory interface { | ||
NewBackOff() BackOff | ||
} | ||
|
||
// FactoryFunc is a function that returns a new backoff policy | ||
type FactoryFunc func() BackOff | ||
|
||
// NewBackOff implements Factory, allowing a FactoryFunc to be passed to anyywhere that accepts a Factory | ||
func (ff FactoryFunc) NewBackOff() BackOff { | ||
return ff() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package backoff | ||
|
||
import "testing" | ||
|
||
func TestFactoryFunc(t *testing.T) { | ||
backoff := NewExponentialBackOff() | ||
|
||
ff := FactoryFunc(func() BackOff { | ||
return backoff | ||
}) | ||
|
||
newBackOff := ff.NewBackOff() | ||
|
||
expontential, ok := newBackOff.(*ExponentialBackOff) | ||
if !ok { | ||
t.Error("wrong type from NewBackOff") | ||
} | ||
|
||
if *expontential != *backoff { | ||
t.Error("backoff was not equal to expected backoff") | ||
} | ||
} |