From dc495e8423dd35070f136ab4b18c6ef2605f276b Mon Sep 17 00:00:00 2001 From: fishtailfu Date: Mon, 21 Jul 2025 16:32:10 +0800 Subject: [PATCH] feat: add delay test interface in quickstart. --- CHANGELOG.md | 1 + .../callee/QuickstartCalleeController.java | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e1ee9a0..ae5fc66b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,3 +8,4 @@ - [fix: fix ConfigChangeListener ut bug](https://github.com/Tencent/spring-cloud-tencent/pull/1663) - [feat: support shortest response time lb and least connection lb](https://github.com/Tencent/spring-cloud-tencent/pull/1637) - [feat:support traffic mirroring.](https://github.com/Tencent/spring-cloud-tencent/pull/1647) +- [feat: add delay test interface in quickstart.](https://github.com/Tencent/spring-cloud-tencent/pull/1666) diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java index 4f0ed5ace..30b9a6136 100644 --- a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java @@ -66,7 +66,7 @@ public class QuickstartCalleeController { @Autowired private DataSourceProperties dataSourceProperties; private boolean ifBadGateway = true; - private boolean ifDelay = false; + private long delay = 0; /** * Get sum of two value. @@ -122,8 +122,8 @@ public class QuickstartCalleeController { LOG.info("Quickstart Callee Service [{}:{}] is called wrong.", ip, port); return new ResponseEntity<>("failed for call quickstart callee service.", HttpStatus.BAD_GATEWAY); } - if (ifDelay) { - Thread.sleep(200); + if (delay > 0) { + Thread.sleep(delay); LOG.info("Quickstart Callee Service [{}:{}] is called slow.", ip, port); return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called slow.", ip, port), HttpStatus.OK); } @@ -142,8 +142,8 @@ public class QuickstartCalleeController { LOG.info("Quickstart Callee Service with uid {} [{}:{}] is called wrong.", uid, ip, port); return new ResponseEntity<>("failed for call quickstart callee service wildcard.", HttpStatus.BAD_GATEWAY); } - if (ifDelay) { - Thread.sleep(200); + if (delay > 0) { + Thread.sleep(delay); LOG.info("Quickstart Callee Service uid {} [{}:{}] is called slow.", uid, ip, port); return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called slow.", ip, port), HttpStatus.OK); } @@ -165,16 +165,17 @@ public class QuickstartCalleeController { } @GetMapping("/setDelay") - public String setDelay(@RequestParam boolean param) { - this.ifDelay = param; - if (param) { - LOG.info("info is set to delay 200ms."); - return "info is set to delay 200ms."; + public ResponseEntity setDelay(@RequestParam long param) { + this.delay = param; + if (param > 0) { + LOG.info("info is set to delay {}}ms.", param); + return new ResponseEntity<>(String.format("info is set to delay %sms.", param), HttpStatus.OK); } - else { + if (param == 0) { LOG.info("info is set to no delay."); - return "info is set to no delay."; + return new ResponseEntity<>("info is set to no delay.", HttpStatus.OK); } + return new ResponseEntity<>("delay must be non-negative", HttpStatus.BAD_REQUEST); } @GetMapping("/faultDetect") @@ -183,8 +184,8 @@ public class QuickstartCalleeController { LOG.info("Quickstart Callee Service [{}:{}] is detected wrong.", ip, port); return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected wrong.", ip, port), HttpStatus.BAD_GATEWAY); } - if (ifDelay) { - Thread.sleep(200); + if (delay > 0) { + Thread.sleep(delay); LOG.info("Quickstart Callee Service [{}:{}] is detected slow.", ip, port); return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected slow.", ip, port), HttpStatus.OK); }