Package org.apache.beam.sdk.testing
Class PAssert
- java.lang.Object
-
- org.apache.beam.sdk.testing.PAssert
-
public class PAssert extends java.lang.Object
An assertion on the contents of aPCollection
incorporated into the pipeline. Such an assertion can be checked no matter what kind ofPipelineRunner
is used.Note that the
PAssert
call must precede the call toPipeline.run()
.Examples of use:
Pipeline p = TestPipeline.create(); ... PCollection<String> output = input .apply(ParDo.of(new TestDoFn())); PAssert.that(output) .containsInAnyOrder("out1", "out2", "out3"); ... PCollection<Integer> ints = ... PCollection<Integer> sum = ints .apply(Combine.globally(new SumInts())); PAssert.thatSingleton(sum) .isEqualTo(42); ... p.run();
JUnit and Hamcrest must be linked in by any code that uses PAssert.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PAssert.DefaultConcludeTransform
Default transform to check that a PAssert was successful.static class
PAssert.GroupThenAssert<T>
A transform that applies an assertion-checking function over iterables ofActualT
to the entirety of the contents of its input.static class
PAssert.GroupThenAssertForSingleton<T>
A transform that applies an assertion-checking function to the sole element of aPCollection
.static interface
PAssert.IterableAssert<T>
Builder interface for assertions applicable to iterables and PCollection contents.protected static class
PAssert.MatcherCheckerFn<T>
Check that the passed-in matchers match the existing data.static class
PAssert.OneSideInputAssert<ActualT>
An assertion checker that takes a singlePCollectionView<ActualT>
and an assertion overActualT
, and checks it within a Beam pipeline.static class
PAssert.PAssertionSite
Track the place where an assertion is defined.protected static class
PAssert.PCollectionContentsAssert<T>
AnPAssert.IterableAssert
about the contents of aPCollection
.protected static class
PAssert.PCollectionListContentsAssert<T>
An assert about the contents of eachPCollection
in the givenPCollectionList
.static interface
PAssert.SingletonAssert<T>
Builder interface for assertions applicable to a single value.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
FAILURE_COUNTER
static java.lang.String
SUCCESS_COUNTER
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
countAsserts(Pipeline pipeline)
protected static <ActualT> SuccessOrFailure
doChecks(PAssert.PAssertionSite site, ActualT actualContents, SerializableFunction<ActualT,java.lang.Void> checkerFn)
static <T> PAssert.IterableAssert<T>
that(java.lang.String reason, PCollection<T> actual)
Constructs anPAssert.IterableAssert
for the elements of the providedPCollection
with the specified reason.static <T> PAssert.IterableAssert<T>
that(PCollection<T> actual)
Constructs anPAssert.IterableAssert
for the elements of the providedPCollection
.static <T> PAssert.IterableAssert<T>
thatFlattened(java.lang.String reason, PCollectionList<T> actual)
Constructs anPAssert.IterableAssert
for the elements of the flattenedPCollectionList
with the specified reason.static <T> PAssert.IterableAssert<T>
thatFlattened(PCollectionList<T> actual)
Constructs anPAssert.IterableAssert
for the elements of the flattenedPCollectionList
.static <T> PAssert.PCollectionListContentsAssert<T>
thatList(PCollectionList<T> actual)
Constructs anPAssert.PCollectionListContentsAssert
for the providedPCollectionList
.static <K,V>
PAssert.SingletonAssert<java.util.Map<K,V>>thatMap(java.lang.String reason, PCollection<KV<K,V>> actual)
Constructs aPAssert.SingletonAssert
for the value of the providedPCollection
with the specified reason.static <K,V>
PAssert.SingletonAssert<java.util.Map<K,V>>thatMap(PCollection<KV<K,V>> actual)
Constructs aPAssert.SingletonAssert
for the value of the providedPCollection
, which must have at most one value per key.static <K,V>
PAssert.SingletonAssert<java.util.Map<K,java.lang.Iterable<V>>>thatMultimap(java.lang.String reason, PCollection<KV<K,V>> actual)
Constructs aPAssert.SingletonAssert
for the value of the providedPCollection
with the specified reason.static <K,V>
PAssert.SingletonAssert<java.util.Map<K,java.lang.Iterable<V>>>thatMultimap(PCollection<KV<K,V>> actual)
Constructs aPAssert.SingletonAssert
for the value of the providedPCollection
.static <T> PAssert.SingletonAssert<T>
thatSingleton(java.lang.String reason, PCollection<T> actual)
Constructs aPAssert.SingletonAssert
for the value of the providedPCollection PCollection<T>
with the specified reason.static <T> PAssert.SingletonAssert<T>
thatSingleton(PCollection<T> actual)
Constructs aPAssert.SingletonAssert
for the value of the providedPCollection PCollection<T>
, which must be a singleton.static <T> PAssert.IterableAssert<T>
thatSingletonIterable(java.lang.String reason, PCollection<? extends java.lang.Iterable<T>> actual)
Constructs anPAssert.IterableAssert
for the value of the providedPCollection
with the specified reason.static <T> PAssert.IterableAssert<T>
thatSingletonIterable(PCollection<? extends java.lang.Iterable<T>> actual)
Constructs anPAssert.IterableAssert
for the value of the providedPCollection
which must contain a singleIterable<T>
value.
-
-
-
Field Detail
-
SUCCESS_COUNTER
public static final java.lang.String SUCCESS_COUNTER
- See Also:
- Constant Field Values
-
FAILURE_COUNTER
public static final java.lang.String FAILURE_COUNTER
- See Also:
- Constant Field Values
-
-
Method Detail
-
that
public static <T> PAssert.IterableAssert<T> that(PCollection<T> actual)
Constructs anPAssert.IterableAssert
for the elements of the providedPCollection
.
-
that
public static <T> PAssert.IterableAssert<T> that(java.lang.String reason, PCollection<T> actual)
Constructs anPAssert.IterableAssert
for the elements of the providedPCollection
with the specified reason.
-
thatSingletonIterable
public static <T> PAssert.IterableAssert<T> thatSingletonIterable(PCollection<? extends java.lang.Iterable<T>> actual)
Constructs anPAssert.IterableAssert
for the value of the providedPCollection
which must contain a singleIterable<T>
value.
-
thatSingletonIterable
public static <T> PAssert.IterableAssert<T> thatSingletonIterable(java.lang.String reason, PCollection<? extends java.lang.Iterable<T>> actual)
Constructs anPAssert.IterableAssert
for the value of the providedPCollection
with the specified reason. The provided PCollection must contain a singleIterable<T>
value.
-
thatSingleton
public static <T> PAssert.SingletonAssert<T> thatSingleton(PCollection<T> actual)
Constructs aPAssert.SingletonAssert
for the value of the providedPCollection PCollection<T>
, which must be a singleton.
-
thatSingleton
public static <T> PAssert.SingletonAssert<T> thatSingleton(java.lang.String reason, PCollection<T> actual)
Constructs aPAssert.SingletonAssert
for the value of the providedPCollection PCollection<T>
with the specified reason. The provided PCollection must be a singleton.
-
thatMultimap
public static <K,V> PAssert.SingletonAssert<java.util.Map<K,java.lang.Iterable<V>>> thatMultimap(PCollection<KV<K,V>> actual)
Constructs aPAssert.SingletonAssert
for the value of the providedPCollection
.Note that the actual value must be coded by a
KvCoder
, not just anyCoder<K, V>
.
-
thatMultimap
public static <K,V> PAssert.SingletonAssert<java.util.Map<K,java.lang.Iterable<V>>> thatMultimap(java.lang.String reason, PCollection<KV<K,V>> actual)
Constructs aPAssert.SingletonAssert
for the value of the providedPCollection
with the specified reason.Note that the actual value must be coded by a
KvCoder
, not just anyCoder<K, V>
.
-
thatMap
public static <K,V> PAssert.SingletonAssert<java.util.Map<K,V>> thatMap(PCollection<KV<K,V>> actual)
Constructs aPAssert.SingletonAssert
for the value of the providedPCollection
, which must have at most one value per key.Note that the actual value must be coded by a
KvCoder
, not just anyCoder<K, V>
.
-
thatMap
public static <K,V> PAssert.SingletonAssert<java.util.Map<K,V>> thatMap(java.lang.String reason, PCollection<KV<K,V>> actual)
Constructs aPAssert.SingletonAssert
for the value of the providedPCollection
with the specified reason. ThePCollection
must have at most one value per key.Note that the actual value must be coded by a
KvCoder
, not just anyCoder<K, V>
.
-
thatList
public static <T> PAssert.PCollectionListContentsAssert<T> thatList(PCollectionList<T> actual)
Constructs anPAssert.PCollectionListContentsAssert
for the providedPCollectionList
.
-
thatFlattened
public static <T> PAssert.IterableAssert<T> thatFlattened(PCollectionList<T> actual)
Constructs anPAssert.IterableAssert
for the elements of the flattenedPCollectionList
.
-
thatFlattened
public static <T> PAssert.IterableAssert<T> thatFlattened(java.lang.String reason, PCollectionList<T> actual)
Constructs anPAssert.IterableAssert
for the elements of the flattenedPCollectionList
with the specified reason.
-
doChecks
protected static <ActualT> SuccessOrFailure doChecks(PAssert.PAssertionSite site, ActualT actualContents, SerializableFunction<ActualT,java.lang.Void> checkerFn)
-
countAsserts
public static int countAsserts(Pipeline pipeline)
-
-