From ed76e77cc8fe70b2b98fc372ee4118433a884324 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 8 Jul 2020 10:34:05 +0100 Subject: [PATCH] ARROW-9371: [Java] Run vector tests for both allocators As per https://github.com/apache/arrow/pull/7619#discussion_r451140735 the vector tests should be run for both netty and unsafe allocators --- java/vector/pom.xml | 131 ++++++++++++------ .../arrow/vector/TestBitVectorHelper.java | 73 +++++----- 2 files changed, 126 insertions(+), 78 deletions(-) diff --git a/java/vector/pom.xml b/java/vector/pom.xml index 6b101373794..aec4f7ef3cc 100644 --- a/java/vector/pom.xml +++ b/java/vector/pom.xml @@ -55,6 +55,12 @@ ${project.version} test + + org.apache.arrow + arrow-memory-unsafe + ${project.version} + test + io.netty netty-common @@ -70,19 +76,19 @@ - - - apache - apache - https://repo.maven.apache.org/maven2/ - - true - - - false - - - + + + apache + apache + https://repo.maven.apache.org/maven2/ + + true + + + false + + + @@ -96,6 +102,47 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + true + true + ${forkCount} + true + + ${project.build.directory} + true + UTC + + + -Darrow.vector.max_allocation_bytes=1048576 + + + + default-test + test + + + org.apache.arrow:arrow-memory-unsafe + + + + + run-unsafe + test + + test + + + + org.apache.arrow:arrow-memory-netty + + + + + maven-resources-plugin @@ -137,35 +184,35 @@ - org.apache.maven.plugins - maven-shade-plugin - 3.1.1 - - - package - - shade - - - - - org.apache.arrow:arrow-format - com.google.flatbuffers:* - - - true - shade-format-flatbuffers - true - true - - - com.google.flatbuffers - arrow.vector.com.google.flatbuffers - - - - - + org.apache.maven.plugins + maven-shade-plugin + 3.1.1 + + + package + + shade + + + + + org.apache.arrow:arrow-format + com.google.flatbuffers:* + + + true + shade-format-flatbuffers + true + true + + + com.google.flatbuffers + arrow.vector.com.google.flatbuffers + + + + + diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java b/java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java index 8cc697e6fcb..4b48876ff16 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestBitVectorHelper.java @@ -22,50 +22,51 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import org.apache.arrow.memory.ArrowBuf; -import org.apache.arrow.memory.ReferenceManager; +import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; import org.junit.Test; -import io.netty.buffer.PooledByteBufAllocatorL; import io.netty.util.internal.PlatformDependent; public class TestBitVectorHelper { @Test public void testGetNullCount() throws Exception { - // test case 1, 1 null value for 0b110 - ArrowBuf validityBuffer = new ArrowBuf( - ReferenceManager.NO_OP, null, 3, new PooledByteBufAllocatorL().empty.memoryAddress()); - // we set validity buffer to be 0b10110, but only have 3 items with 1st item is null - validityBuffer.setByte(0, 0b10110); - - // we will only consider 0b110 here, since we only 3 items and only one is null - int count = BitVectorHelper.getNullCount(validityBuffer, 3); - assertEquals(count, 1); - - // test case 2, no null value for 0xFF - validityBuffer = new ArrowBuf( - ReferenceManager.NO_OP, null, 8, new PooledByteBufAllocatorL().empty.memoryAddress()); - validityBuffer.setByte(0, 0xFF); - - count = BitVectorHelper.getNullCount(validityBuffer, 8); - assertEquals(count, 0); - - // test case 3, 1 null value for 0x7F - validityBuffer = new ArrowBuf( - ReferenceManager.NO_OP, null, 8, new PooledByteBufAllocatorL().empty.memoryAddress()); - validityBuffer.setByte(0, 0x7F); - - count = BitVectorHelper.getNullCount(validityBuffer, 8); - assertEquals(count, 1); - - // test case 4, validity buffer has multiple bytes, 11 items - validityBuffer = new ArrowBuf( - ReferenceManager.NO_OP, null, 11, new PooledByteBufAllocatorL().empty.memoryAddress()); - validityBuffer.setByte(0, 0b10101010); - validityBuffer.setByte(1, 0b01010101); - - count = BitVectorHelper.getNullCount(validityBuffer, 11); - assertEquals(count, 5); + try (BufferAllocator root = new RootAllocator()) { + // test case 1, 1 null value for 0b110 + ArrowBuf validityBuffer = root.buffer(3); + // we set validity buffer to be 0b10110, but only have 3 items with 1st item is null + validityBuffer.setByte(0, 0b10110); + + // we will only consider 0b110 here, since we only 3 items and only one is null + int count = BitVectorHelper.getNullCount(validityBuffer, 3); + assertEquals(count, 1); + validityBuffer.close(); + + // test case 2, no null value for 0xFF + validityBuffer = root.buffer(8); + validityBuffer.setByte(0, 0xFF); + + count = BitVectorHelper.getNullCount(validityBuffer, 8); + assertEquals(count, 0); + validityBuffer.close(); + + // test case 3, 1 null value for 0x7F + validityBuffer = root.buffer(8); + validityBuffer.setByte(0, 0x7F); + + count = BitVectorHelper.getNullCount(validityBuffer, 8); + assertEquals(count, 1); + validityBuffer.close(); + + // test case 4, validity buffer has multiple bytes, 11 items + validityBuffer = root.buffer(11); + validityBuffer.setByte(0, 0b10101010); + validityBuffer.setByte(1, 0b01010101); + + count = BitVectorHelper.getNullCount(validityBuffer, 11); + assertEquals(count, 5); + validityBuffer.close(); + } } @Test