private List<MeasurementPattern> createMeasurementPatterns(Measurement measurement) { List<MeasurementPattern> result = null; if (measurement != null) { result = new ArrayList<MeasurementPattern>(); for (MeasurementSpecification s : measurement.patterns) { result.add(new MeasurementPattern(s.metric, s.measure)); } } return result; }
@Test public void qualifiedNameMeasurement() { PredicateConfig pc = new PredicateConfig("white", new ArrayList()); MetricPredicateTransformer.PredicateConfigMetricPredicate pred = (MetricPredicateTransformer.PredicateConfigMetricPredicate) MetricPredicateTransformer.generatePredicate(pc); Measurement type = new Measurement("white", true); MeasurementPattern pattern = new MeasurementPattern( "^com.addthis.metrics.reporter.config.PredicateConfigTest.+", "min"); List<MeasurementPattern> patternList = new ArrayList<MeasurementPattern>(); patternList.add(pattern); MetricName name1 = new MetricName(PredicateConfigTest.class, "name", "scope"); assertTrue(pred.allowMeasurement(name1, "min", type, patternList)); MetricName name2 = new MetricName(PredicateConfig.class, "name", "scope"); assertFalse(pred.allowMeasurement(name2, "min", type, patternList)); }
@Test public void multiWhiteMeasurement() { MeasurementPattern pattern1 = new MeasurementPattern("^foo.+", "^bar.+"); MeasurementPattern pattern2 = new MeasurementPattern(".*foo$", ".*bar$"); List<MeasurementPattern> patternList = new ArrayList<MeasurementPattern>(); patternList.add(pattern1); patternList.add(pattern2); Measurement type = new Measurement("white", false); assertFalse(PredicateConfig.allowMeasurement("hello", "world", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("hellofooworld", "hellobarworld", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("hellobarworld", "hellofooworld", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("fooworld", "barworld", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("hellofoo", "hellobar", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("foohellofoo", "barhellobar", type, patternList)); }
@Test public void multiBlackMeasurement() { MeasurementPattern pattern1 = new MeasurementPattern("^foo.+", "^bar.+"); MeasurementPattern pattern2 = new MeasurementPattern(".*foo$", ".*bar$"); List<MeasurementPattern> patternList = new ArrayList<MeasurementPattern>(); patternList.add(pattern1); patternList.add(pattern2); Measurement type = new Measurement("black", false); assertTrue(PredicateConfig.allowMeasurement("hello", "world", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("hellofooworld", "hellobarworld", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("hellobarworld", "hellofooworld", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("fooworld", "barworld", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("hellofoo", "hellobar", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("foohellofoo", "barhellobar", type, patternList)); }
private List<MeasurementPattern> createMeasurementPatterns(Measurement measurement) { List<MeasurementPattern> result = null; if (measurement != null) { result = new ArrayList<MeasurementPattern>(); for (MeasurementSpecification s : measurement.patterns) { result.add(new MeasurementPattern(s.metric, s.measure)); } } return result; }
@Test public void singleBlackMeasurement() { MeasurementPattern pattern = new MeasurementPattern("^foo.+", "^bar.+"); List<MeasurementPattern> patternList = new ArrayList<MeasurementPattern>(); patternList.add(pattern); Measurement type = new Measurement("black", false); assertTrue(PredicateConfig.allowMeasurement("foo", "bar", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("foo", "bars", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("foos", "bar", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("foos", "bars", type, patternList)); }
@Test public void singleWhiteMeasurement() { MeasurementPattern pattern = new MeasurementPattern("^foo.+", "^bar.+"); List<MeasurementPattern> patternList = new ArrayList<MeasurementPattern>(); patternList.add(pattern); Measurement type = new Measurement("white", false); assertFalse(PredicateConfig.allowMeasurement("foo", "bar", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("foo", "bars", type, patternList)); assertFalse(PredicateConfig.allowMeasurement("foos", "bar", type, patternList)); assertTrue(PredicateConfig.allowMeasurement("foos", "bars", type, patternList)); }