use of io.netty.buffer.DrillBuf.TransferResult in project drill by apache.
the class TestBaseAllocator method testAllocator_transferOwnership.
@Test
public void testAllocator_transferOwnership() throws Exception {
try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
final BufferAllocator childAllocator1 = rootAllocator.newChildAllocator("changeOwnership1", 0, MAX_ALLOCATION);
final BufferAllocator childAllocator2 = rootAllocator.newChildAllocator("changeOwnership2", 0, MAX_ALLOCATION);
final DrillBuf drillBuf1 = childAllocator1.buffer(MAX_ALLOCATION / 4);
rootAllocator.verify();
TransferResult transferOwnership = drillBuf1.transferOwnership(childAllocator2);
final boolean allocationFit = transferOwnership.allocationFit;
rootAllocator.verify();
assertTrue(allocationFit);
drillBuf1.release();
childAllocator1.close();
rootAllocator.verify();
transferOwnership.buffer.release();
childAllocator2.close();
}
}
use of io.netty.buffer.DrillBuf.TransferResult in project drill by apache.
the class TestBaseAllocator method testAllocator_transferSliced.
@Test
public void testAllocator_transferSliced() throws Exception {
try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
final BufferAllocator childAllocator1 = rootAllocator.newChildAllocator("transferSliced1", 0, MAX_ALLOCATION);
final BufferAllocator childAllocator2 = rootAllocator.newChildAllocator("transferSliced2", 0, MAX_ALLOCATION);
final DrillBuf drillBuf1 = childAllocator1.buffer(MAX_ALLOCATION / 8);
final DrillBuf drillBuf2 = childAllocator2.buffer(MAX_ALLOCATION / 8);
final DrillBuf drillBuf1s = drillBuf1.slice(0, drillBuf1.capacity() / 2);
final DrillBuf drillBuf2s = drillBuf2.slice(0, drillBuf2.capacity() / 2);
rootAllocator.verify();
TransferResult result1 = drillBuf2s.transferOwnership(childAllocator1);
rootAllocator.verify();
TransferResult result2 = drillBuf1s.transferOwnership(childAllocator2);
rootAllocator.verify();
result1.buffer.release();
result2.buffer.release();
// releases drillBuf1
drillBuf1s.release();
// releases drillBuf2
drillBuf2s.release();
childAllocator1.close();
childAllocator2.close();
}
}
use of io.netty.buffer.DrillBuf.TransferResult in project drill by apache.
the class TestBaseAllocator method testAllocator_transferShared.
@Test
public void testAllocator_transferShared() throws Exception {
try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
final BufferAllocator childAllocator1 = rootAllocator.newChildAllocator("transferShared1", 0, MAX_ALLOCATION);
final BufferAllocator childAllocator2 = rootAllocator.newChildAllocator("transferShared2", 0, MAX_ALLOCATION);
final BufferAllocator childAllocator3 = rootAllocator.newChildAllocator("transferShared3", 0, MAX_ALLOCATION);
final DrillBuf drillBuf1 = childAllocator1.buffer(MAX_ALLOCATION / 8);
boolean allocationFit;
DrillBuf drillBuf2 = drillBuf1.retain(childAllocator2);
rootAllocator.verify();
assertNotNull(drillBuf2);
assertNotEquals(drillBuf2, drillBuf1);
TransferResult result = drillBuf1.transferOwnership(childAllocator3);
allocationFit = result.allocationFit;
final DrillBuf drillBuf3 = result.buffer;
assertTrue(allocationFit);
rootAllocator.verify();
// Since childAllocator3 now has childAllocator1's buffer, 1, can close
drillBuf1.release();
childAllocator1.close();
rootAllocator.verify();
drillBuf2.release();
childAllocator2.close();
rootAllocator.verify();
final BufferAllocator childAllocator4 = rootAllocator.newChildAllocator("transferShared4", 0, MAX_ALLOCATION);
TransferResult result2 = drillBuf3.transferOwnership(childAllocator4);
allocationFit = result.allocationFit;
final DrillBuf drillBuf4 = result2.buffer;
assertTrue(allocationFit);
rootAllocator.verify();
drillBuf3.release();
childAllocator3.close();
rootAllocator.verify();
drillBuf4.release();
childAllocator4.close();
rootAllocator.verify();
}
}
Aggregations