reswqa commented on code in PR #22432: URL: https://github.com/apache/flink/pull/22432#discussion_r1188921664
########## flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/OneInputStreamTaskTest.java: ########## @@ -996,6 +1002,88 @@ public void testCanEmitBatchOfRecords() throws Exception { } } + @Test + public void testTaskSideOutputStatistics() throws Exception { + TaskMetricGroup taskMetricGroup = + UnregisteredMetricGroups.createUnregisteredTaskMetricGroup(); + + ResultPartitionWriter[] partitionWriters = new ResultPartitionWriter[3]; + for (int i = 0; i < partitionWriters.length; ++i) { + partitionWriters[i] = + new RecordOrEventCollectingResultPartitionWriter<>( + new ArrayDeque<>(), + new StreamElementSerializer<>( + BasicTypeInfo.INT_TYPE_INFO.createSerializer( + new ExecutionConfig()))); + partitionWriters[i].setup(); + } + + try (StreamTaskMailboxTestHarness<Integer> testHarness = + new StreamTaskMailboxTestHarnessBuilder<>( + OneInputStreamTask::new, BasicTypeInfo.INT_TYPE_INFO) + .addInput(BasicTypeInfo.INT_TYPE_INFO) + .addAdditionalOutput(partitionWriters) + .setupOperatorChain(new OperatorID(), new OddEvenOperator()) + .chain(BasicTypeInfo.INT_TYPE_INFO.createSerializer(new ExecutionConfig())) + .setOperatorFactory(SimpleOperatorFactory.of(new OddEvenOperator())) + .addNonChainedOutputsCount( + new OutputTag<>("odd", BasicTypeInfo.INT_TYPE_INFO), 2) + .addNonChainedOutputsCount(1) + .build() + .chain(BasicTypeInfo.INT_TYPE_INFO.createSerializer(new ExecutionConfig())) + .setOperatorFactory(SimpleOperatorFactory.of(new DuplicatingOperator())) + .addNonChainedOutputsCount(1) + .build() + .finish() + .setTaskMetricGroup(taskMetricGroup) + .build()) { + Counter numRecordsInCounter = + taskMetricGroup.getIOMetricGroup().getNumRecordsInCounter(); + Counter numRecordsOutCounter = + taskMetricGroup.getIOMetricGroup().getNumRecordsOutCounter(); + + final int numEvenRecords = 5; + final int numOddRecords = 3; + + for (int x = 0; x < numEvenRecords; x++) { + testHarness.processElement(new StreamRecord<>(2 * x)); + } + + for (int x = 0; x < numOddRecords; x++) { + testHarness.processElement(new StreamRecord<>(2 * x + 1)); + } + assertEquals(numOddRecords + numEvenRecords, numRecordsInCounter.getCount()); + assertEquals( + numOddRecords + + (numOddRecords + numEvenRecords) + + (numOddRecords + numEvenRecords) * 2, + numRecordsOutCounter.getCount()); Review Comment: > ditto for the multi and two input case.](nit: Also it would help if you could extract the components of the total expected output records count to a separate local/named variables) This really a good suggestion. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org