Skip to content
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

Migrate to Java 16 records (part 2) #82914

Merged
merged 2 commits into from
Jan 24, 2022
Merged

Conversation

arteam
Copy link
Contributor

@arteam arteam commented Jan 22, 2022

Try to represent immutable data with Java records introduced in JEP 395

Convert only existing immutable classes, no "POJO with setters to a record" refactorings.

@arteam arteam changed the title Migrate to Java16 records (part 2) Migrate to Java 16 records (part 2) Jan 22, 2022
@arteam arteam force-pushed the records-part2 branch 6 times, most recently from b7abdf8 to ccf09a1 Compare January 23, 2022 12:05
@arteam arteam added >non-issue >refactoring :Core/Infra/Core Core issues without another label labels Jan 24, 2022
@arteam arteam marked this pull request as ready for review January 24, 2022 08:36
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Jan 24, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@arteam arteam added auto-backport Automatically create backport pull requests when merged v8.0.0 labels Jan 24, 2022
Copy link
Contributor

@grcevski grcevski left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks Artem.

I left two questions about some small test changes.

ShardSegments shardSegmentsOne = Mockito.mock(ShardSegments.class);
ShardSegments[] shardSegmentsArray = new ShardSegments[] { shardSegmentsOne };
IndexShardSegments indexShardSegments = new IndexShardSegments(ShardId.fromString("[idx][123]"), shardSegmentsArray);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, what was the reason for this test change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It used to be a mock via Mockito.mock(IndexShardSegments.class), but with the change IndexShardSegments is now a record which is final. Mockito can't mock final classes without additional Java agent instrumentation. So we have to use a "real" data class here.

final Build mockBuild = mock(Build.class);
when(mockBuild.flavor()).thenReturn(Build.Flavor.DEFAULT);
when(mockBuild.type()).thenReturn(Build.Type.DOCKER);
final Build mockBuild = new Build(Build.Flavor.DEFAULT, Build.Type.DOCKER, "", "", false, "");
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar question about this test change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same purpose here. We can't mock records and Mockito usually advice against mocking data classes.

@arteam arteam merged commit cce5ad2 into elastic:master Jan 24, 2022
@arteam
Copy link
Contributor Author

arteam commented Jan 24, 2022

Thanks Nikola!

@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.0 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 82914

arteam added a commit to arteam/elasticsearch that referenced this pull request Jan 24, 2022
@arteam arteam deleted the records-part2 branch January 25, 2022 06:58
arteam added a commit that referenced this pull request Jan 25, 2022
@pugnascotia pugnascotia removed the v8.0.0 label Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged :Core/Infra/Core Core issues without another label >non-issue >refactoring Team:Core/Infra Meta label for core/infra team v8.0.0-rc2 v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants