mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
add branch 1.x, support spring boot 1.x
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba</artifactId>
|
||||
<version>0.2.0.BUILD-SNAPSHOT</version>
|
||||
<version>0.1.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -39,13 +39,6 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
|
@@ -71,8 +71,8 @@ public class SentinelWebAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnWebApplication
|
||||
public FilterRegistrationBean<Filter> servletRequestListener() {
|
||||
FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
|
||||
public FilterRegistrationBean servletRequestListener() {
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
|
||||
SentinelProperties.Filter filterConfig = properties.getFilter();
|
||||
|
||||
|
@@ -27,21 +27,23 @@ import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.system.SystemRule;
|
||||
import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
|
||||
import org.springframework.cloud.alibaba.sentinel.SentinelProperties;
|
||||
|
||||
/**
|
||||
* Endpoint for Sentinel, contains ans properties and rules
|
||||
* @author xiaojing
|
||||
*/
|
||||
@Endpoint(id = "sentinel")
|
||||
public class SentinelEndpoint {
|
||||
public class SentinelEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
|
||||
@Autowired
|
||||
private SentinelProperties sentinelProperties;
|
||||
|
||||
@ReadOperation
|
||||
public SentinelEndpoint() {
|
||||
super("sentinel");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> invoke() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
|
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.alibaba.sentinel.endpoint;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@@ -33,7 +33,7 @@ public class SentinelEndpointAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnEnabledEndpoint
|
||||
@ConditionalOnEnabledEndpoint("sentinel")
|
||||
public SentinelEndpoint sentinelEndPoint() {
|
||||
return new SentinelEndpoint();
|
||||
}
|
||||
|
@@ -16,12 +16,14 @@
|
||||
|
||||
package org.springframework.cloud.alibaba.sentinel;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.cloud.alibaba.sentinel.custom.SentinelAspect;
|
||||
import org.springframework.cloud.alibaba.sentinel.custom.SentinelCustomAspectAutoConfiguration;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,35 +33,42 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class SentinelAutoConfigurationTests {
|
||||
|
||||
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(SentinelCustomAspectAutoConfiguration.class, SentinelWebAutoConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.sentinel.port=8888")
|
||||
.withPropertyValues("spring.cloud.sentinel.filter.order=123")
|
||||
.withPropertyValues("spring.cloud.sentinel.filter.urlPatterns=/*,/test");
|
||||
private final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
context.register(SentinelCustomAspectAutoConfiguration.class, SentinelWebAutoConfiguration.class);
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.cloud.sentinel.port=8888",
|
||||
"spring.cloud.sentinel.filter.order=123",
|
||||
"spring.cloud.sentinel.filter.urlPatterns=/*,/test");
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
@After
|
||||
public void closeContext() {
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSentinelAspect() {
|
||||
this.contextRunner.run(context -> assertThat(context).hasSingleBean(SentinelAspect.class));
|
||||
assertThat(context.getBean(SentinelAspect.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
this.contextRunner.run(context -> {
|
||||
assertThat(context.getBean(
|
||||
"servletRequestListener").getClass() == FilterRegistrationBean.class).isTrue();
|
||||
});
|
||||
assertThat(context.getBean(
|
||||
"servletRequestListener").getClass() == FilterRegistrationBean.class).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperties() {
|
||||
this.contextRunner.run(context -> {
|
||||
SentinelProperties sentinelProperties = context.getBean(SentinelProperties.class);
|
||||
assertThat(sentinelProperties.getPort()).isEqualTo("8888");
|
||||
assertThat(sentinelProperties.getFilter().getUrlPatterns().size()).isEqualTo(2);
|
||||
assertThat(sentinelProperties.getFilter().getUrlPatterns().get(0)).isEqualTo("/*");
|
||||
assertThat(sentinelProperties.getFilter().getUrlPatterns().get(1)).isEqualTo("/test");
|
||||
});
|
||||
SentinelProperties sentinelProperties = context.getBean(SentinelProperties.class);
|
||||
assertThat(sentinelProperties).isNotNull();
|
||||
assertThat(sentinelProperties.getPort()).isEqualTo("8888");
|
||||
assertThat(sentinelProperties.getFilter().getUrlPatterns().size()).isEqualTo(2);
|
||||
assertThat(sentinelProperties.getFilter().getUrlPatterns().get(0)).isEqualTo("/*");
|
||||
assertThat(sentinelProperties.getFilter().getUrlPatterns().get(1)).isEqualTo("/test");
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user