feat: add delay test interface in quickstart.

pull/1666/head
fishtailfu 2 months ago
parent 70218c3a22
commit dc495e8423

@ -8,3 +8,4 @@
- [fix: fix ConfigChangeListener ut bug](https://github.com/Tencent/spring-cloud-tencent/pull/1663) - [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 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: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)

@ -66,7 +66,7 @@ public class QuickstartCalleeController {
@Autowired @Autowired
private DataSourceProperties dataSourceProperties; private DataSourceProperties dataSourceProperties;
private boolean ifBadGateway = true; private boolean ifBadGateway = true;
private boolean ifDelay = false; private long delay = 0;
/** /**
* Get sum of two value. * Get sum of two value.
@ -122,8 +122,8 @@ public class QuickstartCalleeController {
LOG.info("Quickstart Callee Service [{}:{}] is called wrong.", ip, port); LOG.info("Quickstart Callee Service [{}:{}] is called wrong.", ip, port);
return new ResponseEntity<>("failed for call quickstart callee service.", HttpStatus.BAD_GATEWAY); return new ResponseEntity<>("failed for call quickstart callee service.", HttpStatus.BAD_GATEWAY);
} }
if (ifDelay) { if (delay > 0) {
Thread.sleep(200); Thread.sleep(delay);
LOG.info("Quickstart Callee Service [{}:{}] is called slow.", ip, port); 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); 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); 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); return new ResponseEntity<>("failed for call quickstart callee service wildcard.", HttpStatus.BAD_GATEWAY);
} }
if (ifDelay) { if (delay > 0) {
Thread.sleep(200); Thread.sleep(delay);
LOG.info("Quickstart Callee Service uid {} [{}:{}] is called slow.", uid, ip, port); 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); 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") @GetMapping("/setDelay")
public String setDelay(@RequestParam boolean param) { public ResponseEntity<String> setDelay(@RequestParam long param) {
this.ifDelay = param; this.delay = param;
if (param) { if (param > 0) {
LOG.info("info is set to delay 200ms."); LOG.info("info is set to delay {}}ms.", param);
return "info is set to delay 200ms."; 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."); 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") @GetMapping("/faultDetect")
@ -183,8 +184,8 @@ public class QuickstartCalleeController {
LOG.info("Quickstart Callee Service [{}:{}] is detected wrong.", ip, port); 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); return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected wrong.", ip, port), HttpStatus.BAD_GATEWAY);
} }
if (ifDelay) { if (delay > 0) {
Thread.sleep(200); Thread.sleep(delay);
LOG.info("Quickstart Callee Service [{}:{}] is detected slow.", ip, port); 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); return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected slow.", ip, port), HttpStatus.OK);
} }

Loading…
Cancel
Save