test: add comprehensive unit tests for operation log feature

- Add IpUtilsTest with 9 test cases covering all IP extraction scenarios
- Add OperationLogAspectTest with 8 test cases covering all aspect behaviors
- Fix error handling in OperationLogAspect to prevent log failures from affecting main flow
- Add onErrorResume handlers for graceful degradation
- Ensure all tests pass (17/17, 100% pass rate)

Test Coverage:
- IP extraction from various sources (X-Forwarded-For, X-Real-IP, RemoteAddress)
- IPv6 to IPv4 conversion
- Reactive type support (Mono, Flux)
- Error handling and graceful degradation
- Parameter serialization and truncation
- Edge cases and boundary conditions
This commit is contained in:
张翔
2026-04-03 20:42:10 +08:00
parent c4dc1d2ee1
commit 22d5948994
3 changed files with 407 additions and 0 deletions
@@ -47,11 +47,13 @@ public class OperationLogAspect {
.flatMap(res -> {
long duration = System.currentTimeMillis() - startTime;
return saveLogAsync(operationLogAnnotation, username, ip, method, params, res, duration, "0", null)
.onErrorResume(e -> Mono.empty())
.thenReturn(res);
})
.onErrorResume(error -> {
long duration = System.currentTimeMillis() - startTime;
return saveLogAsync(operationLogAnnotation, username, ip, method, params, null, duration, "1", error.getMessage())
.onErrorResume(e -> Mono.empty())
.then(Mono.error(error));
})
);
@@ -62,11 +64,13 @@ public class OperationLogAspect {
.flatMapMany(res -> {
long duration = System.currentTimeMillis() - startTime;
return saveLogAsync(operationLogAnnotation, username, ip, method, params, res, duration, "0", null)
.onErrorResume(e -> Mono.empty())
.thenMany(Flux.fromIterable(res));
})
.onErrorResume(error -> {
long duration = System.currentTimeMillis() - startTime;
return saveLogAsync(operationLogAnnotation, username, ip, method, params, null, duration, "1", error.getMessage())
.onErrorResume(e -> Mono.empty())
.thenMany(Flux.error(error));
})
);