apache_beam.testing.test_stream module

Provides TestStream for verifying streaming runner semantics.

For internal use only; no backwards-compatibility guarantees.

class apache_beam.testing.test_stream.Event[source]

Bases: object

Test stream event to be emitted during execution of a TestStream.

to_runner_api(element_coder)[source]
static from_runner_api(proto, element_coder)[source]
class apache_beam.testing.test_stream.ElementEvent(timestamped_values, tag=None)[source]

Bases: apache_beam.testing.test_stream.Event

Element-producing test stream event.

to_runner_api(element_coder)[source]
class apache_beam.testing.test_stream.WatermarkEvent(new_watermark, tag=None)[source]

Bases: apache_beam.testing.test_stream.Event

Watermark-advancing test stream event.

to_runner_api(unused_element_coder)[source]
class apache_beam.testing.test_stream.ProcessingTimeEvent(advance_by)[source]

Bases: apache_beam.testing.test_stream.Event

Processing time-advancing test stream event.

to_runner_api(unused_element_coder)[source]
class apache_beam.testing.test_stream.TestStream(coder=FastPrimitivesCoder, events=None, output_tags=None)[source]

Bases: apache_beam.transforms.ptransform.PTransform

Test stream that generates events on an unbounded PCollection of elements.

Each event emits elements, advances the watermark or advances the processing time. After all of the specified elements are emitted, ceases to produce output.

To use the multi-output functionality pelase use the ‘passthrough_pcollection_output_ids’ flag. See BEAM-9322 for more info.

To add flag:

from apache_beam.options.pipeline_options import DebugOptions
options = ...
options.view_as(DebugOptions).add_experiment(
    'passthrough_pcollection_output_ids')
get_windowing(unused_inputs)[source]
expand(pbegin)[source]
add_elements(elements, tag=None, event_timestamp=None)[source]

Add elements to the TestStream.

Elements added to the TestStream will be produced during pipeline execution. These elements can be TimestampedValue, WindowedValue or raw unwrapped elements that are serializable using the TestStream’s specified Coder. When a TimestampedValue or a WindowedValue element is used, the timestamp of the TimestampedValue or WindowedValue will be the timestamp of the produced element; otherwise, the current watermark timestamp will be used for that element. The windows of a given WindowedValue are ignored by the TestStream.

advance_watermark_to(new_watermark, tag=None)[source]

Advance the watermark to a given Unix timestamp.

The Unix timestamp value used must be later than the previous watermark value and should be given as an int, float or utils.timestamp.Timestamp object.

advance_watermark_to_infinity(tag=None)[source]

Advance the watermark to the end of time, completing this TestStream.

advance_processing_time(advance_by)[source]

Advance the current processing time by a given duration in seconds.

The duration must be a positive second duration and should be given as an int, float or utils.timestamp.Duration object.

to_runner_api_parameter(context)[source]
static from_runner_api_parameter(ptransform, payload, context)[source]