Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/11193#discussion_r53049084
--- Diff:
network/common/src/test/java/org/apache/spark/network/protocol/MessageWithHeaderSuite.java
---
@@ -46,20 +50,43 @@ public void testShortWrite() throws Exception {
@Test
public void testByteBufBody() throws Exception {
ByteBuf header = Unpooled.copyLong(42);
- ByteBuf body = Unpooled.copyLong(84);
- MessageWithHeader msg = new MessageWithHeader(header, body,
body.readableBytes());
+ ByteBuf bodyPassedToNettyManagedBuffer = Unpooled.copyLong(84);
+ assertEquals(1, header.refCnt());
+ assertEquals(1, bodyPassedToNettyManagedBuffer.refCnt());
+ ManagedBuffer managedBuf = new
NettyManagedBuffer(bodyPassedToNettyManagedBuffer);
+ Object body = managedBuf.convertToNetty();
+ assertEquals(2, bodyPassedToNettyManagedBuffer.refCnt());
+ assertEquals(1, header.refCnt());
+
+ MessageWithHeader msg = new MessageWithHeader(managedBuf, header,
body, managedBuf.size());
ByteBuf result = doWrite(msg, 1);
assertEquals(msg.count(), result.readableBytes());
assertEquals(42, result.readLong());
assertEquals(84, result.readLong());
+
+ msg.deallocate();
+ assertEquals(0, bodyPassedToNettyManagedBuffer.refCnt());
+ assertEquals(0, header.refCnt());
+ }
+
+ @Test
+ public void testDeallocateReleasesManagedBuffer() throws Exception {
+ ByteBuf header = Unpooled.copyLong(42);
+ ManagedBuffer managedBuf = Mockito.spy(new TestManagedBuffer(84));
+ ByteBuf body = (ByteBuf) managedBuf.convertToNetty();
+ assertEquals(2, body.refCnt());
+ MessageWithHeader msg = new MessageWithHeader(managedBuf, header,
body, body.readableBytes());
+ msg.deallocate();
--- End diff --
Done.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]