public interface Tester extends TopologyElement
Tester
adds the ability to test a topology in a test framework such
as JUnit.
The main feature is the ability to capture tuples from a TStream
in
order to perform some form of verification on them. There are two mechanisms
to perform verifications:
TStream<String>
can have conditions or handlers attached.
A Tester
modifies its Topology
to achieve the above purpose.
Modifier and Type | Method and Description |
---|---|
Condition<java.lang.Boolean> |
and(Condition<?>... conditions)
Return a condition that is valid only if all of
conditions are valid. |
Condition<java.lang.Long> |
atLeastTupleCount(TStream<?> stream,
long expectedCount)
Return a condition that evaluates if
stream has submitted at
least expectedCount number of tuples. |
boolean |
complete(Submitter<Topology,? extends Job> submitter,
com.google.gson.JsonObject config,
Condition<?> endCondition,
long timeout,
java.util.concurrent.TimeUnit unit)
Submit the topology for this tester and wait for it to complete, or reach
an end condition.
|
<T> Condition<java.util.List<T>> |
contentsUnordered(TStream<T> stream,
T... values)
Return a condition that evaluates if
stream has submitted
tuples matching values in any order. |
Job |
getJob()
Get the
Job reference for the topology submitted by complete() . |
<T> Condition<java.util.List<T>> |
streamContents(TStream<T> stream,
T... values)
Return a condition that evaluates if
stream has submitted
tuples matching values in the same order. |
Condition<java.lang.Long> |
tupleCount(TStream<?> stream,
long expectedCount)
Return a condition that evaluates if
stream has submitted exactly
expectedCount number of tuples. |
topology
Condition<java.lang.Long> tupleCount(TStream<?> stream, long expectedCount)
stream
has submitted exactly
expectedCount
number of tuples. The function may be evaluated
after the submit
call has returned. result
of the returned
Condition
is the number of tuples seen on stream
so far.
Condition.valid()
and Condition.getResult()
may change as
more tuples are seen on stream
. stream
- Stream to be tested.expectedCount
- Number of tuples expected on stream
.expectedCount
number of tuples, false otherwise.Condition<java.lang.Long> atLeastTupleCount(TStream<?> stream, long expectedCount)
stream
has submitted at
least expectedCount
number of tuples. The function may be
evaluated after the
submit
call has returned. result
of the returned
Condition
is the number of tuples seen on stream
so far.
Condition.valid()
and Condition.getResult()
may change as
more tuples are seen on stream
. stream
- Stream to be tested.expectedCount
- Number of tuples expected on stream
.expectedCount
number of tuples, false otherwise.<T> Condition<java.util.List<T>> streamContents(TStream<T> stream, T... values)
stream
has submitted
tuples matching values
in the same order. result
of the returned
Condition
is the tuples seen on stream
so far. Condition.valid()
and Condition.getResult()
may change as
more tuples are seen on stream
. T
- Tuple typestream
- Stream to be tested.values
- Expected tuples on stream
.values
in the same order, false
otherwise.<T> Condition<java.util.List<T>> contentsUnordered(TStream<T> stream, T... values)
stream
has submitted
tuples matching values
in any order. result
of the returned
Condition
is the tuples seen on stream
so far. Condition.valid()
and Condition.getResult()
may change as
more tuples are seen on stream
. T
- Tuple typestream
- Stream to be tested.values
- Expected tuples on stream
.values
in the any order, false
otherwise.Condition<java.lang.Boolean> and(Condition<?>... conditions)
conditions
are valid.
The result of the condition is Condition.valid()
conditions
- Conditions to AND together.conditions
are valid.boolean complete(Submitter<Topology,? extends Job> submitter, com.google.gson.JsonObject config, Condition<?> endCondition, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
timeout
then it is terminated.
End condition is usually a Condition
returned from
atLeastTupleCount(TStream, long)
or
tupleCount(TStream, long)
so that this method returns once the
stream has submitted a sufficient number of tuples.
Note that the condition will be only checked periodically up to
timeout
, so that if the condition is only valid for a brief
period of time, then its valid state may not be seen, and thus this
method will wait for the timeout period.
submitter
- the Submitter
config
- submission configuration.endCondition
- Condition that will cause this method to return if it is true.timeout
- Maximum time to wait for the topology to complete or reach its
end condition.unit
- Unit for timeout
.endCondition.valid()
.java.lang.Exception
- Failure submitting or executing the topology.Job getJob()
Job
reference for the topology submitted by complete()
.Job
reference for the topology submitted by complete()
.
Null if the complete()
has not been called or the Job
instance is not yet available.Copyright © 2016 The Apache Software Foundation. All Rights Reserved - bbe71fa-20161201-1641