本文整理了Java中com.eudemon.ratelimiter.rule.parser.YamlRuleConfigParser.<init>()
方法的一些代码示例,展示了YamlRuleConfigParser.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlRuleConfigParser.<init>()
方法的具体详情如下:
包路径:com.eudemon.ratelimiter.rule.parser.YamlRuleConfigParser
类名称:YamlRuleConfigParser
方法名:<init>
暂无
代码示例来源:origin: wangzheng0822/ratelimiter4j
/**
* Obtain {@link RuleConfigParser}.
*
* @param ruleConfigSource the rule config source which can be null.
* @return the input parameter {@code ruleConfigSource} if not null, otherwise return a new
* {@link RuleConfigSource}.
*/
public RuleConfigParser obtainRuleConfigParser(RuleConfigParser ruleConfigParser) {
/* create according to SPI */
if (ruleConfigParser == null) {
ruleConfigParser = ExtensionLoader.getExtension(RuleConfigParser.class, false);
}
/* create according to configuration */
if (ruleConfigParser == null) {
String parserType = RateLimiterConfig.instance().getRuleConfigParserType();
// TODO(zheng): ugly code, refactor it!
if (parserType.equals("yaml")) {
ruleConfigParser = new YamlRuleConfigParser();
} else if (parserType.equals("json")) {
ruleConfigParser = new JsonRuleConfigParser();
}
}
/* use default rule config source. */
if (ruleConfigParser == null) {
ruleConfigParser = new YamlRuleConfigParser();
}
return ruleConfigParser;
}
代码示例来源:origin: wangzheng0822/ratelimiter4j
public void testParse_withInputStream() {
InputStream inputStream = new ByteArrayInputStream(VALID_YAML_1.getBytes());
YamlRuleConfigParser parser = new YamlRuleConfigParser();
UniformRuleConfigMapping result = parser.parse(inputStream);
Assert.assertNotNull(result);
System.out.println(result);
}
代码示例来源:origin: wangzheng0822/ratelimiter4j
@Test(expectedExceptions = {RuntimeException.class}, expectedExceptionsMessageRegExp = ".*init.*")
public void testLoad_withZkClientException() throws Exception {
CuratorFramework client = Mockito.mock(CuratorFramework.class);
doThrow(new RuntimeException()).when(client).start();
RuleConfigSource source =
new ZookeeperRuleConfigSource(client, new YamlRuleConfigParser());
source.load();
}
代码示例来源:origin: wangzheng0822/ratelimiter4j
@Test(expectedExceptions = {RuntimeException.class}, expectedExceptionsMessageRegExp = ".*init.*")
public void testLoad_withZkNodeCacheException() throws Exception {
CuratorFramework client = Mockito.mock(CuratorFramework.class);
doNothing().when(client).start();
RuleConfigSource source = new ZookeeperRuleConfigSource(client, new YamlRuleConfigParser());
source.load();
}
代码示例来源:origin: wangzheng0822/ratelimiter4j
@Test(expectedExceptions = {ConfigurationResolveException.class } )
public void testParse_withInvalidYaml() throws YAMLException {
YamlRuleConfigParser parser = new YamlRuleConfigParser();
parser.parse(INVALID_YAML_1);
}
代码示例来源:origin: wangzheng0822/ratelimiter4j
@Test(expectedExceptions = {ConfigurationResolveException.class } )
public void testParse_withInvalidInputStream() throws YAMLException {
InputStream inputStream = new ByteArrayInputStream(INVALID_YAML_1.getBytes());
YamlRuleConfigParser parser = new YamlRuleConfigParser();
parser.parse(inputStream);
}
代码示例来源:origin: wangzheng0822/ratelimiter4j
@Test(expectedExceptions = {RuntimeException.class},
expectedExceptionsMessageRegExp = ".*address.*")
public void testLoad_withEmptyAddrOrPath() {
RuleConfigSource source = new ZookeeperRuleConfigSource("", "", new YamlRuleConfigParser());
source.load();
}
代码示例来源:origin: wangzheng0822/ratelimiter4j
@Test(expectedExceptions = {ConfigurationResolveException.class})
public void testLoad_withValidData() throws Exception {
CuratorFramework client = Mockito.mock(CuratorFramework.class);
doNothing().when(client).start();
when(client.blockUntilConnected(anyInt(), any())).thenReturn(true);
String ruleStr = "invalid string";
GetDataBuilder dataBuilder = new GetDataBuilderImpl(null, null, null, null, false) {
@Override
public byte[] forPath(String path) throws Exception {
return ruleStr.getBytes("UTF-8");
}
};
when(client.getData()).thenReturn(dataBuilder);
RuleConfigSource source = new ZookeeperRuleConfigSource(client, new YamlRuleConfigParser());
source.load();
}
代码示例来源:origin: wangzheng0822/ratelimiter4j
public void testParse() throws IOException {
YamlRuleConfigParser parser = new YamlRuleConfigParser();
UniformRuleConfigMapping result = parser.parse(VALID_YAML_1);
Assert.assertNotNull(result);
Assert.assertTrue(result.getConfigs().size() == 2);
print(result);
System.out.println(System.getProperty("line.separator"));
}
代码示例来源:origin: wangzheng0822/ratelimiter4j
public MemoryUrlRateLimiter build() {
RuleConfigParser parser = null;
if (this.ruleParserType.equals("yaml")) {
parser = new YamlRuleConfigParser();
} else if (this.ruleParserType.equals("json")) {
parser = new JsonRuleConfigParser();
} else {
throw new RuntimeException("Do not support the rule paser type: " + this.ruleParserType);
}
RuleConfigSource source = null;
if (this.ruleSourceType.equals("file")) {
source = new FileRuleConfigSource();
} else if (this.ruleSourceType.equals("zookeeper")) {
if (zookeeperConfig != null && StringUtils.isNoneBlank(zookeeperConfig.getAddress())
&& StringUtils.isNoneBlank(zookeeperConfig.getPath())) {
source = new ZookeeperRuleConfigSource(zookeeperConfig.getAddress(),
zookeeperConfig.getPath(), parser);
} else {
throw new RuntimeException("some zookeeper configuration is empty.");
}
} else {
throw new RuntimeException("Do not support the rule source type: " + this.ruleSourceType);
}
MemoryUrlRateLimiter ratelimiter = new MemoryUrlRateLimiter(source);
if (this.interceptors != null && !this.interceptors.isEmpty()) {
ratelimiter.addInteceptors(interceptors);
}
return ratelimiter;
}
代码示例来源:origin: wangzheng0822/ratelimiter4j
public void testLoad_withEmptyData() throws Exception {
CuratorFramework client = Mockito.mock(CuratorFramework.class);
doNothing().when(client).start();
when(client.blockUntilConnected(anyInt(), any())).thenReturn(true);
String ruleStr = "";
GetDataBuilder dataBuilder = new GetDataBuilderImpl(null, null, null, null, false) {
@Override
public byte[] forPath(String path) throws Exception {
return ruleStr.getBytes("UTF-8");
}
};
when(client.getData()).thenReturn(dataBuilder);
RuleConfigSource source = new ZookeeperRuleConfigSource(client, new YamlRuleConfigParser());
UniformRuleConfigMapping mapping = source.load();
assertNull(mapping);
mapping = source.load();
assertNull(mapping);
}
代码示例来源:origin: wangzheng0822/ratelimiter4j
parser = new YamlRuleConfigParser();
} else if (this.ruleParserType.equals("json")) {
parser = new JsonRuleConfigParser();
代码示例来源:origin: wangzheng0822/ratelimiter4j
new ZookeeperRuleConfigSource(client, new YamlRuleConfigParser());
UniformRuleConfigMapping mapping = source.load();
assertNotNull(mapping);
内容来源于网络,如有侵权,请联系作者删除!