mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
upgrade sentinel version and enhance
This commit is contained in:
@@ -24,7 +24,6 @@ import com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration;
|
||||
import com.alibaba.cloud.sentinel.custom.SentinelBeanPostProcessor;
|
||||
import com.alibaba.cloud.sentinel.endpoint.SentinelEndpoint;
|
||||
import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse;
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig;
|
||||
import com.alibaba.csp.sentinel.config.SentinelConfig;
|
||||
import com.alibaba.csp.sentinel.log.LogBase;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
@@ -43,7 +42,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpRequest;
|
||||
@@ -55,6 +53,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static com.alibaba.cloud.sentinel.SentinelConstants.BLOCK_PAGE_URL_CONF_KEY;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -70,7 +69,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
"spring.cloud.sentinel.filter.urlPatterns=/*,/test",
|
||||
"spring.cloud.sentinel.metric.fileSingleSize=9999",
|
||||
"spring.cloud.sentinel.metric.fileTotalCount=100",
|
||||
"spring.cloud.sentinel.servlet.blockPage=/error",
|
||||
"spring.cloud.sentinel.blockPage=/error",
|
||||
"spring.cloud.sentinel.flow.coldFactor=3",
|
||||
"spring.cloud.sentinel.eager=true",
|
||||
"spring.cloud.sentinel.log.switchPid=true",
|
||||
@@ -84,9 +83,6 @@ public class SentinelAutoConfigurationTests {
|
||||
@Autowired
|
||||
private SentinelProperties sentinelProperties;
|
||||
|
||||
@Autowired
|
||||
private FilterRegistrationBean filterRegistrationBean;
|
||||
|
||||
@Autowired
|
||||
private SentinelBeanPostProcessor sentinelBeanPostProcessor;
|
||||
|
||||
@@ -130,9 +126,6 @@ public class SentinelAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
|
||||
assertThat(filterRegistrationBean).isNotNull();
|
||||
assertThat(filterRegistrationBean).isNotNull();
|
||||
assertThat(sentinelBeanPostProcessor).isNotNull();
|
||||
|
||||
checkSentinelLog();
|
||||
@@ -195,12 +188,6 @@ public class SentinelAutoConfigurationTests {
|
||||
assertThat(sentinelProperties.getLog().isSwitchPid()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
assertThat(123).isEqualTo(filterRegistrationBean.getOrder());
|
||||
assertThat(2).isEqualTo(filterRegistrationBean.getUrlPatterns().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSentinelSystemProperties() {
|
||||
assertThat(LogBase.isLogNameUsePid()).isEqualTo(true);
|
||||
@@ -212,7 +199,7 @@ public class SentinelAutoConfigurationTests {
|
||||
assertThat(SentinelConfig.singleMetricFileSize()).isEqualTo(9999);
|
||||
assertThat(SentinelConfig.totalMetricFileCount()).isEqualTo(100);
|
||||
assertThat(SentinelConfig.charset()).isEqualTo("UTF-8");
|
||||
assertThat(WebServletConfig.getBlockPage()).isEqualTo("/error");
|
||||
assertThat(SentinelConfig.getConfig(BLOCK_PAGE_URL_CONF_KEY)).isEqualTo("/error");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -16,18 +16,14 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration;
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler;
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner;
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.util.FilterUtil;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
|
||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.DefaultBlockExceptionHandler;
|
||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
|
||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.UrlCleaner;
|
||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.config.SentinelWebMvcConfig;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -53,7 +49,7 @@ public class SentinelBeanAutowiredTests {
|
||||
private UrlCleaner urlCleaner;
|
||||
|
||||
@Autowired
|
||||
private UrlBlockHandler urlBlockHandler;
|
||||
private BlockExceptionHandler blockExceptionHandler;
|
||||
|
||||
@Autowired
|
||||
private RequestOriginParser requestOriginParser;
|
||||
@@ -61,10 +57,13 @@ public class SentinelBeanAutowiredTests {
|
||||
@Autowired
|
||||
private SentinelProperties sentinelProperties;
|
||||
|
||||
@Autowired
|
||||
private SentinelWebMvcConfig sentinelWebMvcConfig;
|
||||
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
assertThat(urlCleaner).isNotNull();
|
||||
assertThat(urlBlockHandler).isNotNull();
|
||||
assertThat(blockExceptionHandler).isNotNull();
|
||||
assertThat(requestOriginParser).isNotNull();
|
||||
assertThat(sentinelProperties).isNotNull();
|
||||
|
||||
@@ -80,10 +79,10 @@ public class SentinelBeanAutowiredTests {
|
||||
|
||||
@Test
|
||||
public void testBeanAutowired() {
|
||||
assertThat(WebCallbackManager.getUrlCleaner()).isEqualTo(urlCleaner);
|
||||
assertThat(WebCallbackManager.getUrlBlockHandler()).isEqualTo(urlBlockHandler);
|
||||
assertThat(WebCallbackManager.getRequestOriginParser())
|
||||
.isEqualTo(requestOriginParser);
|
||||
assertThat(sentinelWebMvcConfig.getUrlCleaner()).isEqualTo(urlCleaner);
|
||||
assertThat(sentinelWebMvcConfig.getBlockExceptionHandler())
|
||||
.isEqualTo(blockExceptionHandler);
|
||||
assertThat(sentinelWebMvcConfig.getOriginParser()).isEqualTo(requestOriginParser);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -113,15 +112,8 @@ public class SentinelBeanAutowiredTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UrlBlockHandler urlBlockHandler() {
|
||||
return new UrlBlockHandler() {
|
||||
@Override
|
||||
public void blocked(HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse, BlockException e)
|
||||
throws IOException {
|
||||
FilterUtil.blockRequest(httpServletRequest, httpServletResponse);
|
||||
}
|
||||
};
|
||||
public BlockExceptionHandler blockExceptionHandler() {
|
||||
return new DefaultBlockExceptionHandler();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user