【问题标题】:Is there a way to assert an expected exception with Apache beam PAssert?有没有办法用 Apache Beam PAssert 断言预期的异常?
【发布时间】:2021-11-25 15:11:04
【问题描述】:

我正在为在 Apache 光束管道中运行的类构建单元测试。 在尝试对PCollection 进行某些操作后,我正在测试的一种方法应该引发异常。 PAssert 有没有办法期待这个异常?

例如

//Expect SomeClass to throw an exception when instantiated with this argument
val invalidParDo = ParDo.of(new SomeClass("This is an invalid parameter"))

val actualOutput = inputPCollection.apply("",invalidParDo)
//Here I'd like a way to assert that I expected a particular exception
PAssert.that(someWayToExpectExceptionHere)
testPipeline.run()

或任何类似的替代品

【问题讨论】:

    标签: scala unit-testing apache-beam


    【解决方案1】:

    请注意,PAssert 是一种 Beam 变换,用于验证给定的 PCollection 是否等于一个或多个给定值。 invalidParDo 中引发的未处理的异常将导致管道故障(重试后),因此无法在后续步骤中验证此类故障。但是,如果您更新invalidParDo 以生成无效值而不是引发异常,您应该能够使用PAssert 来验证此类无效值的生成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-21
      • 1970-01-01
      • 2012-05-23
      相关资源
      最近更新 更多