Skip to content

Commit

Permalink
rename MinAddresses -> MinConnections
Browse files Browse the repository at this point in the history
  • Loading branch information
jhump committed Feb 28, 2024
1 parent 09f5b9a commit ac9cc34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions resolver/minaddr.go → resolver/min_conns.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"io"
)

// MinAddresses decorates the given resolver so it sends a set of addresses that has at
// MinConnections decorates the given resolver so it sends a set of addresses that has at
// least as many entries as the given minimum. If the given resolver provides a smaller
// set of addresses, it replicates those addresses until the give minimum is reached.
//
Expand All @@ -33,25 +33,25 @@ import (
// always fully replicates the set. So it will always report at least minAddresses, but
// could report nearly twice as many: in the case where the set from the underlying
// resolver has minAddresses-1 entries, this will provide (minAddresses-1)*2 entries.
func MinAddresses(other Resolver, minAddresses int) Resolver {
return &minAddrsResolver{res: other, min: minAddresses}
func MinConnections(other Resolver, minAddresses int) Resolver {
return &minConnsResolver{res: other, min: minAddresses}
}

type minAddrsResolver struct {
type minConnsResolver struct {
res Resolver
min int
}

func (m *minAddrsResolver) New(ctx context.Context, scheme, hostPort string, receiver Receiver, refresh <-chan struct{}) io.Closer {
return m.res.New(ctx, scheme, hostPort, &minAddrsReceiver{rcvr: receiver, min: m.min}, refresh)
func (m *minConnsResolver) New(ctx context.Context, scheme, hostPort string, receiver Receiver, refresh <-chan struct{}) io.Closer {
return m.res.New(ctx, scheme, hostPort, &minConnsReceiver{rcvr: receiver, min: m.min}, refresh)
}

type minAddrsReceiver struct {
type minConnsReceiver struct {
rcvr Receiver
min int
}

func (m *minAddrsReceiver) OnResolve(addresses []Address) {
func (m *minConnsReceiver) OnResolve(addresses []Address) {
if len(addresses) >= m.min || len(addresses) == 0 {
// Already enough addresses; OR zero addresses, in which case, no amount of replication can help.
m.rcvr.OnResolve(addresses)
Expand All @@ -68,6 +68,6 @@ func (m *minAddrsReceiver) OnResolve(addresses []Address) {
m.rcvr.OnResolve(scaledAddrs)
}

func (m *minAddrsReceiver) OnResolveError(err error) {
func (m *minConnsReceiver) OnResolveError(err error) {
m.rcvr.OnResolveError(err)
}
6 changes: 3 additions & 3 deletions resolver/minaddr_test.go → resolver/min_conns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestMinAddresses(t *testing.T) {
func TestMinConnections(t *testing.T) {
t.Parallel()

refreshCh := make(chan struct{})
Expand All @@ -35,7 +35,7 @@ func TestMinAddresses(t *testing.T) {
addresses := []Address{addrFoo, addrBar, addrBaz, addrQux}

var resolver fakeResolver
minResolver := MinAddresses(&resolver, 6)
minResolver := MinConnections(&resolver, 6)
var receiver fakeReceiver
_ = minResolver.New(context.Background(), "", "", &receiver, refreshCh)

Expand All @@ -57,7 +57,7 @@ func TestMinAddresses(t *testing.T) {
addrFoo, addrBar, addrBaz, addrQux, addrFoo, addrBar, addrBaz, addrQux,
})

minResolver = MinAddresses(&resolver, 3)
minResolver = MinConnections(&resolver, 3)
_ = minResolver.New(context.Background(), "", "", &receiver, refreshCh)

resolver.receiver.OnResolve(append([]Address{}, addresses...))
Expand Down

0 comments on commit ac9cc34

Please sign in to comment.