Skip to content

[BEAM-2558] Migrate checkCombineFn in TestUtils to CombineFnTester#3628

Closed
tgroh wants to merge 2 commits intoapache:masterfrom
tgroh:combine_fn_tester
Closed

[BEAM-2558] Migrate checkCombineFn in TestUtils to CombineFnTester#3628
tgroh wants to merge 2 commits intoapache:masterfrom
tgroh:combine_fn_tester

Conversation

@tgroh
Copy link
Member

@tgroh tgroh commented Jul 24, 2017

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

This makes CombineFnTester significantly more discoverable, and usable
without having dependencies on the test JAR.

Update existing tests.

This is purely a move of code with minor renaming, visibility limiting, and
updates to include empty accumulators on both ends of mergeAccumulators.

Worth considering is also ensuring that the output (as returned by extractOutput)
is not the same as any of the merged accumulators (as doing so potentially interacts
poorly with a lifted Combine)

@tgroh
Copy link
Member Author

tgroh commented Jul 24, 2017

R: @robertwb @kennknowles (either)

@tgroh tgroh force-pushed the combine_fn_tester branch 2 times, most recently from e350c59 to e930810 Compare July 25, 2017 18:14
List<? extends Iterable<InputT>> shards,
Matcher<? super OutputT> matcher) {
checkCombineFnShardsWithEmptyAccumulators(fn, shards, matcher);
Collections.shuffle(shards); checkCombineFnShardsWithEmptyAccumulators(fn, shards, matcher);
Copy link
Contributor

Choose a reason for hiding this comment

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

Split into two lines?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Collections.shuffle(shards); checkCombineFnShardsWithEmptyAccumulators(fn, shards, matcher);
}

private static <InputT, AccumT, OutputT> void checkCombineFnShardsWithEmptyAccumulators(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also check without empty accumulators?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

checkCombineFnShardsMultipleOrders(fn, shardExponentially(input, 1.4), matcher);
checkCombineFnShardsMultipleOrders(fn, shardExponentially(input, 2), matcher);
checkCombineFnShardsMultipleOrders(fn, shardExponentially(input, Math.E), matcher);
}
Copy link
Contributor

@robertwb robertwb Jul 25, 2017

Choose a reason for hiding this comment

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

This utility was written before streaming. Should we also test that style of combining, e.g.

extractOutput(
  merge(createAccumulator().addInput(v1),
    merge(createAccumulator().addInput(v2),
        merge(createAccumulator().addInput(v3),
          ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

This makes CombineFnTester significantly more discoverable, and usable
without having dependencies on the test JAR.

Update existing tests.
@tgroh tgroh force-pushed the combine_fn_tester branch from e930810 to 3509c11 Compare July 25, 2017 21:56
Copy link
Contributor

@robertwb robertwb left a comment

Choose a reason for hiding this comment

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

LGTM, pending tests. Thanks.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f5edcc8 on tgroh:combine_fn_tester into ** on apache:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f5edcc8 on tgroh:combine_fn_tester into ** on apache:master**.

@tgroh
Copy link
Member Author

tgroh commented Jul 26, 2017

Added tests.

@mingmxu
Copy link

mingmxu commented Jul 26, 2017

retest this please

public class CombineFnTesterTest {
@Test
public void checksMergeWithEmptyAccumulators() {
final AtomicBoolean sawEmpty = new AtomicBoolean(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need to be atomic?

Copy link
Member Author

Choose a reason for hiding this comment

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

It needs to be mutable and also final; AtomicBoolean is just an easy way to do that.

@Test
public void checksWithShards() {
final AtomicBoolean sawManyShards = new AtomicBoolean();
CombineFn<Integer, int[], Integer> combineFn =
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be cleaner to just use an Integer for the accumulator as performance doesn't matter here.


@Override
public List<Integer> addInput(List<Integer> accumulator, Integer input) {
if (!accumulator.isEmpty() && accumulator.get(accumulator.size() - 1) > input) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is a bit obscure, comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

}
};
CombineFnTester.testCombineFn(
Sum.ofIntegers(), Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5), matcher);
Copy link
Contributor

Choose a reason for hiding this comment

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

For this kind of test I think it's more succinct to use a matcher that matches nothing (or the wrong thing) and verify that CombineFnTester.testCombine fails. (For writing TesterTesters, my preference is generally to write a Fn that fails (just) the property you are trying to validate, and verify that the tester rejects it. However, this works as well.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I have done both.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 70.478% when pulling 00ccc9f on tgroh:combine_fn_tester into 69a51c9 on apache:master.

@tgroh tgroh force-pushed the combine_fn_tester branch from 00ccc9f to 2215f4a Compare July 26, 2017 21:06
Copy link
Contributor

@robertwb robertwb left a comment

Choose a reason for hiding this comment

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

LGTM

@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 70.464% when pulling 2215f4a on tgroh:combine_fn_tester into b67a30b on apache:master.

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