zhijiangW commented on a change in pull request #12243:
URL: https://github.com/apache/flink/pull/12243#discussion_r427414666



##########
File path: 
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/io/InputProcessorUtilTest.java
##########
@@ -58,4 +79,57 @@ public void testGenerateInputGateToChannelIndexOffsetMap() {
                assertEquals(0, 
inputGateToChannelIndexOffsetMap.get(ig1).intValue());
                assertEquals(3, 
inputGateToChannelIndexOffsetMap.get(ig2).intValue());
        }
+
+       @Test
+       public void testCreateCheckpointedMultipleInputGate() throws Exception {
+               try (CloseableRegistry registry = new CloseableRegistry()) {
+                       MockEnvironment environment = new 
MockEnvironmentBuilder().build();
+                       MockStreamTask streamTask = new 
MockStreamTaskBuilder(environment).build();
+                       StreamConfig streamConfig = new 
StreamConfig(environment.getJobConfiguration());
+                       
streamConfig.setCheckpointMode(CheckpointingMode.EXACTLY_ONCE);
+                       streamConfig.setUnalignedCheckpointsEnabled(true);
+
+                       // First input gate has index larger than the second
+                       Collection<IndexedInputGate>[] inputGates = new 
Collection[] {
+                               Collections.singletonList(new 
MockIndexedInputGate(1, 4)),
+                               Collections.singletonList(new 
MockIndexedInputGate(0, 2)),
+                       };
+
+                       new MockChannelStateWriter() {
+                               @Override
+                               public void addInputData(
+                                       long checkpointId,
+                                       InputChannelInfo info,
+                                       int startSeqNum,
+                                       Buffer... data) {
+                                       super.addInputData(checkpointId, info, 
startSeqNum, data);
+                               }
+                       };
+
+                       CheckpointedInputGate[] checkpointedMultipleInputGate = 
InputProcessorUtil.createCheckpointedMultipleInputGate(
+                               streamTask,
+                               streamConfig,
+                               new MockChannelStateWriter(),
+                               environment.getMetricGroup().getIOMetricGroup(),
+                               streamTask.getName(),
+                               inputGates);
+                       for (CheckpointedInputGate checkpointedInputGate : 
checkpointedMultipleInputGate) {
+                               
registry.registerCloseable(checkpointedInputGate);
+                       }
+
+                       CheckpointBarrierHandler barrierHandler = 
checkpointedMultipleInputGate[0].getCheckpointBarrierHandler();
+
+                       List<IndexedInputGate> allInputGates = 
Arrays.stream(inputGates).flatMap(gates -> 
gates.stream()).collect(Collectors.toList());
+                       for (IndexedInputGate inputGate : allInputGates) {
+                               for (int channelId = 0; channelId < 
inputGate.getNumberOfInputChannels(); channelId++) {
+                                       
assertTrue(barrierHandler.getBufferReceivedListener().isPresent());

Review comment:
       nit: might be better to place these two lines out of loop to together 
with `barrierHandler`
   
   ```
   CheckpointBarrierHandler barrierHandler = 
checkpointedMultipleInputGate[0].getCheckpointBarrierHandler();
   assertTrue(barrierHandler.getBufferReceivedListener().isPresent());
   BufferReceivedListener bufferReceivedListener = 
barrierHandler.getBufferReceivedListener().get();
   ```
   




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to