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,
|
||||
@@ -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