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

仍有两个测试过不了

1. NacosConfigurationXmlJsonTest#contextLoads
2. NacosConfigurationNoSuffixTest#contextLoads
Merge branch 'master' into finchley
This commit is contained in:
派哒
2021-02-03 20:34:16 +08:00
188 changed files with 4938 additions and 2289 deletions

View File

@@ -232,8 +232,9 @@ public class SentinelProperties {
private String blockPage;
@Deprecated
@DeprecatedConfigurationProperty(reason = "replaced to SentinelProperties#blockPage.", replacement = SentinelConstants.PROPERTY_PREFIX
+ ".block-page")
@DeprecatedConfigurationProperty(
reason = "replaced to SentinelProperties#blockPage.",
replacement = SentinelConstants.PROPERTY_PREFIX + ".block-page")
public String getBlockPage() {
return blockPage;
}

View File

@@ -83,14 +83,16 @@ public class SentinelWebAutoConfiguration implements WebMvcConfigurer {
}
@Bean
@ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled", matchIfMissing = true)
@ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled",
matchIfMissing = true)
public SentinelWebInterceptor sentinelWebInterceptor(
SentinelWebMvcConfig sentinelWebMvcConfig) {
return new SentinelWebInterceptor(sentinelWebMvcConfig);
}
@Bean
@ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled", matchIfMissing = true)
@ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled",
matchIfMissing = true)
public SentinelWebMvcConfig sentinelWebMvcConfig() {
SentinelWebMvcConfig sentinelWebMvcConfig = new SentinelWebMvcConfig();
sentinelWebMvcConfig.setHttpMethodSpecify(properties.getHttpMethodSpecify());

View File

@@ -77,14 +77,16 @@ public class SentinelWebFluxAutoConfiguration {
@Bean
@Order(-2)
@ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled", matchIfMissing = true)
@ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled",
matchIfMissing = true)
public SentinelBlockExceptionHandler sentinelBlockExceptionHandler() {
return new SentinelBlockExceptionHandler(viewResolvers, serverCodecConfigurer);
}
@Bean
@Order(-1)
@ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled", matchIfMissing = true)
@ConditionalOnProperty(name = "spring.cloud.sentinel.filter.enabled",
matchIfMissing = true)
public SentinelWebFluxFilter sentinelWebFluxFilter() {
log.info("[Sentinel Starter] register Sentinel SentinelWebFluxFilter");
return new SentinelWebFluxFilter();

View File

@@ -27,7 +27,9 @@ import com.alibaba.csp.sentinel.util.StringUtil;
*/
final class BlockClassRegistry {
private static final Map<String, Method> FALLBACK_MAP = new ConcurrentHashMap<>();
private static final Map<String, Method> BLOCK_HANDLER_MAP = new ConcurrentHashMap<>();
private static final Map<String, Method> URL_CLEANER_MAP = new ConcurrentHashMap<>();

View File

@@ -145,7 +145,8 @@ public class SentinelAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
@ConditionalOnProperty(name = "resttemplate.sentinel.enabled", havingValue = "true", matchIfMissing = true)
@ConditionalOnProperty(name = "resttemplate.sentinel.enabled", havingValue = "true",
matchIfMissing = true)
public SentinelBeanPostProcessor sentinelBeanPostProcessor(
ApplicationContext applicationContext) {
return new SentinelBeanPostProcessor(applicationContext);

View File

@@ -52,14 +52,21 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton {
private static final Logger log = LoggerFactory
.getLogger(SentinelDataSourceHandler.class);
private final String DATA_TYPE_FIELD = "dataType";
private final String CUSTOM_DATA_TYPE = "custom";
private final String CONVERTER_CLASS_FIELD = "converterClass";
private final DefaultListableBeanFactory beanFactory;
private final SentinelProperties sentinelProperties;
private final Environment env;
private List<String> dataTypeList = Arrays.asList("json", "xml");
private final String DATA_TYPE_FIELD = "dataType";
private final String CUSTOM_DATA_TYPE = "custom";
private final String CONVERTER_CLASS_FIELD = "converterClass";
private final DefaultListableBeanFactory beanFactory;
private final SentinelProperties sentinelProperties;
private final Environment env;
public SentinelDataSourceHandler(DefaultListableBeanFactory beanFactory,
SentinelProperties sentinelProperties, Environment env) {
this.beanFactory = beanFactory;

View File

@@ -19,6 +19,7 @@ package com.alibaba.cloud.sentinel.endpoint;
import com.alibaba.cloud.sentinel.SentinelProperties;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
//import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;

View File

@@ -76,7 +76,9 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator {
// detail
if (!sentinelProperties.isEnabled()) {
detailMap.put("enabled", false);
withDetails(builder.up(), detailMap);
detailMap.forEach((key, value)->{
builder.up().withDetail(key, value);
});
return;
}
@@ -144,16 +146,15 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator {
// If Dashboard and DataSource are both OK, the health status is UP
if (dashboardUp && dataSourceUp) {
withDetails(builder.up(), detailMap);
detailMap.forEach((key, value)->{
builder.up().withDetail(key, value);
});
}
else {
withDetails(builder.unknown(), detailMap);
detailMap.forEach((key, value)->{
builder.unknown().withDetail(key, value);
});
}
}
private void withDetails(Health.Builder builder, Map<String, Object> detailMap) {
for (String key : detailMap.keySet()) {
builder.withDetail(key, detailMap.get(key));
}
}
}

View File

@@ -32,12 +32,13 @@ import feign.MethodMetadata;
*/
public class SentinelContractHolder implements Contract {
private final Contract delegate;
/**
* map key is constructed by ClassFullName + configKey. configKey is constructed by
* {@link feign.Feign#configKey}
*/
public final static Map<String, MethodMetadata> METADATA_MAP = new HashMap<>();
private final Contract delegate;
public SentinelContractHolder(Contract delegate) {
this.delegate = delegate;

View File

@@ -80,8 +80,7 @@ public class SentinelInvocationHandler implements InvocationHandler {
if ("equals".equals(method.getName())) {
try {
Object otherHandler = args.length > 0 && args[0] != null
? Proxy.getInvocationHandler(args[0])
: null;
? Proxy.getInvocationHandler(args[0]) : null;
return equals(otherHandler);
}
catch (IllegalArgumentException e) {

View File

@@ -24,7 +24,14 @@
"defaultValue": true,
"description": "Specify whether unify web context(i.e. use the default context name), and is true by default."
},
{ "name": "spring.cloud.sentinel.transport.port",
{
"name": "spring.cloud.sentinel.web-context-unify",
"type": "java.lang.Boolean",
"defaultValue": true,
"description": "Specify whether unify web context(i.e. use the default context name), and is true by default."
},
{
"name": "spring.cloud.sentinel.transport.port",
"type": "java.lang.String",
"defaultValue": "8719",
"description": "sentinel api port."

View File

@@ -63,9 +63,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
* @author jiashuai.xie
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {
SentinelAutoConfigurationTests.TestConfig.class }, properties = {
"spring.cloud.sentinel.filter.order=123",
@SpringBootTest(classes = { SentinelAutoConfigurationTests.TestConfig.class },
properties = { "spring.cloud.sentinel.filter.order=123",
"spring.cloud.sentinel.filter.urlPatterns=/*,/test",
"spring.cloud.sentinel.metric.fileSingleSize=9999",
"spring.cloud.sentinel.metric.fileTotalCount=100",
@@ -76,7 +75,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
"spring.cloud.sentinel.transport.dashboard=http://localhost:8080,http://localhost:8081",
"spring.cloud.sentinel.transport.port=9999",
"spring.cloud.sentinel.transport.clientIp=1.1.1.1",
"spring.cloud.sentinel.transport.heartbeatIntervalMs=20000" }, webEnvironment = RANDOM_PORT)
"spring.cloud.sentinel.transport.heartbeatIntervalMs=20000" },
webEnvironment = RANDOM_PORT)
public class SentinelAutoConfigurationTests {
@Autowired
@@ -239,13 +239,15 @@ public class SentinelAutoConfigurationTests {
}
@Bean
@SentinelRestTemplate(blockHandlerClass = ExceptionUtil.class, blockHandler = "handleException")
@SentinelRestTemplate(blockHandlerClass = ExceptionUtil.class,
blockHandler = "handleException")
RestTemplate restTemplateWithBlockClass() {
return new RestTemplate();
}
@Bean
@SentinelRestTemplate(fallbackClass = ExceptionUtil.class, fallback = "fallbackException")
@SentinelRestTemplate(fallbackClass = ExceptionUtil.class,
fallback = "fallbackException")
RestTemplate restTemplateWithFallbackClass() {
return new RestTemplate();
}

View File

@@ -45,8 +45,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { SentinelFeignTests.TestConfig.class }, properties = {
"feign.sentinel.enabled=true" })
@SpringBootTest(classes = { SentinelFeignTests.TestConfig.class },
properties = { "feign.sentinel.enabled=true" })
public class SentinelFeignTests {
@Autowired
@@ -118,22 +118,6 @@ public class SentinelFeignTests {
assertThat(echoService.equals(fooService)).isEqualTo(Boolean.FALSE);
}
@FeignClient(value = "test-service", fallback = EchoServiceFallback.class)
public interface EchoService {
@RequestMapping(path = "echo/{str}")
String echo(@RequestParam("str") String param);
}
@FeignClient(value = "foo-service", fallbackFactory = CustomFallbackFactory.class)
public interface FooService {
@RequestMapping(path = "echo/{str}")
String echo(@RequestParam("str") String param);
}
@FeignClient("bar-service")
public interface BarService {
@@ -172,6 +156,23 @@ public class SentinelFeignTests {
}
@FeignClient(value = "test-service", fallback = EchoServiceFallback.class)
public interface EchoService {
@RequestMapping(path = "echo/{str}")
String echo(@RequestParam("str") String param);
}
@FeignClient(value = "foo-service", fallbackFactory = CustomFallbackFactory.class)
public interface FooService {
@RequestMapping(path = "echo/{str}")
String echo(@RequestParam("str") String param);
}
public static class EchoServiceFallback implements EchoService {
@Override

View File

@@ -20,6 +20,7 @@ import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.alibaba.cloud.sentinel.custom.SentinelBeanPostProcessor;
import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
@@ -188,7 +189,7 @@ public class SentinelRestTemplateTests {
}
@Bean
@SentinelRestTemplate(blockHandlerClass = ExceptionUtil.class, blockHandler = "handleException", fallbackClass = ExceptionUtil.class, fallback = "fallbackException", urlCleanerClass = UrlCleanUtil.class, urlCleaner = "clean")
@SentinelRestTemplate(blockHandlerClass = SentinelRestTemplateTests.ExceptionUtil.class, blockHandler = "handleException", fallbackClass = SentinelRestTemplateTests.ExceptionUtil.class, fallback = "fallbackException", urlCleanerClass = SentinelRestTemplateTests.UrlCleanUtil.class, urlCleaner = "clean")
RestTemplate restTemplate() {
return new RestTemplate();
}
@@ -205,7 +206,7 @@ public class SentinelRestTemplateTests {
}
@Bean
@SentinelRestTemplate(blockHandlerClass = ExceptionUtil.class, blockHandler = "handleException1")
@SentinelRestTemplate(blockHandlerClass = SentinelRestTemplateTests.ExceptionUtil.class, blockHandler = "handleException1")
RestTemplate restTemplate() {
return new RestTemplate();
}
@@ -239,7 +240,7 @@ public class SentinelRestTemplateTests {
}
@Bean
@SentinelRestTemplate(blockHandlerClass = ExceptionUtil.class, blockHandler = "handleException2")
@SentinelRestTemplate(blockHandlerClass = SentinelRestTemplateTests.ExceptionUtil.class, blockHandler = "handleException2")
RestTemplate restTemplate() {
return new RestTemplate();
}
@@ -330,7 +331,7 @@ public class SentinelRestTemplateTests {
}
@Bean
@SentinelRestTemplate(urlCleanerClass = UrlCleanUtil.class, urlCleaner = "clean1")
@SentinelRestTemplate(urlCleanerClass = SentinelRestTemplateTests.UrlCleanUtil.class, urlCleaner = "clean1")
RestTemplate restTemplate() {
return new RestTemplate();
}
@@ -347,13 +348,19 @@ public class SentinelRestTemplateTests {
}
@Bean
@SentinelRestTemplate(urlCleanerClass = UrlCleanUtil.class, urlCleaner = "clean2")
@SentinelRestTemplate(urlCleanerClass = SentinelRestTemplateTests.UrlCleanUtil.class, urlCleaner = "clean2")
RestTemplate restTemplate() {
return new RestTemplate();
}
}
@Bean
@SentinelRestTemplate
RestTemplate restTemplate2() {
return new RestTemplate();
}
public static class ExceptionUtil {
public static SentinelClientHttpResponse handleException(HttpRequest request,
@@ -390,5 +397,4 @@ public class SentinelRestTemplateTests {
}
}
}