-
Notifications
You must be signed in to change notification settings - Fork 4.5k
BEAM-13765 missing PAssert methods #16668
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,6 +233,19 @@ public interface IterableAssert<T> { | |
| */ | ||
| IterableAssert<T> inWindow(BoundedWindow window); | ||
|
|
||
| /** | ||
| * Creates a new {@link IterableAssert} like this one, but with the assertion restricted to only | ||
| * run on the provided window. | ||
| * | ||
| * <p>The assertion will expect outputs to be produced to the provided window exactly once. If | ||
| * the upstream {@link Trigger} may produce output multiple times, consider instead using {@link | ||
| * #inFinalPane(BoundedWindow)} or {@link #inOnTimePane(BoundedWindow)}. | ||
| * | ||
| * @return a new {@link IterableAssert} like this one but with the assertion only applied to the | ||
| * specified window. | ||
| */ | ||
| IterableAssert<T> inOnlyPane(BoundedWindow window); | ||
|
|
||
| /** | ||
| * Creates a new {@link IterableAssert} like this one, but with the assertion restricted to only | ||
| * run on the provided window, running the checker only on the final pane for each key. | ||
|
|
@@ -340,6 +353,20 @@ public interface IterableAssert<T> { | |
|
|
||
| /** Builder interface for assertions applicable to a single value. */ | ||
| public interface SingletonAssert<T> { | ||
| /** | ||
| * Creates a new {@link SingletonAssert} like this one, but with the assertion restricted to | ||
| * only run on the provided window. | ||
| * | ||
| * <p>The assertion will concatenate all panes present in the provided window if the {@link | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion sort of applies to multiple values inherently, so that is probably why it wasn't present.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, 'inWindow' assertion means that only window boundaries should be checked but I don't care if the element is early, on-time or late. If there is a single element in the result the SingletonAssert is needed. For example (Scio like DSL for testing): |
||
| * Trigger} produces multiple panes. If the windowing strategy accumulates fired panes and | ||
| * triggers fire multple times, consider using instead {@link #inFinalPane(BoundedWindow)} or | ||
| * {@link #inOnTimePane(BoundedWindow)}. | ||
| * | ||
| * @return a new {@link SingletonAssert} like this one but with the assertion only applied to | ||
| * the specified window. | ||
| */ | ||
| SingletonAssert<T> inWindow(BoundedWindow window); | ||
|
|
||
| /** | ||
| * Creates a new {@link SingletonAssert} like this one, but with the assertion restricted to | ||
| * only run on the provided window. | ||
|
|
@@ -631,6 +658,11 @@ public PCollectionContentsAssert<T> inWindow(BoundedWindow window) { | |
| return withPane(window, PaneExtractors.allPanes()); | ||
| } | ||
|
|
||
| @Override | ||
| public PCollectionContentsAssert<T> inOnlyPane(BoundedWindow window) { | ||
| return withPane(window, PaneExtractors.onlyPane(site)); | ||
| } | ||
|
|
||
| @Override | ||
| public PCollectionContentsAssert<T> inFinalPane(BoundedWindow window) { | ||
| return withPane(window, PaneExtractors.finalPane()); | ||
|
|
@@ -822,6 +854,11 @@ public PCollectionSingletonIterableAssert<T> inWindow(BoundedWindow window) { | |
| return withPanes(window, PaneExtractors.allPanes()); | ||
| } | ||
|
|
||
| @Override | ||
| public PCollectionSingletonIterableAssert<T> inOnlyPane(BoundedWindow window) { | ||
| return withPanes(window, PaneExtractors.onlyPane(site)); | ||
| } | ||
|
|
||
| @Override | ||
| public PCollectionSingletonIterableAssert<T> inFinalPane(BoundedWindow window) { | ||
| return withPanes(window, PaneExtractors.finalPane()); | ||
|
|
@@ -943,6 +980,11 @@ private static class PCollectionSingletonAssert<T> implements SingletonAssert<T> | |
| this.site = site; | ||
| } | ||
|
|
||
| @Override | ||
| public PCollectionSingletonAssert<T> inWindow(BoundedWindow window) { | ||
| return withPanes(window, PaneExtractors.allPanes()); | ||
| } | ||
|
|
||
| @Override | ||
| public PCollectionSingletonAssert<T> inFinalPane(BoundedWindow window) { | ||
| return withPanes(window, PaneExtractors.finalPane()); | ||
|
|
@@ -1071,6 +1113,11 @@ private PCollectionViewAssert( | |
| this.site = site; | ||
| } | ||
|
|
||
| @Override | ||
| public PCollectionViewAssert<ElemT, ViewT> inWindow(BoundedWindow window) { | ||
| return inPane(window, PaneExtractors.allPanes()); | ||
| } | ||
|
|
||
| @Override | ||
| public PCollectionViewAssert<ElemT, ViewT> inOnlyPane(BoundedWindow window) { | ||
| return inPane(window, PaneExtractors.onlyPane(site)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I double checked that adequate validation is in place to ensure this is not applied when there is more than one pane. Curiously the validation occurs on the
PaneInfoof emitted elements rather than by examining the trigger. But anyhow this one seems safe enough.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of validation do you mean? If I understood the code, the assertions like
inOnTimePane,inLatePane, orinWindowapply a simple filter usingPaneInfoto ensure that only data from given pane is passed for further assertions.The
PaneExtractors.onlyPaneis somehow special because it might throw anAssertionError, it seems to be correct, the filtering is not enough to ensure that it is the only pane.The condition for "only pane" is defined as
not(!pane.isFirst() || !pane.isLast()). Wouldn't it be more straightforward to throw an error ifpane.index > 0?