mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
format code with maven plugins
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -19,8 +19,6 @@ package com.alibaba.cloud.sentinel.datasource;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.config.AbstractDataSourceProperties;
|
||||
import com.alibaba.csp.sentinel.slots.block.AbstractRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
|
||||
@@ -29,57 +27,59 @@ 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.system.SystemRule;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Enum for {@link AbstractRule} class, using in
|
||||
* {@link AbstractDataSourceProperties#ruleType}
|
||||
* {@link AbstractDataSourceProperties#ruleType}.
|
||||
*
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
public enum RuleType {
|
||||
|
||||
/**
|
||||
* flow
|
||||
* flow.
|
||||
*/
|
||||
FLOW("flow", FlowRule.class),
|
||||
/**
|
||||
* degrade
|
||||
* degrade.
|
||||
*/
|
||||
DEGRADE("degrade", DegradeRule.class),
|
||||
/**
|
||||
* param flow
|
||||
* param flow.
|
||||
*/
|
||||
PARAM_FLOW("param-flow", ParamFlowRule.class),
|
||||
/**
|
||||
* system
|
||||
* system.
|
||||
*/
|
||||
SYSTEM("system", SystemRule.class),
|
||||
/**
|
||||
* authority
|
||||
* authority.
|
||||
*/
|
||||
AUTHORITY("authority", AuthorityRule.class),
|
||||
/**
|
||||
* gateway flow
|
||||
* gateway flow.
|
||||
*/
|
||||
GW_FLOW("gw-flow",
|
||||
"com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule"),
|
||||
/**
|
||||
* api
|
||||
* api.
|
||||
*/
|
||||
GW_API_GROUP("gw-api-group",
|
||||
"com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition");
|
||||
|
||||
/**
|
||||
* alias for {@link AbstractRule}
|
||||
* alias for {@link AbstractRule}.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* concrete {@link AbstractRule} class
|
||||
* concrete {@link AbstractRule} class.
|
||||
*/
|
||||
private Class clazz;
|
||||
|
||||
/**
|
||||
* concrete {@link AbstractRule} class name
|
||||
* concrete {@link AbstractRule} class name.
|
||||
*/
|
||||
private String clazzName;
|
||||
|
||||
|
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
public interface SentinelDataSourceConstants {
|
||||
|
||||
String PROPERTY_PREFIX = "spring.cloud.sentinel";
|
||||
|
||||
}
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -19,8 +19,6 @@ package com.alibaba.cloud.sentinel.datasource.config;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.RuleType;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.common.api.GatewayApiDefinitionManager;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
|
||||
@@ -30,11 +28,12 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* Abstract class Using by {@link DataSourcePropertiesConfiguration}
|
||||
* Abstract class Using by {@link DataSourcePropertiesConfiguration}.
|
||||
*
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
@@ -42,11 +41,15 @@ public class AbstractDataSourceProperties {
|
||||
|
||||
@NotEmpty
|
||||
private String dataType = "json";
|
||||
|
||||
@NotNull
|
||||
private RuleType ruleType;
|
||||
|
||||
private String converterClass;
|
||||
|
||||
@JsonIgnore
|
||||
private final String factoryBeanName;
|
||||
|
||||
@JsonIgnore
|
||||
private Environment env;
|
||||
|
||||
@@ -121,4 +124,5 @@ public class AbstractDataSourceProperties {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -22,7 +22,7 @@ import com.alibaba.cloud.sentinel.datasource.factorybean.ApolloDataSourceFactory
|
||||
|
||||
/**
|
||||
* Apollo Properties class Using by {@link DataSourcePropertiesConfiguration} and
|
||||
* {@link ApolloDataSourceFactoryBean}
|
||||
* {@link ApolloDataSourceFactoryBean}.
|
||||
*
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
@@ -30,8 +30,10 @@ public class ApolloDataSourceProperties extends AbstractDataSourceProperties {
|
||||
|
||||
@NotEmpty
|
||||
private String namespaceName;
|
||||
|
||||
@NotEmpty
|
||||
private String flowRulesKey;
|
||||
|
||||
private String defaultFlowRuleValue;
|
||||
|
||||
public ApolloDataSourceProperties() {
|
||||
@@ -61,4 +63,5 @@ public class ApolloDataSourceProperties extends AbstractDataSourceProperties {
|
||||
public void setDefaultFlowRuleValue(String defaultFlowRuleValue) {
|
||||
this.defaultFlowRuleValue = defaultFlowRuleValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -21,10 +21,10 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Using By ConfigurationProperties.
|
||||
*
|
||||
@@ -66,11 +66,11 @@ public class DataSourcePropertiesConfiguration {
|
||||
this.apollo = apollo;
|
||||
}
|
||||
|
||||
public DataSourcePropertiesConfiguration(RedisDataSourceProperties redis) {
|
||||
this.redis = redis;
|
||||
}
|
||||
public DataSourcePropertiesConfiguration(RedisDataSourceProperties redis) {
|
||||
this.redis = redis;
|
||||
}
|
||||
|
||||
public FileDataSourceProperties getFile() {
|
||||
public FileDataSourceProperties getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -20,14 +20,14 @@ import java.io.IOException;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.factorybean.FileRefreshableDataSourceFactoryBean;
|
||||
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.factorybean.FileRefreshableDataSourceFactoryBean;
|
||||
|
||||
/**
|
||||
* File Properties class Using by {@link DataSourcePropertiesConfiguration} and
|
||||
* {@link FileRefreshableDataSourceFactoryBean}
|
||||
* {@link FileRefreshableDataSourceFactoryBean}.
|
||||
*
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
@@ -35,8 +35,11 @@ public class FileDataSourceProperties extends AbstractDataSourceProperties {
|
||||
|
||||
@NotEmpty
|
||||
private String file;
|
||||
|
||||
private String charset = "utf-8";
|
||||
|
||||
private long recommendRefreshMs = 3000L;
|
||||
|
||||
private int bufSize = 1024 * 1024;
|
||||
|
||||
public FileDataSourceProperties() {
|
||||
@@ -90,4 +93,5 @@ public class FileDataSourceProperties extends AbstractDataSourceProperties {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -18,13 +18,13 @@ package com.alibaba.cloud.sentinel.datasource.config;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Nacos Properties class Using by {@link DataSourcePropertiesConfiguration} and
|
||||
* {@link NacosDataSourceFactoryBean}
|
||||
* {@link NacosDataSourceFactoryBean}.
|
||||
*
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
@@ -39,8 +39,11 @@ public class NacosDataSourceProperties extends AbstractDataSourceProperties {
|
||||
private String dataId;
|
||||
|
||||
private String endpoint;
|
||||
|
||||
private String namespace;
|
||||
|
||||
private String accessKey;
|
||||
|
||||
private String secretKey;
|
||||
|
||||
public NacosDataSourceProperties() {
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -14,160 +14,161 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource.config;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.factorybean.RedisDataSourceFactoryBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.factorybean.RedisDataSourceFactoryBean;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Zookeeper Properties class Using by {@link DataSourcePropertiesConfiguration} and
|
||||
* {@link RedisDataSourceFactoryBean}
|
||||
* {@link RedisDataSourceFactoryBean}.
|
||||
*
|
||||
* @author <a href="mailto:wangiegie@gmail.com">lengleng</a>
|
||||
*/
|
||||
public class RedisDataSourceProperties extends AbstractDataSourceProperties {
|
||||
|
||||
public RedisDataSourceProperties() {
|
||||
super(RedisDataSourceFactoryBean.class.getName());
|
||||
}
|
||||
public RedisDataSourceProperties() {
|
||||
super(RedisDataSourceFactoryBean.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* redis server host
|
||||
*/
|
||||
private String host = "localhost";
|
||||
/**
|
||||
* redis server host.
|
||||
*/
|
||||
private String host = "localhost";
|
||||
|
||||
/**
|
||||
* redis server port
|
||||
*/
|
||||
private int port = 6379;
|
||||
/**
|
||||
* redis server port.
|
||||
*/
|
||||
private int port = 6379;
|
||||
|
||||
/**
|
||||
* redis server password
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* redis server password.
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* redis server default select database
|
||||
*/
|
||||
private int database;
|
||||
/**
|
||||
* redis server default select database.
|
||||
*/
|
||||
private int database;
|
||||
|
||||
/**
|
||||
* redis server timeout
|
||||
*/
|
||||
private Duration timeout;
|
||||
/**
|
||||
* redis server timeout.
|
||||
*/
|
||||
private Duration timeout;
|
||||
|
||||
/**
|
||||
* Comma-separated list of "host:port" pairs.
|
||||
*/
|
||||
private List<String> nodes;
|
||||
/**
|
||||
* Comma-separated list of "host:port" pairs.
|
||||
*/
|
||||
private List<String> nodes;
|
||||
|
||||
/**
|
||||
* data key in Redis
|
||||
*/
|
||||
private String ruleKey;
|
||||
/**
|
||||
* data key in Redis.
|
||||
*/
|
||||
private String ruleKey;
|
||||
|
||||
/**
|
||||
* channel to subscribe in Redis
|
||||
*/
|
||||
private String channel;
|
||||
/**
|
||||
* channel to subscribe in Redis.
|
||||
*/
|
||||
private String channel;
|
||||
|
||||
/**
|
||||
* redis sentinel model
|
||||
*/
|
||||
private String masterId;
|
||||
/**
|
||||
* redis sentinel model.
|
||||
*/
|
||||
private String masterId;
|
||||
|
||||
@Override
|
||||
public void preCheck(String dataSourceName) {
|
||||
super.preCheck(dataSourceName);
|
||||
if (StringUtils.isEmpty(ruleKey)) {
|
||||
throw new IllegalArgumentException(
|
||||
"RedisDataSource ruleKey can not be empty");
|
||||
}
|
||||
@Override
|
||||
public void preCheck(String dataSourceName) {
|
||||
super.preCheck(dataSourceName);
|
||||
if (StringUtils.isEmpty(ruleKey)) {
|
||||
throw new IllegalArgumentException(
|
||||
"RedisDataSource ruleKey can not be empty");
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(channel)) {
|
||||
throw new IllegalArgumentException(
|
||||
"RedisDataSource channel can not be empty");
|
||||
}
|
||||
if (StringUtils.isEmpty(channel)) {
|
||||
throw new IllegalArgumentException(
|
||||
"RedisDataSource channel can not be empty");
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(masterId) && StringUtils.isEmpty(masterId)) {
|
||||
throw new IllegalArgumentException(
|
||||
"RedisDataSource sentinel model,masterId can not be empty");
|
||||
}
|
||||
}
|
||||
if (!StringUtils.isEmpty(masterId) && StringUtils.isEmpty(masterId)) {
|
||||
throw new IllegalArgumentException(
|
||||
"RedisDataSource sentinel model,masterId can not be empty");
|
||||
}
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getRuleKey() {
|
||||
return ruleKey;
|
||||
}
|
||||
public String getRuleKey() {
|
||||
return ruleKey;
|
||||
}
|
||||
|
||||
public void setRuleKey(String ruleKey) {
|
||||
this.ruleKey = ruleKey;
|
||||
}
|
||||
public void setRuleKey(String ruleKey) {
|
||||
this.ruleKey = ruleKey;
|
||||
}
|
||||
|
||||
public String getChannel() {
|
||||
return channel;
|
||||
}
|
||||
public String getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void setChannel(String channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
public void setChannel(String channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public int getDatabase() {
|
||||
return database;
|
||||
}
|
||||
public int getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
public void setDatabase(int database) {
|
||||
this.database = database;
|
||||
}
|
||||
public void setDatabase(int database) {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public Duration getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
public Duration getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(Duration timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
public void setTimeout(Duration timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public List<String> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
public List<String> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public void setNodes(List<String> nodes) {
|
||||
this.nodes = nodes;
|
||||
}
|
||||
public void setNodes(List<String> nodes) {
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
public String getMasterId() {
|
||||
return masterId;
|
||||
}
|
||||
public String getMasterId() {
|
||||
return masterId;
|
||||
}
|
||||
|
||||
public void setMasterId(String masterId) {
|
||||
this.masterId = masterId;
|
||||
}
|
||||
|
||||
public void setMasterId(String masterId) {
|
||||
this.masterId = masterId;
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource.config;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.factorybean.ZookeeperDataSourceFactoryBean;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Zookeeper Properties class Using by {@link DataSourcePropertiesConfiguration} and
|
||||
* {@link ZookeeperDataSourceFactoryBean}
|
||||
* {@link ZookeeperDataSourceFactoryBean}.
|
||||
*
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
@@ -83,4 +83,5 @@ public class ZookeeperDataSourceProperties extends AbstractDataSourceProperties
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -21,11 +21,10 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
|
||||
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.system.SystemRule;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* Convert sentinel rules for json array Using strict mode to parse json
|
||||
* Convert sentinel rules for json array Using strict mode to parse json.
|
||||
*
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
* @see FlowRule
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -24,22 +24,21 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
|
||||
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.system.SystemRule;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Convert sentinel rules for json or xml array Using strict mode to parse json or xml
|
||||
* Convert sentinel rules for json or xml array Using strict mode to parse json or xml.
|
||||
*
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
* @see FlowRule
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -21,12 +21,11 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
|
||||
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.system.SystemRule;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
|
||||
/**
|
||||
* Convert sentinel rules for xml array Using strict mode to parse xml
|
||||
* Convert sentinel rules for xml array Using strict mode to parse xml.
|
||||
*
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
* @see FlowRule
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource.factorybean;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
/**
|
||||
* A {@link FactoryBean} for creating {@link ApolloDataSource} instance.
|
||||
*
|
||||
@@ -30,8 +30,11 @@ import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource;
|
||||
public class ApolloDataSourceFactoryBean implements FactoryBean<ApolloDataSource> {
|
||||
|
||||
private String namespaceName;
|
||||
|
||||
private String flowRulesKey;
|
||||
|
||||
private String defaultFlowRuleValue;
|
||||
|
||||
private Converter converter;
|
||||
|
||||
@Override
|
||||
@@ -76,4 +79,5 @@ public class ApolloDataSourceFactoryBean implements FactoryBean<ApolloDataSource
|
||||
public void setConverter(Converter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -19,11 +19,11 @@ package com.alibaba.cloud.sentinel.datasource.factorybean;
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
/**
|
||||
* A {@link FactoryBean} for creating {@link FileRefreshableDataSource} instance.
|
||||
*
|
||||
@@ -34,9 +34,13 @@ public class FileRefreshableDataSourceFactoryBean
|
||||
implements FactoryBean<FileRefreshableDataSource> {
|
||||
|
||||
private String file;
|
||||
|
||||
private String charset;
|
||||
|
||||
private long recommendRefreshMs;
|
||||
|
||||
private int bufSize;
|
||||
|
||||
private Converter converter;
|
||||
|
||||
@Override
|
||||
@@ -89,4 +93,5 @@ public class FileRefreshableDataSourceFactoryBean
|
||||
public void setConverter(Converter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -18,13 +18,13 @@ package com.alibaba.cloud.sentinel.datasource.factorybean;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A {@link FactoryBean} for creating {@link NacosDataSource} instance.
|
||||
*
|
||||
@@ -34,13 +34,19 @@ import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource> {
|
||||
|
||||
private String serverAddr;
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String dataId;
|
||||
|
||||
private Converter converter;
|
||||
|
||||
private String endpoint;
|
||||
|
||||
private String namespace;
|
||||
|
||||
private String accessKey;
|
||||
|
||||
private String secretKey;
|
||||
|
||||
@Override
|
||||
@@ -128,4 +134,5 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,17 +16,18 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource.factorybean;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.redis.RedisDataSource;
|
||||
import com.alibaba.csp.sentinel.datasource.redis.config.RedisConnectionConfig;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A {@link FactoryBean} for creating {@link RedisDataSource} instance.
|
||||
*
|
||||
@@ -35,152 +36,155 @@ import java.util.List;
|
||||
*/
|
||||
public class RedisDataSourceFactoryBean implements FactoryBean<RedisDataSource> {
|
||||
|
||||
private String host;
|
||||
private String host;
|
||||
|
||||
private int port;
|
||||
private int port;
|
||||
|
||||
private int database;
|
||||
private int database;
|
||||
|
||||
private Duration timeout;
|
||||
private Duration timeout;
|
||||
|
||||
/**
|
||||
* Comma-separated list of "host:port" pairs.
|
||||
*/
|
||||
private List<String> nodes;
|
||||
/**
|
||||
* Comma-separated list of "host:port" pairs.
|
||||
*/
|
||||
private List<String> nodes;
|
||||
|
||||
private Converter converter;
|
||||
private Converter converter;
|
||||
|
||||
/**
|
||||
* data key in Redis
|
||||
*/
|
||||
private String ruleKey;
|
||||
/**
|
||||
* data key in Redis.
|
||||
*/
|
||||
private String ruleKey;
|
||||
|
||||
/**
|
||||
* channel to subscribe in Redis
|
||||
*/
|
||||
private String channel;
|
||||
/**
|
||||
* channel to subscribe in Redis.
|
||||
*/
|
||||
private String channel;
|
||||
|
||||
/**
|
||||
* redis server password
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* redis server password.
|
||||
*/
|
||||
private String password;
|
||||
|
||||
private String masterId;
|
||||
private String masterId;
|
||||
|
||||
@Override
|
||||
public RedisDataSource getObject() {
|
||||
RedisConnectionConfig.Builder builder = RedisConnectionConfig.builder();
|
||||
@Override
|
||||
public RedisDataSource getObject() {
|
||||
RedisConnectionConfig.Builder builder = RedisConnectionConfig.builder();
|
||||
|
||||
if (nodes == null || nodes.isEmpty()) {
|
||||
builder.withHost(host)
|
||||
.withPort(port)
|
||||
.withDatabase(database);
|
||||
} else {
|
||||
nodes.forEach(node -> {
|
||||
try {
|
||||
String[] parts = StringUtils.split(node, ":");
|
||||
Assert.state(parts.length == 2, "Must be defined as 'host:port'");
|
||||
builder.withRedisSentinel(parts[0], Integer.parseInt(parts[1]));
|
||||
} catch (RuntimeException ex) {
|
||||
throw new IllegalStateException("Invalid redis sentinel property " + node, ex);
|
||||
}
|
||||
});
|
||||
builder.withSentinelMasterId(masterId);
|
||||
}
|
||||
if (nodes == null || nodes.isEmpty()) {
|
||||
builder.withHost(host).withPort(port).withDatabase(database);
|
||||
}
|
||||
else {
|
||||
nodes.forEach(node -> {
|
||||
try {
|
||||
String[] parts = StringUtils.split(node, ":");
|
||||
Assert.state(parts.length == 2, "Must be defined as 'host:port'");
|
||||
builder.withRedisSentinel(parts[0], Integer.parseInt(parts[1]));
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
throw new IllegalStateException(
|
||||
"Invalid redis sentinel property " + node, ex);
|
||||
}
|
||||
});
|
||||
builder.withSentinelMasterId(masterId);
|
||||
}
|
||||
|
||||
if (timeout != null) {
|
||||
builder.withTimeout(timeout.toMillis());
|
||||
}
|
||||
if (timeout != null) {
|
||||
builder.withTimeout(timeout.toMillis());
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(password)) {
|
||||
builder.withPassword(password);
|
||||
}
|
||||
if (StringUtils.hasText(password)) {
|
||||
builder.withPassword(password);
|
||||
}
|
||||
|
||||
return new RedisDataSource<List<FlowRule>>(builder.build(), ruleKey, channel, converter);
|
||||
}
|
||||
return new RedisDataSource<List<FlowRule>>(builder.build(), ruleKey, channel,
|
||||
converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return RedisDataSource.class;
|
||||
}
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return RedisDataSource.class;
|
||||
}
|
||||
|
||||
public Converter getConverter() {
|
||||
return converter;
|
||||
}
|
||||
public Converter getConverter() {
|
||||
return converter;
|
||||
}
|
||||
|
||||
public void setConverter(Converter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
public void setConverter(Converter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getRuleKey() {
|
||||
return ruleKey;
|
||||
}
|
||||
public String getRuleKey() {
|
||||
return ruleKey;
|
||||
}
|
||||
|
||||
public void setRuleKey(String ruleKey) {
|
||||
this.ruleKey = ruleKey;
|
||||
}
|
||||
public void setRuleKey(String ruleKey) {
|
||||
this.ruleKey = ruleKey;
|
||||
}
|
||||
|
||||
public String getChannel() {
|
||||
return channel;
|
||||
}
|
||||
public String getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void setChannel(String channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
public void setChannel(String channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public int getDatabase() {
|
||||
return database;
|
||||
}
|
||||
public int getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
public void setDatabase(int database) {
|
||||
this.database = database;
|
||||
}
|
||||
public void setDatabase(int database) {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public Duration getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
public Duration getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(Duration timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
public void setTimeout(Duration timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public List<String> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
public List<String> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public void setNodes(List<String> nodes) {
|
||||
this.nodes = nodes;
|
||||
}
|
||||
public void setNodes(List<String> nodes) {
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
public String getMasterId() {
|
||||
return masterId;
|
||||
}
|
||||
public String getMasterId() {
|
||||
return masterId;
|
||||
}
|
||||
|
||||
public void setMasterId(String masterId) {
|
||||
this.masterId = masterId;
|
||||
}
|
||||
|
||||
public void setMasterId(String masterId) {
|
||||
this.masterId = masterId;
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource.factorybean;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
/**
|
||||
* A {@link FactoryBean} for creating {@link ZookeeperDataSource} instance.
|
||||
@@ -35,6 +35,7 @@ public class ZookeeperDataSourceFactoryBean implements FactoryBean<ZookeeperData
|
||||
private String path;
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String dataId;
|
||||
|
||||
private Converter converter;
|
||||
@@ -95,4 +96,5 @@ public class ZookeeperDataSourceFactoryBean implements FactoryBean<ZookeeperData
|
||||
public void setConverter(Converter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,4 +2,4 @@ nacos = com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource
|
||||
file =com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource
|
||||
apollo = com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource
|
||||
zk = com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource
|
||||
redis = com.alibaba.csp.sentinel.datasource.redis.RedisDataSource
|
||||
redis = com.alibaba.csp.sentinel.datasource.redis.RedisDataSource
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,18 +16,17 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter;
|
||||
import com.alibaba.cloud.sentinel.datasource.factorybean.ApolloDataSourceFactoryBean;
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
@@ -35,7 +34,9 @@ import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource;
|
||||
public class ApolloDataSourceFactoryBeanTests {
|
||||
|
||||
private String flowRuleKey = "sentinel";
|
||||
|
||||
private String namespace = "namespace";
|
||||
|
||||
private String defaultFlowValue = "{}";
|
||||
|
||||
@Test
|
||||
@@ -54,18 +55,12 @@ public class ApolloDataSourceFactoryBeanTests {
|
||||
when(apolloDataSource.readSource()).thenReturn("{}");
|
||||
doReturn(apolloDataSource).when(factoryBean).getObject();
|
||||
|
||||
assertEquals("ApolloDataSourceFactoryBean getObject error", apolloDataSource,
|
||||
factoryBean.getObject());
|
||||
assertEquals("ApolloDataSource read source value was wrong", "{}",
|
||||
factoryBean.getObject().readSource());
|
||||
assertEquals("ApolloDataSource converter was wrong", converter,
|
||||
factoryBean.getConverter());
|
||||
assertEquals("ApolloDataSourceFactoryBean flowRuleKey was wrong", flowRuleKey,
|
||||
factoryBean.getFlowRulesKey());
|
||||
assertEquals("ApolloDataSourceFactoryBean namespace was wrong", namespace,
|
||||
factoryBean.getNamespaceName());
|
||||
assertEquals("ApolloDataSourceFactoryBean defaultFlowValue was wrong",
|
||||
defaultFlowValue, factoryBean.getDefaultFlowRuleValue());
|
||||
assertThat(factoryBean.getObject()).isEqualTo(apolloDataSource);
|
||||
assertThat(factoryBean.getObject().readSource()).isEqualTo("{}");
|
||||
assertThat(factoryBean.getConverter()).isEqualTo(converter);
|
||||
assertThat(factoryBean.getFlowRulesKey()).isEqualTo(flowRuleKey);
|
||||
assertThat(factoryBean.getNamespaceName()).isEqualTo(namespace);
|
||||
assertThat(factoryBean.getDefaultFlowRuleValue()).isEqualTo(defaultFlowValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,250 +0,0 @@
|
||||
/// *
|
||||
// * Copyright (C) 2018 the original author or authors.
|
||||
// *
|
||||
// * 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
|
||||
// *
|
||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||
// *
|
||||
// * Unless required by applicable law or agreed to in writing, software
|
||||
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// * See the License for the specific language governing permissions and
|
||||
// * limitations under the License.
|
||||
// */
|
||||
//
|
||||
// package com.alibaba.cloud.sentinel.datasource;
|
||||
//
|
||||
// import static org.junit.Assert.assertEquals;
|
||||
// import static org.junit.Assert.assertNotNull;
|
||||
// import static org.junit.Assert.assertNull;
|
||||
//
|
||||
// import org.junit.Test;
|
||||
// import ApolloDataSourceProperties;
|
||||
// import DataSourcePropertiesConfiguration;
|
||||
// import FileDataSourceProperties;
|
||||
// import NacosDataSourceProperties;
|
||||
// import ZookeeperDataSourceProperties;
|
||||
//
|
||||
/// **
|
||||
// * @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
// */
|
||||
// public class DataSourcePropertiesConfigurationTests {
|
||||
//
|
||||
// @Test
|
||||
// public void testFileAttr() {
|
||||
// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new
|
||||
/// DataSourcePropertiesConfiguration();
|
||||
// assertEquals("DataSourcePropertiesConfiguration valid field size was wrong", 0,
|
||||
// dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNull("DataSourcePropertiesConfiguration valid properties was not null",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
//
|
||||
// FileDataSourceProperties fileDataSourceProperties = buildFileProperties();
|
||||
//
|
||||
// dataSourcePropertiesConfiguration.setFile(fileDataSourceProperties);
|
||||
//
|
||||
// assertEquals(
|
||||
// "DataSourcePropertiesConfiguration valid field size was wrong after set file
|
||||
/// attribute",
|
||||
// 1, dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNotNull(
|
||||
// "DataSourcePropertiesConfiguration file properties was null after set file attribute",
|
||||
// dataSourcePropertiesConfiguration.getFile());
|
||||
// assertNotNull(
|
||||
// "DataSourcePropertiesConfiguration valid properties was null after set file attribute",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testNacosAttr() {
|
||||
// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new
|
||||
/// DataSourcePropertiesConfiguration();
|
||||
// assertEquals("DataSourcePropertiesConfiguration valid field size was wrong", 0,
|
||||
// dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNull("DataSourcePropertiesConfiguration valid properties was not null",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
//
|
||||
// NacosDataSourceProperties nacosDataSourceProperties = buildNacosProperties();
|
||||
//
|
||||
// dataSourcePropertiesConfiguration.setNacos(nacosDataSourceProperties);
|
||||
//
|
||||
// assertEquals(
|
||||
// "DataSourcePropertiesConfiguration valid field size was wrong after set nacos
|
||||
/// attribute",
|
||||
// 1, dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNotNull(
|
||||
// "DataSourcePropertiesConfiguration nacos properties was null after set nacos
|
||||
/// attribute",
|
||||
// dataSourcePropertiesConfiguration.getNacos());
|
||||
// assertNotNull(
|
||||
// "DataSourcePropertiesConfiguration valid properties was null after set nacos
|
||||
/// attribute",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testZKAttr() {
|
||||
// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new
|
||||
/// DataSourcePropertiesConfiguration();
|
||||
// assertEquals("DataSourcePropertiesConfiguration valid field size was wrong", 0,
|
||||
// dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNull("DataSourcePropertiesConfiguration valid properties was not null",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
//
|
||||
// ZookeeperDataSourceProperties zookeeperDataSourceProperties = buildZKProperties();
|
||||
//
|
||||
// dataSourcePropertiesConfiguration.setZk(zookeeperDataSourceProperties);
|
||||
//
|
||||
// assertEquals(
|
||||
// "DataSourcePropertiesConfiguration valid field size was wrong after set zk attribute",
|
||||
// 1, dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNotNull(
|
||||
// "DataSourcePropertiesConfiguration zk properties was null after set zk attribute",
|
||||
// dataSourcePropertiesConfiguration.getZk());
|
||||
// assertNotNull(
|
||||
// "DataSourcePropertiesConfiguration valid properties was null after set zk attribute",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testApolloAttr() {
|
||||
// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new
|
||||
/// DataSourcePropertiesConfiguration();
|
||||
// assertEquals("DataSourcePropertiesConfiguration valid field size was wrong", 0,
|
||||
// dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNull("DataSourcePropertiesConfiguration valid properties was not null",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
//
|
||||
// ApolloDataSourceProperties apolloDataSourceProperties = buildApolloProperties();
|
||||
//
|
||||
// dataSourcePropertiesConfiguration.setApollo(apolloDataSourceProperties);
|
||||
//
|
||||
// assertEquals(
|
||||
// "DataSourcePropertiesConfiguration valid field size was wrong after set apollo
|
||||
/// attribute",
|
||||
// 1, dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNotNull(
|
||||
// "DataSourcePropertiesConfiguration apollo properties was null after set apollo
|
||||
/// attribute",
|
||||
// dataSourcePropertiesConfiguration.getApollo());
|
||||
// assertNotNull(
|
||||
// "DataSourcePropertiesConfiguration valid properties was null after set apollo
|
||||
/// attribute",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testMultiAttr() {
|
||||
// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new
|
||||
/// DataSourcePropertiesConfiguration();
|
||||
// assertEquals("DataSourcePropertiesConfiguration valid field size was wrong", 0,
|
||||
// dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNull("DataSourcePropertiesConfiguration valid properties was not null",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
//
|
||||
// FileDataSourceProperties fileDataSourceProperties = buildFileProperties();
|
||||
// NacosDataSourceProperties nacosDataSourceProperties = buildNacosProperties();
|
||||
//
|
||||
// dataSourcePropertiesConfiguration.setFile(fileDataSourceProperties);
|
||||
// dataSourcePropertiesConfiguration.setNacos(nacosDataSourceProperties);
|
||||
//
|
||||
// assertEquals(
|
||||
// "DataSourcePropertiesConfiguration valid field size was wrong after set file and nacos
|
||||
/// attribute",
|
||||
// 2, dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNull(
|
||||
// "DataSourcePropertiesConfiguration valid properties was not null after set file and
|
||||
/// nacos attribute",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testFileConstructor() {
|
||||
// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new
|
||||
/// DataSourcePropertiesConfiguration(
|
||||
// buildFileProperties());
|
||||
// assertEquals(
|
||||
// "DataSourcePropertiesConfiguration file constructor valid field size was wrong",
|
||||
// 1, dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNotNull(
|
||||
// "DataSourcePropertiesConfiguration file constructor valid properties was null",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testNacosConstructor() {
|
||||
// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new
|
||||
/// DataSourcePropertiesConfiguration(
|
||||
// buildNacosProperties());
|
||||
// assertEquals(
|
||||
// "DataSourcePropertiesConfiguration nacos constructor valid field size was wrong",
|
||||
// 1, dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNotNull(
|
||||
// "DataSourcePropertiesConfiguration nacos constructor valid properties was null",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testApolloConstructor() {
|
||||
// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new
|
||||
/// DataSourcePropertiesConfiguration(
|
||||
// buildApolloProperties());
|
||||
// assertEquals(
|
||||
// "DataSourcePropertiesConfiguration apollo constructor valid field size was wrong",
|
||||
// 1, dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNotNull(
|
||||
// "DataSourcePropertiesConfiguration apollo constructor valid properties was null",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testZKConstructor() {
|
||||
// DataSourcePropertiesConfiguration dataSourcePropertiesConfiguration = new
|
||||
/// DataSourcePropertiesConfiguration(
|
||||
// buildZKProperties());
|
||||
// assertEquals(
|
||||
// "DataSourcePropertiesConfiguration zk constructor valid field size was wrong",
|
||||
// 1, dataSourcePropertiesConfiguration.getValidField().size());
|
||||
// assertNotNull(
|
||||
// "DataSourcePropertiesConfiguration zk constructor valid properties was null",
|
||||
// dataSourcePropertiesConfiguration.getValidDataSourceProperties());
|
||||
// }
|
||||
//
|
||||
// private FileDataSourceProperties buildFileProperties() {
|
||||
// FileDataSourceProperties fileDataSourceProperties = new FileDataSourceProperties();
|
||||
//
|
||||
// fileDataSourceProperties.setFile("/tmp/test.json");
|
||||
// fileDataSourceProperties.setBufSize(1024);
|
||||
// fileDataSourceProperties.setRecommendRefreshMs(2000);
|
||||
// return fileDataSourceProperties;
|
||||
// }
|
||||
//
|
||||
// private NacosDataSourceProperties buildNacosProperties() {
|
||||
// NacosDataSourceProperties nacosDataSourceProperties = new NacosDataSourceProperties();
|
||||
// nacosDataSourceProperties.setServerAddr("127.0.0.1:8848");
|
||||
// nacosDataSourceProperties.setDataId("sentinel");
|
||||
// nacosDataSourceProperties.setGroupId("custom-group");
|
||||
// return nacosDataSourceProperties;
|
||||
// }
|
||||
//
|
||||
// private ApolloDataSourceProperties buildApolloProperties() {
|
||||
// ApolloDataSourceProperties apolloDataSourceProperties = new
|
||||
/// ApolloDataSourceProperties();
|
||||
// apolloDataSourceProperties.setFlowRulesKey("test-key");
|
||||
// apolloDataSourceProperties.setDefaultFlowRuleValue("dft-val");
|
||||
// apolloDataSourceProperties.setNamespaceName("namespace");
|
||||
// return apolloDataSourceProperties;
|
||||
// }
|
||||
//
|
||||
// private ZookeeperDataSourceProperties buildZKProperties() {
|
||||
// ZookeeperDataSourceProperties zookeeperDataSourceProperties = new
|
||||
/// ZookeeperDataSourceProperties();
|
||||
//
|
||||
// zookeeperDataSourceProperties.setServerAddr("localhost:2181");
|
||||
// zookeeperDataSourceProperties.setPath("/path");
|
||||
// return zookeeperDataSourceProperties;
|
||||
// }
|
||||
//
|
||||
// }
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,17 +16,9 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.config.ApolloDataSourceProperties;
|
||||
import com.alibaba.cloud.sentinel.datasource.config.FileDataSourceProperties;
|
||||
import com.alibaba.cloud.sentinel.datasource.config.ZookeeperDataSourceProperties;
|
||||
@@ -37,9 +29,14 @@ import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
@@ -53,21 +50,16 @@ public class DataSourcePropertiesTests {
|
||||
apolloDataSourceProperties.setDefaultFlowRuleValue("dft-val");
|
||||
apolloDataSourceProperties.setNamespaceName("namespace");
|
||||
apolloDataSourceProperties.setRuleType(RuleType.DEGRADE);
|
||||
assertEquals("Apollo flow rule key was wrong", "test-key",
|
||||
apolloDataSourceProperties.getFlowRulesKey());
|
||||
assertEquals("Apollo namespace was wrong", "namespace",
|
||||
apolloDataSourceProperties.getNamespaceName());
|
||||
assertEquals("Apollo default data type was wrong", "json",
|
||||
apolloDataSourceProperties.getDataType());
|
||||
Assert.assertEquals("Apollo rule type was wrong", RuleType.DEGRADE,
|
||||
apolloDataSourceProperties.getRuleType());
|
||||
assertEquals("Apollo default flow value was wrong", "dft-val",
|
||||
apolloDataSourceProperties.getDefaultFlowRuleValue());
|
||||
assertEquals("Apollo factory bean was wrong",
|
||||
ApolloDataSourceFactoryBean.class.getName(),
|
||||
apolloDataSourceProperties.getFactoryBeanName());
|
||||
assertNull("Apollo converterClass was not null",
|
||||
apolloDataSourceProperties.getConverterClass());
|
||||
|
||||
assertThat(apolloDataSourceProperties.getFlowRulesKey()).isEqualTo("test-key");
|
||||
assertThat(apolloDataSourceProperties.getNamespaceName()).isEqualTo("namespace");
|
||||
assertThat(apolloDataSourceProperties.getDataType()).isEqualTo("json");
|
||||
assertThat(apolloDataSourceProperties.getRuleType()).isEqualTo(RuleType.DEGRADE);
|
||||
assertThat(apolloDataSourceProperties.getDefaultFlowRuleValue())
|
||||
.isEqualTo("dft-val");
|
||||
assertThat(apolloDataSourceProperties.getFactoryBeanName())
|
||||
.isEqualTo(ApolloDataSourceFactoryBean.class.getName());
|
||||
assertThat(apolloDataSourceProperties.getConverterClass()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,21 +73,17 @@ public class DataSourcePropertiesTests {
|
||||
zookeeperDataSourceProperties.setConverterClass("test.ConverterClass");
|
||||
zookeeperDataSourceProperties.setRuleType(RuleType.AUTHORITY);
|
||||
|
||||
assertEquals("ZK serverAddr was wrong", "localhost:2181",
|
||||
zookeeperDataSourceProperties.getServerAddr());
|
||||
assertEquals("ZK groupId was wrong", "groupId",
|
||||
zookeeperDataSourceProperties.getGroupId());
|
||||
assertEquals("ZK dataId was wrong", "dataId",
|
||||
zookeeperDataSourceProperties.getDataId());
|
||||
assertEquals("ZK path was wrong", "/path",
|
||||
zookeeperDataSourceProperties.getPath());
|
||||
assertEquals("ZK factory bean was wrong",
|
||||
ZookeeperDataSourceFactoryBean.class.getName(),
|
||||
zookeeperDataSourceProperties.getFactoryBeanName());
|
||||
assertEquals("ZK custom converter class was wrong", "test.ConverterClass",
|
||||
zookeeperDataSourceProperties.getConverterClass());
|
||||
Assert.assertEquals("ZK rule type was wrong", RuleType.AUTHORITY,
|
||||
zookeeperDataSourceProperties.getRuleType());
|
||||
assertThat(zookeeperDataSourceProperties.getServerAddr())
|
||||
.isEqualTo("localhost:2181");
|
||||
assertThat(zookeeperDataSourceProperties.getGroupId()).isEqualTo("groupId");
|
||||
assertThat(zookeeperDataSourceProperties.getDataId()).isEqualTo("dataId");
|
||||
assertThat(zookeeperDataSourceProperties.getPath()).isEqualTo("/path");
|
||||
assertThat(zookeeperDataSourceProperties.getFactoryBeanName())
|
||||
.isEqualTo(ZookeeperDataSourceFactoryBean.class.getName());
|
||||
assertThat(zookeeperDataSourceProperties.getConverterClass())
|
||||
.isEqualTo("test.ConverterClass");
|
||||
assertThat(zookeeperDataSourceProperties.getRuleType())
|
||||
.isEqualTo(RuleType.AUTHORITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,19 +93,13 @@ public class DataSourcePropertiesTests {
|
||||
fileDataSourceProperties.setFile("/tmp/test.json");
|
||||
fileDataSourceProperties.setRuleType(RuleType.PARAM_FLOW);
|
||||
|
||||
assertEquals("File path was wrong", "/tmp/test.json",
|
||||
fileDataSourceProperties.getFile());
|
||||
assertEquals("File charset was wrong", "utf-8",
|
||||
fileDataSourceProperties.getCharset());
|
||||
assertEquals("File refresh time was wrong", 3000L,
|
||||
fileDataSourceProperties.getRecommendRefreshMs());
|
||||
assertEquals("File buf size was wrong", 1024 * 1024,
|
||||
fileDataSourceProperties.getBufSize());
|
||||
assertEquals("File factory bean was wrong",
|
||||
FileRefreshableDataSourceFactoryBean.class.getName(),
|
||||
fileDataSourceProperties.getFactoryBeanName());
|
||||
Assert.assertEquals("File rule type was wrong", RuleType.PARAM_FLOW,
|
||||
fileDataSourceProperties.getRuleType());
|
||||
assertThat(fileDataSourceProperties.getFile()).isEqualTo("/tmp/test.json");
|
||||
assertThat(fileDataSourceProperties.getCharset()).isEqualTo("utf-8");
|
||||
assertThat(fileDataSourceProperties.getRecommendRefreshMs()).isEqualTo(3000L);
|
||||
assertThat(fileDataSourceProperties.getBufSize()).isEqualTo(1024 * 1024);
|
||||
assertThat(fileDataSourceProperties.getFactoryBeanName())
|
||||
.isEqualTo(FileRefreshableDataSourceFactoryBean.class.getName());
|
||||
assertThat(fileDataSourceProperties.getRuleType()).isEqualTo(RuleType.PARAM_FLOW);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,14 +111,10 @@ public class DataSourcePropertiesTests {
|
||||
fileDataSourceProperties.setRecommendRefreshMs(2000);
|
||||
fileDataSourceProperties.setCharset("ISO8859-1");
|
||||
|
||||
assertEquals("File path was wrong", "/tmp/test.json",
|
||||
fileDataSourceProperties.getFile());
|
||||
assertEquals("File charset was wrong", "ISO8859-1",
|
||||
fileDataSourceProperties.getCharset());
|
||||
assertEquals("File refresh time was wrong", 2000L,
|
||||
fileDataSourceProperties.getRecommendRefreshMs());
|
||||
assertEquals("File buf size was wrong", 1024,
|
||||
fileDataSourceProperties.getBufSize());
|
||||
assertThat(fileDataSourceProperties.getFile()).isEqualTo("/tmp/test.json");
|
||||
assertThat(fileDataSourceProperties.getCharset()).isEqualTo("ISO8859-1");
|
||||
assertThat(fileDataSourceProperties.getRecommendRefreshMs()).isEqualTo(2000L);
|
||||
assertThat(fileDataSourceProperties.getBufSize()).isEqualTo(1024);
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
@@ -175,8 +153,8 @@ public class DataSourcePropertiesTests {
|
||||
}
|
||||
});
|
||||
fileDataSourceProperties.postRegister(fileRefreshableDataSource);
|
||||
assertEquals("DataSourceProperties postRegister error",
|
||||
fileRefreshableDataSource.loadConfig(), FlowRuleManager.getRules());
|
||||
assertThat(FlowRuleManager.getRules())
|
||||
.isEqualTo(fileRefreshableDataSource.loadConfig());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,26 +16,24 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.factorybean.FileRefreshableDataSourceFactoryBean;
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
@@ -46,24 +44,18 @@ public class FileRefreshableDataSourceFactoryBeanTests {
|
||||
public void testFile() throws Exception {
|
||||
AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(
|
||||
TestConfig.class);
|
||||
assertNotNull("FileRefreshableDataSourceFactoryBean was not created",
|
||||
annotationConfigApplicationContext.getBean("fileBean"));
|
||||
assertThat(annotationConfigApplicationContext.getBean("fileBean")).isNotNull();
|
||||
FileRefreshableDataSource fileRefreshableDataSource = annotationConfigApplicationContext
|
||||
.getBean("fileBean", FileRefreshableDataSource.class);
|
||||
assertEquals("FileRefreshableDataSourceFactoryBean flow rule size was wrong", 1,
|
||||
((List<FlowRule>) fileRefreshableDataSource.loadConfig()).size());
|
||||
assertThat(((List<FlowRule>) fileRefreshableDataSource.loadConfig()).size())
|
||||
.isEqualTo(1);
|
||||
FileRefreshableDataSourceFactoryBean factoryBean = annotationConfigApplicationContext
|
||||
.getBean("&fileBean", FileRefreshableDataSourceFactoryBean.class);
|
||||
assertEquals("FileRefreshableDataSourceFactoryBean buf size was wrong", 1024,
|
||||
factoryBean.getBufSize());
|
||||
assertEquals("FileRefreshableDataSourceFactoryBean charset was wrong", "utf-8",
|
||||
factoryBean.getCharset());
|
||||
assertEquals("FileRefreshableDataSourceFactoryBean recommendRefreshMs was wrong",
|
||||
2000, factoryBean.getRecommendRefreshMs());
|
||||
assertNotNull("FileRefreshableDataSourceFactoryBean file was null",
|
||||
factoryBean.getFile());
|
||||
assertNotNull("FileRefreshableDataSourceFactoryBean converter was null",
|
||||
factoryBean.getConverter());
|
||||
assertThat(factoryBean.getBufSize()).isEqualTo(1024);
|
||||
assertThat(factoryBean.getCharset()).isEqualTo("utf-8");
|
||||
assertThat(factoryBean.getRecommendRefreshMs()).isEqualTo(2000);
|
||||
assertThat(factoryBean.getFile()).isNotNull();
|
||||
assertThat(factoryBean.getConverter()).isNotNull();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,18 +16,17 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.converter.SentinelConverter;
|
||||
import com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean;
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
@@ -35,11 +34,17 @@ import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
|
||||
public class NacosDataSourceFactoryBeanTests {
|
||||
|
||||
private String dataId = "sentinel";
|
||||
|
||||
private String groupId = "DEFAULT_GROUP";
|
||||
|
||||
private String serverAddr = "localhost:8848";
|
||||
|
||||
private String accessKey = "ak";
|
||||
|
||||
private String secretKey = "sk";
|
||||
|
||||
private String endpoint = "endpoint";
|
||||
|
||||
private String namespace = "namespace";
|
||||
|
||||
@Test
|
||||
@@ -58,18 +63,12 @@ public class NacosDataSourceFactoryBeanTests {
|
||||
doReturn(nacosDataSource).when(factoryBean).getObject();
|
||||
when(nacosDataSource.readSource()).thenReturn("{}");
|
||||
|
||||
assertEquals("NacosDataSourceFactoryBean getObject was wrong", nacosDataSource,
|
||||
factoryBean.getObject());
|
||||
assertEquals("NacosDataSource read source value was wrong", "{}",
|
||||
factoryBean.getObject().readSource());
|
||||
assertEquals("NacosDataSource converter was wrong", converter,
|
||||
factoryBean.getConverter());
|
||||
assertEquals("NacosDataSourceFactoryBean dataId was wrong", dataId,
|
||||
factoryBean.getDataId());
|
||||
assertEquals("NacosDataSourceFactoryBean groupId was wrong", groupId,
|
||||
factoryBean.getGroupId());
|
||||
assertEquals("NacosDataSourceFactoryBean serverAddr was wrong", serverAddr,
|
||||
factoryBean.getServerAddr());
|
||||
assertThat(factoryBean.getObject()).isEqualTo(nacosDataSource);
|
||||
assertThat(factoryBean.getObject().readSource()).isEqualTo("{}");
|
||||
assertThat(factoryBean.getConverter()).isEqualTo(converter);
|
||||
assertThat(factoryBean.getDataId()).isEqualTo(dataId);
|
||||
assertThat(factoryBean.getGroupId()).isEqualTo(groupId);
|
||||
assertThat(factoryBean.getServerAddr()).isEqualTo(serverAddr);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,25 +90,15 @@ public class NacosDataSourceFactoryBeanTests {
|
||||
doReturn(nacosDataSource).when(factoryBean).getObject();
|
||||
when(nacosDataSource.readSource()).thenReturn("{}");
|
||||
|
||||
assertEquals("NacosDataSourceFactoryBean getObject was wrong", nacosDataSource,
|
||||
factoryBean.getObject());
|
||||
assertEquals("NacosDataSource read source value was wrong", "{}",
|
||||
factoryBean.getObject().readSource());
|
||||
assertEquals("NacosDataSource converter was wrong", converter,
|
||||
factoryBean.getConverter());
|
||||
assertEquals("NacosDataSourceFactoryBean dataId was wrong", dataId,
|
||||
factoryBean.getDataId());
|
||||
assertEquals("NacosDataSourceFactoryBean groupId was wrong", groupId,
|
||||
factoryBean.getGroupId());
|
||||
assertEquals("NacosDataSourceFactoryBean namespace was wrong", namespace,
|
||||
factoryBean.getNamespace());
|
||||
assertEquals("NacosDataSourceFactoryBean endpoint was wrong", endpoint,
|
||||
factoryBean.getEndpoint());
|
||||
assertEquals("NacosDataSourceFactoryBean ak was wrong", accessKey,
|
||||
factoryBean.getAccessKey());
|
||||
assertEquals("NacosDataSourceFactoryBean sk was wrong", secretKey,
|
||||
factoryBean.getSecretKey());
|
||||
|
||||
assertThat(factoryBean.getObject()).isEqualTo(nacosDataSource);
|
||||
assertThat(factoryBean.getObject().readSource()).isEqualTo("{}");
|
||||
assertThat(factoryBean.getConverter()).isEqualTo(converter);
|
||||
assertThat(factoryBean.getDataId()).isEqualTo(dataId);
|
||||
assertThat(factoryBean.getGroupId()).isEqualTo(groupId);
|
||||
assertThat(factoryBean.getNamespace()).isEqualTo(namespace);
|
||||
assertThat(factoryBean.getEndpoint()).isEqualTo(endpoint);
|
||||
assertThat(factoryBean.getAccessKey()).isEqualTo(accessKey);
|
||||
assertThat(factoryBean.getSecretKey()).isEqualTo(secretKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.config.NacosDataSourceProperties;
|
||||
import com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
@@ -38,17 +36,12 @@ public class NacosDataSourcePropertiesTests {
|
||||
nacosDataSourceProperties.setGroupId("custom-group");
|
||||
nacosDataSourceProperties.setDataType("xml");
|
||||
|
||||
assertEquals("Nacos groupId was wrong", "custom-group",
|
||||
nacosDataSourceProperties.getGroupId());
|
||||
assertEquals("Nacos dataId was wrong", "sentinel",
|
||||
nacosDataSourceProperties.getDataId());
|
||||
assertEquals("Nacos default data type was wrong", "xml",
|
||||
nacosDataSourceProperties.getDataType());
|
||||
Assert.assertEquals("Nacos rule type was wrong", RuleType.FLOW,
|
||||
nacosDataSourceProperties.getRuleType());
|
||||
assertEquals("Nacos default factory bean was wrong",
|
||||
NacosDataSourceFactoryBean.class.getName(),
|
||||
nacosDataSourceProperties.getFactoryBeanName());
|
||||
assertThat(nacosDataSourceProperties.getGroupId()).isEqualTo("custom-group");
|
||||
assertThat(nacosDataSourceProperties.getDataId()).isEqualTo("sentinel");
|
||||
assertThat(nacosDataSourceProperties.getDataType()).isEqualTo("xml");
|
||||
assertThat(nacosDataSourceProperties.getRuleType()).isEqualTo(RuleType.FLOW);
|
||||
assertThat(nacosDataSourceProperties.getFactoryBeanName())
|
||||
.isEqualTo(NacosDataSourceFactoryBean.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,16 +53,11 @@ public class NacosDataSourcePropertiesTests {
|
||||
nacosDataSourceProperties.setNamespace("namespace");
|
||||
nacosDataSourceProperties.setRuleType(RuleType.SYSTEM);
|
||||
|
||||
assertEquals("Nacos ak was wrong", "ak",
|
||||
nacosDataSourceProperties.getAccessKey());
|
||||
assertEquals("Nacos sk was wrong", "sk",
|
||||
nacosDataSourceProperties.getSecretKey());
|
||||
assertEquals("Nacos endpoint was wrong", "endpoint",
|
||||
nacosDataSourceProperties.getEndpoint());
|
||||
assertEquals("Nacos namespace was wrong", "namespace",
|
||||
nacosDataSourceProperties.getNamespace());
|
||||
Assert.assertEquals("Nacos rule type was wrong", RuleType.SYSTEM,
|
||||
nacosDataSourceProperties.getRuleType());
|
||||
assertThat(nacosDataSourceProperties.getAccessKey()).isEqualTo("ak");
|
||||
assertThat(nacosDataSourceProperties.getSecretKey()).isEqualTo("sk");
|
||||
assertThat(nacosDataSourceProperties.getEndpoint()).isEqualTo("endpoint");
|
||||
assertThat(nacosDataSourceProperties.getNamespace()).isEqualTo("namespace");
|
||||
assertThat(nacosDataSourceProperties.getRuleType()).isEqualTo(RuleType.SYSTEM);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,18 +16,15 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.csp.sentinel.slots.block.AbstractRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
|
||||
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.system.SystemRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
@@ -36,52 +33,39 @@ public class RuleTypeTests {
|
||||
|
||||
@Test
|
||||
public void testGetByName() {
|
||||
assertFalse("empty str rule name was not null",
|
||||
RuleType.getByName("").isPresent());
|
||||
assertFalse("test rule name was not null",
|
||||
RuleType.getByName("test").isPresent());
|
||||
assertFalse("param_flow rule name was not null",
|
||||
RuleType.getByName("param_flow").isPresent());
|
||||
assertFalse("param rule name was not null",
|
||||
RuleType.getByName("param").isPresent());
|
||||
assertFalse("FLOW rule name was not null",
|
||||
RuleType.getByName("FLOW").isPresent());
|
||||
assertTrue("flow rule name was null", RuleType.getByName("flow").isPresent());
|
||||
assertTrue("degrade rule name was null",
|
||||
RuleType.getByName("degrade").isPresent());
|
||||
assertTrue("param-flow rule name was null",
|
||||
RuleType.getByName("param-flow").isPresent());
|
||||
assertTrue("system rule name was null", RuleType.getByName("system").isPresent());
|
||||
assertTrue("authority rule name was null",
|
||||
RuleType.getByName("authority").isPresent());
|
||||
assertEquals("flow rule name was not equals RuleType.FLOW", RuleType.FLOW,
|
||||
RuleType.getByName("flow").get());
|
||||
assertEquals("flow rule name was not equals RuleType.DEGRADE", RuleType.DEGRADE,
|
||||
RuleType.getByName("degrade").get());
|
||||
assertEquals("flow rule name was not equals RuleType.PARAM_FLOW",
|
||||
RuleType.PARAM_FLOW, RuleType.getByName("param-flow").get());
|
||||
assertEquals("flow rule name was not equals RuleType.SYSTEM", RuleType.SYSTEM,
|
||||
RuleType.getByName("system").get());
|
||||
assertEquals("flow rule name was not equals RuleType.AUTHORITY",
|
||||
RuleType.AUTHORITY, RuleType.getByName("authority").get());
|
||||
assertThat(RuleType.getByName("").isPresent()).isEqualTo(Boolean.FALSE);
|
||||
assertThat(RuleType.getByName("test").isPresent()).isEqualTo(Boolean.FALSE);
|
||||
assertThat(RuleType.getByName("param_flow").isPresent()).isEqualTo(Boolean.FALSE);
|
||||
assertThat(RuleType.getByName("param").isPresent()).isEqualTo(Boolean.FALSE);
|
||||
assertThat(RuleType.getByName("FLOW").isPresent()).isEqualTo(Boolean.FALSE);
|
||||
assertThat(RuleType.getByName("flow").isPresent()).isEqualTo(Boolean.TRUE);
|
||||
assertThat(RuleType.getByName("degrade").isPresent()).isEqualTo(Boolean.TRUE);
|
||||
assertThat(RuleType.getByName("param-flow").isPresent()).isEqualTo(Boolean.TRUE);
|
||||
assertThat(RuleType.getByName("system").isPresent()).isEqualTo(Boolean.TRUE);
|
||||
assertThat(RuleType.getByName("authority").isPresent()).isEqualTo(Boolean.TRUE);
|
||||
assertThat(RuleType.getByName("flow").get()).isEqualTo(RuleType.FLOW);
|
||||
assertThat(RuleType.getByName("degrade").get()).isEqualTo(RuleType.DEGRADE);
|
||||
assertThat(RuleType.getByName("param-flow").get()).isEqualTo(RuleType.PARAM_FLOW);
|
||||
assertThat(RuleType.getByName("system").get()).isEqualTo(RuleType.SYSTEM);
|
||||
assertThat(RuleType.getByName("authority").get()).isEqualTo(RuleType.AUTHORITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetByClass() {
|
||||
assertFalse("Object.class type type was not null",
|
||||
RuleType.getByClass(Object.class).isPresent());
|
||||
assertFalse("AbstractRule.class rule type was not null",
|
||||
RuleType.getByClass(AbstractRule.class).isPresent());
|
||||
assertTrue("FlowRule.class rule type was null",
|
||||
RuleType.getByClass(FlowRule.class).isPresent());
|
||||
assertTrue("DegradeRule.class rule type was null",
|
||||
RuleType.getByClass(DegradeRule.class).isPresent());
|
||||
assertTrue("ParamFlowRule.class rule type was null",
|
||||
RuleType.getByClass(ParamFlowRule.class).isPresent());
|
||||
assertTrue("SystemRule.class rule type was null",
|
||||
RuleType.getByClass(SystemRule.class).isPresent());
|
||||
assertTrue("AuthorityRule.class rule type was null",
|
||||
RuleType.getByClass(AuthorityRule.class).isPresent());
|
||||
assertThat(RuleType.getByClass(Object.class).isPresent())
|
||||
.isEqualTo(Boolean.FALSE);
|
||||
assertThat(RuleType.getByClass(AbstractRule.class).isPresent())
|
||||
.isEqualTo(Boolean.FALSE);
|
||||
assertThat(RuleType.getByClass(FlowRule.class).isPresent())
|
||||
.isEqualTo(Boolean.TRUE);
|
||||
assertThat(RuleType.getByClass(DegradeRule.class).isPresent())
|
||||
.isEqualTo(Boolean.TRUE);
|
||||
assertThat(RuleType.getByClass(ParamFlowRule.class).isPresent())
|
||||
.isEqualTo(Boolean.TRUE);
|
||||
assertThat(RuleType.getByClass(SystemRule.class).isPresent())
|
||||
.isEqualTo(Boolean.TRUE);
|
||||
assertThat(RuleType.getByClass(AuthorityRule.class).isPresent())
|
||||
.isEqualTo(Boolean.TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,23 +16,22 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter;
|
||||
import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter;
|
||||
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
@@ -48,27 +47,23 @@ public class SentinelConverterTests {
|
||||
JsonConverter jsonConverter = new JsonConverter(objectMapper, FlowRule.class);
|
||||
List<FlowRule> flowRules = (List<FlowRule>) jsonConverter
|
||||
.convert(readFileContent("classpath: flowrule.json"));
|
||||
assertEquals("json converter flow rule size was wrong", 1, flowRules.size());
|
||||
assertEquals("json converter flow rule resource name was wrong", "resource",
|
||||
flowRules.get(0).getResource());
|
||||
assertEquals("json converter flow rule limit app was wrong", "default",
|
||||
flowRules.get(0).getLimitApp());
|
||||
assertEquals("json converter flow rule count was wrong", "1.0",
|
||||
String.valueOf(flowRules.get(0).getCount()));
|
||||
assertEquals("json converter flow rule control behavior was wrong",
|
||||
RuleConstant.CONTROL_BEHAVIOR_DEFAULT,
|
||||
flowRules.get(0).getControlBehavior());
|
||||
assertEquals("json converter flow rule strategy was wrong",
|
||||
RuleConstant.STRATEGY_DIRECT, flowRules.get(0).getStrategy());
|
||||
assertEquals("json converter flow rule grade was wrong",
|
||||
RuleConstant.FLOW_GRADE_QPS, flowRules.get(0).getGrade());
|
||||
|
||||
assertThat(flowRules.size()).isEqualTo(1);
|
||||
assertThat(flowRules.get(0).getResource()).isEqualTo("resource");
|
||||
assertThat(flowRules.get(0).getLimitApp()).isEqualTo("default");
|
||||
assertThat(String.valueOf(flowRules.get(0).getCount())).isEqualTo("1.0");
|
||||
assertThat(flowRules.get(0).getControlBehavior())
|
||||
.isEqualTo(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
|
||||
assertThat(flowRules.get(0).getStrategy())
|
||||
.isEqualTo(RuleConstant.STRATEGY_DIRECT);
|
||||
assertThat(flowRules.get(0).getGrade()).isEqualTo(RuleConstant.FLOW_GRADE_QPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConverterEmptyContent() {
|
||||
JsonConverter jsonConverter = new JsonConverter(objectMapper, FlowRule.class);
|
||||
List<FlowRule> flowRules = (List<FlowRule>) jsonConverter.convert("");
|
||||
assertEquals("json converter flow rule size was not empty", 0, flowRules.size());
|
||||
assertThat(flowRules.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
@@ -88,34 +83,25 @@ public class SentinelConverterTests {
|
||||
XmlConverter jsonConverter = new XmlConverter(xmlMapper, FlowRule.class);
|
||||
List<FlowRule> flowRules = (List<FlowRule>) jsonConverter
|
||||
.convert(readFileContent("classpath: flowrule.xml"));
|
||||
assertEquals("xml converter flow rule size was wrong", 2, flowRules.size());
|
||||
assertEquals("xml converter flow rule1 resource name was wrong", "resource",
|
||||
flowRules.get(0).getResource());
|
||||
assertEquals("xml converter flow rule2 limit app was wrong", "default",
|
||||
flowRules.get(0).getLimitApp());
|
||||
assertEquals("xml converter flow rule1 count was wrong", "1.0",
|
||||
String.valueOf(flowRules.get(0).getCount()));
|
||||
assertEquals("xml converter flow rule1 control behavior was wrong",
|
||||
RuleConstant.CONTROL_BEHAVIOR_DEFAULT,
|
||||
flowRules.get(0).getControlBehavior());
|
||||
assertEquals("xml converter flow rule1 strategy was wrong",
|
||||
RuleConstant.STRATEGY_DIRECT, flowRules.get(0).getStrategy());
|
||||
assertEquals("xml converter flow rule1 grade was wrong",
|
||||
RuleConstant.FLOW_GRADE_QPS, flowRules.get(0).getGrade());
|
||||
|
||||
assertEquals("xml converter flow rule2 resource name was wrong", "test",
|
||||
flowRules.get(1).getResource());
|
||||
assertEquals("xml converter flow rule2 limit app was wrong", "default",
|
||||
flowRules.get(1).getLimitApp());
|
||||
assertEquals("xml converter flow rule2 count was wrong", "1.0",
|
||||
String.valueOf(flowRules.get(1).getCount()));
|
||||
assertEquals("xml converter flow rule2 control behavior was wrong",
|
||||
RuleConstant.CONTROL_BEHAVIOR_DEFAULT,
|
||||
flowRules.get(1).getControlBehavior());
|
||||
assertEquals("xml converter flow rule2 strategy was wrong",
|
||||
RuleConstant.STRATEGY_DIRECT, flowRules.get(1).getStrategy());
|
||||
assertEquals("xml converter flow rule2 grade was wrong",
|
||||
RuleConstant.FLOW_GRADE_QPS, flowRules.get(1).getGrade());
|
||||
assertThat(flowRules.size()).isEqualTo(2);
|
||||
assertThat(flowRules.get(0).getResource()).isEqualTo("resource");
|
||||
assertThat(flowRules.get(0).getLimitApp()).isEqualTo("default");
|
||||
assertThat(String.valueOf(flowRules.get(0).getCount())).isEqualTo("1.0");
|
||||
assertThat(flowRules.get(0).getControlBehavior())
|
||||
.isEqualTo(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
|
||||
assertThat(flowRules.get(0).getStrategy())
|
||||
.isEqualTo(RuleConstant.STRATEGY_DIRECT);
|
||||
assertThat(flowRules.get(0).getGrade()).isEqualTo(RuleConstant.FLOW_GRADE_QPS);
|
||||
|
||||
assertThat(flowRules.get(1).getResource()).isEqualTo("test");
|
||||
assertThat(flowRules.get(1).getLimitApp()).isEqualTo("default");
|
||||
assertThat(String.valueOf(flowRules.get(1).getCount())).isEqualTo("1.0");
|
||||
assertThat(flowRules.get(1).getControlBehavior())
|
||||
.isEqualTo(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
|
||||
assertThat(flowRules.get(1).getStrategy())
|
||||
.isEqualTo(RuleConstant.STRATEGY_DIRECT);
|
||||
assertThat(flowRules.get(1).getGrade()).isEqualTo(RuleConstant.FLOW_GRADE_QPS);
|
||||
}
|
||||
|
||||
private String readFileContent(String file) {
|
||||
|
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,18 +16,17 @@
|
||||
|
||||
package com.alibaba.cloud.sentinel.datasource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter;
|
||||
import com.alibaba.cloud.sentinel.datasource.factorybean.ZookeeperDataSourceFactoryBean;
|
||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||
import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
@@ -35,7 +34,9 @@ import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource;
|
||||
public class ZookeeperDataSourceFactoryBeanTests {
|
||||
|
||||
private String dataId = "dataId";
|
||||
|
||||
private String groupId = "groupId";
|
||||
|
||||
private String serverAddr = "localhost:2181";
|
||||
|
||||
private String path = "/sentinel";
|
||||
@@ -57,18 +58,12 @@ public class ZookeeperDataSourceFactoryBeanTests {
|
||||
when(zookeeperDataSource.readSource()).thenReturn("{}");
|
||||
doReturn(zookeeperDataSource).when(factoryBean).getObject();
|
||||
|
||||
assertEquals("ZookeeperDataSource getObject was wrong", zookeeperDataSource,
|
||||
factoryBean.getObject());
|
||||
assertEquals("ZookeeperDataSource read source value was wrong", "{}",
|
||||
factoryBean.getObject().readSource());
|
||||
assertEquals("ZookeeperDataSourceFactoryBean dataId was wrong", dataId,
|
||||
factoryBean.getDataId());
|
||||
assertEquals("ZookeeperDataSourceFactoryBean converter was wrong", converter,
|
||||
factoryBean.getConverter());
|
||||
assertEquals("ZookeeperDataSourceFactoryBean groupId was wrong", groupId,
|
||||
factoryBean.getGroupId());
|
||||
assertEquals("ZookeeperDataSourceFactoryBean serverAddr was wrong", serverAddr,
|
||||
factoryBean.getServerAddr());
|
||||
assertThat(factoryBean.getObject()).isEqualTo(zookeeperDataSource);
|
||||
assertThat(factoryBean.getObject().readSource()).isEqualTo("{}");
|
||||
assertThat(factoryBean.getDataId()).isEqualTo(dataId);
|
||||
assertThat(factoryBean.getConverter()).isEqualTo(converter);
|
||||
assertThat(factoryBean.getGroupId()).isEqualTo(groupId);
|
||||
assertThat(factoryBean.getServerAddr()).isEqualTo(serverAddr);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,16 +82,11 @@ public class ZookeeperDataSourceFactoryBeanTests {
|
||||
when(zookeeperDataSource.readSource()).thenReturn("{}");
|
||||
doReturn(zookeeperDataSource).when(factoryBean).getObject();
|
||||
|
||||
assertEquals("ZookeeperDataSource value was wrong", zookeeperDataSource,
|
||||
factoryBean.getObject());
|
||||
assertEquals("ZookeeperDataSource read source value was wrong", "{}",
|
||||
factoryBean.getObject().readSource());
|
||||
assertEquals("ZookeeperDataSourceFactoryBean converter was wrong", converter,
|
||||
factoryBean.getConverter());
|
||||
assertEquals("ZookeeperDataSourceFactoryBean path was wrong", path,
|
||||
factoryBean.getPath());
|
||||
assertEquals("ZookeeperDataSourceFactoryBean serverAddr was wrong", serverAddr,
|
||||
factoryBean.getServerAddr());
|
||||
assertThat(factoryBean.getObject()).isEqualTo(zookeeperDataSource);
|
||||
assertThat(factoryBean.getObject().readSource()).isEqualTo("{}");
|
||||
assertThat(factoryBean.getConverter()).isEqualTo(converter);
|
||||
assertThat(factoryBean.getPath()).isEqualTo(path);
|
||||
assertThat(factoryBean.getServerAddr()).isEqualTo(serverAddr);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user