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 da044e8b fix(model): correct lite topic TTL status ordering (#1153)
da044e8b is described below
commit da044e8b6c4bc9265ccd282ce8ac5295d158dafa
Author: 0 <[email protected]>
AuthorDate: Fri Aug 7 16:12:51 2026 +0800
fix(model): correct lite topic TTL status ordering (#1153)
---
.../rocketmq/studio/model/LiteTopicSummary.java | 8 ++--
.../studio/model/LiteTopicSummaryTest.java | 46 ++++++++++++++++++++++
2 files changed, 51 insertions(+), 3 deletions(-)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/model/LiteTopicSummary.java
b/server/src/main/java/org/apache/rocketmq/studio/model/LiteTopicSummary.java
index 925c2dee..94507d7c 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/model/LiteTopicSummary.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/model/LiteTopicSummary.java
@@ -55,10 +55,12 @@ public class LiteTopicSummary {
long now = System.currentTimeMillis();
long elapsed = now - lastActiveTime.getTime();
- if (averageTTL != null && elapsed > averageTTL * 0.8) {
- return "EXPIRING_SOON";
- } else if (averageTTL != null && elapsed > averageTTL) {
+ // EXPIRED must be checked first: elapsed > averageTTL implies elapsed
> averageTTL * 0.8,
+ // so ordering it second would make EXPIRED unreachable.
+ if (averageTTL != null && elapsed > averageTTL) {
return "EXPIRED";
+ } else if (averageTTL != null && elapsed > averageTTL * 0.8) {
+ return "EXPIRING_SOON";
} else {
return "ACTIVE";
}
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/model/LiteTopicSummaryTest.java
b/server/src/test/java/org/apache/rocketmq/studio/model/LiteTopicSummaryTest.java
new file mode 100644
index 00000000..f6841418
--- /dev/null
+++
b/server/src/test/java/org/apache/rocketmq/studio/model/LiteTopicSummaryTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.apache.rocketmq.studio.model;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Date;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class LiteTopicSummaryTest {
+
+ @Test
+ void ttlStatusShouldPreferExpiredOverExpiringSoon() {
+ LiteTopicSummary summary = new LiteTopicSummary();
+ summary.setLastActiveTime(new Date(System.currentTimeMillis() -
20_000));
+ summary.setAverageTTL(10_000L);
+
+ assertThat(summary.getTTLStatus()).isEqualTo("EXPIRED");
+ }
+
+ @Test
+ void ttlStatusShouldReturnExpiringSoonWithinThreshold() {
+ LiteTopicSummary summary = new LiteTopicSummary();
+ summary.setLastActiveTime(new Date(System.currentTimeMillis() -
9_000));
+ summary.setAverageTTL(10_000L);
+
+ assertThat(summary.getTTLStatus()).isEqualTo("EXPIRING_SOON");
+ }
+
+ @Test
+ void ttlStatusShouldReturnActiveWhenNoTTLConfigured() {
+ LiteTopicSummary summary = new LiteTopicSummary();
+ summary.setLastActiveTime(new Date(System.currentTimeMillis() -
1_000));
+
+ assertThat(summary.getTTLStatus()).isEqualTo("ACTIVE");
+ }
+}