1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

2020 build done, unit test failed

This commit is contained in:
theonefx
2021-02-23 18:06:31 +08:00
parent 29091948e9
commit e7521c02c9
41 changed files with 339 additions and 1408 deletions

View File

@@ -25,8 +25,8 @@ import feign.Contract;
import feign.Feign;
import feign.InvocationHandlerFactory;
import feign.Target;
import feign.hystrix.FallbackFactory;
import feign.hystrix.HystrixFeign;
//import feign.hystrix.FallbackFactory;
//import feign.hystrix.HystrixFeign;
import org.springframework.beans.BeansException;
import org.springframework.cloud.openfeign.FeignContext;
@@ -80,35 +80,35 @@ public final class SentinelFeign {
// using reflect get fallback and fallbackFactory properties from
// FeignClientFactoryBean because FeignClientFactoryBean is a package
// level class, we can not use it in our package
Object feignClientFactoryBean = Builder.this.applicationContext
.getBean("&" + target.type().getName());
Class fallback = (Class) getFieldValue(feignClientFactoryBean,
"fallback");
Class fallbackFactory = (Class) getFieldValue(feignClientFactoryBean,
"fallbackFactory");
String beanName = (String) getFieldValue(feignClientFactoryBean,
"contextId");
if (!StringUtils.hasText(beanName)) {
beanName = (String) getFieldValue(feignClientFactoryBean, "name");
}
Object fallbackInstance;
FallbackFactory fallbackFactoryInstance;
// check fallback and fallbackFactory properties
if (void.class != fallback) {
fallbackInstance = getFromContext(beanName, "fallback", fallback,
target.type());
return new SentinelInvocationHandler(target, dispatch,
new FallbackFactory.Default(fallbackInstance));
}
if (void.class != fallbackFactory) {
fallbackFactoryInstance = (FallbackFactory) getFromContext(
beanName, "fallbackFactory", fallbackFactory,
FallbackFactory.class);
return new SentinelInvocationHandler(target, dispatch,
fallbackFactoryInstance);
}
// Object feignClientFactoryBean = Builder.this.applicationContext
// .getBean("&" + target.type().getName());
//
// Class fallback = (Class) getFieldValue(feignClientFactoryBean,
// "fallback");
// Class fallbackFactory = (Class) getFieldValue(feignClientFactoryBean,
// "fallbackFactory");
// String beanName = (String) getFieldValue(feignClientFactoryBean,
// "contextId");
// if (!StringUtils.hasText(beanName)) {
// beanName = (String) getFieldValue(feignClientFactoryBean, "name");
// }
//
// Object fallbackInstance;
// FallbackFactory fallbackFactoryInstance;
// // check fallback and fallbackFactory properties
// if (void.class != fallback) {
// fallbackInstance = getFromContext(beanName, "fallback", fallback,
// target.type());
// return new SentinelInvocationHandler(target, dispatch,
// new FallbackFactory.Default(fallbackInstance));
// }
// if (void.class != fallbackFactory) {
// fallbackFactoryInstance = (FallbackFactory) getFromContext(
// beanName, "fallbackFactory", fallbackFactory,
// FallbackFactory.class);
// return new SentinelInvocationHandler(target, dispatch,
// fallbackFactoryInstance);
// }
return new SentinelInvocationHandler(target, dispatch);
}

View File

@@ -33,7 +33,6 @@ import feign.Feign;
import feign.InvocationHandlerFactory.MethodHandler;
import feign.MethodMetadata;
import feign.Target;
import feign.hystrix.FallbackFactory;
import static feign.Util.checkNotNull;
@@ -48,18 +47,8 @@ public class SentinelInvocationHandler implements InvocationHandler {
private final Map<Method, MethodHandler> dispatch;
private FallbackFactory fallbackFactory;
private Map<Method, Method> fallbackMethodMap;
SentinelInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch,
FallbackFactory fallbackFactory) {
this.target = checkNotNull(target, "target");
this.dispatch = checkNotNull(dispatch, "dispatch");
this.fallbackFactory = fallbackFactory;
this.fallbackMethodMap = toFallbackMethod(dispatch);
}
SentinelInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch) {
this.target = checkNotNull(target, "target");
this.dispatch = checkNotNull(dispatch, "dispatch");
@@ -111,25 +100,8 @@ public class SentinelInvocationHandler implements InvocationHandler {
if (!BlockException.isBlockException(ex)) {
Tracer.trace(ex);
}
if (fallbackFactory != null) {
try {
Object fallbackResult = fallbackMethodMap.get(method)
.invoke(fallbackFactory.create(ex), args);
return fallbackResult;
}
catch (IllegalAccessException e) {
// shouldn't happen as method is public due to being an
// interface
throw new AssertionError(e);
}
catch (InvocationTargetException e) {
throw new AssertionError(e.getCause());
}
}
else {
// throw exception if fallbackFactory is null
throw ex;
}
// throw exception if fallbackFactory is null
throw ex;
}
finally {
if (entry != null) {

View File

@@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -122,7 +123,7 @@ public class ContextIdSentinelFeignTests {
}
public static class CustomFallbackFactory
implements feign.hystrix.FallbackFactory<FooService> {
implements FallbackFactory<FooService> {
private FooService fooService = new FooServiceFallback();

View File

@@ -31,6 +31,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -191,7 +192,7 @@ public class SentinelFeignTests {
}
public static class CustomFallbackFactory
implements feign.hystrix.FallbackFactory<FooService> {
implements FallbackFactory<FooService> {
private FooService fooService = new FooServiceFallback();