diff --git a/docs/source/developers/java/building.rst b/docs/source/developers/java/building.rst index 63a7b4369b809..3904841de9c5a 100644 --- a/docs/source/developers/java/building.rst +++ b/docs/source/developers/java/building.rst @@ -321,6 +321,54 @@ Building Java JNI Modules -Darrow.c.jni.dist.dir=/java-dist/lib/ \ -Parrow-jni clean install +Testing +======= + +By default, Maven uses the same Java version to both build the code and run the tests. + +It is also possible to use a different JDK version for the tests. This requires Maven +toolchains to be configured beforehand, and then a specific test property needs to be set. + +Configuring Maven toolchains +---------------------------- + +To be able to use a JDK version for testing, it needs to be registered first in Maven ``toolchains.xml`` +configuration file usually located under ``${HOME}/.m2`` with the following snippet added to it: + + .. code-block:: + + + + + [...] + + + jdk + + 21 + temurin + + + path/to/jdk/home + + + + [...] + + + +Testing with a specific JDK +--------------------------- + +To run Arrow tests with a specific JDK version, use the ``arrow.test.jdk-version`` property. + +For example, to run Arrow tests with JDK 17, use the following snippet: + + .. code-block:: + + $ cd arrow/java + $ mvn -Darrow.test.jdk-version=17 clean verify + IDE Configuration ================= diff --git a/java/flight/flight-core/pom.xml b/java/flight/flight-core/pom.xml index d4083383a2f44..be3c191654a58 100644 --- a/java/flight/flight-core/pom.xml +++ b/java/flight/flight-core/pom.xml @@ -32,6 +32,8 @@ under the License. 1 + + --add-opens=org.apache.arrow.flight.core/org.apache.arrow.flight.perf.impl=protobuf.java --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED diff --git a/java/flight/flight-sql-jdbc-driver/pom.xml b/java/flight/flight-sql-jdbc-driver/pom.xml index 3dfe3bcd33f50..148319e5d9d64 100644 --- a/java/flight/flight-sql-jdbc-driver/pom.xml +++ b/java/flight/flight-sql-jdbc-driver/pom.xml @@ -59,6 +59,7 @@ under the License. maven-failsafe-plugin + default-it integration-test verify diff --git a/java/flight/flight-sql/pom.xml b/java/flight/flight-sql/pom.xml index 81bdc1a25636a..c9c589d202ac6 100644 --- a/java/flight/flight-sql/pom.xml +++ b/java/flight/flight-sql/pom.xml @@ -32,6 +32,8 @@ under the License. 1 + + --add-reads=org.apache.arrow.flight.sql=org.slf4j --add-reads=org.apache.arrow.flight.core=ALL-UNNAMED --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED diff --git a/java/memory/memory-core/pom.xml b/java/memory/memory-core/pom.xml index b9fa8ab1a6942..9b24cee032023 100644 --- a/java/memory/memory-core/pom.xml +++ b/java/memory/memory-core/pom.xml @@ -30,6 +30,11 @@ under the License. Arrow Memory - Core Core off-heap memory management libraries for Arrow ValueVectors. + + + --add-reads=org.apache.arrow.memory.core=ch.qos.logback.classic --add-opens=java.base/java.lang.reflect=org.apache.arrow.memory.core --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED + + org.slf4j @@ -85,42 +90,25 @@ under the License. **/TestOpens.java + + + + opens-tests + + test + + test + + + + + + **/TestOpens.java + + + + - - - - opens-tests - - - [16,] - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - opens-tests - - test - - test - - - - - - **/TestOpens.java - - - - - - - - - diff --git a/java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestOpens.java b/java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestOpens.java index 756aa2919789b..b5e0a71e7ee0e 100644 --- a/java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestOpens.java +++ b/java/memory/memory-core/src/test/java/org/apache/arrow/memory/TestOpens.java @@ -18,12 +18,15 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.condition.JRE.JAVA_16; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledForJreRange; public class TestOpens { /** Instantiating the RootAllocator should poke MemoryUtil and fail. */ @Test + @EnabledForJreRange(min = JAVA_16) public void testMemoryUtilFailsLoudly() { // This test is configured by Maven to run WITHOUT add-opens. So this should fail on JDK16+ // (where JEP396 means that add-opens is required to access JDK internals). @@ -44,6 +47,6 @@ public void testMemoryUtilFailsLoudly() { break; } } - assertTrue(found, "Expected exception as not thrown"); + assertTrue(found, "Expected exception was not thrown"); } } diff --git a/java/memory/memory-netty/pom.xml b/java/memory/memory-netty/pom.xml index e29ca3a4d053c..f2d4d2d0fe3bc 100644 --- a/java/memory/memory-netty/pom.xml +++ b/java/memory/memory-netty/pom.xml @@ -78,6 +78,7 @@ under the License. maven-failsafe-plugin + default-it integration-test verify diff --git a/java/pom.xml b/java/pom.xml index be49b6610f3f6..35c2a433033bf 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -112,6 +112,8 @@ under the License. 3.45.0 none -Xdoclint:none + + --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED 11 11 @@ -303,7 +305,7 @@ under the License. maven-surefire-plugin - --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED + ${surefire.add-opens.argLine} true true ${forkCount} @@ -322,7 +324,7 @@ under the License. maven-failsafe-plugin - --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED + ${surefire.add-opens.argLine} ${project.build.directory} true @@ -1265,5 +1267,59 @@ under the License. + + + + cross-jdk-testing + + + arrow.test.jdk-version + + + + + + maven-enforcer-plugin + + + check-jdk-version-property + + enforce + + validate + + + + arrow.test.jdk-version + "JDK version used for test must be specified." + ^\d{2,} + "JDK version used for test must be 11, 17, 21, ..." + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${arrow.test.jdk-version} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + ${arrow.test.jdk-version} + + + + + + diff --git a/java/vector/pom.xml b/java/vector/pom.xml index 7a53bf754aae4..73d76fc7306ae 100644 --- a/java/vector/pom.xml +++ b/java/vector/pom.xml @@ -188,6 +188,7 @@ under the License. + default-it integration-test verify