3535/** Exception-safety tests for record batch serialization. */
3636class TestVectorUnloaderFailure {
3737
38- @ ParameterizedTest
39- @ ValueSource (longs = {0 , 16 })
40- void compressionAllocationFailureReleasesBuffers (long availableBytes ) {
38+ @ Test
39+ void compressionAllocationFailureReleasesBuffers () {
4140 try (BufferAllocator allocator = new RootAllocator ();
4241 IntVector vector = new IntVector ("values" , allocator );
4342 VectorSchemaRoot root = VectorSchemaRoot .of (vector )) {
@@ -46,8 +45,9 @@ void compressionAllocationFailureReleasesBuffers(long availableBytes) {
4645 root .setRowCount (1 );
4746 long allocatedBefore = allocator .getAllocatedMemory ();
4847 int referencesBefore = vector .getDataBuffer ().getReferenceManager ().getRefCount ();
49- allocator .setLimit (allocatedBefore + availableBytes );
50- VectorUnloader unloader = new VectorUnloader (root , true , new CopyCodec (), true );
48+ // Any compression allocation must fail, regardless of allocator rounding.
49+ allocator .setLimit (allocatedBefore );
50+ VectorUnloader unloader = new VectorUnloader (root , true , new SimulatedLz4Codec (), true );
5151
5252 assertThrows (OutOfMemoryException .class , unloader ::getRecordBatch );
5353 assertEquals (allocatedBefore , allocator .getAllocatedMemory ());
@@ -71,8 +71,8 @@ void compressionFailurePreservesExceptionAndSource(boolean throwError) {
7171 root .setRowCount (1 );
7272 long allocatedBefore = allocator .getAllocatedMemory ();
7373 int referencesBefore = vector .getDataBuffer ().getReferenceManager ().getRefCount ();
74- CopyCodec codec =
75- new CopyCodec () {
74+ SimulatedLz4Codec codec =
75+ new SimulatedLz4Codec () {
7676 private int calls ;
7777
7878 @ Override
@@ -101,7 +101,8 @@ void emptyBufferAllocationFailureReleasesInput() {
101101 ArrowBuf input = allocator .buffer (8 );
102102 allocator .setLimit (allocator .getAllocatedMemory ());
103103
104- assertThrows (OutOfMemoryException .class , () -> new CopyCodec ().compress (allocator , input ));
104+ assertThrows (
105+ OutOfMemoryException .class , () -> new SimulatedLz4Codec ().compress (allocator , input ));
105106 assertEquals (0 , input .getReferenceManager ().getRefCount ());
106107 assertEquals (0 , allocator .getAllocatedMemory ());
107108 }
@@ -131,7 +132,8 @@ public List<ArrowBuf> getFieldBuffers() {
131132 }
132133 }
133134
134- private static class CopyCodec extends AbstractCompressionCodec {
135+ // Compression-only stub for allocation and ownership tests, not LZ4 round trips.
136+ private static class SimulatedLz4Codec extends AbstractCompressionCodec {
135137 @ Override
136138 protected ArrowBuf doCompress (BufferAllocator allocator , ArrowBuf input ) {
137139 return CompressionUtil .packageRawBuffer (allocator , input );
0 commit comments