Package org.apache.beam.sdk.testing
Class PAssert
java.lang.Object
org.apache.beam.sdk.testing.PAssert
An assertion on the contents of a
PCollection incorporated into the pipeline. Such an
assertion can be checked no matter what kind of PipelineRunner is used.
Note that the PAssert call must precede the call to Pipeline.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 ClassesModifier and TypeClassDescriptionstatic classDefault transform to check that a PAssert was successful.static classA transform that applies an assertion-checking function over iterables ofActualTto the entirety of the contents of its input.static classA transform that applies an assertion-checking function to the sole element of aPCollection.static interfaceBuilder interface for assertions applicable to iterables and PCollection contents.protected static classCheck that the passed-in matchers match the existing data.static classAn assertion checker that takes a singlePCollectionView<ActualT>and an assertion overActualT, and checks it within a Beam pipeline.static classTrack the place where an assertion is defined.protected static classAnPAssert.IterableAssertabout the contents of aPCollection.protected static classAn assert about the contents of eachPCollectionin the givenPCollectionList.static interfaceBuilder interface for assertions applicable to a single value. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic intcountAsserts(Pipeline pipeline) protected static <ActualT> SuccessOrFailuredoChecks(PAssert.PAssertionSite site, ActualT actualContents, SerializableFunction<ActualT, Void> checkerFn) static <T> PAssert.IterableAssert<T> that(String reason, PCollection<T> actual) Constructs anPAssert.IterableAssertfor the elements of the providedPCollectionwith the specified reason.static <T> PAssert.IterableAssert<T> that(PCollection<T> actual) Constructs anPAssert.IterableAssertfor the elements of the providedPCollection.static <T> PAssert.IterableAssert<T> thatFlattened(String reason, PCollectionList<T> actual) Constructs anPAssert.IterableAssertfor the elements of the flattenedPCollectionListwith the specified reason.static <T> PAssert.IterableAssert<T> thatFlattened(PCollectionList<T> actual) Constructs anPAssert.IterableAssertfor the elements of the flattenedPCollectionList.static <T> PAssert.PCollectionListContentsAssert<T> thatList(PCollectionList<T> actual) Constructs anPAssert.PCollectionListContentsAssertfor the providedPCollectionList.static <K,V> PAssert.SingletonAssert <Map<K, V>> thatMap(String reason, PCollection<KV<K, V>> actual) Constructs aPAssert.SingletonAssertfor the value of the providedPCollectionwith the specified reason.static <K,V> PAssert.SingletonAssert <Map<K, V>> thatMap(PCollection<KV<K, V>> actual) Constructs aPAssert.SingletonAssertfor the value of the providedPCollection, which must have at most one value per key.static <K,V> PAssert.SingletonAssert <Map<K, Iterable<V>>> thatMultimap(String reason, PCollection<KV<K, V>> actual) Constructs aPAssert.SingletonAssertfor the value of the providedPCollectionwith the specified reason.static <K,V> PAssert.SingletonAssert <Map<K, Iterable<V>>> thatMultimap(PCollection<KV<K, V>> actual) Constructs aPAssert.SingletonAssertfor the value of the providedPCollection.static <T> PAssert.SingletonAssert<T> thatSingleton(String reason, PCollection<T> actual) Constructs aPAssert.SingletonAssertfor the value of the providedPCollection PCollection<T>with the specified reason.static <T> PAssert.SingletonAssert<T> thatSingleton(PCollection<T> actual) Constructs aPAssert.SingletonAssertfor the value of the providedPCollection PCollection<T>, which must be a singleton.static <T> PAssert.IterableAssert<T> thatSingletonIterable(String reason, PCollection<? extends Iterable<T>> actual) Constructs anPAssert.IterableAssertfor the value of the providedPCollectionwith the specified reason.static <T> PAssert.IterableAssert<T> thatSingletonIterable(PCollection<? extends Iterable<T>> actual) Constructs anPAssert.IterableAssertfor the value of the providedPCollectionwhich must contain a singleIterable<T>value.
-
Field Details
-
SUCCESS_COUNTER
- See Also:
-
FAILURE_COUNTER
- See Also:
-
-
Method Details
-
that
Constructs anPAssert.IterableAssertfor the elements of the providedPCollection. -
that
Constructs anPAssert.IterableAssertfor the elements of the providedPCollectionwith the specified reason. -
thatSingletonIterable
public static <T> PAssert.IterableAssert<T> thatSingletonIterable(PCollection<? extends Iterable<T>> actual) Constructs anPAssert.IterableAssertfor the value of the providedPCollectionwhich must contain a singleIterable<T>value. -
thatSingletonIterable
public static <T> PAssert.IterableAssert<T> thatSingletonIterable(String reason, PCollection<? extends Iterable<T>> actual) Constructs anPAssert.IterableAssertfor the value of the providedPCollectionwith the specified reason. The provided PCollection must contain a singleIterable<T>value. -
thatSingleton
Constructs aPAssert.SingletonAssertfor the value of the providedPCollection PCollection<T>, which must be a singleton. -
thatSingleton
Constructs aPAssert.SingletonAssertfor 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<Map<K,Iterable<V>>> thatMultimap(PCollection<KV<K, V>> actual) Constructs aPAssert.SingletonAssertfor 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<Map<K,Iterable<V>>> thatMultimap(String reason, PCollection<KV<K, V>> actual) Constructs aPAssert.SingletonAssertfor the value of the providedPCollectionwith the specified reason.Note that the actual value must be coded by a
KvCoder, not just anyCoder<K, V>. -
thatMap
Constructs aPAssert.SingletonAssertfor 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<Map<K,V>> thatMap(String reason, PCollection<KV<K, V>> actual) Constructs aPAssert.SingletonAssertfor the value of the providedPCollectionwith the specified reason. ThePCollectionmust have at most one value per key.Note that the actual value must be coded by a
KvCoder, not just anyCoder<K, V>. -
thatList
Constructs anPAssert.PCollectionListContentsAssertfor the providedPCollectionList. -
thatFlattened
Constructs anPAssert.IterableAssertfor the elements of the flattenedPCollectionList. -
thatFlattened
Constructs anPAssert.IterableAssertfor the elements of the flattenedPCollectionListwith the specified reason. -
doChecks
protected static <ActualT> SuccessOrFailure doChecks(PAssert.PAssertionSite site, ActualT actualContents, SerializableFunction<ActualT, Void> checkerFn) -
countAsserts
-