Skip to content

test(core): Add oshi 测试case #2134

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

Merged
merged 3 commits into from
May 5, 2025
Merged

test(core): Add oshi 测试case #2134

merged 3 commits into from
May 5, 2025

Conversation

unknowIfGuestInDream
Copy link
Owner

@unknowIfGuestInDream unknowIfGuestInDream commented May 5, 2025

Close #1215

Fixes #

Proposed Changes

  1. ...
  2. ...
  3. ...

Readiness Checklist

Author/Contributor

  • If documentation is needed for this change, has that been included in this pull request

Reviewing Maintainer

  • Label as either enhancement, bug, documentation or dependencies
  • Verify design and implementation

Summary by Sourcery

Enhance Oshi test coverage by adding comprehensive system information tests across various hardware and software domains

Enhancements:

  • Refactor existing Oshi tests to provide more detailed system information logging
  • Add tagged test methods for different system information categories

Tests:

  • Add extensive test cases for system hardware and software information using Oshi library
  • Implement tests for OS, processor, memory, file stores, processes, USB devices, and network interfaces

Chores:

  • Update copyright year from 2024 to 2025
  • Modify test class visibility to public

Summary by CodeRabbit

  • 测试
    • 扩展并重构了系统与硬件信息相关的测试用例,涵盖操作系统、CPU、内存、存储、进程、USB 和网络等多项内容,提升了测试覆盖面和输出信息的丰富度。
    • 新增 OshiUtil 工具类的测试,包括 CPU 信息、内存、当前进程等功能的验证。
    • 所有新增测试均默认禁用,不会自动执行。
  • Chores
    • 优化了依赖检查的 GitHub Actions 工作流,新增针对非 dependabot 提交的条件处理,提升 CI 流程的灵活性。

Close #1215

Signed-off-by: unknowIfGuestInDream <liang.tang.cx@gmail.com>
Copy link

Thank you for following naming conventions! 😻

Copy link

vercel bot commented May 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
javafx-tool ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2025 2:30pm

Copy link

sourcery-ai bot commented May 5, 2025

Reviewer's Guide

This pull request introduces a comprehensive suite of JUnit 5 tests for the oshi library integration within the OshiTest class. It utilizes the OshiUtil helper class to retrieve and print various system hardware and operating system details (CPU, memory, processes, network, etc.) to standard output for verification. Tests are categorized using @Tag annotations, replacing previous assertion-based tests.

File-Level Changes

Change Details Files
Added extensive test cases for oshi functionality.
  • Implemented new @Test methods covering OS, processor, display, hardware, memory, CPU, file store, process, USB, and network information retrieval using OshiUtil.
  • Used System.out.println to output retrieved system information.
  • Applied @Tag annotations to categorize tests (e.g., OS_HWInfo, Memory, CPU).
core/src/test/java/com/tlcsdm/core/oshi/OshiTest.java
Refactored existing tests and updated metadata.
  • Removed previous assertion-based tests.
  • Updated the copyright year in the file header.
core/src/test/java/com/tlcsdm/core/oshi/OshiTest.java

Assessment against linked issues

Issue Objective Addressed Explanation
#1215 Add oshi library support to the project.
#1215 Provide basic usage examples and tests for oshi functionality.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

quine-bot bot commented May 5, 2025

👋 Figuring out if a PR is useful is hard, hopefully this will help.

  • @unknowIfGuestInDream has been on GitHub since 2019 and in that time has had 1240 public PRs merged
  • Don't you recognize them? They've been here before 🎉
  • Here's a good example of their work: javafxTool (Javafx scaffolding, built on JDK17 + JavaFX21 + controlsfx 11.x.x + Maven)
  • From looking at their profile, they seem to be good with Java and HTML.

Their most recently public accepted PR is: #2130

Close #1215

Signed-off-by: unknowIfGuestInDream <liang.tang.cx@gmail.com>
Copy link

coderabbitai bot commented May 5, 2025

"""

Walkthrough

本次变更主要扩展和重构了 OshiTest 测试类,并新增了 OshiUtilTest 测试类。OshiTest 现已覆盖操作系统、硬件、内存、CPU、文件存储、进程、USB 及网络等多个维度的详细信息获取,测试方法均按功能分组并打上了 @Tag 标签。OshiUtilTest 用于验证 OshiUtil 工具类的相关功能,包括 CPU 信息、内存、当前进程等。两个测试类均用 @Disabled 注解默认跳过执行。

Changes

文件/组 变更摘要
core/src/test/.../OshiTest.java 类由包私有改为 public,新增大量按功能分组的测试方法,涵盖 OS、硬件、内存、CPU、文件存储、进程、USB、网络等信息获取,移除原有简单测试,新增私有辅助方法。
core/src/test/.../OshiUtilTest.java 新增测试类,包含对 OshiUtil 工具类的 CPU、内存、当前进程等功能的测试方法,均带有断言和输出。
.github/workflows/check-aliyun-maven.yml 新增 uncheck-dependencies 任务,针对非 dependabot 提交跳过依赖检查,输出提示信息。

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant OshiTest
    participant OshiUtil
    participant OSHI

    TestRunner->>OshiTest: 执行各类测试方法
    OshiTest->>OSHI: 获取硬件/系统信息
    OshiTest-->>TestRunner: 打印/输出结果

    TestRunner->>OshiUtilTest: 执行工具类测试方法
    OshiUtilTest->>OshiUtil: 调用工具方法(如 getCpuInfo, getMemory)
    OshiUtil->>OSHI: 获取底层系统信息
    OshiUtil-->>OshiUtilTest: 返回信息
    OshiUtilTest-->>TestRunner: 断言/输出结果
Loading

Assessment against linked issues

Objective Addressed Explanation
oshi 支持相关功能的测试用例实现(#1215

Poem

小兔写代码,测试 OSHI 真精彩,
硬件内存全覆盖,CPU 网络也不赖。
工具方法细细查,断言输出齐欢快。
代码如春草,测试如花开,
跳一跳,跑一跑,
OSHI 之旅乐无涯! 🐰✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86b0295 and 7780c7d.

📒 Files selected for processing (1)
  • .github/workflows/check-aliyun-maven.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/check-aliyun-maven.yml

241-241: could not parse as YAML: yaml: line 241: did not find expected key

(syntax-check)

🪛 YAMLlint (1.35.1)
.github/workflows/check-aliyun-maven.yml

[error] 242-242: syntax error: expected , but found ''

(syntax)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: build (17, windows-latest, false)
  • GitHub Check: build (17, macos-latest, false)
  • GitHub Check: build (21, macos-latest, false)
  • GitHub Check: build (21, ubuntu-latest, false)
  • GitHub Check: build (17, ubuntu-latest, false)
  • GitHub Check: build (21, windows-latest, false)
  • GitHub Check: StepSecurity Harden-Runner
  • GitHub Check: Summary

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @unknowIfGuestInDream - I've reviewed your changes - here's some feedback:

  • The copyright year appears to have been incorrectly updated to 2025.
  • Consider adding assertions to the new test methods to verify the expected behavior or data format, rather than just printing to the console.
  • The entire test class is marked as @Disabled; clarify if these tests are intended to be run automatically or remove the annotation if they should be active.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 5 issues found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (6)
core/src/test/java/com/tlcsdm/core/oshi/OshiUtilTest.java (1)

64-67: 仅打印 CPU 使用率,建议增加数值区间断言

如果希望保留输出,可同时校验:

double used = OshiUtil.getCpuInfo().getUsed();
System.out.println("CPU Used: " + used);
Assertions.assertTrue(used >= 0 && used <= 100, "CPU 使用率应在 0~100 之间");
core/src/test/java/com/tlcsdm/core/oshi/OshiTest.java (5)

55-58: 大体测试均被 @disabled 且只打印,无断言

本类更多像演示/调试脚本而非单元测试,会导致覆盖率统计失真,也无法在 CI 中捕获异常。
可考虑:

  1. 将关键逻辑验证迁移到 OshiUtilTest 并保留少量集成测试;
  2. 对仍需手动检查的用例保留 @Disabled("manual")
  3. 或使用 JUnit 5 的 assumeTrue 在条件不满足时跳过。

121-129: phyMemory 用例缺少断言,仅输出信息

建议至少校验物理内存条数量或容量大于 0,示例:

Assertions.assertFalse(pmList.isEmpty(), "未检测到物理内存");
Assertions.assertTrue(OshiUtil.getMemory().getTotal() > 0, "总内存应大于 0");

148-153: cpu() 测试同样缺少有效断言

可复用 CpuInfo 中的数值进行区间校验,避免仅打印:见 OshiUtilTest 建议。


172-188: 遍历所有进程并大量打印,运行成本高

getProcesses(null, null, 0) 可能返回上千进程,输出巨大且拖慢测试。若确为调试用途,建议:

  • 限制数量,如 getProcesses(5, OperatingSystem.ProcessSort.CPU)
  • 或移至单独的性能/诊断工具类,不放在常规测试套件中。

238-252: getIPAddressesString 可用 String.join 简化

-private String getIPAddressesString(String[] ipAddressArr) {
-    StringBuilder sb = new StringBuilder();
-    boolean first = true;
-    for (String ipAddress : ipAddressArr) {
-        if (first) {
-            first = false;
-        } else {
-            sb.append("; ");
-        }
-        sb.append(ipAddress);
-    }
-    return sb.toString();
-}
+private String getIPAddressesString(String[] ipAddressArr) {
+    return String.join("; ", ipAddressArr);
+}

更简洁、无需显式循环。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e504a59 and 86b0295.

📒 Files selected for processing (2)
  • core/src/test/java/com/tlcsdm/core/oshi/OshiTest.java (2 hunks)
  • core/src/test/java/com/tlcsdm/core/oshi/OshiUtilTest.java (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
core/src/test/java/com/tlcsdm/core/oshi/OshiUtilTest.java (1)
core/src/main/java/com/tlcsdm/core/oshi/OshiUtil.java (1)
  • OshiUtil (53-176)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: build (21, ubuntu-latest, false)
  • GitHub Check: build (17, ubuntu-latest, false)
  • GitHub Check: qodana
  • GitHub Check: build (21, windows-latest, false)
  • GitHub Check: build (17, macos-latest, false)
  • GitHub Check: build (21, macos-latest, false)
  • GitHub Check: build (17, windows-latest, false)
  • GitHub Check: Summary
🔇 Additional comments (1)
core/src/test/java/com/tlcsdm/core/oshi/OshiUtilTest.java (1)

38-40: 谨慎使用类级别 @disabled,可能导致 CI 完全跳过新用例

整个测试类被 @Disabled 标记,CI / 构建流水线将不会执行任何断言,从而无法及时发现回归问题。
若仅是环境限制(如需物理硬件),建议:

  1. 为每个测试单独加 @Disabled("原因"),并留下 TODO,方便后期定位与启用;
  2. 或使用 @EnabledIfEnvironmentVariable 等条件化注解,只在满足条件时跳过。
    请确认这是团队的预期行为。

Copy link
Contributor

github-actions bot commented May 5, 2025

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

Close #1215

Signed-off-by: unknowIfGuestInDream <liang.tang.cx@gmail.com>
Copy link

sonarqubecloud bot commented May 5, 2025

@unknowIfGuestInDream unknowIfGuestInDream merged commit 099061b into master May 5, 2025
30 checks passed
@unknowIfGuestInDream unknowIfGuestInDream deleted the oshi branch May 5, 2025 14:43
This was referenced May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] oshi支持
1 participant