Fix NullPointerExceptions in MetricFilteringBolt

This happened because MetricDefinitionAndTenantIdMatcher wasn't handling
the same Alarm Definition being added. This happens because there are
multiple MetricFilteringBolts using the same
MetricDefinitionAndTenantIdMatcher. The Alarm Definition is now
checked if is already there before being added

Change-Id: I9f382e8da5193b60a64dbe40c9fcf321fc47766f
This commit is contained in:
Craig Bryant 2015-06-05 10:52:54 -06:00
parent 9c4bd6cc99
commit c400895872
2 changed files with 11 additions and 5 deletions

View File

@ -57,7 +57,9 @@ public class MetricDefinitionAndTenantIdMatcher {
}
final AlarmDefinitionDimensions dimensionSet =
createDimensionSet(metricDefinitionAndTenantId.metricDefinition, alarmDefinitionId);
alarmDefDimensions.add(dimensionSet);
if (!alarmDefDimensions.contains(dimensionSet)) {
alarmDefDimensions.add(dimensionSet);
}
}
private AlarmDefinitionDimensions createDimensionSet(MetricDefinition metricDefinition,

View File

@ -19,6 +19,7 @@ package monasca.thresh.domain.model;
import static org.testng.Assert.assertEqualsNoOrder;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import monasca.common.model.metric.MetricDefinition;
@ -132,23 +133,26 @@ public class MetricDefinitionAndTenantIdMatcherTest {
final String groupMatchId = getNextId();
matcher.add(groupMatch, groupMatchId);
// Add it twice just to make sure that doesn't cause problems
matcher.add(groupMatch, groupMatchId);
verifyMatch(toMatch, noMatchId, hostMatchId, groupMatchId);
matcher.add(toMatch, toMatchId);
verifyMatch(toMatch, noMatchId, hostMatchId, groupMatchId, toMatchId);
matcher.remove(groupMatch, groupMatchId);
assertTrue(matcher.remove(groupMatch, groupMatchId));
verifyMatch(toMatch, noMatchId, hostMatchId, toMatchId);
matcher.remove(noMatch, noMatchId);
assertTrue(matcher.remove(noMatch, noMatchId));
verifyMatch(toMatch, hostMatchId, toMatchId);
matcher.remove(toMatch, toMatchId);
assertTrue(matcher.remove(toMatch, toMatchId));
verifyMatch(toMatch, hostMatchId);
// Remove it again to ensure it won't throw an exception if the MetricDefinitionAndTenantId
// doesn't exist
matcher.remove(toMatch, toMatchId);
assertFalse(matcher.remove(toMatch, toMatchId));
final MetricDefinitionAndTenantId loadMetric =
new MetricDefinitionAndTenantId(new MetricDefinition("load", new HashMap<String, String>(