Skip to content

[ISSUE #8262] [Enhancement] Add tests and harden UtilAll.isItTimeToDo#10409

Open
ChaoXoX wants to merge 1 commit into
apache:developfrom
ChaoXoX:develop
Open

[ISSUE #8262] [Enhancement] Add tests and harden UtilAll.isItTimeToDo#10409
ChaoXoX wants to merge 1 commit into
apache:developfrom
ChaoXoX:develop

Conversation

@ChaoXoX
Copy link
Copy Markdown

@ChaoXoX ChaoXoX commented May 30, 2026

Before Creating the Enhancement Request
I have confirmed that this should be classified as an enhancement rather than a bug/feature.
Summary
为 UtilAll.isItTimeToDo 增加边界输入的容错处理,并补充对应单测,提高 common 模块覆盖率。

Motivation
当前方法对 null、空白和非法数字输入会抛 NumberFormatException,容易影响定时任务判断流程。补充容错逻辑与单测能提高健壮性并提升覆盖率。

Describe the Solution You'd Like
UtilAll.isItTimeToDo 对 null/空白/非法 token 安全忽略,跳过越界小时值。
新增单测覆盖:
当前小时命中
含非法 token 的混合输入
null/空串/空白/非法数字/越界小时
Describe Alternatives You've Considered
暂无

Additional Context
关联 #8262(提升项目整体测试覆盖率)。

Copy link
Copy Markdown
Contributor

@RongtongJin RongtongJin left a comment

Choose a reason for hiding this comment

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

Thanks for the patch. I left two review comments around the behavior change and test stability.

if (hour == nowHour) {
return true;
}
} catch (NumberFormatException ignored) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we avoid silently ignoring invalid when tokens here, or at least log a warning when a token cannot be parsed or is outside the 0-23 range? This helper is used by scheduled maintenance paths such as commitlog cleanup and topic queue mapping cleanup. If deleteWhen or a similar schedule is misconfigured, returning false forever would silently disable the task and make the operator miss the configuration problem. The previous behavior failed loudly; changing that to silent ignore seems risky without some visibility.

assertTrue(UtilAll.isItTimeToDo("foo; " + currentHour + " ; 25"));
assertTrue(UtilAll.isItTimeToDo(" " + currentHour + " "));

assertFalse(UtilAll.isItTimeToDo(null));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test depends on the hour read here matching the hour read inside UtilAll.isItTimeToDo. It can theoretically become flaky if the test crosses an hour boundary between the two calls. Could we make the positive case independent of wall-clock timing, for example by passing all valid hours (0;1;...;23) and asserting it returns true, while keeping the invalid-token cases separate?

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.94%. Comparing base (9879968) to head (1333802).
⚠️ Report is 25 commits behind head on develop.

Files with missing lines Patch % Lines
.../main/java/org/apache/rocketmq/common/UtilAll.java 83.33% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #10409      +/-   ##
=============================================
- Coverage      48.99%   47.94%   -1.06%     
+ Complexity     13459    13258     -201     
=============================================
  Files           1375     1376       +1     
  Lines         100394   100546     +152     
  Branches       12964    12985      +21     
=============================================
- Hits           49188    48202     -986     
- Misses         45217    46401    +1184     
+ Partials        5989     5943      -46     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants