Skip to content

Commit

Permalink
BEAM-13765 missing PAssert methods (#16668)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuthan authored Mar 8, 2022
1 parent 9afde56 commit 9833b7b
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
* 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.
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 9833b7b

Please sign in to comment.