[BEAM-2558] Migrate checkCombineFn in TestUtils to CombineFnTester#3628
[BEAM-2558] Migrate checkCombineFn in TestUtils to CombineFnTester#3628tgroh wants to merge 2 commits intoapache:masterfrom
Conversation
|
R: @robertwb @kennknowles (either) |
e350c59 to
e930810
Compare
| List<? extends Iterable<InputT>> shards, | ||
| Matcher<? super OutputT> matcher) { | ||
| checkCombineFnShardsWithEmptyAccumulators(fn, shards, matcher); | ||
| Collections.shuffle(shards); checkCombineFnShardsWithEmptyAccumulators(fn, shards, matcher); |
| Collections.shuffle(shards); checkCombineFnShardsWithEmptyAccumulators(fn, shards, matcher); | ||
| } | ||
|
|
||
| private static <InputT, AccumT, OutputT> void checkCombineFnShardsWithEmptyAccumulators( |
There was a problem hiding this comment.
Should we also check without empty accumulators?
| checkCombineFnShardsMultipleOrders(fn, shardExponentially(input, 1.4), matcher); | ||
| checkCombineFnShardsMultipleOrders(fn, shardExponentially(input, 2), matcher); | ||
| checkCombineFnShardsMultipleOrders(fn, shardExponentially(input, Math.E), matcher); | ||
| } |
There was a problem hiding this comment.
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),
...
This makes CombineFnTester significantly more discoverable, and usable without having dependencies on the test JAR. Update existing tests.
robertwb
left a comment
There was a problem hiding this comment.
LGTM, pending tests. Thanks.
|
Changes Unknown when pulling f5edcc8 on tgroh:combine_fn_tester into ** on apache:master**. |
|
Changes Unknown when pulling f5edcc8 on tgroh:combine_fn_tester into ** on apache:master**. |
|
Added tests. |
|
retest this please |
| public class CombineFnTesterTest { | ||
| @Test | ||
| public void checksMergeWithEmptyAccumulators() { | ||
| final AtomicBoolean sawEmpty = new AtomicBoolean(false); |
There was a problem hiding this comment.
Why does this need to be atomic?
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
This line is a bit obscure, comment?
| } | ||
| }; | ||
| CombineFnTester.testCombineFn( | ||
| Sum.ofIntegers(), Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5), matcher); |
There was a problem hiding this comment.
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.)
Follow this checklist to help us incorporate your contribution quickly and easily:
[BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replaceBEAM-XXXwith the appropriate JIRA issue.mvn clean verifyto make sure basic checks pass. A more thorough check will be performed on your pull request automatically.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)