public class PAssert
extends java.lang.Object
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.that(sum)
.is(42);
...
p.run();
JUnit and Hamcrest must be linked in by any code that uses PAssert.
Modifier and Type | Class and 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 of
ActualT to
the entirety of the contents of its input. |
static class |
PAssert.GroupThenAssertForSingleton<T>
A transform that applies an assertion-checking function to a single iterable contained as the
sole element of a
PCollection . |
static interface |
PAssert.IterableAssert<T>
Builder interface for assertions applicable to iterables and PCollection contents.
|
static class |
PAssert.OneSideInputAssert<ActualT>
An assertion checker that takes a single
PCollectionView<ActualT> and an assertion over ActualT , 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>
An
PAssert.IterableAssert about the contents of a PCollection . |
static interface |
PAssert.SingletonAssert<T>
Builder interface for assertions applicable to a single value.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FAILURE_COUNTER |
static java.lang.String |
SUCCESS_COUNTER |
Modifier and Type | Method and 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(PCollection<T> actual)
Constructs an
PAssert.IterableAssert for the elements of the provided PCollection . |
static <T> PAssert.IterableAssert<T> |
that(java.lang.String reason,
PCollection<T> actual)
Constructs an
PAssert.IterableAssert for the elements of the provided PCollection
with the specified reason. |
static <K,V> PAssert.SingletonAssert<java.util.Map<K,V>> |
thatMap(PCollection<KV<K,V>> actual)
Constructs a
PAssert.SingletonAssert for the value of the provided PCollection , which
must have at most one value per key. |
static <K,V> PAssert.SingletonAssert<java.util.Map<K,V>> |
thatMap(java.lang.String reason,
PCollection<KV<K,V>> actual)
Constructs a
PAssert.SingletonAssert for the value of the provided PCollection with
the specified reason. |
static <K,V> PAssert.SingletonAssert<java.util.Map<K,java.lang.Iterable<V>>> |
thatMultimap(PCollection<KV<K,V>> actual)
Constructs a
PAssert.SingletonAssert for the value of the provided PCollection . |
static <K,V> PAssert.SingletonAssert<java.util.Map<K,java.lang.Iterable<V>>> |
thatMultimap(java.lang.String reason,
PCollection<KV<K,V>> actual)
Constructs a
PAssert.SingletonAssert for the value of the provided PCollection with the
specified reason. |
static <T> PAssert.SingletonAssert<T> |
thatSingleton(PCollection<T> actual)
Constructs a
PAssert.SingletonAssert for the value of the provided
PCollection PCollection<T> , which must be a singleton. |
static <T> PAssert.SingletonAssert<T> |
thatSingleton(java.lang.String reason,
PCollection<T> actual)
Constructs a
PAssert.SingletonAssert for the value of the provided
PCollection PCollection<T> with the specified reason. |
static <T> PAssert.IterableAssert<T> |
thatSingletonIterable(PCollection<? extends java.lang.Iterable<T>> actual)
Constructs an
PAssert.IterableAssert for the value of the provided PCollection which
must contain a single Iterable<T> value. |
static <T> PAssert.IterableAssert<T> |
thatSingletonIterable(java.lang.String reason,
PCollection<? extends java.lang.Iterable<T>> actual)
Constructs an
PAssert.IterableAssert for the value of the provided PCollection with
the specified reason. |
public static final java.lang.String SUCCESS_COUNTER
public static final java.lang.String FAILURE_COUNTER
public static <T> PAssert.IterableAssert<T> that(PCollection<T> actual)
PAssert.IterableAssert
for the elements of the provided PCollection
.public static <T> PAssert.IterableAssert<T> that(java.lang.String reason, PCollection<T> actual)
PAssert.IterableAssert
for the elements of the provided PCollection
with the specified reason.public static <T> PAssert.IterableAssert<T> thatSingletonIterable(PCollection<? extends java.lang.Iterable<T>> actual)
PAssert.IterableAssert
for the value of the provided PCollection
which
must contain a single Iterable<T>
value.public static <T> PAssert.IterableAssert<T> thatSingletonIterable(java.lang.String reason, PCollection<? extends java.lang.Iterable<T>> actual)
PAssert.IterableAssert
for the value of the provided PCollection
with
the specified reason. The provided PCollection must contain a single Iterable<T>
value.public static <T> PAssert.SingletonAssert<T> thatSingleton(PCollection<T> actual)
PAssert.SingletonAssert
for the value of the provided
PCollection PCollection<T>
, which must be a singleton.public static <T> PAssert.SingletonAssert<T> thatSingleton(java.lang.String reason, PCollection<T> actual)
PAssert.SingletonAssert
for the value of the provided
PCollection PCollection<T>
with the specified reason. The provided PCollection must be
a singleton.public static <K,V> PAssert.SingletonAssert<java.util.Map<K,java.lang.Iterable<V>>> thatMultimap(PCollection<KV<K,V>> actual)
PAssert.SingletonAssert
for the value of the provided PCollection
.
Note that the actual value must be coded by a KvCoder
, not just any
Coder<K, V>
.
public static <K,V> PAssert.SingletonAssert<java.util.Map<K,java.lang.Iterable<V>>> thatMultimap(java.lang.String reason, PCollection<KV<K,V>> actual)
PAssert.SingletonAssert
for the value of the provided PCollection
with the
specified reason.
Note that the actual value must be coded by a KvCoder
, not just any
Coder<K, V>
.
public static <K,V> PAssert.SingletonAssert<java.util.Map<K,V>> thatMap(PCollection<KV<K,V>> actual)
PAssert.SingletonAssert
for the value of the provided PCollection
, which
must have at most one value per key.
Note that the actual value must be coded by a KvCoder
, not just any
Coder<K, V>
.
public static <K,V> PAssert.SingletonAssert<java.util.Map<K,V>> thatMap(java.lang.String reason, PCollection<KV<K,V>> actual)
PAssert.SingletonAssert
for the value of the provided PCollection
with
the specified reason. The PCollection
must have at most one value per key.
Note that the actual value must be coded by a KvCoder
, not just any
Coder<K, V>
.
protected static <ActualT> SuccessOrFailure doChecks(PAssert.PAssertionSite site, ActualT actualContents, SerializableFunction<ActualT,java.lang.Void> checkerFn)
public static int countAsserts(Pipeline pipeline)