RockteMQ-AI commented on code in PR #4204:
URL: 
https://github.com/apache/rocketmq-dashboard/pull/4204#discussion_r3970810687


##########
server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertAcknowledgementTransactionTest.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rocketmq.studio.ops.alert;
+
+import org.apache.rocketmq.studio.audit.OperationAuditService;
+import org.apache.rocketmq.studio.cluster.metrics.MetricProfileService;
+import org.apache.rocketmq.studio.common.domain.enums.AlertLevel;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.annotation.Import;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDateTime;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@JdbcTest(properties = "spring.sql.init.mode=never")
+@Import(AlertService.class)
+@EnableTransactionManagement
+@Transactional(propagation = Propagation.NOT_SUPPORTED)
+class AlertAcknowledgementTransactionTest {
+
+    @Autowired
+    private AlertService alertService;
+
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+    @MockBean
+    private AlertRepository alertRepository;
+
+    @MockBean
+    private AlertStateRepository alertStateRepository;
+
+    @MockBean
+    private AlertRuleAssetService alertRuleAssetService;
+

Review Comment:
   **[Info]** Well-designed test. The probe-table approach 
(`alert_ack_tx_probe`) to verify transactional atomicity is clever — it 
sidesteps the difficulty of inspecting mock interactions across transaction 
boundaries. Using `Propagation.NOT_SUPPORTED` on the test class correctly lets 
the service's own `@Transactional` boundary take effect.
   
   Minor: the method name 
`stateFailureRollsBackAlertAcknowledgementButSuccessfulRetryCommitsTest` is 
quite long. Consider splitting into two focused test methods 
(`shouldRollBackBothWritesOnStateFailure` and `shouldCommitBothWritesOnRetry`) 
for better readability and failure isolation.



##########
server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertService.java:
##########
@@ -556,6 +556,7 @@ public List<SystemAlertVO> findRelatedAlerts(Long id) {
     }
 
 
+    @Transactional

Review Comment:
   **[Info]** The `@Transactional` annotation works correctly here since 
`acknowledgeAlert` is called externally (from a controller). One thing to be 
aware of: if this method is ever called from another method within the same 
class, the proxy will be bypassed and the transaction boundary will not apply. 
Consider adding a brief comment or documenting this constraint for future 
maintainers.



-- 
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