NicoK commented on a change in pull request #6417: [FLINK-9913][runtime] 
Improve output serialization only once in RecordWriter
URL: https://github.com/apache/flink/pull/6417#discussion_r217415039
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/api/writer/RecordWriterTest.java
 ##########
 @@ -377,6 +388,86 @@ public void testBroadcastEmitBufferIndependence() throws 
Exception {
                assertEquals("Buffer 2 shares the same reader index as buffer 
1", 0, buffer2.getReaderIndex());
        }
 
+       /**
+        * Tests that records are broadcast via {@link ChannelSelector} and
+        * {@link RecordWriter#emit(IOReadableWritable)}.
+        */
+       @Test
+       public void testEmitRecordWithBroadcastPartitioner() throws Exception {
+               emitRecordWithBroadcastPartitionerOrBroadcastEmitRecord(false);
+       }
+
+       /**
+        * Tests that records are broadcast via {@link 
RecordWriter#broadcastEmit(IOReadableWritable)}.
+        */
+       @Test
+       public void testBroadcastEmitRecord() throws Exception {
+               emitRecordWithBroadcastPartitionerOrBroadcastEmitRecord(true);
+       }
+
+       /**
+        * The results of emitting records via BroadcastPartitioner or 
broadcasting records directly are the same,
+        * that is all the target channels can receive the whole outputs.
+        *
+        * @param isBroadcastEmit whether using {@link 
RecordWriter#broadcastEmit(IOReadableWritable)} or not
+        */
+       private void 
emitRecordWithBroadcastPartitionerOrBroadcastEmitRecord(boolean 
isBroadcastEmit) throws Exception {
+               final int numChannels = 4;
+               final int bufferSize = 32;
+               final int numValues = 8;
+               final int serializationLength = 4;
+
+               @SuppressWarnings("unchecked")
+               final Queue<BufferConsumer>[] queues = new Queue[numChannels];
+               for (int i = 0; i < numChannels; i++) {
+                       queues[i] = new ArrayDeque<>();
+               }
+
+               final TestPooledBufferProvider bufferProvider = new 
TestPooledBufferProvider(Integer.MAX_VALUE, bufferSize);
+               final ResultPartitionWriter partitionWriter = new 
CollectingPartitionWriter(queues, bufferProvider);
+               final RecordWriter<SerializationTestType> writer = new 
RecordWriter<>(partitionWriter, new Broadcast<>());
 
 Review comment:
   I meant using
   ```
   final RecordWriter<SerializationTestType> writer = isBroadcastEmit ?
                        new RecordWriter<>(partitionWriter) :
                        new RecordWriter<>(partitionWriter, new Broadcast<>());
   ```
   This would also check that `broadcastEmit()` does not rely on a broadcasting 
channel selector.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to