added test for parsing strings
This commit is contained in:
parent
b06f1703e6
commit
e102817f30
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@
|
|||||||
*.project
|
*.project
|
||||||
*.target/
|
*.target/
|
||||||
*.settings/
|
*.settings/
|
||||||
|
.idea
|
||||||
target/
|
target/
|
||||||
test-output/
|
test-output/
|
||||||
test-config.yml
|
test-config.yml
|
||||||
|
@ -14,26 +14,52 @@ import com.hpcloud.mon.common.model.metric.MetricDefinition;
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public class AlarmExpressionTest {
|
public class AlarmExpressionTest {
|
||||||
public void shouldParseExpression() {
|
public void shouldParseExpression() {
|
||||||
AlarmExpression expr = new AlarmExpression(
|
AlarmExpression expr = new AlarmExpression(
|
||||||
"avg(hpcs.compute{instance_id=5,metric_name=cpu,device=1}, 1) > 5 times 3 and avg(hpcs.compute{flavor_id=3,metric_name=mem}, 2) < 4 times 3");
|
"avg(hpcs.compute{instance_id=5,metric_name=cpu,device=1}, 1) > 5 times 3 and avg(hpcs.compute{flavor_id=3,metric_name=mem}, 2) < 4 times 3");
|
||||||
List<AlarmSubExpression> alarms = expr.getSubExpressions();
|
List<AlarmSubExpression> alarms = expr.getSubExpressions();
|
||||||
|
|
||||||
AlarmSubExpression expected1 = new AlarmSubExpression(AggregateFunction.AVG,
|
AlarmSubExpression expected1 = new AlarmSubExpression(AggregateFunction.AVG,
|
||||||
new MetricDefinition("hpcs.compute", ImmutableMap.<String, String>builder()
|
new MetricDefinition("hpcs.compute", ImmutableMap.<String, String>builder()
|
||||||
.put("instance_id", "5")
|
.put("instance_id", "5")
|
||||||
.put("metric_name", "cpu")
|
.put("metric_name", "cpu")
|
||||||
.put("device", "1")
|
.put("device", "1")
|
||||||
.build()), AlarmOperator.GT, 5, 1, 3);
|
.build()), AlarmOperator.GT, 5, 1, 3);
|
||||||
AlarmSubExpression expected2 = new AlarmSubExpression(AggregateFunction.AVG,
|
AlarmSubExpression expected2 = new AlarmSubExpression(AggregateFunction.AVG,
|
||||||
new MetricDefinition("hpcs.compute", ImmutableMap.<String, String>builder()
|
new MetricDefinition("hpcs.compute", ImmutableMap.<String, String>builder()
|
||||||
.put("flavor_id", "3")
|
.put("flavor_id", "3")
|
||||||
.put("metric_name", "mem")
|
.put("metric_name", "mem")
|
||||||
.build()), AlarmOperator.LT, 4, 2, 3);
|
.build()), AlarmOperator.LT, 4, 2, 3);
|
||||||
|
|
||||||
assertEquals(alarms.get(0), expected1);
|
assertEquals(alarms.get(0), expected1);
|
||||||
assertEquals(alarms.get(1), expected2);
|
assertEquals(alarms.get(1), expected2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void shouldParseString() {
|
||||||
|
|
||||||
|
|
||||||
|
AlarmExpression expr = new AlarmExpression(
|
||||||
|
"avg(hpcs.compute{instance_id=5,metric_name=cpu,device=1, url=\"https://www.google.com/?startpage=3&happygoing\"}, 1) > 5 times 3 and avg(hpcs.compute{flavor_id=3,metric_name=mem, specialchars=\"!@#$%^&*()~<>{}[],.\"}, 2) < 4 times 3");
|
||||||
|
List<AlarmSubExpression> alarms = expr.getSubExpressions();
|
||||||
|
|
||||||
|
AlarmSubExpression expected1 = new AlarmSubExpression(AggregateFunction.AVG,
|
||||||
|
new MetricDefinition("hpcs.compute", ImmutableMap.<String, String>builder()
|
||||||
|
.put("instance_id", "5")
|
||||||
|
.put("metric_name", "cpu")
|
||||||
|
.put("url","\"https://www.google.com/?startpage=3&happygoing\"" )
|
||||||
|
.put("device", "1")
|
||||||
|
.build()), AlarmOperator.GT, 5, 1, 3);
|
||||||
|
|
||||||
|
AlarmSubExpression expected2 = new AlarmSubExpression(AggregateFunction.AVG,
|
||||||
|
new MetricDefinition("hpcs.compute", ImmutableMap.<String, String>builder()
|
||||||
|
.put("flavor_id", "3")
|
||||||
|
.put("metric_name", "mem")
|
||||||
|
.put("specialchars","\"!@#$%^&*()~<>{}[],.\"")
|
||||||
|
.build()), AlarmOperator.LT, 4, 2, 3);
|
||||||
|
|
||||||
|
assertEquals(alarms.get(0), expected1);
|
||||||
|
assertEquals(alarms.get(1), expected2);
|
||||||
|
}
|
||||||
|
|
||||||
public void shouldParseExpressionWithoutType() {
|
public void shouldParseExpressionWithoutType() {
|
||||||
AlarmExpression expr = new AlarmExpression(
|
AlarmExpression expr = new AlarmExpression(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user