ConfigurableCodaHaleMetricFilter implements MetricFilter { @Override public boolean matches(String s, Metric metric) { if (!isFilterEnabled()) { return true; } boolean matchesFilter = archaiusPropertyFactory.getBooleanProperty(s, false).get(); LOGGER.debug("Does metric [{}] match filter? [{}]",s,matchesFilter); return matchesFilter; } ConfigurableCodaHaleMetricFilter(DynamicPropertyFactory archaiusPropertyFactory); @Override boolean matches(String s, Metric metric);  }
@Test public void testMetricConfiguredInFilterWithFilterEnabled() { when(archiausPropertyFactory.getBooleanProperty(eq("filter.graphite.metrics"), any(Boolean.class))).thenReturn(DYNAMIC_BOOLEAN_TRUE); ConfigurableCodaHaleMetricFilter filter = new ConfigurableCodaHaleMetricFilter(archiausPropertyFactory); assertTrue(filter.matches("this.metric.is.allowed", metric)); }
@Test public void testMetricConfiguredInFilterWithFilterDisabled() { when(archiausPropertyFactory.getBooleanProperty(eq("filter.graphite.metrics"), any(Boolean.class))).thenReturn(DYNAMIC_BOOLEAN_FALSE); ConfigurableCodaHaleMetricFilter filter = new ConfigurableCodaHaleMetricFilter(archiausPropertyFactory); assertTrue(filter.matches("this.metric.is.allowed", metric)); }
@Test public void testMetricNotConfiguredInFilterWithFilterEnabled() { when(archiausPropertyFactory.getBooleanProperty(eq("filter.graphite.metrics"), any(Boolean.class))).thenReturn(DYNAMIC_BOOLEAN_TRUE); ConfigurableCodaHaleMetricFilter filter = new ConfigurableCodaHaleMetricFilter(archiausPropertyFactory); assertFalse(filter.matches("this.metric.is.not.allowed", metric)); }
@Test public void testMetricNotConfiguredInFilterWithFilterDisabled() { when(archiausPropertyFactory.getBooleanProperty(eq("filter.graphite.metrics"), any(Boolean.class))).thenReturn(DYNAMIC_BOOLEAN_FALSE); ConfigurableCodaHaleMetricFilter filter = new ConfigurableCodaHaleMetricFilter(archiausPropertyFactory); assertTrue(filter.matches("this.metric.is.not.allowed", metric)); }