refactor(loader): adjust LoadContext to 1.7.0 version#687
refactor(loader): adjust LoadContext to 1.7.0 version#687Pengzna merged 23 commits intoapache:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## master #687 +/- ##
=============================================
- Coverage 62.49% 51.59% -10.91%
+ Complexity 1903 971 -932
=============================================
Files 262 111 -151
Lines 9541 5828 -3713
Branches 886 750 -136
=============================================
- Hits 5963 3007 -2956
+ Misses 3190 2562 -628
+ Partials 388 259 -129 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/HugeGraphLoader.java
Show resolved
Hide resolved
hugegraph-client/src/main/java/org/apache/hugegraph/api/graphs/GraphsAPI.java
Show resolved
Hide resolved
hugegraph-client/src/main/java/org/apache/hugegraph/api/graphs/GraphsAPI.java
Show resolved
Hide resolved
| bin/init-store.sh || exit 1 | ||
| sed -i 's|gremlin.graph=org.apache.hugegraph.HugeFactory|gremlin.graph=org.apache.hugegraph.auth.HugeFactoryAuthProxy|' conf/graphs/hugegraph.properties | ||
| sed -i 's|#auth.authenticator=.*|auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator|' conf/rest-server.properties | ||
| sed -i 's|#auth.admin_pa=.*|auth.admin_pa=pa|' conf/rest-server.properties |
There was a problem hiding this comment.
在测试脚本中直接硬编码 admin/pa 凭证存在以下问题:
- 降低了测试的灵活性
- 如果服务器配置改变,测试会失败
- 不符合配置外部化最佳实践
建议:
- 使用环境变量
HUGEGRAPH_ADMIN_PASSWORD - 或从配置文件读取
- 提供默认值作为后备
| sed -i 's|#auth.admin_pa=.*|auth.admin_pa=pa|' conf/rest-server.properties | |
| ADMIN_PASSWORD=${HUGEGRAPH_ADMIN_PASSWORD:-pa} | |
| sed -i "s|#auth.admin_pa=.*|auth.admin_pa=$ADMIN_PASSWORD|" conf/rest-server.properties | |
| echo -e "$ADMIN_PASSWORD" | bin/init-store.sh || exit 1 |
There was a problem hiding this comment.
the username and password are already written in .properties, the sed command is only to let them show out
hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java
Outdated
Show resolved
Hide resolved
hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull Request Overview
This PR enables authentication support in HugeGraph Loader tests by configuring the test environment to use StandardAuthenticator and updating all test cases to include username/password credentials ("admin"/"pa"). This brings the tests in line with a more secure, authenticated setup.
- Adds authentication configuration to the Travis CI installation script for HugeGraph server
- Updates all functional test classes to include authentication credentials when invoking the loader
- Refactors code in
GraphsAPI.javaandGraphsManager.javato remove unused graphSpace-related overloads - Removes a dead
System.exit(1)call inHugeGraphLoader.javathat was unreachable after the return statement
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| LoadTest.java | Changed hardcoded password from "admin" to "pa" in the authmain helper method |
| KafkaLoadTest.java | Added ArrayList/Arrays imports and replaced HugeGraphLoader.main() calls with authmain(), added credentials to tests requiring manual argument construction |
| JDBCLoadTest.java | Replaced HugeGraphLoader.main() calls with authmain() to include authentication |
| HDFSLoadTest.java | Added ArrayList/Arrays imports and updated tests to append authentication credentials to argument lists |
| FileLoadTest.java | Replaced HugeGraphLoader.main() calls with authmain() and updated tests constructing loaders manually to include credentials |
| HugeGraphLoader.java | Removed unreachable System.exit(1) statement following a return |
| install-hugegraph-from-source.sh | Configured HugeGraph servers with StandardAuthenticator and set admin password to "pa" |
| GraphsManager.java | Removed unused graphSpace parameter overload methods |
| GraphsAPI.java | Simplified API methods by removing graphSpace parameter support and refactoring mode retrieval logic |
| loader-ci.yml | Updated HugeGraph commit ID reference |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/KafkaLoadTest.java
Outdated
Show resolved
Hide resolved
hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/HDFSLoadTest.java
Outdated
Show resolved
Hide resolved
hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/HDFSLoadTest.java
Outdated
Show resolved
Hide resolved
hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/HDFSLoadTest.java
Outdated
Show resolved
Hide resolved
hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java
Outdated
Show resolved
Hide resolved
| try { | ||
| loader = new HugeGraphLoader(args); | ||
| } catch (Throwable e) { | ||
| Printer.printError("Failed to start loading", e); |
There was a problem hiding this comment.
移除 System.exit(1) 调用会改变程序的错误处理行为:
问题:
- 原代码在加载失败时会立即终止 JVM 进程(退出码 1)
- 新代码只是 return,程序会继续执行
影响:
- 在单元测试中,这可能导致测试无法正确检测失败情况
- 在生产环境中可能导致错误被静默忽略
建议:
如果这个改动是为了改善测试体验,建议:
- 考虑通过抛出异常而不是静默返回
- 或者添加注释说明为什么移除 System.exit(1)
- 确保所有调用方都能正确处理这种情况
hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/LoadTest.java
Show resolved
Hide resolved
| * @see HugeGraphLoader#main(String[]) | ||
| */ | ||
| public static void authmain(String[] args) { | ||
| ArrayList list = new ArrayList(Arrays.asList(args)); |
There was a problem hiding this comment.
🧹 代码风格 - 可以简化泛型声明
这行代码可以使用菱形操作符简化:
| ArrayList list = new ArrayList(Arrays.asList(args)); | |
| ArrayList list = new ArrayList<>(Arrays.asList(args)); |
或者更好的做法是添加类型参数:
ArrayList<String> list = new ArrayList<>(Arrays.asList(args));这样可以:
- 避免原始类型警告
- 提供更好的类型安全性
- 代码更清晰易读
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * @see HugeGraphLoader#main(String[]) | ||
| */ | ||
| public static void authmain(String[] args) { | ||
| ArrayList list = new ArrayList(Arrays.asList(args)); |
There was a problem hiding this comment.
The ArrayList should use generic type parameter ArrayList<String> instead of raw type to avoid unchecked warnings and provide type safety.
| * Specifically, it appends: | ||
| * --username admin | ||
| * --password pa | ||
| * to the end of the original argument list before delegating to HugeGraphLoader. |
There was a problem hiding this comment.
The documentation states '--password pa' but should be updated to clarify this is a simplified test password. Consider documenting why this specific value was chosen or if it's a placeholder that should be changed in production environments.
| * to the end of the original argument list before delegating to HugeGraphLoader. | |
| * to the end of the original argument list before delegating to HugeGraphLoader. | |
| * <p> | |
| * <b>Note:</b> The password "pa" is a simplified test password used only for testing purposes. | |
| * It is a placeholder and <b>must be changed</b> in production environments to a secure value. | |
| * The choice of "pa" is arbitrary and intended to facilitate automated testing. |
| } catch (Throwable e) { | ||
| Printer.printError("Failed to start loading", e); | ||
| System.exit(1); | ||
| return; |
There was a problem hiding this comment.
After removing System.exit(1), the method now returns normally after an error. This could cause confusion as the error is printed but execution continues in the calling context. Consider documenting this behavior change or ensuring callers check for errors appropriately.
| return; | |
| System.exit(1); |
Purpose of the PR
Main Changes
Verifying these changes
Does this PR potentially affect the following parts?
Documentation Status
Doc - TODODoc - DoneDoc - No Need