You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "joao-r-reis (via GitHub)" <gi...@apache.org> on 2025/06/13 16:16:02 UTC
[PR] CASSGO-71 Add way to create HostInfo objects for testing purposes [cassandra-gocql-driver]
joao-r-reis opened a new pull request, #1892:
URL: https://github.com/apache/cassandra-gocql-driver/pull/1892
Also renamed NewHostInfo to NewHostInfoFromContactPoint, this isn't a breaking change because this function was exported recently and no release has gone out since then
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSGO-71 Add way to create HostInfo objects for testing purposes [cassandra-gocql-driver]
Posted by "joao-r-reis (via GitHub)" <gi...@apache.org>.
joao-r-reis commented on code in PR #1892:
URL: https://github.com/apache/cassandra-gocql-driver/pull/1892#discussion_r2149914600
##########
host_source.go:
##########
@@ -492,17 +497,42 @@ func checkSystemSchema(control *controlConn) (bool, error) {
return true, nil
}
-func (s *Session) newHostInfoFromMap(addr net.IP, port int, row map[string]interface{}) (*HostInfo, error) {
- return s.hostInfoFromMap(row, &HostInfo{connectAddress: addr, port: port})
-}
-
// Given a map that represents a row from either system.local or system.peers
// return as much information as we can in *HostInfo
-func (s *Session) hostInfoFromMap(row map[string]interface{}, host *HostInfo) (*HostInfo, error) {
+func (s *Session) newHostInfoFromMap(addr net.IP, port int, row map[string]interface{}) (*HostInfo, error) {
+ return newHostInfoFromRow(s, addr, port, row)
+}
+
+// NewTestHostInfoFromRow creates a new HostInfo object from a system.peers or system.local row. The port
+// defaults to 9042.
+//
+// You can create a HostInfo object for testing purposes using this function:
+//
+// Example usage:
+//
+// row := map[string]interface{}{
+// "broadcast_address": net.ParseIP("10.0.0.1"),
+// "listen_address": net.ParseIP("10.0.0.1"),
+// "rpc_address": net.ParseIP("10.0.0.1"),
+// "peer": net.ParseIP("10.0.0.1"), // system.peers only
+// "data_center": "dc1",
+// "rack": "rack1",
+// "host_id": MustRandomUUID(), // can also use ParseUUID("550e8400-e29b-41d4-a716-446655440000")
+// "release_version": "4.0.0",
+// "native_port": 9042,
+// }
+// host, err := NewTestHostInfoFromRow(row)
+func NewTestHostInfoFromRow(row map[string]interface{}) (*HostInfo, error) {
Review Comment:
Since this is meant to be used for unit testing implementations of policies and other gocql public interfaces I don't think users will be using it with a `session` so I don't think it's necessary to involve the address translator. Maybe we can consider it if we get requests for it in the future?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSGO-71 Add way to create HostInfo objects for testing purposes [cassandra-gocql-driver]
Posted by "joao-r-reis (via GitHub)" <gi...@apache.org>.
joao-r-reis commented on code in PR #1892:
URL: https://github.com/apache/cassandra-gocql-driver/pull/1892#discussion_r2149911351
##########
host_source.go:
##########
@@ -181,9 +183,12 @@ type HostInfo struct {
tokens []string
}
-// NewHostInfo creates HostInfo with provided connectAddress and port.
+// NewHostInfoFromContactPoint creates HostInfo with provided connectAddress and port.
// It returns an error if addr is invalid.
-func NewHostInfo(addr net.IP, port int) (*HostInfo, error) {
+//
+// If you're looking for a way to create a HostInfo object with more than just an address and port for
+// testing purposes then you can use NewTestHostInfoFromRow
+func NewHostInfoFromContactPoint(addr net.IP, port int) (*HostInfo, error) {
Review Comment:
I checked and the only time we create host info objects from Addr and Port is during init when we are converting contact points into HostPoints, everywhere else we always use the row from the system table. I'm ok with changing to `NewHostInfoFromAddrPort` though
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSGO-71 Add way to create HostInfo objects for testing purposes [cassandra-gocql-driver]
Posted by "jameshartig (via GitHub)" <gi...@apache.org>.
jameshartig commented on code in PR #1892:
URL: https://github.com/apache/cassandra-gocql-driver/pull/1892#discussion_r2148901594
##########
host_source.go:
##########
@@ -492,17 +497,42 @@ func checkSystemSchema(control *controlConn) (bool, error) {
return true, nil
}
-func (s *Session) newHostInfoFromMap(addr net.IP, port int, row map[string]interface{}) (*HostInfo, error) {
- return s.hostInfoFromMap(row, &HostInfo{connectAddress: addr, port: port})
-}
-
// Given a map that represents a row from either system.local or system.peers
// return as much information as we can in *HostInfo
-func (s *Session) hostInfoFromMap(row map[string]interface{}, host *HostInfo) (*HostInfo, error) {
+func (s *Session) newHostInfoFromMap(addr net.IP, port int, row map[string]interface{}) (*HostInfo, error) {
+ return newHostInfoFromRow(s, addr, port, row)
+}
+
+// NewTestHostInfoFromRow creates a new HostInfo object from a system.peers or system.local row. The port
+// defaults to 9042.
+//
+// You can create a HostInfo object for testing purposes using this function:
+//
+// Example usage:
+//
+// row := map[string]interface{}{
+// "broadcast_address": net.ParseIP("10.0.0.1"),
+// "listen_address": net.ParseIP("10.0.0.1"),
+// "rpc_address": net.ParseIP("10.0.0.1"),
+// "peer": net.ParseIP("10.0.0.1"), // system.peers only
+// "data_center": "dc1",
+// "rack": "rack1",
+// "host_id": MustRandomUUID(), // can also use ParseUUID("550e8400-e29b-41d4-a716-446655440000")
+// "release_version": "4.0.0",
+// "native_port": 9042,
+// }
+// host, err := NewTestHostInfoFromRow(row)
+func NewTestHostInfoFromRow(row map[string]interface{}) (*HostInfo, error) {
Review Comment:
Should we have the same method on `*Session` too so it could still call `AddressTranslator`?
##########
host_source.go:
##########
@@ -181,9 +183,12 @@ type HostInfo struct {
tokens []string
}
-// NewHostInfo creates HostInfo with provided connectAddress and port.
+// NewHostInfoFromContactPoint creates HostInfo with provided connectAddress and port.
// It returns an error if addr is invalid.
-func NewHostInfo(addr net.IP, port int) (*HostInfo, error) {
+//
+// If you're looking for a way to create a HostInfo object with more than just an address and port for
+// testing purposes then you can use NewTestHostInfoFromRow
+func NewHostInfoFromContactPoint(addr net.IP, port int) (*HostInfo, error) {
Review Comment:
nit: What's the reason behind "ContactPoint"? What about "NewHostInfoFromAddrPort"? Not terribly opposed with contact point though
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSGO-71 Add way to create HostInfo objects for testing purposes [cassandra-gocql-driver]
Posted by "joao-r-reis (via GitHub)" <gi...@apache.org>.
joao-r-reis commented on code in PR #1892:
URL: https://github.com/apache/cassandra-gocql-driver/pull/1892#discussion_r2152519207
##########
host_source.go:
##########
@@ -181,9 +183,12 @@ type HostInfo struct {
tokens []string
}
-// NewHostInfo creates HostInfo with provided connectAddress and port.
+// NewHostInfoFromContactPoint creates HostInfo with provided connectAddress and port.
// It returns an error if addr is invalid.
-func NewHostInfo(addr net.IP, port int) (*HostInfo, error) {
+//
+// If you're looking for a way to create a HostInfo object with more than just an address and port for
+// testing purposes then you can use NewTestHostInfoFromRow
+func NewHostInfoFromContactPoint(addr net.IP, port int) (*HostInfo, error) {
Review Comment:
Changed it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSGO-71 Add way to create HostInfo objects for testing purposes [cassandra-gocql-driver]
Posted by "joao-r-reis (via GitHub)" <gi...@apache.org>.
joao-r-reis merged PR #1892:
URL: https://github.com/apache/cassandra-gocql-driver/pull/1892
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org