Skip to content

Commit

Permalink
feat(dsmiddleware/rpcretry): rename WithLogf function to WithLogger f…
Browse files Browse the repository at this point in the history
…unction

For consistency with other middleware
  • Loading branch information
vvakame committed May 30, 2018
1 parent f3d87d1 commit 2453e9b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion clouddatastore/testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestCloudDatastoreWithRPCRetryAndChaosRPCTestSuite(t *testing.T) {
rpcretry.WithRetryLimit(10),
rpcretry.WithMinBackoffDuration(1),
rpcretry.WithMaxBackoffDuration(1),
rpcretry.WithLogf(func(ctx context.Context, format string, args ...interface{}) {
rpcretry.WithLogger(func(ctx context.Context, format string, args ...interface{}) {
t.Logf(format, args...)
}),
)
Expand Down
14 changes: 10 additions & 4 deletions dsmiddleware/rpcretry/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,22 @@ func (w *withMaxDoublings) Apply(rh *retryHandler) {
rh.maxDoublings = w.maxDoublings
}

// WithLogger creates a ClientOption that uses the specified logger.
func WithLogger(logf func(ctx context.Context, format string, args ...interface{})) RetryOption {
return &withLogger{logf}
}

// WithLogf creates a ClientOption that uses the specified logger.
// TODO rename to WithLogger
//
// Deprecated: use WithLogger instead.
func WithLogf(logf func(ctx context.Context, format string, args ...interface{})) RetryOption {
return &withLogf{logf}
return WithLogger(logf)
}

type withLogf struct {
type withLogger struct {
logf func(ctx context.Context, format string, args ...interface{})
}

func (w *withLogf) Apply(rh *retryHandler) {
func (w *withLogger) Apply(rh *retryHandler) {
rh.logf = w.logf
}
10 changes: 5 additions & 5 deletions dsmiddleware/rpcretry/rpcretry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestRPCRetry_Basic(t *testing.T) {
}()

rh := New(
WithLogf(logf),
WithLogger(logf),
WithMinBackoffDuration(1),
WithRetryLimit(4),
)
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestRPCRetry_Transaction(t *testing.T) {
}()

rh := New(
WithLogf(logf),
WithLogger(logf),
WithMinBackoffDuration(1),
WithRetryLimit(2),
)
Expand Down Expand Up @@ -420,7 +420,7 @@ func TestRPCRetry_AllocateIDs(t *testing.T) {
}()

rh := New(
WithLogf(logf),
WithLogger(logf),
WithMinBackoffDuration(1),
WithRetryLimit(2),
)
Expand Down Expand Up @@ -507,7 +507,7 @@ func TestRPCRetry_GetAll(t *testing.T) {
}()

rh := New(
WithLogf(logf),
WithLogger(logf),
WithMinBackoffDuration(1),
WithRetryLimit(2),
)
Expand Down Expand Up @@ -648,7 +648,7 @@ func TestRPCRetry_Count(t *testing.T) {
}()

rh := New(
WithLogf(logf),
WithLogger(logf),
WithMinBackoffDuration(1),
WithRetryLimit(2),
)
Expand Down
10 changes: 5 additions & 5 deletions testsuite/dsmiddleware/rpcretry/rpcretry.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func basic(ctx context.Context, t *testing.T, client datastore.Client) {
}()

rh := rpcretry.New(
rpcretry.WithLogf(logf),
rpcretry.WithLogger(logf),
rpcretry.WithMinBackoffDuration(1),
rpcretry.WithRetryLimit(4),
)
Expand Down Expand Up @@ -170,7 +170,7 @@ func transaction(ctx context.Context, t *testing.T, client datastore.Client) {
}()

rh := rpcretry.New(
rpcretry.WithLogf(logf),
rpcretry.WithLogger(logf),
rpcretry.WithMinBackoffDuration(1),
rpcretry.WithRetryLimit(2),
)
Expand Down Expand Up @@ -377,7 +377,7 @@ func allocateIDs(ctx context.Context, t *testing.T, client datastore.Client) {
}()

rh := rpcretry.New(
rpcretry.WithLogf(logf),
rpcretry.WithLogger(logf),
rpcretry.WithMinBackoffDuration(1),
rpcretry.WithRetryLimit(2),
)
Expand Down Expand Up @@ -468,7 +468,7 @@ func getAll(ctx context.Context, t *testing.T, client datastore.Client) {
}()

rh := rpcretry.New(
rpcretry.WithLogf(logf),
rpcretry.WithLogger(logf),
rpcretry.WithMinBackoffDuration(1),
rpcretry.WithRetryLimit(2),
)
Expand Down Expand Up @@ -613,7 +613,7 @@ func count(ctx context.Context, t *testing.T, client datastore.Client) {
}()

rh := rpcretry.New(
rpcretry.WithLogf(logf),
rpcretry.WithLogger(logf),
rpcretry.WithMinBackoffDuration(1),
rpcretry.WithRetryLimit(2),
)
Expand Down

0 comments on commit 2453e9b

Please sign in to comment.