Skip to content

Commit ccf9a65

Browse files
devadhe sbyangxk
andauthored
added logic for finding test data in root and parent dir of project f… (#824)
* added logic for finding test data in root and parent dir of project for easy testing * try to fix * added directory checks and updated error messages --------- Co-authored-by: yangxk <yang_xk@qq.com>
1 parent 76b5163 commit ccf9a65

3 files changed

Lines changed: 66 additions & 5 deletions

File tree

.github/workflows/pyspark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Install Poetry
5656
working-directory: pyspark
5757
run: |
58-
yes | sudo python3 -m pip install poetry --quiet
58+
yes | python3 -m pip install poetry --quiet
5959
poetry env use python3
6060
6161
- name: Lint

maven-projects/java/src/test/java/org/apache/graphar/graphinfo/GraphInfoTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,36 @@
3232
import org.junit.Test;
3333

3434
public class GraphInfoTest {
35-
public static final String root = System.getenv("GAR_TEST_DATA") + "/java";
35+
private static String resolveTestData() {
36+
String path = System.getenv("GAR_TEST_DATA");
37+
if (path == null) {
38+
path = System.getProperty("gar.test.data");
39+
}
40+
if (path == null) {
41+
String[] candidates = {"../../testing", "../testing", "testing"};
42+
for (String p : candidates) {
43+
java.io.File dir = new java.io.File(p).getAbsoluteFile();
44+
if (new java.io.File(dir, "ldbc_sample/csv/ldbc_sample.graph.yml").exists()) {
45+
path = dir.getAbsolutePath();
46+
break;
47+
}
48+
}
49+
if (path == null) {
50+
throw new RuntimeException(
51+
"GAR_TEST_DATA not found or invalid. Please set GAR_TEST_DATA environment variable to point to the testing directory or ensure the testing directory exists with ldbc_sample/csv/ldbc_sample.graph.yml");
52+
}
53+
}
54+
java.io.File baseDir = new java.io.File(path).getAbsoluteFile();
55+
java.io.File markerFile =
56+
new java.io.File(baseDir, "ldbc_sample/csv/ldbc_sample.graph.yml");
57+
if (!baseDir.isDirectory() || !markerFile.exists()) {
58+
throw new RuntimeException(
59+
"GAR_TEST_DATA not found or invalid. Please set GAR_TEST_DATA environment variable to point to the testing directory or ensure the testing directory exists with ldbc_sample/csv/ldbc_sample.graph.yml");
60+
}
61+
return baseDir.getAbsolutePath();
62+
}
63+
64+
public static final String root = resolveTestData() + "/java";
3665

3766
@Test
3867
public void test1() {

maven-projects/spark/graphar/src/test/scala/org/apache/graphar/BaseTestSuite.scala

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,42 @@ abstract class BaseTestSuite extends AnyFunSuite with BeforeAndAfterAll {
2929
var spark: SparkSession = _
3030

3131
override def beforeAll(): Unit = {
32-
if (System.getenv("GAR_TEST_DATA") == null) {
33-
throw new IllegalArgumentException("GAR_TEST_DATA is not set")
32+
def resolveTestData(): String = {
33+
var testDataPath: String =
34+
Option(System.getenv("GAR_TEST_DATA"))
35+
.orElse(Option(System.getProperty("gar.test.data")))
36+
.orNull
37+
38+
if (testDataPath == null) {
39+
val candidates = Seq("../../testing", "../testing", "testing")
40+
candidates.foreach { p =>
41+
val dir = new java.io.File(p).getAbsoluteFile
42+
val marker =
43+
new java.io.File(dir, "ldbc_sample/csv/ldbc_sample.graph.yml")
44+
if (dir.exists() && dir.isDirectory && marker.isFile) {
45+
testDataPath = dir.getAbsolutePath
46+
return testDataPath
47+
}
48+
}
49+
}
50+
51+
if (testDataPath != null) {
52+
val dir = new java.io.File(testDataPath)
53+
val marker =
54+
new java.io.File(dir, "ldbc_sample/csv/ldbc_sample.graph.yml")
55+
if (dir.exists() && dir.isDirectory && marker.isFile) {
56+
return testDataPath
57+
}
58+
}
59+
60+
throw new RuntimeException(
61+
"GAR_TEST_DATA not found or invalid. " +
62+
"Please set GAR_TEST_DATA environment variable to point to the testing directory " +
63+
"or ensure the testing directory exists with ldbc_sample/csv/ldbc_sample.graph.yml"
64+
)
3465
}
35-
testData = System.getenv("GAR_TEST_DATA")
66+
67+
testData = resolveTestData()
3668
spark = SparkSession
3769
.builder()
3870
.enableHiveSupport()

0 commit comments

Comments
 (0)