-
Notifications
You must be signed in to change notification settings - Fork 88
feat(java, scala): added logic for finding test data in root and parent dir of project #824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,7 +32,25 @@ | |||||||||||||||||||||||||||||||||||||||||||
| import org.junit.Test; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| public class GraphInfoTest { | ||||||||||||||||||||||||||||||||||||||||||||
| public static final String root = System.getenv("GAR_TEST_DATA") + "/java"; | ||||||||||||||||||||||||||||||||||||||||||||
| private static String resolveTestData() { | ||||||||||||||||||||||||||||||||||||||||||||
| String path = System.getenv("GAR_TEST_DATA"); | ||||||||||||||||||||||||||||||||||||||||||||
| if (path == null) { | ||||||||||||||||||||||||||||||||||||||||||||
| path = System.getProperty("gar.test.data"); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| if (path == null) { | ||||||||||||||||||||||||||||||||||||||||||||
| String[] candidates = {"../../testing", "../testing", "testing"}; | ||||||||||||||||||||||||||||||||||||||||||||
| for (String p : candidates) { | ||||||||||||||||||||||||||||||||||||||||||||
| java.io.File dir = new java.io.File(p).getAbsoluteFile(); | ||||||||||||||||||||||||||||||||||||||||||||
| if (new java.io.File(dir, "ldbc_sample/csv/ldbc_sample.graph.yml").exists()) { | ||||||||||||||||||||||||||||||||||||||||||||
| return dir.getAbsolutePath(); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| throw new IllegalStateException("GAR_TEST_DATA not found"); | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| throw new IllegalStateException("GAR_TEST_DATA not found"); | |
| throw new RuntimeException("GAR_TEST_DATA not found"); |
Outdated
Copilot
AI
Jan 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation approach differs from TestUtil.java which performs additional verification after finding a path. TestUtil.java re-validates the chosen path to ensure both the directory and the marker file exist. This double-checking approach is more robust and catches edge cases. Consider adding a final validation step after selecting a path to ensure it's valid before returning it.
| return dir.getAbsolutePath(); | |
| } | |
| } | |
| throw new IllegalStateException("GAR_TEST_DATA not found"); | |
| } | |
| return path; | |
| path = dir.getAbsolutePath(); | |
| break; | |
| } | |
| } | |
| if (path == null) { | |
| throw new IllegalStateException("GAR_TEST_DATA not found"); | |
| } | |
| } | |
| java.io.File baseDir = new java.io.File(path).getAbsoluteFile(); | |
| java.io.File markerFile = | |
| new java.io.File(baseDir, "ldbc_sample/csv/ldbc_sample.graph.yml"); | |
| if (!baseDir.isDirectory() || !markerFile.exists()) { | |
| throw new IllegalStateException("GAR_TEST_DATA not found"); | |
| } | |
| return baseDir.getAbsolutePath(); |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,10 +29,25 @@ abstract class BaseTestSuite extends AnyFunSuite with BeforeAndAfterAll { | |||||||||||||
| var spark: SparkSession = _ | ||||||||||||||
|
|
||||||||||||||
| override def beforeAll(): Unit = { | ||||||||||||||
| if (System.getenv("GAR_TEST_DATA") == null) { | ||||||||||||||
| throw new IllegalArgumentException("GAR_TEST_DATA is not set") | ||||||||||||||
| def resolveTestData(): String = { | ||||||||||||||
| Option(System.getenv("GAR_TEST_DATA")) | ||||||||||||||
| .orElse(Option(System.getProperty("gar.test.data"))) | ||||||||||||||
| .getOrElse { | ||||||||||||||
| val candidates = Seq("../../testing", "../testing", "testing") | ||||||||||||||
| candidates | ||||||||||||||
| .map(p => new java.io.File(p).getAbsoluteFile) | ||||||||||||||
| .find(d => | ||||||||||||||
| new java.io.File(d, "ldbc_sample/csv/ldbc_sample.graph.yml") | ||||||||||||||
| .exists() | ||||||||||||||
|
||||||||||||||
| new java.io.File(d, "ldbc_sample/csv/ldbc_sample.graph.yml") | |
| .exists() | |
| d.exists() && d.isDirectory && | |
| new java.io.File(d, "ldbc_sample/csv/ldbc_sample.graph.yml") | |
| .isFile |
Outdated
Copilot
AI
Jan 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception type differs from the one used in TestUtil.java, which uses RuntimeException. Consider using RuntimeException instead of IllegalArgumentException for consistency across the codebase, or document why a different exception type is appropriate here.
| throw new IllegalArgumentException("GAR_TEST_DATA not found") | |
| throw new RuntimeException("GAR_TEST_DATA not found") |
Outdated
Copilot
AI
Jan 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is less informative than the one used in TestUtil.java. TestUtil.java provides a more detailed message that explains both the environment variable option and the directory structure requirement. Consider updating the message to match the clarity of TestUtil.java's error message which states: "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".
| throw new IllegalArgumentException("GAR_TEST_DATA not found") | |
| throw new IllegalArgumentException( | |
| "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" | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shivendra-dev54, You can consider adopting this suggestion, it makes the error message clearer
Copilot
AI
Jan 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation approach differs from TestUtil.java which performs additional verification after finding a path. TestUtil.java re-validates the chosen path to ensure both the directory and the marker file exist. This double-checking approach is more robust and catches edge cases. Consider adding a final validation step after selecting a path to ensure it's valid before returning it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shivendra-dev54 Please consider this comment, it looks good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation logic is inconsistent with the existing implementation in TestUtil.java. The current code only checks if the file exists, but TestUtil.java also verifies that the directory exists and is actually a directory. This could lead to false positives if the parent path doesn't exist. Consider adding an additional check to verify that the parent directory exists and is a directory before checking for the specific file.