fix: bound dashboard monitoring queries

This commit is contained in:
zgw
2026-09-04 13:30:45 +08:00
parent 731c140d24
commit 58c7fff4a9
7 changed files with 146 additions and 73 deletions

View File

@@ -0,0 +1,71 @@
package com.ruoyi.index;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import static org.assertj.core.api.Assertions.assertThat;
class BoundedDashboardQueryTest {
private final Path root = projectRoot();
@Test
void dashboardBillEndpointUsesBoundedServiceQuery() throws IOException {
String controller = text("ruoyi-admin/src/main/java/com/ruoyi/index/controller/IndexController.java");
String mapper = normalized("ruoyi-admin/src/main/resources/mapper/index/BillStatusCountMapper.xml");
assertThat(controller).contains(
"billStatusCountService.selectAllBillStatusCount(new BaseEntity())",
"return success(list);");
assertThat(controller).doesNotContain("Collections.emptyList()");
assertThat(occurrences(mapper, "top (30)")).isEqualTo(4);
assertThat(mapper).contains("union all", "order by create_date desc, id desc");
assertThat(occurrences(mapper, "${params.warehousedatascope}")).isEqualTo(3);
}
@Test
void requestLogPageAndOptionsAreBoundedToRecentRows() throws IOException {
String mapper = normalized("ruoyi-admin/src/main/resources/mapper/requestInterface/RequestLogMapper.xml");
String controller = text("ruoyi-admin/src/main/java/com/ruoyi/log/controller/RequestLogController.java");
assertThat(occurrences(mapper, "top (10000)")).isEqualTo(4);
assertThat(mapper).contains("order by request_id desc");
assertThat(mapper).contains(
"inner join request_log log on log.request_id = recent_log.recent_request_id",
"select top (10000) request_id as recent_request_id");
assertThat(mapper).contains(
"select distinct endpoint",
"select distinct source_system",
"select distinct target_system");
assertThat(occurrences(controller, "requestLogService.getMethod()")).isEqualTo(1);
assertThat(occurrences(controller, "requestLogService.getSource()")).isEqualTo(1);
assertThat(occurrences(controller, "requestLogService.getTarget()")).isEqualTo(1);
}
private String text(String relativePath) throws IOException {
return Files.readString(root.resolve(relativePath), StandardCharsets.UTF_8);
}
private String normalized(String relativePath) throws IOException {
return text(relativePath).replaceAll("\\s+", " ").toLowerCase(Locale.ROOT);
}
private int occurrences(String value, String token) {
return (value.length() - value.replace(token, "").length()) / token.length();
}
private Path projectRoot() {
Path current = Path.of("").toAbsolutePath().normalize();
while (current != null && !Files.exists(current.resolve("ruoyi-admin/pom.xml"))) {
current = current.getParent();
}
if (current == null) {
throw new IllegalStateException("Could not locate project root");
}
return current;
}
}