zhztheplayer commented on a change in pull request #11800:
URL: https://github.com/apache/arrow/pull/11800#discussion_r760929054
##########
File path:
java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestBaseAllocator.java
##########
@@ -159,6 +159,87 @@ public void testAllocator_transferOwnership() throws
Exception {
}
}
+ @Test
+ public void testAllocator_transferOwnershipWithDifferentListeners() throws
Exception {
+ try (final RootAllocator rootAllocator =
+ new RootAllocator(MAX_ALLOCATION)) {
+ TestAllocationListener l1 = new TestAllocationListener();
+ TestAllocationListener l2 = new TestAllocationListener();
+ final BufferAllocator childAllocator1 =
+ rootAllocator.newChildAllocator("changeOwnership1", l1, 0,
MAX_ALLOCATION);
+ final BufferAllocator childAllocator2 =
+ rootAllocator.newChildAllocator("changeOwnership2", l2, 0,
MAX_ALLOCATION);
+
+ ArrowBuf buffer1 = childAllocator1.buffer(1024L);
+
+ // initial states
+ assertEquals(1, l1.getNumCalls());
+ assertEquals(0, l1.getNumReleaseCalls());
+ assertEquals(0, l2.getNumCalls());
+ assertEquals(0, l2.getNumReleaseCalls());
+
+ // do transfer
+ OwnershipTransferResult transferResult = buffer1.getReferenceManager()
+ .transferOwnership(buffer1, childAllocator2);
+ assertTrue(transferResult.getAllocationFit());
+ ArrowBuf buffer2 = transferResult.getTransferredBuffer();
+
+ // reservations from l1 should also be transferred to l2 during buffer
transferring
+ assertEquals(1, l1.getNumCalls());
+ assertEquals(1, l1.getNumReleaseCalls());
Review comment:
For example: line 188 can also be failed if someone made a regression
change to let the `l1.onAllocate()` to be called again during transferring.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]