pnowojski commented on a change in pull request #6705: [FLINK-10356][network] 
add sanity checks to SpillingAdaptiveSpanningRecordDeserializer
URL: https://github.com/apache/flink/pull/6705#discussion_r227336511
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/api/serialization/SpanningRecordSerializationTest.java
 ##########
 @@ -104,11 +120,236 @@ public void testHandleMixedLargeRecords() throws 
Exception {
                testSerializationRoundTrip(originalRecords, segmentSize);
        }
 
+       /**
+        * Non-spanning, deserialization reads one byte too many and succeeds.
+        */
+       @Test
+       public void testHandleDeserializingTooMuchNonSpanning1() throws 
Exception {
+               testHandleWrongDeserialization(
+                       new StringValueDeserializingTooMuch("Test string"),
+                       32 * 1024,
+                       null);
+       }
+
+       /**
+        * Non-spanning, serialization length is 16 (including headers), 
deserialization reads one byte
+        * too many and succeeds.
+        */
+       @Test
+       public void testHandleDeserializingTooMuchNonSpanning2() throws 
Exception {
+               testHandleWrongDeserialization(
+                       new StringValueDeserializingTooMuch("Test string"),
+                       17,
+                       null);
+       }
+
+       /**
+        * Non-spanning, serialization length is 16 (including headers), 
deserialization reads one byte
+        * too many and fails.
+        */
+       @Test
+       public void testHandleDeserializingTooMuchNonSpanning3() throws 
Exception {
+               testHandleWrongDeserialization(
+                       new StringValueDeserializingTooMuch("Test string"),
+                       16,
+                       isA(IndexOutOfBoundsException.class));
+       }
+
+       /**
+        * Spanning, serialization length is 16 (including headers), 
deserialization reads one byte
+        * too many and fails.
+        */
+       @Test
+       public void testHandleDeserializingTooMuchSpanning1() throws Exception {
+               testHandleWrongDeserialization(
+                       new StringValueDeserializingTooMuch("Test string"),
+                       15,
+                       isA(EOFException.class));
+       }
+
+       /**
+        * Spanning, serialization length is 16 (including headers), 
deserialization reads one byte
+        * too many and fails.
+        */
+       @Test
+       public void testHandleDeserializingTooMuchSpanning2() throws Exception {
+               testHandleWrongDeserialization(
+                       new StringValueDeserializingTooMuch("Test string"),
+                       1,
+                       isA(EOFException.class));
+       }
+
+       /**
+        * Spanning, spilling, deserialization reads one byte too many.
+        */
+       @Test
+       public void testHandleDeserializingTooMuchSpanningLargeRecord() throws 
Exception {
+               LargeObjectTypeDeserializingTooMuch genLarge = new 
LargeObjectTypeDeserializingTooMuch();
+               testHandleWrongDeserialization(
+                       genLarge.getRandom(new Random()),
+                       32 * 1024,
+                       isA(EOFException.class));
+       }
+
+       /**
+        * Non-spanning, deserialization forgets to read one byte.
+        */
+       @Test
+       public void testHandleDeserializingNotEnoughNonSpanning() throws 
Exception {
+               testHandleWrongDeserialization(
+                       new StringValueDeserializingNotEnough("Test string"),
+                       32 * 1024,
+                       null);
+       }
+
+       /**
+        * Spanning, serialization length is 17 (including headers), 
deserialization forgets to read one
+        * byte.
+        */
+       @Test
+       public void testHandleDeserializingNotEnoughSpanning1() throws 
Exception {
+               testHandleWrongDeserialization(
+                       new StringValueDeserializingNotEnough("Test string"),
+                       16,
+                       null);
+       }
+
+       /**
+        * Spanning, serialization length is 17 (including headers), 
deserialization forgets to read one
+        * byte.
+        */
+       @Test
+       public void testHandleDeserializingNotEnoughSpanning2() throws 
Exception {
+               testHandleWrongDeserialization(
+                       new StringValueDeserializingNotEnough("Test string"),
+                       1,
+                       null);
+       }
+
+       /**
+        * Spanning, spilling, deserialization forgets to read one byte.
+        */
+       @Test
+       public void testHandleDeserializingNotEnoughSpanningLargeRecord() 
throws Exception {
+               LargeObjectTypeDeserializingNotEnough genLarge = new 
LargeObjectTypeDeserializingNotEnough();
+               testHandleWrongDeserialization(
+                       genLarge.getRandom(new Random()),
+                       32 * 1024,
+                       null);
+       }
+
+       private void testHandleWrongDeserialization(
+                       WrongDeserializationValue testValue,
+                       int segmentSize,
+                       @Nullable Matcher<? extends Throwable> expectedCause) 
throws Exception {
 
 Review comment:
   Do not use `null`. Overload with:
   ```
   private void testHandleWrongDeserialization(
     WrongDeserializationValue testValue,
     int segmentSize,
     Matcher<? extends Throwable> expectedCause) throws Exception  {
   
     expectedException.expectCause(expectedCause);
     testHandleWrongDeserialization(testValue, segmentSize);
   }
   ```
   or sth among the lines. If this doesn't work, use as a last resort 
`Optional`. `@Nullable` is almost worthless in our code base :(

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to