Skip to content

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

OleksiienkoMykyta
Copy link
Contributor

@OleksiienkoMykyta OleksiienkoMykyta commented Apr 2, 2025

Closes #1311
Currently, external HostFilter implementations cannot be tested against HostFilter interface.
To fix that, the Accept method has an Host interface as the parameter instead of HostInfo so that it is possible to mock it.

Currently external HostFilter implementations cannot
be tested against HostFilter interface.
To fix that the Accept method should have an interface as the
parameter instead of HostInfo so that it is possible to mock it.

Patch by: Mykyta Oleksiienko; Revieved by: ***; For CASSGO-71.
@OleksiienkoMykyta
Copy link
Contributor Author

@joao-r-reis, could you please review the PR?

Copy link
Contributor

@tengu-alt tengu-alt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one comment. Overall LGTM

Set(v string) error
UnmarshalCQL(info TypeInfo, data []byte) error
AtLeast(major, minor, patch int) bool
String() string
}

// HostFilterFunc converts a func(host HostInfo) bool into a HostFilter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it also needs to be updated to func(host Host) bool

@joao-r-reis joao-r-reis changed the title Make HostFilter interface easier to test CASSGO-71 Make HostFilter interface easier to test Apr 21, 2025
Copy link
Contributor

@joao-r-reis joao-r-reis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments.

I think there's other parts of the public API that need their HostInfo references changed to Host like observers, Iter and policies

@@ -480,6 +480,12 @@ func TestCAS(t *testing.T) {
t.Fatalf("insert should have not been applied: title=%v revID=%v modified=%v", titleCAS, revidCAS, modifiedCAS)
}

// TODO: This test failing with error due to "function dateof" on cassandra side.
// It was officially removed in version 5.0.0. The recommended replacement for dateOf is the toTimestamp function.
// As we are not testing against deprecated cassandra versions, it makes sense to update tests to keep them up to date
Copy link
Contributor

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

@@ -227,9 +227,6 @@ func (s *Session) handleNodeUp(eventIp net.IP, eventPort int) {
return
}

if d := host.Version().nodeUpDelay(); d > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

Set(v string) error
UnmarshalCQL(info TypeInfo, data []byte) error
AtLeast(major, minor, patch int) bool
String() string
Copy link
Contributor

Choose a reason for hiding this comment

The 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 Set or Unmarshal method and we should definitely expose a way to get the actual version fields.

Ideally CassVersion would be:

type CassVersion interface {
	Major() int
        Minor() int
        Patch() int
        Qualifier() string
	String() string
}

The methods on cassVersion can be converted into global private functions.

func (c *cassVersion) Set(v string) error 
func (c *cassVersion) UnmarshalCQL(info TypeInfo, data []byte) error 
func (c *cassVersion) unmarshal(data []byte) error {
func (c cassVersion) Before(major, minor, patch int) bool 
func (c cassVersion) AtLeast(major, minor, patch int) bool
func parseCassVersion(v string) (CassVersion, error) {
        c := &cassVersion{}
	if v == "" {
		return c, nil
	}

	return c.unmarshalCQL(nil, []byte(v))
}

func (c *cassVersion) unmarshalCQL(info TypeInfo, data []byte) error {
	return c.unmarshal(data)
}

// can be kept as is
func (c *cassVersion) unmarshal(data []byte) error

// these two should just be global, private and have `CassVersion` parameters instead
func before(v1 CassVersion, v2 CassVersion) bool 
func atLeast(v1 CassVersion, v2 CassVersion) bool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CASSGO-71 External HostFilter implementations cannot be tested against HostFilter interface
3 participants