Merge pull request #628 from george510257/master

Polish spring-cloud-incubator/spring-cloud-alibaba/#626
pull/1497/head
format 6 years ago committed by GitHub
commit afabc7a83a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -91,8 +91,8 @@ public class SentinelInvocationHandler implements InvocationHandler {
if (target instanceof Target.HardCodedTarget) { if (target instanceof Target.HardCodedTarget) {
Target.HardCodedTarget hardCodedTarget = (Target.HardCodedTarget) target; Target.HardCodedTarget hardCodedTarget = (Target.HardCodedTarget) target;
MethodMetadata methodMetadata = SentinelContractHolder.metadataMap MethodMetadata methodMetadata = SentinelContractHolder.metadataMap
.get(method.getDeclaringClass().getName() .get(hardCodedTarget.type().getName()
+ Feign.configKey(method.getDeclaringClass(), method)); + Feign.configKey(hardCodedTarget.type(), method));
// resource default is HttpMethod:protocol://url // resource default is HttpMethod:protocol://url
String resourceName = methodMetadata.template().method().toUpperCase() + ":" String resourceName = methodMetadata.template().method().toUpperCase() + ":"
+ hardCodedTarget.url() + methodMetadata.template().path(); + hardCodedTarget.url() + methodMetadata.template().path();

@ -60,6 +60,9 @@ public class SentinelFeignTests {
@Autowired @Autowired
private BarService barService; private BarService barService;
@Autowired
private BazService bazService;
@Before @Before
public void setUp() { public void setUp() {
FlowRule rule1 = new FlowRule(); FlowRule rule1 = new FlowRule();
@ -83,7 +86,14 @@ public class SentinelFeignTests {
rule3.setLimitApp("default"); rule3.setLimitApp("default");
rule3.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT); rule3.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
rule3.setStrategy(RuleConstant.STRATEGY_DIRECT); rule3.setStrategy(RuleConstant.STRATEGY_DIRECT);
FlowRuleManager.loadRules(Arrays.asList(rule1, rule2, rule3)); FlowRule rule4 = new FlowRule();
rule4.setGrade(RuleConstant.FLOW_GRADE_QPS);
rule4.setCount(0);
rule4.setResource("GET:http://baz-service/baz");
rule4.setLimitApp("default");
rule4.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
rule4.setStrategy(RuleConstant.STRATEGY_DIRECT);
FlowRuleManager.loadRules(Arrays.asList(rule1, rule2, rule3,rule4));
} }
@Test @Test
@ -101,6 +111,9 @@ public class SentinelFeignTests {
assertThatExceptionOfType(Exception.class).isThrownBy(() -> { assertThatExceptionOfType(Exception.class).isThrownBy(() -> {
barService.bar(); barService.bar();
}); });
assertThatExceptionOfType(Exception.class).isThrownBy(() -> {
bazService.baz();
});
assertNotEquals("ToString method invoke was not in SentinelInvocationHandler", assertNotEquals("ToString method invoke was not in SentinelInvocationHandler",
echoService.toString(), fooService.toString()); echoService.toString(), fooService.toString());
@ -146,6 +159,15 @@ public class SentinelFeignTests {
String bar(); String bar();
} }
public interface BazService {
@RequestMapping(path = "baz")
String baz();
}
@FeignClient(value = "baz-service")
public interface BazClient extends BazService {
}
public static class EchoServiceFallback implements EchoService { public static class EchoServiceFallback implements EchoService {
@Override @Override

Loading…
Cancel
Save