Google cloud dataflow 如何用python在ApacheBeam中(单元)测试流管道?

Google cloud dataflow 如何用python在ApacheBeam中(单元)测试流管道?,google-cloud-dataflow,apache-beam,Google Cloud Dataflow,Apache Beam,我编写了一些流媒体管道(从Pub/Sub开始),我想在其中添加一些窗口机制。我现在想以某种适当的方式测试它,那么如何创建一些“虚拟”流呢 我的代码: pipeline\u options=PipelineOptions() 管道选项。查看为(设置选项)。保存主会话=真 管道选项。查看为(标准选项)。流=真 p=TestPipeline(options=pipeline\u options,runner=DirectRunner()) xmls_beam=beam.Create(xmls) x=p

我编写了一些流媒体管道(从Pub/Sub开始),我想在其中添加一些窗口机制。我现在想以某种适当的方式测试它,那么如何创建一些“虚拟”流呢

我的代码:

pipeline\u options=PipelineOptions()
管道选项。查看为(设置选项)。保存主会话=真
管道选项。查看为(标准选项)。流=真
p=TestPipeline(options=pipeline\u options,runner=DirectRunner())
xmls_beam=beam.Create(xmls)
x=p | xmls | beam | beam.FlatMap(process | xmls)| beam.ParDo(FilterTI())| beam.WindowInto(window.FixedWindows(200))| beam.GroupByKey()
结果=p.运行()
结果。等待直到完成()
您可以使用TimestampedValue的PCollection模拟“虚拟流”

例如,如果您的输入是:

l=[window.TimestampedValue('a',100),window.TimestampedValue('b',300)]
pc=p |梁。创建(l)|。。。
在您的情况下(宽度为200的固定窗口),您可以预期在输出中,元素“a”落入第一个窗口,“b”落入第二个窗口