Apache flink Flink TestHarness输出不';托收后不清

Apache flink Flink TestHarness输出不';托收后不清,apache-flink,Apache Flink,我有以下测试: testHarness.processElement2(new StreamRecord<>(element1)); testHarness.processElement1(new StreamRecord<>(new Tuple2<>(id, element2))); testHarness.setProcessingTime(1); //let's assume it's the correct time for the timer in

我有以下测试:

testHarness.processElement2(new StreamRecord<>(element1));
testHarness.processElement1(new StreamRecord<>(new Tuple2<>(id, element2)));

testHarness.setProcessingTime(1); //let's assume it's the correct time for the timer inside the function
softly.assertThat(testHarness.getOutput()).containsExactly(new StreamRecord<>(expectedResult)); //this one is passed

testHarness.setProcessingTime(2); // setting second timer which will trigger different timer
softly.assertThat(testHarness.getOutput()).containsExactly(new StreamRecord<>(expectedResult2)); //fails cause output has  expectedResult & expectedResult2
testHarness.processElement2(新的StreamRecord(element1));
processElement1(新的StreamRecord(新的Tuple2(id,element2));
testHarness.setProcessingTime(1)//让我们假设这是函数中计时器的正确时间
assertThat(testHarness.getOutput()).containsActly(newstreamrecord(expectedResult))//这个通过了
testHarness.setProcessingTime(2);//设置将触发不同计时器的第二个计时器
assertThat(testHarness.getOutput()).containsActly(新的StreamRecord(expectedResult2))//失败原因输出有expectedResult和expectedResult2

为什么TestHarness在调用getOutput()后不清除其元素?是否可以通过某种方式实现此功能?

这可以通过在输出上调用clear()来实现:

testHarness.processElement2(new StreamRecord<>(element1));
testHarness.processElement1(new StreamRecord<>(new Tuple2<>(id, element2)));

testHarness.setProcessingTime(1); //let's assume it's the correct time for the timer inside the function
softly.assertThat(testHarness.getOutput()).containsExactly(new StreamRecord<>(expectedResult)); // Pass

testHarness.getOutput().clear();

testHarness.setProcessingTime(2); // setting second timer which will trigger different timer
softly.assertThat(testHarness.getOutput()).containsExactly(new StreamRecord<>(expectedResult2)); // Pass
testHarness.processElement2(新的StreamRecord(element1));
processElement1(新的StreamRecord(新的Tuple2(id,element2));
testHarness.setProcessingTime(1)//让我们假设这是函数中计时器的正确时间
.assertThat(testHarness.getOutput()).containsActly(新的StreamRecord(expectedResult));//通过
testHarness.getOutput().clear();
testHarness.setProcessingTime(2);//设置将触发不同计时器的第二个计时器
.assertThat(testHarness.getOutput()).containsActly(新的StreamRecord(expectedResult2));//通过