-
Notifications
You must be signed in to change notification settings - Fork 642
CASSGO-71 Make HostFilter interface easier to test #1874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -227,9 +227,6 @@ func (s *Session) handleNodeUp(eventIp net.IP, eventPort int) { | |
| return | ||
| } | ||
|
|
||
| if d := host.Version().nodeUpDelay(); d > 0 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove this? |
||
| time.Sleep(d) | ||
| } | ||
| s.startPoolFill(host) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,39 +24,74 @@ | |
|
|
||
| package gocql | ||
|
|
||
| import "fmt" | ||
| import ( | ||
| "fmt" | ||
| "net" | ||
| ) | ||
|
|
||
| // HostFilter interface is used when a host is discovered via server sent events. | ||
| type HostFilter interface { | ||
| // Called when a new host is discovered, returning true will cause the host | ||
| // to be added to the pools. | ||
| Accept(host *HostInfo) bool | ||
| Accept(host Host) bool | ||
| } | ||
|
|
||
| // Host interface is provided to enable testing of custom implementations of the HostFilter interface. | ||
| type Host interface { | ||
| Peer() net.IP | ||
| ConnectAddress() net.IP | ||
| BroadcastAddress() net.IP | ||
| ListenAddress() net.IP | ||
| RPCAddress() net.IP | ||
| PreferredIP() net.IP | ||
| DataCenter() string | ||
| Rack() string | ||
| HostID() string | ||
| WorkLoad() string | ||
| Graph() bool | ||
| DSEVersion() string | ||
| Partitioner() string | ||
| ClusterName() string | ||
| Version() CassVersion | ||
| Tokens() []string | ||
| Port() int | ||
| IsUp() bool | ||
| String() string | ||
| } | ||
|
|
||
| // Since cassVersion is an unexported type, the CassVersion interface is introduced | ||
| // to allow better testability and increase test coverage. | ||
| type CassVersion interface { | ||
| Set(v string) error | ||
| UnmarshalCQL(info TypeInfo, data []byte) error | ||
| AtLeast(major, minor, patch int) bool | ||
| String() string | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs some changes, just making an interface out of the methods of the private type feels wrong here, we shouldn't expose Ideally The methods on |
||
| } | ||
|
|
||
| // HostFilterFunc converts a func(host HostInfo) bool into a HostFilter | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it also needs to be updated to |
||
| type HostFilterFunc func(host *HostInfo) bool | ||
| type HostFilterFunc func(host Host) bool | ||
|
|
||
| func (fn HostFilterFunc) Accept(host *HostInfo) bool { | ||
| func (fn HostFilterFunc) Accept(host Host) bool { | ||
| return fn(host) | ||
| } | ||
|
|
||
| // AcceptAllFilter will accept all hosts | ||
| func AcceptAllFilter() HostFilter { | ||
| return HostFilterFunc(func(host *HostInfo) bool { | ||
| return HostFilterFunc(func(host Host) bool { | ||
| return true | ||
| }) | ||
| } | ||
|
|
||
| func DenyAllFilter() HostFilter { | ||
| return HostFilterFunc(func(host *HostInfo) bool { | ||
| return HostFilterFunc(func(host Host) bool { | ||
| return false | ||
| }) | ||
| } | ||
|
|
||
| // DataCenterHostFilter filters all hosts such that they are in the same data center | ||
| // as the supplied data center. | ||
| func DataCenterHostFilter(dataCenter string) HostFilter { | ||
| return HostFilterFunc(func(host *HostInfo) bool { | ||
| return HostFilterFunc(func(host Host) bool { | ||
| return host.DataCenter() == dataCenter | ||
| }) | ||
| } | ||
|
|
@@ -81,7 +116,7 @@ func WhiteListHostFilter(hosts ...string) HostFilter { | |
| m[host.ConnectAddress().String()] = true | ||
| } | ||
|
|
||
| return HostFilterFunc(func(host *HostInfo) bool { | ||
| return HostFilterFunc(func(host Host) bool { | ||
| return m[host.ConnectAddress().String()] | ||
| }) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this was done in #1828 so once that is merged and this PR is rebased it should be fixed