[英]Scala Unit testing for ProcessAllWindowFunction
After Reading the official flink testing documentation ( https://ci.apache.org/projects/flink/flink-docs-release-1.9/dev/stream/testing.html ) I was able to develop tests for a ProcessFunction, using a測試線束,像這樣:
pendingPartitionBuilder = new PendingPartitionBuilder(":::some_name", "")
testHarness =
new OneInputStreamOperatorTestHarness[StaticAdequacyTilePublishedData, PendingPartition](
new ProcessOperator[StaticAdequacyTilePublishedData, PendingPartition](pendingPartitionBuilder)
)
testHarness.open()
現在,我正在嘗試對 ProcessAllWindowFunction 執行相同的操作,如下所示:
class MapVersionValidationDistributor(batchSize: Int) extends
ProcessAllWindowFunction[MapVersionValidation, Seq[StaticAdequacyTilePublishedData],TimeWindow] {
lazy val state: ValueState[Long] = getRuntimeContext .getState(new ValueStateDescriptor[Long]("latestMapVersion", classOf[Long]))
(...)
首先我意識到我不能對 ProcessAllWindowFunction 使用 TestHarness,因為它沒有 processElement 方法。 在這種情況下,我應該遵循什么單元測試策略?
編輯:目前我的測試代碼如下所示:
val collector = mock[Collector[Seq[StaticAdequacyTilePublishedData]]]
val mvv = new MapVersionValidationDistributor(1)
val input3 = Iterable(new MapVersionValidation("123",Seq(TileValidation(1,true,Seq(1,3,4)))))
val ctx = mock[mvv.Context]
val streamContext = mock[RuntimeContext]
mvv.setRuntimeContext(streamContext)
mvv.open(mock[Configuration])
mvv.process(ctx,input3,collector)
我收到了這個錯誤:
Unexpected call: <mock-3> RuntimeContext.getState[T](ValueStateDescriptor{name=latestMapVersion, defaultValue=null, serializer=null}) Expected: inAnyOrder { }
您真的不需要測試工具來對ProcessAllWindowFunction
的process
方法進行單元測試。 process
function 需要 3 個 arguments: Context
, Iterable[IN]
, Collector[OUT]
。 您可以根據用於模擬Context
的語言使用一些庫。 您還可以在此處根據您的偏好輕松實現或模擬Collector
。 而 Iterable[IN] 只是一個包含您的 window 元素的Iterable
,在觸發 window 后將傳遞給 function。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.