Search in sources :

Example 1 with FileDataSourceProperties

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");
}
Also used : FileDataSourceProperties(com.alibaba.cloud.sentinel.datasource.config.FileDataSourceProperties) Test(org.junit.Test)

Example 2 with FileDataSourceProperties

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());
}
Also used : FileDataSourceProperties(com.alibaba.cloud.sentinel.datasource.config.FileDataSourceProperties) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) IOException(java.io.IOException) FileRefreshableDataSource(com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with FileDataSourceProperties

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);
}
Also used : FileRefreshableDataSourceFactoryBean(com.alibaba.cloud.sentinel.datasource.factorybean.FileRefreshableDataSourceFactoryBean) FileDataSourceProperties(com.alibaba.cloud.sentinel.datasource.config.FileDataSourceProperties) Test(org.junit.Test)

Example 4 with FileDataSourceProperties

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);
}
Also used : FileDataSourceProperties(com.alibaba.cloud.sentinel.datasource.config.FileDataSourceProperties) Test(org.junit.Test)

Aggregations

FileDataSourceProperties (com.alibaba.cloud.sentinel.datasource.config.FileDataSourceProperties)4 Test (org.junit.Test)4 FileRefreshableDataSourceFactoryBean (com.alibaba.cloud.sentinel.datasource.factorybean.FileRefreshableDataSourceFactoryBean)1 FileRefreshableDataSource (com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource)1 FlowRule (com.alibaba.csp.sentinel.slots.block.flow.FlowRule)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 List (java.util.List)1