From 651cc2dfcfdca87dac4b82e1fa942e197d3b1aab Mon Sep 17 00:00:00 2001 From: chentianming Date: Tue, 24 May 2022 23:57:25 +0800 Subject: [PATCH] test update --- .../custom/okhttp/CustomSourceOkHttpClientRegistrar.java | 8 ++++++++ .../test/degrade/CustomCircuitBreakerConfigRegistrar.java | 4 ++-- .../retrofit/spring/boot/test/degrade/DegradeR4jTest.java | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/custom/okhttp/CustomSourceOkHttpClientRegistrar.java b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/custom/okhttp/CustomSourceOkHttpClientRegistrar.java index 67263a9..bea86e6 100644 --- a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/custom/okhttp/CustomSourceOkHttpClientRegistrar.java +++ b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/custom/okhttp/CustomSourceOkHttpClientRegistrar.java @@ -1,5 +1,7 @@ package com.github.lianjiatech.retrofit.spring.boot.test.custom.okhttp; +import java.time.Duration; + import org.springframework.stereotype.Component; import com.github.lianjiatech.retrofit.spring.boot.core.Constants; @@ -22,6 +24,9 @@ public void register(SourceOkHttpClientRegistry registry) { // 替换默认的SourceOkHttpClient registry.register(Constants.DEFAULT_SOURCE_OK_HTTP_CLIENT, new OkHttpClient.Builder() + .connectTimeout(Duration.ofSeconds(5)) + .writeTimeout(Duration.ofSeconds(5)) + .readTimeout(Duration.ofSeconds(5)) .addInterceptor(chain -> { log.info("============替换默认的SourceOkHttpClient============="); return chain.proceed(chain.request()); @@ -30,6 +35,9 @@ public void register(SourceOkHttpClientRegistry registry) { // 添加新的SourceOkHttpClient registry.register("testSourceOkHttpClient", new OkHttpClient.Builder() + .connectTimeout(Duration.ofSeconds(5)) + .writeTimeout(Duration.ofSeconds(5)) + .readTimeout(Duration.ofSeconds(5)) .addInterceptor(chain -> { log.info("============使用testSourceOkHttpClient============="); return chain.proceed(chain.request()); diff --git a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/degrade/CustomCircuitBreakerConfigRegistrar.java b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/degrade/CustomCircuitBreakerConfigRegistrar.java index 9dbec05..9cc6a41 100644 --- a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/degrade/CustomCircuitBreakerConfigRegistrar.java +++ b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/degrade/CustomCircuitBreakerConfigRegistrar.java @@ -24,8 +24,8 @@ public void register(CircuitBreakerConfigRegistry registry) { // 注册其它的CircuitBreakerConfig registry.register("testCircuitBreakerConfig", CircuitBreakerConfig.custom() .slidingWindowType(CircuitBreakerConfig.SlidingWindowType.TIME_BASED) - .failureRateThreshold(30) - .minimumNumberOfCalls(10) + .failureRateThreshold(20) + .minimumNumberOfCalls(5) .permittedNumberOfCallsInHalfOpenState(5) .build()); } diff --git a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/degrade/DegradeR4jTest.java b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/degrade/DegradeR4jTest.java index 7b4f588..6aa1df8 100644 --- a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/degrade/DegradeR4jTest.java +++ b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/degrade/DegradeR4jTest.java @@ -71,7 +71,7 @@ public void testDegradeR4j() { .addHeader("Content-Type", "application/text; charset=utf-8") .addHeader("Cache-Control", "no-cache") .setBody(objectMapper.writeValueAsString(mockResult)) - .setBodyDelay(10, TimeUnit.SECONDS); + .setBodyDelay(6, TimeUnit.SECONDS); server.enqueue(response); return degradeR4jApi.getPerson1(2L).getCode(); } catch (Exception e) {