dengxiaofu opened a new pull request, #11605:
URL: https://github.com/apache/rocketmq/pull/11605

   <!-- Please make sure the target branch is right. In most case, the target 
branch should be `develop`. -->
   
   ### Which Issue(s) This PR Fixes
   
   <!-- Please ensure that the related issue has already been created, and 
[link this pull request to that issue using 
keywords](<https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword>)
 to ensure automatic closure. -->
   
   - Fixes #11604
   
   ### Brief Description
   
   <!-- Write a brief description for your pull request to help the maintainer 
understand the reasons behind your changes. -->
   
   Add `StatisticsItemTest` in the `common` module. `StatisticsItem` previously 
had no
   dedicated unit tests even though `StatisticsManager` and
   `StatisticsItemScheduledIncrementPrinter` depend on its `snapshot()`,
   `subtract()`, `allZeros()` and `getItemAccumulate()` behavior.
   
   The new test class adds 16 JUnit 4 tests:
   
   - **Constructor**: rejects null / empty `itemNames`; initializes kind, 
object,
     item names, zero accumulators, zero invoke times and the last timestamp.
   - **incItems**: fewer values only update leading items; extra values are 
ignored;
     every call (even without values) increments `invokeTimes` and refreshes
     `lastTimeStamp`; the `Interceptor` receives all passed values without 
truncation.
   - **allZeros**: true for untouched, all-zero and net-zero items, false 
otherwise;
     short-circuits to true when `invokeTimes` is 0.
   - **getItemAccumulate**: returns the live counter for a known name and a 
detached
     zero counter for an unknown name.
   - **snapshot**: returns an independent copy (values, invoke times, last 
timestamp)
     and does not carry the interceptor.
   - **subtract**: `subtract(null)` behaves like `snapshot()`; incompatible 
kind,
     object or item names (content, order, length) throw 
`IllegalArgumentException`;
     normal subtraction computes per-item deltas without modifying either 
operand,
     and negative deltas are not clamped.
   
   Notes:
   - Only one new test file; no production code, `pom.xml` or dependency 
changes.
   - Interceptor calls are verified with a small hand-written recording stub 
instead
     of Mockito, consistent with existing tests in the `common` module.
   - Timestamp assertions use preset values or a `[before, after]` range, so the
     tests are deterministic and do not sleep or start threads.
   - `testAllZerosReturnsTrueWhenNeverInvoked` and 
`testSubtractCanProduceNegativeDelta`
     document current behavior rather than a specification.
   
   ### How Did You Test This Change?
   
   <!-- In order to ensure the code quality of Apache RocketMQ, we expect every 
pull request to have undergone thorough testing. -->
   
   Ran locally (JDK 17.0.12, Maven 3.8.8, Windows 11):
   
   - `mvn -pl common test -Dtest=StatisticsItemTest -DfailIfNoTests=false`
     → Tests run: 16, Failures: 0, Errors: 0, Skipped: 0
   - `mvn -pl common test`
     → Tests run: 341, Failures: 0, Errors: 0, Skipped: 0
   - `mvn -pl common validate apache-rat:check`
     → 0 Checkstyle violations (`style/rmq_checkstyle.xml`, test sources 
included);
       RAT: 0 unapproved files
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to