Skip to content

JAVA-1397: Handle duration as native datatype in protocol v5+#801

Merged
olim7t merged 1 commit into
3.xfrom
java1397
Feb 10, 2017
Merged

JAVA-1397: Handle duration as native datatype in protocol v5+#801
olim7t merged 1 commit into
3.xfrom
java1397

Conversation

@olim7t

@olim7t olim7t commented Feb 10, 2017

Copy link
Copy Markdown
Contributor

Protocol v5 is still beta, I temporarily added this (not committed) in DurationIntegrationTest to test:

    @Override
    public Cluster.Builder createClusterBuilder() {
        return super.createClusterBuilder().allowBetaProtocolVersion();
    }

@olim7t olim7t added this to the 3.2.0 milestone Feb 10, 2017
@olim7t

olim7t commented Feb 10, 2017

Copy link
Copy Markdown
Contributor Author

I think we should also update DataTypeIntegrationTest and similar, looking into that.

@olim7t

olim7t commented Feb 10, 2017

Copy link
Copy Markdown
Contributor Author

In hindsight, it's better to keep duration tests separate because the type has specific restrictions (e.g. can't be used in collections) so it can't be handled as a "regular" primitive type by DataTypeIntegrationTest.
I've added the logic to exclude it so that things don't break when v5 becomes non-beta.

@Test(groups = "unit")
@Test(groups = "unit", enabled = false)
public void should_return_same_elements_with_all_primitive_types_using_latest_protocol_version() {
assertThat(DataType.allPrimitiveTypes(ProtocolVersion.NEWEST_SUPPORTED)).isEqualTo(DataType.allPrimitiveTypes());

@olim7t olim7t Feb 10, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This fails, I'm not sure if we should adapt it or remove it altogether.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I vote for removing it. The method under test – DataType.allPrimitiveTypes(ProtocolVersion) – is itself a test method and the assumption – NEWEST_SUPPORTED should contain all known primitive types – is simply not true anymore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

should_not_return_v4_types_in_all_primitive_types_with_v3 (right above) could be deleted too.

@adutra adutra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving my own changes \o/

TINYINT(20, ProtocolVersion.V4),
DATE(17, ProtocolVersion.V4),
TIME(18, ProtocolVersion.V4);
TUPLE(49, ProtocolVersion.V3);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you re-order by protocolId, why not fully re-order?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, I missed a few of them.


@Override
public boolean apply(DataType dataType) {
return protocolVersion.compareTo(dataType.getName().minProtocolVersion) >= 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This method is only used in tests, therefore I would suggest that we move it to TestUtils, wdyt? To buy us some time, I will push a commit to do that myself, but feel free to revert if you disagree.

return protocolVersion.compareTo(dataType.getName().minProtocolVersion) >= 0;
// Duration is handled separately in DurationIntegrationTest, because it has specific restrictions (e.g.
// not allowed in collections).
return dataType.getName() != Name.DURATION &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, I think the "base" method should return all types for a given version, and let individual tests filter out undesired ones, like in DataTypeTest.exclude(DataType).

@Test(groups = "unit")
@Test(groups = "unit", enabled = false)
public void should_return_same_elements_with_all_primitive_types_using_latest_protocol_version() {
assertThat(DataType.allPrimitiveTypes(ProtocolVersion.NEWEST_SUPPORTED)).isEqualTo(DataType.allPrimitiveTypes());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I vote for removing it. The method under test – DataType.allPrimitiveTypes(ProtocolVersion) – is itself a test method and the assumption – NEWEST_SUPPORTED should contain all known primitive types – is simply not true anymore.

* This class is a singleton; to obtain its unique instance,
* call {@link #duration()}.
*/
public static class DurationType extends CustomType {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pushed a small commit to delete this.

*
* @param protocolVersion protocol version to get types for.
* @return returns a set of all the primitive types for the given protocolVersion.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Moved to TestUtils as per my own suggestion.

@Test(groups = "unit")
public void should_return_same_elements_with_all_primitive_types_using_latest_protocol_version() {
assertThat(DataType.allPrimitiveTypes(ProtocolVersion.NEWEST_SUPPORTED)).isEqualTo(DataType.allPrimitiveTypes());
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed these two tests, as they cover a method that has been moved to TestUtils.

@tolbertam tolbertam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good to me! 👍

@olim7t olim7t merged commit a12116a into 3.x Feb 10, 2017
@olim7t olim7t deleted the java1397 branch February 10, 2017 18:03
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.

3 participants