pull/1020/head
seanyu 2 years ago
parent 2291b9436f
commit f8155989c2

@ -122,7 +122,9 @@ public class PolarisFeignCircuitBreakerInvocationHandler implements InvocationHa
}
try {
return circuitBreaker.run(supplier, fallbackFunction);
} catch (FallbackWrapperException e) {
}
catch (FallbackWrapperException e) {
// unwrap And Rethrow
throw e.getCause();
}
}
@ -134,9 +136,9 @@ public class PolarisFeignCircuitBreakerInvocationHandler implements InvocationHa
throw (RuntimeException) underlyingException;
}
if (underlyingException != null) {
throw new IllegalStateException(underlyingException);
throw new FallbackWrapperException(underlyingException);
}
throw new IllegalStateException(exception);
throw new FallbackWrapperException(exception);
}
}

@ -98,11 +98,10 @@ public class PolarisCircuitBreakerRestTemplateInterceptor implements ClientHttpR
throw new FallbackWrapperException(t);
}
);
} catch (FallbackWrapperException e) {
Throwable underlyingException = e.getCause();
if (underlyingException instanceof IllegalStateException) {
throw e;
}
catch (FallbackWrapperException e) {
// unwrap And Rethrow
Throwable underlyingException = e.getCause();
if (underlyingException instanceof RuntimeException) {
throw (RuntimeException) underlyingException;
}

@ -111,7 +111,7 @@ public class PolarisCircuitBreakerFeignIntegrationTest {
Utils.sleepUninterrupted(2000);
assertThatThrownBy(() -> {
echoService.echo(null);
}).isInstanceOf(Exception.class);
}).isInstanceOf(InvocationTargetException.class);
assertThatThrownBy(() -> {
fooService.echo("test");
}).isInstanceOf(NoFallbackAvailableException.class);
@ -244,7 +244,7 @@ public class PolarisCircuitBreakerFeignIntegrationTest {
@Override
public String echo(@RequestParam("str") String param) throws InvocationTargetException {
if (param == null) {
throw new InvocationTargetException(new Exception());
throw new InvocationTargetException(new Exception(), "test InvocationTargetException");
}
return "echo fallback";
}

@ -75,6 +75,7 @@ import org.springframework.web.util.DefaultUriBuilderFactory;
import static com.tencent.polaris.test.common.Consts.NAMESPACE_TEST;
import static com.tencent.polaris.test.common.TestUtils.SERVER_ADDRESS_ENV;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
@ -142,12 +143,14 @@ public class PolarisCircuitBreakerRestTemplateIntegrationTest {
assertThat(defaultRestTemplate.getForObject("http://localhost:18001/example/service/b/info", String.class)).isEqualTo("fallback");
mockServer.verify();
mockServer.reset();
assertThatThrownBy(() -> {
restTemplateFallbackFromPolaris.getForObject("/example/service/b/info", String.class);
}).isInstanceOf(IllegalStateException.class);
assertThat(restTemplateFallbackFromCode.getForObject("/example/service/b/info", String.class)).isEqualTo("\"this is a fallback class\"");
Utils.sleepUninterrupted(2000);
assertThat(restTemplateFallbackFromCode2.getForObject("/example/service/b/info", String.class)).isEqualTo("\"this is a fallback class\"");
Utils.sleepUninterrupted(2000);
assertThat(restTemplateFallbackFromCode3.getForEntity("/example/service/b/info", String.class)
.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(restTemplateFallbackFromCode3.getForEntity("/example/service/b/info", String.class).getStatusCode()).isEqualTo(HttpStatus.OK);
Utils.sleepUninterrupted(2000);
assertThat(restTemplateFallbackFromCode4.getForObject("/example/service/b/info", String.class)).isEqualTo("fallback");
Utils.sleepUninterrupted(2000);

Loading…
Cancel
Save