liyafan82 commented on a change in pull request #8194: [FLINK-12216][Runtime]Respect the number
of bytes from input parameters in HybridMemorySegment
URL: https://github.com/apache/flink/pull/8194#discussion_r341036760
##########
File path: flink-core/src/test/java/org/apache/flink/core/memory/HybridOnHeapMemorySegmentTest.java
##########
@@ -77,4 +82,54 @@ public void testHybridHeapSegmentSpecifics() {
assertEquals(3, buf2.position());
assertEquals(7, buf2.limit());
}
+
+ @Test
+ public void testReadOnlyByteBufferPut() {
+ final byte[] buffer = new byte[100];
+ HybridMemorySegment seg = new HybridMemorySegment(buffer, null);
+
+ String content = "hello world";
+ ByteBuffer bb = ByteBuffer.allocate(20);
+ bb.put(content.getBytes());
+ bb.rewind();
+
+ int offset = 10;
+ int numBytes = 5;
+
+ ByteBuffer readOnlyBuf = bb.asReadOnlyBuffer();
+ assertFalse(readOnlyBuf.isDirect());
+ assertFalse(readOnlyBuf.hasArray());
+
+ seg.put(offset, readOnlyBuf, numBytes);
+
+ // verify the area before the written region.
+ for (int i = 0; i < offset; i++) {
+ assertEquals(0, buffer[i]);
+ }
+
+ // verify the region that is written.
+ assertEquals("hello", new String(buffer, offset, numBytes));
+
+ // verify the area after the written region.
+ for (int i = offset + numBytes; i < buffer.length; i++) {
+ assertEquals(0, buffer[i]);
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testReadOnlyByteBufferGet() {
Review comment:
Thanks for your suggestion. I have removed this test case.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
|