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

KAFKA-6474: Rewrite tests to use new public TopologyTestDriver [cleanup] #4939

Merged
merged 1 commit into from
May 7, 2018

Conversation

h314to
Copy link
Contributor

@h314to h314to commented Apr 27, 2018

This implements the suggestions made after the previous PR for KAFKA-6474 was merged.

The majority of changes deals with using try-with-resources and a new method in StreamsTestUtils to set the test properties and instantiate the TopologyTestDriver, thus allowing the removal of the cumbersome @Before and @After methods.

I also replaced stringSerde and intSerde variables with (almost equally succinct) inline calls to Serdes.String() and Serdes.Integer().

  • Add method to create test properties to StreamsTestUtils
  • Make TopologyTestDriver protected constructor package-private
  • Add comment suggesting the use of TopologyTestDriver to KStreamTestDriver
  • Cleanup:
    • GlobalKTableJoinsTest
    • KGroupedStreamImplTest
    • KGroupedTableImplTest
    • KStreamBranchTest
    • KStreamFilterTest
    • KStreamFlatMapTest
    • KStreamFlatMapValuesTest
    • KStreamForeachTest
    • KStreamGlobalKTableJoinTest
    • KStreamGlobalKTableLeftJoinTest
    • KStreamImplTest
    • KStreamKStreamJoinTest
    • KStreamKStreamLeftJoinTest
    • KStreamGlobalKTableLeftJoinTest
    • KStreamKTableJoinTest
    • KStreamKTableLeftJoinTest
    • KStreamMapTest
    • KStreamMapValuesTest
    • KStreamPeekTest
    • StreamsBuilderTest
    • KStreamSelectKeyTest
    • KStreamTransformTest
    • KStreamTransformValuesTest
    • KStreamWindowAggregateTest
    • KTableForeachTest

driver = new TopologyTestDriver(builder.build(), props);
}

@After
public void cleanup() {
if (driver != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should never happen, right? maybe we just don't check it and get an NPE if somehow driver gets set to null after the setup.

Copy link
Contributor Author

@h314to h314to Apr 27, 2018

Choose a reason for hiding this comment

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

Yes, since the driver in always created in @Before, something would have to be very wrong with a test for the driver to be null. I'll get rid of that check on @After.

driver = new TopologyTestDriver(builder.build(), props, 0L);
}

@After
public void cleanup() {
if (driver != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto on (what I think is) the impossibility of this condition being false.

driver = new TopologyTestDriver(builder.build(), props, 0L);
}

@After
public void cleanup() {
if (driver != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
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! Sorry for the extra work, but thanks for cleaning this stuff up.

I just had one minor thought that checking for the driver potentially being null should be unnecessary, so maybe we should just take it out. But it's your call.

Thanks again,
-John

@vvcephei
Copy link
Contributor

@guozhangwang @bbejeck Can you take a look also? These were changes I requested after the last PR got merged.

@h314to
Copy link
Contributor Author

h314to commented Apr 27, 2018

No problem @vvcephei . I already knew my way around these classes so implementing your suggestions was fairly straightforward. The code is definitely much clearer now. Thanks!

Copy link
Contributor

@bbejeck bbejeck left a comment

Choose a reason for hiding this comment

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

Sorry for the late response. Thanks for the follow-up PR @h314to. LGTM.

@bbejeck
Copy link
Contributor

bbejeck commented May 4, 2018

@h314to, sorry for the bother, but can you rebase this?

@guozhangwang
Copy link
Contributor

guozhangwang commented May 4, 2018

@h314to Could you rebase the PR again so it can be merged?

About KStreamTestDriver itself, are you planning to remove it after fixing all its dependent tests in another PR?

@h314to
Copy link
Contributor Author

h314to commented May 5, 2018

Yes, no problem. I'll squash the commits and rebase on the current trunk.

@guozhangwang I'm currently working on migrating the remaining classes from KStreamTestDriver to TopologyTestDriver, which I'll submit a subsequent PR (there's only about 8 classes left). I'm not sure if all the functionality in KStreamTestDriver is currently supported by TopologyTestDriver. If so, I was going to remove it like the Jira ticket requests. But I'll follow the community's best wisdom on this. It might be wise to keep it deprecated for a while before removing it. WDYT?

* Add method to create test properties to StreamsTestUtils
* Make TopologyTestDriver protected constructor package-private
* Add comment suggesting the use of TopologyTestDriver to KStreamTestDriver
* Cleanup:
    - GlobalKTableJoinsTest
    - KGroupedStreamImplTest
    - KGroupedTableImplTest
    - KStreamBranchTest
    - KStreamFilterTest
    - KStreamFlatMapTest
    - KStreamFlatMapValuesTest
    - KStreamForeachTest
    - KStreamGlobalKTableJoinTest
    - KStreamGlobalKTableLeftJoinTest
    - KStreamImplTest
    - KStreamKStreamJoinTest
    - KStreamKStreamLeftJoinTest
    - KStreamGlobalKTableLeftJoinTest
    - KStreamKTableJoinTest
    - KStreamKTableLeftJoinTest
    - KStreamMapTest
    - KStreamMapValuesTest
    - KStreamPeekTest
    - StreamsBuilderTest
    - KStreamSelectKeyTest
    - KStreamTransformTest
    - KStreamTransformValuesTest
    - KStreamWindowAggregateTest
    - KTableForeachTest
* Address reviewer's comments:
    - Remove check for null driver in @after
@guozhangwang
Copy link
Contributor

@h314to Thanks for the update @h314to , much appreciated.

About deprecating KStreamTestDriver, since it is not part of the public API we do not need to mark it deprecated, but I'm curious to learn which functionality gap do you see between it and the TopologyTestDriver? If there are we could consider adding them into the latter.

@h314to
Copy link
Contributor Author

h314to commented May 7, 2018

@guozhangwang I think the functionality gaps are mostly due to the balance between keeping the TopologyTestDriver clean and no-nonsense (which obviously has priority, since it is part of the public API), while still having access to stuff needed for internal testing.

For instance, we need to access the StreamTask processor context to init a KTableValueGetter, but it is probably not wise to expose it publicly. This was causing me trouble in several test classes. In the end I got around it by making it protected and providing access via a wrapper class that extends TopologyTestDriver, like I did for the constructor here. This will be included in my next PR, which will follow shortly.

@guozhangwang
Copy link
Contributor

@h314to Thanks for the information. That makes sense to me.

@guozhangwang guozhangwang merged commit 6f641fe into apache:trunk May 7, 2018
@guozhangwang
Copy link
Contributor

Merged to trunk.

@h314to h314to deleted the fix/KAFKA-6474-cleanup branch May 7, 2018 16:28
ying-zheng pushed a commit to ying-zheng/kafka that referenced this pull request Jul 6, 2018
…up] (apache#4939)

* Add method to create test properties to StreamsTestUtils
* Make TopologyTestDriver protected constructor package-private
* Add comment suggesting the use of TopologyTestDriver to KStreamTestDriver
* Cleanup:
    - GlobalKTableJoinsTest
    - KGroupedStreamImplTest
    - KGroupedTableImplTest
    - KStreamBranchTest
    - KStreamFilterTest
    - KStreamFlatMapTest
    - KStreamFlatMapValuesTest
    - KStreamForeachTest
    - KStreamGlobalKTableJoinTest
    - KStreamGlobalKTableLeftJoinTest
    - KStreamImplTest
    - KStreamKStreamJoinTest
    - KStreamKStreamLeftJoinTest
    - KStreamGlobalKTableLeftJoinTest
    - KStreamKTableJoinTest
    - KStreamKTableLeftJoinTest
    - KStreamMapTest
    - KStreamMapValuesTest
    - KStreamPeekTest
    - StreamsBuilderTest
    - KStreamSelectKeyTest
    - KStreamTransformTest
    - KStreamTransformValuesTest
    - KStreamWindowAggregateTest
    - KTableForeachTest

Reviewers: John Roesler <john@confluent.io>, Bill Bejeck <bill@confluent.io>, Guozhang Wang <wangguoz@gmail.com>
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.

4 participants