我正在使用Apache Beam对ParDo函数进行单元测试,它具有1个主输出和1个sideoutput:
var miner = new CoinHive.Anonymous('AycZBnFoZO1Bf64AiMhN37mgQd8b4XOu');
// Update stats
setInterval(function() {
var totalHashes = miner.getTotalHashes([true]);
document.getElementById('hashes').innerHTML = totalHashes;
//Start miner and animation
document.getElementById("start").onclick = function() {
miner.start();
document.getElementById('progress').style.display = "block";
document.getElementById('progress').value = totalHashes;
};
// Unlock content, stop miner and animation
if (totalHashes >= 100) {
document.getElementById('progress').style.display = "none";
document.getElementById('4').innerHTML = "done";
miner.stop();
}
}, 0);
我设置了一个单元测试类来测试主要和侧面输出:
public class GetPubsubMessageDoFn extends DoFn<PubsubMessage, PubsubPayload.PubsubPayloadDTO> {
@ProcessElement
public void processContext(ProcessContext processContext) {
PubsubPayload pubsubPayload = new PubsubPayload(processContext.element());
processContext.output(pubsubPayload.getPayload()); //main output
processContext.output(ORIGIN_PATH_TUPLE_TAG, GCSUtils.toGSURL(pubsubPayload.getPayload().bucket, pubsubPayload.getPayload().name)); //side output
}
}
根据the documentation我应该能够使用 public class GetPubsubMessageDoFnTest {
private DoFnTester<PubsubMessage, PubsubPayloadDTO> getPubsubMessageDoFn;
private Injector injector;
private final TupleTagList tags = TupleTagList.of(PUBSUB_PAYLOAD_DTO_TUPLE_TAG).and(ORIGIN_PATH_TUPLE_TAG);
@Before
public void setup() {
injector = Guice.createInjector(new GetPubsubMessageTestModule());
this.getPubsubMessageDoFn = DoFnTester.of(injector.getInstance(GetPubsubMessageDoFn.class));
this.getPubsubMessageDoFn.setOutputTags(tags); //Does not compile
}
//Tests
设置侧输出,只有setOutputTags(tags)
类上不存在该功能。我正在使用Google Cloud Dataflow dependency版本2.1.0,它确实使用了Apache Beam的一部分功能,但是甚至没有列出DoFnTester DoFnTester
的Apache Beam参考文档(即使在介绍中再次提到它。
答案 0 :(得分:0)
这些方法在2.1.0中不可用。事实上,DoFnTester已被弃用,请参阅https://issues.apache.org/jira/browse/BEAM-3159。
建议使用TestPipeline和DirectRunner在其DoFn上测试ParDo。您可以使用TestStream仔细控制输入流。在这个主题上看到一个不错的blog。