mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
a61f523d78
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<revision>2.2.2-SNAPSHOT</revision>
|
<revision>2.2.2-SNAPSHOT</revision>
|
||||||
<sentinel.version>1.7.2</sentinel.version>
|
<sentinel.version>1.8.0</sentinel.version>
|
||||||
<oss.version>3.1.0</oss.version>
|
<oss.version>3.1.0</oss.version>
|
||||||
<seata.version>1.3.0</seata.version>
|
<seata.version>1.3.0</seata.version>
|
||||||
<nacos.client.version>1.3.2</nacos.client.version>
|
<nacos.client.version>1.3.2</nacos.client.version>
|
||||||
|
@ -91,7 +91,7 @@ public class SentinelSCGAutoConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initAppType() {
|
private void initAppType() {
|
||||||
System.setProperty(SentinelConfig.APP_TYPE, ConfigConstants.APP_TYPE_SCG_GATEWAY);
|
System.setProperty(SentinelConfig.APP_TYPE_PROP_KEY, ConfigConstants.APP_TYPE_SCG_GATEWAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFallback() {
|
private void initFallback() {
|
||||||
|
@ -65,7 +65,7 @@ public class SentinelZuulAutoConfiguration {
|
|||||||
private void init() {
|
private void init() {
|
||||||
requestOriginParserOptional
|
requestOriginParserOptional
|
||||||
.ifPresent(ZuulGatewayCallbackManager::setOriginParser);
|
.ifPresent(ZuulGatewayCallbackManager::setOriginParser);
|
||||||
System.setProperty(SentinelConfig.APP_TYPE,
|
System.setProperty(SentinelConfig.APP_TYPE_PROP_KEY,
|
||||||
String.valueOf(ConfigConstants.APP_TYPE_ZUUL_GATEWAY));
|
String.valueOf(ConfigConstants.APP_TYPE_ZUUL_GATEWAY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ public class ReactiveSentinelCircuitBreakerIntegrationTest {
|
|||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recovered.
|
// Half-open recovery (will re-open the circuit breaker).
|
||||||
StepVerifier.create(service.slow()).expectNext("slow").verifyComplete();
|
StepVerifier.create(service.slow()).expectNext("slow").verifyComplete();
|
||||||
|
|
||||||
StepVerifier.create(service.normalFlux()).expectNext("normalflux")
|
StepVerifier.create(service.normalFlux()).expectNext("normalflux")
|
||||||
@ -99,7 +99,7 @@ public class ReactiveSentinelCircuitBreakerIntegrationTest {
|
|||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recovered.
|
// Half-open recovery (will re-open the circuit breaker).
|
||||||
StepVerifier.create(service.slowFlux()).expectNext("slowflux").verifyComplete();
|
StepVerifier.create(service.slowFlux()).expectNext("slowflux").verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ public class ReactiveSentinelCircuitBreakerIntegrationTest {
|
|||||||
|
|
||||||
@GetMapping("/slow")
|
@GetMapping("/slow")
|
||||||
public Mono<String> slow() {
|
public Mono<String> slow() {
|
||||||
return Mono.just("slow").delayElement(Duration.ofMillis(500));
|
return Mono.just("slow").delayElement(Duration.ofMillis(80));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/normal")
|
@GetMapping("/normal")
|
||||||
@ -120,7 +120,7 @@ public class ReactiveSentinelCircuitBreakerIntegrationTest {
|
|||||||
|
|
||||||
@GetMapping("/slow_flux")
|
@GetMapping("/slow_flux")
|
||||||
public Flux<String> slowFlux() {
|
public Flux<String> slowFlux() {
|
||||||
return Flux.just("slow", "flux").delayElements(Duration.ofMillis(500));
|
return Flux.just("slow", "flux").delayElements(Duration.ofMillis(80));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("normal_flux")
|
@GetMapping("normal_flux")
|
||||||
@ -133,19 +133,19 @@ public class ReactiveSentinelCircuitBreakerIntegrationTest {
|
|||||||
return factory -> {
|
return factory -> {
|
||||||
factory.configure(builder -> builder
|
factory.configure(builder -> builder
|
||||||
.rules(Collections.singletonList(new DegradeRule("slow_mono")
|
.rules(Collections.singletonList(new DegradeRule("slow_mono")
|
||||||
.setGrade(RuleConstant.DEGRADE_GRADE_RT).setCount(100)
|
.setCount(50).setSlowRatioThreshold(0.7).setMinRequestAmount(5)
|
||||||
.setTimeWindow(5))),
|
.setStatIntervalMs(30000).setTimeWindow(5))),
|
||||||
"slow_mono");
|
"slow_mono");
|
||||||
factory.configure(builder -> builder
|
factory.configure(builder -> builder
|
||||||
.rules(Collections.singletonList(new DegradeRule("slow_flux")
|
.rules(Collections.singletonList(new DegradeRule("slow_mono")
|
||||||
.setGrade(RuleConstant.DEGRADE_GRADE_RT).setCount(100)
|
.setCount(50).setSlowRatioThreshold(0.7).setMinRequestAmount(5)
|
||||||
.setTimeWindow(5))),
|
.setStatIntervalMs(30000).setTimeWindow(5))),
|
||||||
"slow_flux");
|
"slow_flux");
|
||||||
factory.configureDefault(id -> new SentinelConfigBuilder()
|
factory.configureDefault(id -> new SentinelConfigBuilder()
|
||||||
.resourceName(id)
|
.resourceName(id)
|
||||||
.rules(Collections.singletonList(new DegradeRule(id)
|
.rules(Collections.singletonList(new DegradeRule(id)
|
||||||
.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
|
.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
|
||||||
.setCount(0.5).setTimeWindow(10)))
|
.setCount(5).setTimeWindow(10)))
|
||||||
.build());
|
.build());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@ -59,21 +60,24 @@ public class SentinelCircuitBreakerIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSlow() throws Exception {
|
public void testSlow() throws Exception {
|
||||||
// The first 5 requests should pass.
|
assertThat(service.slow(true)).isEqualTo("slow");
|
||||||
assertThat(service.slow()).isEqualTo("slow");
|
assertThat(service.slow(true)).isEqualTo("slow");
|
||||||
assertThat(service.slow()).isEqualTo("slow");
|
assertThat(service.slow(true)).isEqualTo("slow");
|
||||||
assertThat(service.slow()).isEqualTo("slow");
|
assertThat(service.slow(false)).isEqualTo("slow");
|
||||||
assertThat(service.slow()).isEqualTo("slow");
|
assertThat(service.slow(false)).isEqualTo("slow");
|
||||||
assertThat(service.slow()).isEqualTo("slow");
|
assertThat(service.slow(true)).isEqualTo("slow");
|
||||||
|
assertThat(service.slow(true)).isEqualTo("slow");
|
||||||
|
|
||||||
// Then in the next 10s, the fallback method should be called.
|
// Then in the next 10s, the fallback method should be called.
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
assertThat(service.slow()).isEqualTo("fallback");
|
assertThat(service.slow(true)).isEqualTo("fallback");
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try a normal request.
|
||||||
|
assertThat(service.slow(false)).isEqualTo("slow");
|
||||||
// Recovered.
|
// Recovered.
|
||||||
assertThat(service.slow()).isEqualTo("slow");
|
assertThat(service.slow(true)).isEqualTo("slow");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -97,8 +101,10 @@ public class SentinelCircuitBreakerIntegrationTest {
|
|||||||
protected static class Application {
|
protected static class Application {
|
||||||
|
|
||||||
@GetMapping("/slow")
|
@GetMapping("/slow")
|
||||||
public String slow() throws InterruptedException {
|
public String slow(@RequestParam(required = false) Boolean slow) throws InterruptedException {
|
||||||
Thread.sleep(500);
|
if (slow == null || slow) {
|
||||||
|
Thread.sleep(80);
|
||||||
|
}
|
||||||
return "slow";
|
return "slow";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,14 +118,15 @@ public class SentinelCircuitBreakerIntegrationTest {
|
|||||||
String slowId = "slow";
|
String slowId = "slow";
|
||||||
List<DegradeRule> rules = Collections.singletonList(
|
List<DegradeRule> rules = Collections.singletonList(
|
||||||
new DegradeRule(slowId).setGrade(RuleConstant.DEGRADE_GRADE_RT)
|
new DegradeRule(slowId).setGrade(RuleConstant.DEGRADE_GRADE_RT)
|
||||||
.setCount(100).setTimeWindow(10));
|
.setCount(50).setSlowRatioThreshold(0.7).setMinRequestAmount(5)
|
||||||
|
.setStatIntervalMs(30000).setTimeWindow(5));
|
||||||
return factory -> {
|
return factory -> {
|
||||||
factory.configure(builder -> builder.rules(rules), slowId);
|
factory.configure(builder -> builder.rules(rules), slowId);
|
||||||
factory.configureDefault(id -> new SentinelConfigBuilder()
|
factory.configureDefault(id -> new SentinelConfigBuilder()
|
||||||
.resourceName(id)
|
.resourceName(id)
|
||||||
.rules(Collections.singletonList(new DegradeRule(id)
|
.rules(Collections.singletonList(new DegradeRule(id)
|
||||||
.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
|
.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
|
||||||
.setCount(0.5).setTimeWindow(10)))
|
.setCount(10).setStatIntervalMs(10000).setTimeWindow(10)))
|
||||||
.build());
|
.build());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -137,9 +144,9 @@ public class SentinelCircuitBreakerIntegrationTest {
|
|||||||
this.cbFactory = cbFactory;
|
this.cbFactory = cbFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String slow() {
|
public String slow(boolean slow) {
|
||||||
return cbFactory.create("slow").run(
|
return cbFactory.create("slow").run(
|
||||||
() -> rest.getForObject("/slow", String.class), t -> "fallback");
|
() -> rest.getForObject("/slow?slow=" + slow, String.class), t -> "fallback");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String normal() {
|
public String normal() {
|
||||||
|
@ -31,7 +31,6 @@ import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
|||||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
|
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
|
||||||
import com.alibaba.csp.sentinel.slots.system.SystemRule;
|
import com.alibaba.csp.sentinel.slots.system.SystemRule;
|
||||||
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
||||||
import com.alibaba.csp.sentinel.util.AppNameUtil;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
@ -79,9 +78,9 @@ public class SentinelAutoConfiguration {
|
|||||||
System.setProperty(LogBase.LOG_NAME_USE_PID,
|
System.setProperty(LogBase.LOG_NAME_USE_PID,
|
||||||
String.valueOf(properties.getLog().isSwitchPid()));
|
String.valueOf(properties.getLog().isSwitchPid()));
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME))
|
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.APP_NAME_PROP_KEY))
|
||||||
&& StringUtils.hasText(projectName)) {
|
&& StringUtils.hasText(projectName)) {
|
||||||
System.setProperty(AppNameUtil.APP_NAME, projectName);
|
System.setProperty(SentinelConfig.APP_NAME_PROP_KEY, projectName);
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))
|
||||||
&& StringUtils.hasText(properties.getTransport().getPort())) {
|
&& StringUtils.hasText(properties.getTransport().getPort())) {
|
||||||
|
@ -28,8 +28,6 @@ import com.alibaba.csp.sentinel.config.SentinelConfig;
|
|||||||
import com.alibaba.csp.sentinel.log.LogBase;
|
import com.alibaba.csp.sentinel.log.LogBase;
|
||||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||||
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
||||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
|
|
||||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
|
|
||||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||||
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
||||||
@ -116,13 +114,6 @@ public class SentinelAutoConfigurationTests {
|
|||||||
rule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
|
rule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
|
||||||
rule.setStrategy(RuleConstant.STRATEGY_DIRECT);
|
rule.setStrategy(RuleConstant.STRATEGY_DIRECT);
|
||||||
FlowRuleManager.loadRules(Arrays.asList(rule));
|
FlowRuleManager.loadRules(Arrays.asList(rule));
|
||||||
|
|
||||||
DegradeRule degradeRule = new DegradeRule();
|
|
||||||
degradeRule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT);
|
|
||||||
degradeRule.setResource("GET:" + degradeUrl);
|
|
||||||
degradeRule.setCount(0);
|
|
||||||
degradeRule.setTimeWindow(60);
|
|
||||||
DegradeRuleManager.loadRules(Arrays.asList(degradeRule));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -208,7 +199,7 @@ public class SentinelAutoConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFlowRestTemplate() {
|
public void testRestTemplateBlockHandler() {
|
||||||
|
|
||||||
assertThat(restTemplate.getInterceptors().size()).isEqualTo(2);
|
assertThat(restTemplate.getInterceptors().size()).isEqualTo(2);
|
||||||
assertThat(restTemplateWithBlockClass.getInterceptors().size()).isEqualTo(1);
|
assertThat(restTemplateWithBlockClass.getInterceptors().size()).isEqualTo(1);
|
||||||
@ -236,15 +227,6 @@ public class SentinelAutoConfigurationTests {
|
|||||||
}).isInstanceOf(RestClientException.class);
|
}).isInstanceOf(RestClientException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFallbackRestTemplate() {
|
|
||||||
ResponseEntity responseEntity = restTemplateWithFallbackClass
|
|
||||||
.getForEntity(degradeUrl, String.class);
|
|
||||||
|
|
||||||
assertThat(responseEntity.getBody()).isEqualTo("Oops fallback");
|
|
||||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
static class SentinelTestConfiguration {
|
static class SentinelTestConfiguration {
|
||||||
|
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Copyright 2013-2018 the original author or authors.
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
@ -14,19 +13,24 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.alibaba.cloud.dubbo.util;
|
package com.alibaba.cloud.dubbo.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constants for Dubbo Spring Cloud
|
* The constants for Dubbo Spring Cloud.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
*/
|
*/
|
||||||
public interface DubboCloudConstants {
|
public final class DubboCloudConstants {
|
||||||
|
|
||||||
|
private DubboCloudConstants() {
|
||||||
|
throw new AssertionError("Must not instantiate constant utility class");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The property prefix of Configuration
|
* The property prefix of Configuration.
|
||||||
*/
|
*/
|
||||||
String CONFIG_PROPERTY_PREFIX = "dubbo.cloud";
|
public static final String CONFIG_PROPERTY_PREFIX = "dubbo.cloud";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The property name of Registry type
|
* The property name of Registry type
|
||||||
|
Loading…
x
Reference in New Issue
Block a user