Skip to content

MINOR: code cleanup#6054

Merged
mjsax merged 3 commits intoapache:trunkfrom
mjsax:minor-code-cleanup-state-test
Jan 14, 2019
Merged

MINOR: code cleanup#6054
mjsax merged 3 commits intoapache:trunkfrom
mjsax:minor-code-cleanup-state-test

Conversation

@mjsax
Copy link
Copy Markdown
Member

@mjsax mjsax commented Dec 20, 2018

Similar PR as #6053

@mjsax mjsax added the streams label Dec 20, 2018
@mjsax
Copy link
Copy Markdown
Member Author

mjsax commented Dec 20, 2018

Call for review @guozhangwang @bbejeck @vvcephei

This was referenced Dec 20, 2018
@bbejeck
Copy link
Copy Markdown
Member

bbejeck commented Dec 20, 2018

retest this please

@mjsax
Copy link
Copy Markdown
Member Author

mjsax commented Jan 2, 2019

Retest this please.

Copy link
Copy Markdown
Contributor

@vvcephei vvcephei 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 for this cleanup also. Just some nits...

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.

Continuing from #6053 (comment), it seems strange to place the assignment at the beginning of a line.

This pattern recurs a lot in this PR, so I'll not comment on it further.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Did a search with Intellij. Hope I found all of them :)

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.

Could shorten this line with a static import and/or splitting it.

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 line is still long.

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 still long

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.

It looks like this method has just one usage. Should it be inlined?

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.

+1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because of new line breaks, the method got too long, and thus, I extracted some parts into own methods to make the build pass (otherwise checkstyle fails).

Happy to address the issue otherwise. But inlining won't work. Please let me know what you think.

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.

Ah, this is unfortunate, but a good enough justification for me.

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 guess the other option would be to disable the long-method checkstyle for tests. this might be reasonable, since test code is often like this (long sequence of operations and assertions) without harming readability.

As opposed to application code, where the methods are full of logic and conditionals and long methods seriously hinder comprehensibility.

I'm curious what @ijuma thinks about potentially making this exclusion for the whole project?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I'm not opposed to that. Another option is to use inline exclusions.

I'd also say that having long test methods is not great and extracting verify methods is not a bad plan. However, having numbers in the name is bad. Typically one can group assertions in a way that makes sense.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So what is the conclusion on that? I am fine any way (merge as-is, remove the checkstyle, rename those method (suggestions for better names), "Typically one can group assertions in a way that makes sense" -- not sure how to apply this to this test...)

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.

Thanks everyone. FWIW, I think my preference is still for putting in a checkstyle exclusion for tests.

But, I'm also fine with merging as-is, if that's your preference @mjsax .

I agree that in general, we can group assertions, but I think in this case it doesn't work out that way.

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.

Same question about this and the following methods... It looks like they're only used once. Should we inline them?

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'm a bit skeptical for functions whose name need a number suffix to distinguish with others, since it usually indicates loss of generality :P Could the common logic be shared, or if not I'd suggest we still inline all of them.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See comment above. The methods have nothing in common besides that they are verifying the store content at some point during the test. Not happy with the naming either, but had no better idea.

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.

Ditto on this method, which also appears to be used just once.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

compare comment above

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.

Just curious, why is this necessary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Intellij warns that some member (eg, processedKeys) are public.

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.

Sorry, my question was ambiguous. I'm wondering if, since this is a test artifact, we can consider it an internal API and therefore just make the method non-public.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess we could, but if one write a test and uses auto-completion it might be better to keep the public -- otherwise, they won't show up.

Copy link
Copy Markdown
Contributor

@guozhangwang guozhangwang left a comment

Choose a reason for hiding this comment

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

Made a pass.

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.

nit: I think this does not need to be broken to two lines as it is still quite short, and less than 3 parameters. Ditto below.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I like it better if we always break it down. But I will revert if you prefer.

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.

These are beyond code cleanup, wondering if it is related to jenkins failures?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Jenkins failed in core test (not sure about older runs -- build was deleted already).

This just closes a test gap.

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.

Ack, thanks for confirming.

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.

+1

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'm a bit skeptical for functions whose name need a number suffix to distinguish with others, since it usually indicates loss of generality :P Could the common logic be shared, or if not I'd suggest we still inline all of them.

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.

ditto here and below

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.

maybe worth specifying charset here

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.

same

@mjsax
Copy link
Copy Markdown
Member Author

mjsax commented Jan 3, 2019

Updated. Open question is about the extracted test methods.

@mjsax mjsax force-pushed the minor-code-cleanup-state-test branch from 518149a to a474b59 Compare January 13, 2019 04:34
@mjsax
Copy link
Copy Markdown
Member Author

mjsax commented Jan 13, 2019

Rebased. Will merge as-is as no other option seems to be better.

@mjsax
Copy link
Copy Markdown
Member Author

mjsax commented Jan 13, 2019

kafka.api.CustomQuotaCallbackTest.testCustomQuotaCallback failed.

Retest this please.

@guozhangwang
Copy link
Copy Markdown
Contributor

I'd suggest we add an exception to allow inlines for the long unit test cases. Otherwise I'm +1 on this PR.

Please feel free to merge afterwards.

@mjsax
Copy link
Copy Markdown
Member Author

mjsax commented Jan 14, 2019

Updated this:

  • inlined methods
  • added method length checkstyle exception
  • replaced double-brace initialization

@mjsax
Copy link
Copy Markdown
Member Author

mjsax commented Jan 14, 2019

Execution failed for task ':core:compileTestScala'

Not sure how this could have happened. Java8 build passed.

Retest this please.

@ijuma
Copy link
Copy Markdown
Member

ijuma commented Jan 14, 2019

I fixed a build issue that only affected Java 11 a few hours ago. Maybe you need to rebase to include that.

@mjsax mjsax merged commit 82d1db6 into apache:trunk Jan 14, 2019
@mjsax mjsax deleted the minor-code-cleanup-state-test branch January 14, 2019 21:36
pengxiaolong pushed a commit to pengxiaolong/kafka that referenced this pull request Jun 14, 2019
Reviewers: Bill Bejeck <bill@confluent.io>, John Roesler <john@confluent.io>, Guozhang Wang <guozhang@confluent.io>, Ryanne Dolan <ryannedolan@gmail.com>, Ismael Juma <ismael@confuent.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants