use of com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource in project Sentinel by alibaba.
the class NacosDataSourceDemo method loadMyNamespaceRules.
private static void loadMyNamespaceRules() {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, remoteAddress);
properties.put(PropertyKeyConst.NAMESPACE, NACOS_NAMESPACE_ID);
ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new NacosDataSource<>(properties, groupId, dataId, source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {
}));
FlowRuleManager.register2Property(flowRuleDataSource.getProperty());
}
use of com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource in project spring-cloud-alibaba by alibaba.
the class NacosDataSourceFactoryBeanTests method testNacosFactoryBeanServerAddr.
@Test
public void testNacosFactoryBeanServerAddr() throws Exception {
NacosDataSourceFactoryBean factoryBean = spy(new NacosDataSourceFactoryBean());
Converter converter = mock(SentinelConverter.class);
factoryBean.setDataId(dataId);
factoryBean.setGroupId(groupId);
factoryBean.setServerAddr(serverAddr);
factoryBean.setContextPath(contextPath);
factoryBean.setConverter(converter);
NacosDataSource nacosDataSource = mock(NacosDataSource.class);
doReturn(nacosDataSource).when(factoryBean).getObject();
when(nacosDataSource.readSource()).thenReturn("{}");
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);
assertThat(factoryBean.getContextPath()).isEqualTo(contextPath);
}
use of com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource in project spring-cloud-alibaba by alibaba.
the class NacosDataSourceFactoryBeanTests method testNacosFactoryBeanProperties.
@Test
public void testNacosFactoryBeanProperties() throws Exception {
NacosDataSourceFactoryBean factoryBean = spy(new NacosDataSourceFactoryBean());
Converter converter = mock(SentinelConverter.class);
factoryBean.setDataId(dataId);
factoryBean.setGroupId(groupId);
factoryBean.setAccessKey(accessKey);
factoryBean.setSecretKey(secretKey);
factoryBean.setEndpoint(endpoint);
factoryBean.setNamespace(namespace);
factoryBean.setConverter(converter);
NacosDataSource nacosDataSource = mock(NacosDataSource.class);
doReturn(nacosDataSource).when(factoryBean).getObject();
when(nacosDataSource.readSource()).thenReturn("{}");
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);
}
Aggregations