use of com.alibaba.cloud.sentinel.datasource.config.FileDataSourceProperties in project spring-cloud-alibaba by alibaba.
the class DataSourcePropertiesTests method testFileException.
@Test(expected = RuntimeException.class)
public void testFileException() {
FileDataSourceProperties fileDataSourceProperties = new FileDataSourceProperties();
fileDataSourceProperties.setFile("classpath: 1.json");
fileDataSourceProperties.preCheck("test-ds");
}
use of com.alibaba.cloud.sentinel.datasource.config.FileDataSourceProperties in project spring-cloud-alibaba by alibaba.
the class DataSourcePropertiesTests method testPostRegister.
@Test
public void testPostRegister() throws Exception {
FileDataSourceProperties fileDataSourceProperties = new FileDataSourceProperties();
fileDataSourceProperties.setFile("classpath: flowrule.json");
fileDataSourceProperties.setRuleType(RuleType.FLOW);
FileRefreshableDataSource fileRefreshableDataSource = new FileRefreshableDataSource(ResourceUtils.getFile(StringUtils.trimAllWhitespace(fileDataSourceProperties.getFile())).getAbsolutePath(), new Converter<String, List<FlowRule>>() {
ObjectMapper objectMapper = new ObjectMapper();
@Override
public List<FlowRule> convert(String source) {
try {
return objectMapper.readValue(source, new TypeReference<List<FlowRule>>() {
});
} catch (IOException e) {
// ignore
}
return null;
}
});
fileDataSourceProperties.postRegister(fileRefreshableDataSource);
assertThat(FlowRuleManager.getRules()).isEqualTo(fileRefreshableDataSource.loadConfig());
}
use of com.alibaba.cloud.sentinel.datasource.config.FileDataSourceProperties in project spring-cloud-alibaba by alibaba.
the class DataSourcePropertiesTests method testFileDefaultValue.
@Test
public void testFileDefaultValue() {
FileDataSourceProperties fileDataSourceProperties = new FileDataSourceProperties();
fileDataSourceProperties.setFile("/tmp/test.json");
fileDataSourceProperties.setRuleType(RuleType.PARAM_FLOW);
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);
}
use of com.alibaba.cloud.sentinel.datasource.config.FileDataSourceProperties in project spring-cloud-alibaba by alibaba.
the class DataSourcePropertiesTests method testFileCustomValue.
@Test
public void testFileCustomValue() {
FileDataSourceProperties fileDataSourceProperties = new FileDataSourceProperties();
fileDataSourceProperties.setFile("/tmp/test.json");
fileDataSourceProperties.setBufSize(1024);
fileDataSourceProperties.setRecommendRefreshMs(2000);
fileDataSourceProperties.setCharset("ISO8859-1");
assertThat(fileDataSourceProperties.getFile()).isEqualTo("/tmp/test.json");
assertThat(fileDataSourceProperties.getCharset()).isEqualTo("ISO8859-1");
assertThat(fileDataSourceProperties.getRecommendRefreshMs()).isEqualTo(2000L);
assertThat(fileDataSourceProperties.getBufSize()).isEqualTo(1024);
}
Aggregations