reswqa commented on code in PR #22432: URL: https://github.com/apache/flink/pull/22432#discussion_r1189760303
########## 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: > If the above is correct, is this construct officially supported behaviour of Flink? Can user create such pipelines? If not, I would either remove the first operator, or replace it with just a no-op/pass-through operator that just forwards input records. Fair enough! This is indeed not a conventional pipeline, I have replaced the first operator by a `PassThroughOperator`. -- 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