Skip to content

Commit f131c70

Browse files
authored
Add native image tests (#155)
1 parent d95323b commit f131c70

31 files changed

+945
-760
lines changed

.github/workflows/tests.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ jobs:
4545

4646
- name: Tests
4747
run: mvn "-Dh3.system.prune=true" "-Dh3.dockcross.only=${{ matrix.dockcross-only }}" -B -V clean test site
48+
env:
49+
OCI_EXE: docker
4850

4951
- name: Format check for C
5052
run: git diff --exit-code
@@ -91,6 +93,8 @@ jobs:
9193
9294
- name: Tests
9395
run: mvn "-Dh3.system.prune=true" "-Dh3.dockcross.tag=${{ matrix.dockcross-tag }}" "-Dh3.dockcross.only=${{ matrix.dockcross-only }}" -B -V clean test
96+
env:
97+
OCI_EXE: docker
9498

9599
tests-no-docker:
96100
name: Java (No Docker) ${{ matrix.java-version }} ${{ matrix.os }}
@@ -217,3 +221,53 @@ jobs:
217221
mvn clean test -Dh3.github.artifacts.use=true -Dh3.github.artifacts.by_run=true
218222
env:
219223
GH_TOKEN: ${{ github.token }}
224+
225+
tests-native:
226+
name: Native image ${{ matrix.java-version }} ${{ matrix.os }}
227+
needs:
228+
- tests
229+
- tests-no-docker
230+
runs-on: ${{ matrix.os }}
231+
232+
strategy:
233+
matrix:
234+
os: [ ubuntu-latest ]
235+
java-distribution: [ graalvm ]
236+
java-version: [ 21 ]
237+
238+
steps:
239+
- uses: actions/[email protected]
240+
with:
241+
submodules: recursive
242+
243+
- uses: actions/setup-java@v4
244+
with:
245+
distribution: "${{ matrix.java-distribution }}"
246+
java-version: "${{ matrix.java-version }}"
247+
248+
- uses: actions/cache@v2
249+
id: maven-cache
250+
with:
251+
path: ~/.m2/
252+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
253+
restore-keys: |
254+
${{ runner.os }}-maven-
255+
256+
- name: Download Docker binaries
257+
uses: actions/[email protected]
258+
with:
259+
pattern: docker-built-shared-objects-*
260+
merge-multiple: true
261+
path: src/main/resources/
262+
263+
- name: Download Mac binaries
264+
uses: actions/[email protected]
265+
with:
266+
name: macos-built-shared-objects
267+
path: src/main/resources/
268+
269+
- name: Download and test
270+
run: |
271+
mvn clean verify -Dnative -Dh3.github.artifacts.use=true -Dh3.github.artifacts.by_run=true
272+
env:
273+
GH_TOKEN: ${{ github.token }}

pom.xml

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6868
<org.openjdk.jmh.version>1.19</org.openjdk.jmh.version>
6969
<maven.javadoc.plugin.version>3.1.1</maven.javadoc.plugin.version>
70+
<maven-surefire.version>3.5.1</maven-surefire.version>
71+
<native-maven-plugin.version>0.10.3</native-maven-plugin.version>
7072

7173
<h3.git.remote>https://github.com/uber/h3.git</h3.git.remote>
7274
<h3.use.docker>true</h3.use.docker>
@@ -163,15 +165,41 @@
163165
</plugins>
164166
</build>
165167
</profile>
168+
<profile>
169+
<id>native-image</id>
170+
<activation>
171+
<property>
172+
<name>native</name>
173+
</property>
174+
</activation>
175+
<build>
176+
<plugins>
177+
<plugin>
178+
<groupId>org.graalvm.buildtools</groupId>
179+
<artifactId>native-maven-plugin</artifactId>
180+
<version>${native-maven-plugin.version}</version>
181+
<extensions>true</extensions>
182+
<configuration>
183+
<metadataRepository>
184+
<enabled>true</enabled>
185+
</metadataRepository>
186+
</configuration>
187+
<executions>
188+
<execution>
189+
<id>test-native</id>
190+
<goals>
191+
<goal>test</goal>
192+
</goals>
193+
<phase>verify</phase>
194+
</execution>
195+
</executions>
196+
</plugin>
197+
</plugins>
198+
</build>
199+
</profile>
166200
</profiles>
167201

168202
<dependencies>
169-
<dependency>
170-
<groupId>junit</groupId>
171-
<artifactId>junit</artifactId>
172-
<version>4.13.2</version>
173-
<scope>test</scope>
174-
</dependency>
175203
<dependency>
176204
<groupId>org.openjdk.jmh</groupId>
177205
<artifactId>jmh-core</artifactId>
@@ -187,7 +215,19 @@
187215
<dependency>
188216
<groupId>com.google.guava</groupId>
189217
<artifactId>guava</artifactId>
190-
<version>33.2.1-jre</version>
218+
<version>33.3.1-jre</version>
219+
<scope>test</scope>
220+
</dependency>
221+
<dependency>
222+
<groupId>org.junit.jupiter</groupId>
223+
<artifactId>junit-jupiter</artifactId>
224+
<version>5.11.2</version>
225+
<scope>test</scope>
226+
</dependency>
227+
<dependency>
228+
<groupId>org.junit.platform</groupId>
229+
<artifactId>junit-platform-launcher</artifactId>
230+
<version>1.11.2</version>
191231
<scope>test</scope>
192232
</dependency>
193233
</dependencies>
@@ -212,10 +252,33 @@
212252
</execution>
213253
</executions>
214254
</plugin>
255+
<plugin>
256+
<groupId>org.apache.maven.plugins</groupId>
257+
<artifactId>maven-surefire-plugin</artifactId>
258+
<version>${maven-surefire.version}</version>
259+
</plugin>
260+
<plugin>
261+
<groupId>org.apache.maven.plugins</groupId>
262+
<artifactId>maven-failsafe-plugin</artifactId>
263+
<version>${maven-surefire.version}</version>
264+
<configuration>
265+
<systemPropertyVariables>
266+
<junit.platform.listeners.uid.tracking.enabled>true</junit.platform.listeners.uid.tracking.enabled>
267+
</systemPropertyVariables>
268+
</configuration>
269+
<executions>
270+
<execution>
271+
<goals>
272+
<goal>integration-test</goal>
273+
<goal>verify</goal>
274+
</goals>
275+
</execution>
276+
</executions>
277+
</plugin>
215278
<plugin>
216279
<groupId>org.apache.maven.plugins</groupId>
217280
<artifactId>maven-compiler-plugin</artifactId>
218-
<version>3.1</version>
281+
<version>3.13.0</version>
219282
<configuration>
220283
<source>1.8</source>
221284
<target>1.8</target>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"resources": {
33
"includes": [
4-
{"pattern": "**libh3-java**"}
4+
{"pattern": ".*libh3-java.*"}
55
]
66
}
77
}

src/test/java/com/uber/h3core/BaseTestH3Core.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
package com.uber.h3core;
1717

1818
import java.io.IOException;
19-
import org.junit.BeforeClass;
19+
import org.junit.jupiter.api.BeforeAll;
2020

2121
/** Base class for tests of the class {@link H3Core} */
2222
public abstract class BaseTestH3Core {
2323
public static final double EPSILON = 1e-6;
2424

2525
protected static H3Core h3;
2626

27-
@BeforeClass
27+
@BeforeAll
2828
public static void setup() throws IOException {
2929
h3 = H3Core.newInstance();
3030
}

src/test/java/com/uber/h3core/TestBindingCompleteness.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.uber.h3core;
1717

18-
import static org.junit.Assert.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
1919

2020
import com.google.common.collect.ImmutableSet;
2121
import java.io.File;
@@ -24,18 +24,20 @@
2424
import java.util.HashSet;
2525
import java.util.Scanner;
2626
import java.util.Set;
27-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.api.condition.DisabledInNativeImage;
2829

2930
/** Tests all expected functions are exposed. */
30-
public class TestBindingCompleteness {
31+
class TestBindingCompleteness {
3132
/** Functions to ignore from the bindings. */
3233
private static final Set<String> WHITELIST =
3334
ImmutableSet.of(
3435
// These are provided by the Java library (java.lang.Math)
3536
"degsToRads", "radsToDegs");
3637

3738
@Test
38-
public void test() throws IOException {
39+
@DisabledInNativeImage
40+
void test() throws IOException {
3941
Set<String> exposed = new HashSet<>();
4042
for (Method m : H3Core.class.getMethods()) {
4143
exposed.add(m.getName());
@@ -50,10 +52,10 @@ public void test() throws IOException {
5052
continue;
5153
}
5254

53-
assertTrue(function + " is exposed in binding", exposed.contains(function));
55+
assertTrue(exposed.contains(function), function + " is exposed in binding");
5456
checkedFunctions++;
5557
}
5658
}
57-
assertTrue("Checked that the API exists", checkedFunctions > 10);
59+
assertTrue(checkedFunctions > 10, "Checked that the API exists");
5860
}
5961
}

src/test/java/com/uber/h3core/TestDirectedEdges.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@
1515
*/
1616
package com.uber.h3core;
1717

18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertFalse;
20-
import static org.junit.Assert.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2122

2223
import com.uber.h3core.exceptions.H3Exception;
2324
import com.uber.h3core.util.LatLng;
2425
import java.util.Collection;
2526
import java.util.List;
26-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2728

2829
/** Tests for unidirectional edge functions. */
29-
public class TestDirectedEdges extends BaseTestH3Core {
30+
class TestDirectedEdges extends BaseTestH3Core {
3031
@Test
31-
public void testUnidirectionalEdges() {
32+
void unidirectionalEdges() {
3233
String start = "891ea6d6533ffff";
3334
String adjacent = "891ea6d65afffff";
3435
String notAdjacent = "891ea6992dbffff";
@@ -59,13 +60,14 @@ public void testUnidirectionalEdges() {
5960
assertEquals(2, boundary.size());
6061
}
6162

62-
@Test(expected = H3Exception.class)
63-
public void testUnidirectionalEdgesNotNeighbors() {
64-
h3.cellsToDirectedEdge("891ea6d6533ffff", "891ea6992dbffff");
63+
@Test
64+
void unidirectionalEdgesNotNeighbors() {
65+
assertThrows(
66+
H3Exception.class, () -> h3.cellsToDirectedEdge("891ea6d6533ffff", "891ea6992dbffff"));
6567
}
6668

67-
@Test(expected = H3Exception.class)
68-
public void testDirectedEdgeInvalid() {
69-
h3.getDirectedEdgeOrigin(0);
69+
@Test
70+
void directedEdgeInvalid() {
71+
assertThrows(H3Exception.class, () -> h3.getDirectedEdgeOrigin(0));
7072
}
7173
}

src/test/java/com/uber/h3core/TestH3CoreCrossCompile.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@
1515
*/
1616
package com.uber.h3core;
1717

18-
import static org.junit.Assert.assertNotNull;
19-
import static org.junit.Assume.assumeTrue;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2020

2121
import com.google.common.collect.ImmutableList;
2222
import java.io.IOException;
2323
import java.util.List;
24-
import org.junit.BeforeClass;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.BeforeAll;
25+
import org.junit.jupiter.api.Test;
2626

2727
/**
2828
* Test that particular resource names exist in the built artifact when cross compiling. Although we
2929
* cannot test that those resources run correctly (since they can't be loaded), we can at least test
3030
* that the cross compiler put resources in the right locations. This test is only run if the system
3131
* property <code>h3.use.docker</code> has the value <code>true</code>.
3232
*/
33-
public class TestH3CoreCrossCompile {
34-
@BeforeClass
35-
public static void assumptions() {
33+
class TestH3CoreCrossCompile {
34+
@BeforeAll
35+
static void assumptions() {
3636
assumeTrue(
37-
"Docker cross compilation enabled", "true".equals(System.getProperty("h3.use.docker")));
37+
"true".equals(System.getProperty("h3.use.docker")), "Docker cross compilation enabled");
3838
}
3939

4040
@Test
41-
public void testResourcesExist() throws IOException {
41+
void resourcesExist() throws IOException {
4242
List<String> resources =
4343
ImmutableList.of(
4444
"/linux-x64/libh3-java.so",
@@ -56,7 +56,7 @@ public void testResourcesExist() throws IOException {
5656
"/android-arm/libh3-java.so",
5757
"/android-arm64/libh3-java.so");
5858
for (String name : resources) {
59-
assertNotNull(name + " is an included resource", H3CoreLoader.class.getResource(name));
59+
assertNotNull(H3CoreLoader.class.getResource(name), name + " is an included resource");
6060
}
6161
}
6262
}

0 commit comments

Comments
 (0)