Skip to content

Commit

Permalink
Try to add test for refcount
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Mar 3, 2024
1 parent 47ddac2 commit 570cdca
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.apache.arrow.memory.ArrowBuf;
Expand Down Expand Up @@ -164,10 +165,22 @@ VectorSchemaRoot vectorSchemaRootRoundtrip(VectorSchemaRoot root) {
}

boolean roundtrip(FieldVector vector, Class<?> clazz) {
List<ArrowBuf> fieldBuffers = vector.getFieldBuffers();
List<Int> orgRefCnts = fieldBuffers.map(buf -> buf.refCnt()).collect(Collectors.toList());

boolean result = false;
try (ValueVector imported = vectorRoundtrip(vector)) {
assertTrue(clazz.isInstance(imported), String.format("expected %s but was %s", clazz, imported.getClass()));
return VectorEqualsVisitor.vectorEquals(vector, imported);
result = VectorEqualsVisitor.vectorEquals(vector, imported);
}

// Check that the ref counts of the buffers are the same after the roundtrip
IntStream.range(0, orgRefCnts.size()).forEach(i -> {
ArrowBuf buf = fieldBuffers.get(i);
assertEquals(buf.refCnt(), orgRefCnts.get(i));
});

return result;
}

@Test
Expand Down

0 comments on commit 570cdca

Please sign in to comment.