8000 JAVA-952 Tests for validating equals/hashCode implementations and include MaterializedViewMetadata#whereClause in equals/hashCo 8000 de by tolbertam · Pull Request #471 · apache/cassandra-java-driver · GitHub
[go: up one dir, main page]

Skip to content

JAVA-952 Tests for validating equals/hashCode implementations and include MaterializedViewMetadata#whereClause in equals/hashCode#471

Closed
tolbertam wants to merge 2 commits into3.0from
equalsVerifier
Closed

JAVA-952 Tests for validating equals/hashCode implementations and include MaterializedViewMetadata#whereClause in equals/hashCode#471
tolbertam wants to merge 2 commits into3.0from
equalsVerifier

Conversation

@tolbertam
Copy link
Contributor

There have been a few occasions now where we've added fields to classes and missed updating equals/hashCode implementations. I thought it would be good to use equalsverifier to validate that equals and hashCode implementations are correct where applicable. Having tests for classes that depend on equals/hashCode will 'future-proof' any changes to these classes by detecting missing field use in these methods.

I didn't implement this comprehensively for all classes overriding equals/hashCode in the driver, just the ones that were related to schema.

I chose to make this change on 3.0 since it adds some API restrictions (marking methods final that previously weren't). We could make this worker on older branches but not sure if it's worth it since schema changes seem less likely.

I found a variety of issues which were since fixed. The only remaining issue I've identifier that should probably be definitively fixed is:

  • MaterializedViewMetadata was not including whereClause in equals/hashcode.

There are a few cases where its debatable where certain fields need to be included in equals/hashCode as they may not factor in what we use these methods for (i.e. keyspace/table parentage of the type). I've added comments in the test classes where this is applicable.

Source-Level Changes:

  • Add test level dependency for equalsverifier to device-core/pom.xml
  • In General
    • Use Objects.equal in favor of .equals() for non-primitives not already using it.
    • Null-checking (Maybe we should use Nonnull annotation instead?)
    • Made equals and hashCode final. Did this instead of making whole class final (as can't mock classes that are final).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that 'tables' is included in equals/hashCode, but not views/userTypes/functions/aggregates. Should that be considered a bug?

@tolbertam tolbertam changed the title Added tests for validating equals/hashCode implementations and fixes. Tests for validating equals/hashCode implementations and fixes. Oct 6, 2015
@tolbertam
Copy link
Contributor Author

Just realized that some of the updates i've made to equals/hashCode should also be applied on older branches, so would be good to mark this as a 'conceptual' PR (work in progress). Would like feedback on the changes / approach and then can open PRs for equals/hashcode fixes as applicable on older branches first.

@tolbertam tolbertam changed the title Tests for validating equals/hashCode implementations and fixes. [wip] Tests for validating equals/hashCode implementations and fixes. Oct 12, 2015
@tolbertam tolbertam changed the title [wip] Tests for validating equals/hashCode implementations and fixes. Tests for validating equals/hashCode implementations and include MaterializedViewMetadata#whereClause in equals/hashCode Oct 15, 2015
Copy link
Contributor Author

Choose a reason for hiding this comment

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

simple names are derived from other fields so don't need to be included, codec doesn't seem relevant either.

@tolbertam
Copy link
Contributor Author

rebased on 3.0 the only change that wasn't already in 3.0 was MaterializedViewMetadata equals/hashCode missing whereClause.

@tolbertam tolbertam changed the title Tests for validating equals/hashCode implementations and include MaterializedViewMetadata#whereClause in equals/hashCode JAVA-952 Tests for validating equals/hashCode implementations and include MaterializedViewMetadata#whereClause in equals/hashCode Oct 15, 2015
@tolbertam
Copy link
Contributor Author

Closing this as it needs to be rebased/revisited, will open up a new PR later.

@tolbertam tolbertam closed this Feb 10, 2016
@tolbertam tolbertam deleted the equalsVerifier branch February 10, 2016 17:22
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.

1 participant

0