Skip to content

Commit

Permalink
Use Java classloader to find test resources (#9760)
Browse files Browse the repository at this point in the history
Updates the Java tests to use the classloader to locate test files rather than reaching directly into the source directory.

Authors:
  - Jason Lowe (https://github.com/jlowe)

Approvers:
  - Gera Shegalov (https://github.com/gerashegalov)

URL: #9760
  • Loading branch information
jlowe authored Nov 30, 2021
1 parent dca8a0a commit 1db05c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
14 changes: 7 additions & 7 deletions java/src/test/java/ai/rapids/cudf/TableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TableTest extends CudfTestBase {
private static final File TEST_PARQUET_FILE = new File("src/test/resources/acq.parquet");
private static final File TEST_ORC_FILE = new File("src/test/resources/TestOrcFile.orc");
private static final File TEST_ORC_TIMESTAMP_DATE_FILE = new File(
"src/test/resources/timestamp-date-test.orc");
private static final File TEST_DECIMAL_PARQUET_FILE = new File("src/test/resources/decimal.parquet");
private static final File TEST_PARQUET_FILE = TestUtils.getResourceAsFile("acq.parquet");
private static final File TEST_ORC_FILE = TestUtils.getResourceAsFile("TestOrcFile.orc");
private static final File TEST_ORC_TIMESTAMP_DATE_FILE = TestUtils.getResourceAsFile("timestamp-date-test.orc");
private static final File TEST_DECIMAL_PARQUET_FILE = TestUtils.getResourceAsFile("decimal.parquet");
private static final File TEST_SIMPLE_CSV_FILE = TestUtils.getResourceAsFile("simple.csv");

private static final Schema CSV_DATA_BUFFER_SCHEMA = Schema.builder()
.column(DType.INT32, "A")
Expand Down Expand Up @@ -548,7 +548,7 @@ void testReadCSVPrune() {
.column(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
.column(110.0, 111.0, 112.0, 113.0, 114.0, 115.0, 116.0, 117.0, 118.2, 119.8)
.build();
Table table = Table.readCSV(schema, opts, new File("./src/test/resources/simple.csv"))) {
Table table = Table.readCSV(schema, opts, TEST_SIMPLE_CSV_FILE)) {
assertTablesAreEqual(expected, table);
}
}
Expand Down Expand Up @@ -675,7 +675,7 @@ void testReadCSV() {
.column(120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L)
.column("one", "two", "three", "four", "five", "six", "seven\ud801\uddb8", "eight\uBF68", "nine\u03E8", "ten")
.build();
Table table = Table.readCSV(schema, new File("./src/test/resources/simple.csv"))) {
Table table = Table.readCSV(schema, TEST_SIMPLE_CSV_FILE)) {
assertTablesAreEqual(expected, table);
}
}
Expand Down
17 changes: 16 additions & 1 deletion java/src/test/java/ai/rapids/cudf/TestUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,9 @@

package ai.rapids.cudf;

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -211,4 +214,16 @@ static Double[] getDoubles(final long seed, final int size, int specialValues) {
});
return result;
}

public static File getResourceAsFile(String resourceName) {
URL url = TestUtils.class.getClassLoader().getResource(resourceName);
if (url == null) {
throw new IllegalArgumentException("Unable to locate resource: " + resourceName);
}
try {
return new File(url.toURI());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 1db05c9

Please sign in to comment.