This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/rocketmq-studio by this push:
new ea2ca283 fix(lite-topic): handle unset quota counters (#1491)
ea2ca283 is described below
commit ea2ca28376dcb9b14afb7f412f69c1f0e20cb28e
Author: yyqdbngt <[email protected]>
AuthorDate: Tue Aug 11 17:50:03 2026 +0800
fix(lite-topic): handle unset quota counters (#1491)
Co-authored-by: yyqdbngt <[email protected]>
---
.../java/org/apache/rocketmq/studio/model/LiteTopicQuota.java | 8 ++++----
.../org/apache/rocketmq/studio/model/LiteTopicQuotaTest.java | 11 +++++++++++
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/model/LiteTopicQuota.java
b/server/src/main/java/org/apache/rocketmq/studio/model/LiteTopicQuota.java
index 7c414cf4..107e07ed 100644
--- a/server/src/main/java/org/apache/rocketmq/studio/model/LiteTopicQuota.java
+++ b/server/src/main/java/org/apache/rocketmq/studio/model/LiteTopicQuota.java
@@ -38,14 +38,14 @@ public class LiteTopicQuota {
private Double maxCreationRate;
public double getUsageRate() {
- if (maxTopicCount == null || maxTopicCount == 0) {
+ if (maxTopicCount == null || maxTopicCount == 0 || currentTopicCount
== null) {
return 0.0;
}
return (double) currentTopicCount / maxTopicCount;
}
public double getSessionUsageRate() {
- if (maxSessionCount == null || maxSessionCount == 0) {
+ if (maxSessionCount == null || maxSessionCount == 0 ||
currentSessionCount == null) {
return 0.0;
}
return (double) currentSessionCount / maxSessionCount;
@@ -65,6 +65,6 @@ public class LiteTopicQuota {
if (maxTopicCount == null) {
return 0;
}
- return Math.max(0, maxTopicCount - currentTopicCount);
+ return Math.max(0, maxTopicCount - (currentTopicCount == null ? 0 :
currentTopicCount));
}
-}
\ No newline at end of file
+}
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/model/LiteTopicQuotaTest.java
b/server/src/test/java/org/apache/rocketmq/studio/model/LiteTopicQuotaTest.java
index 14043ea8..3825f91d 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/model/LiteTopicQuotaTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/model/LiteTopicQuotaTest.java
@@ -32,4 +32,15 @@ class LiteTopicQuotaTest {
assertThat(quota.isQuotaExceeded()).isTrue();
}
+
+ @Test
+ void quotaCalculationsShouldHandleUnsetCurrentCounts() {
+ LiteTopicQuota quota = new LiteTopicQuota();
+ quota.setMaxTopicCount(10);
+ quota.setMaxSessionCount(5);
+
+ assertThat(quota.getUsageRate()).isZero();
+ assertThat(quota.getSessionUsageRate()).isZero();
+ assertThat(quota.getRemainingQuota()).isEqualTo(10);
+ }
}