RegexMetricFilter implements MetricFilter { @Override public boolean matches(final String s, final Metric metric) { if (includes != null && excludes != null) { return includes.matcher(s).matches() && !excludes.matcher(s).matches(); } if (includes != null) { return includes.matcher(s).matches(); } if (excludes != null) { return !excludes.matcher(s).matches(); } return true; } RegexMetricFilter(final String includes, final String excludes); @Override boolean matches(final String s, final Metric metric);  }
@Test public void matchesNoExclusions() { final RegexMetricFilter filter = new RegexMetricFilter(null, null); Assert.assertTrue(filter.matches("rexster.server.http", null)); Assert.assertTrue(filter.matches("rexster.server.http.vertices", null)); Assert.assertTrue(filter.matches("rexster.server.http.edges", null)); Assert.assertTrue(filter.matches("rexster.server.rexpro.edges", null)); }
@Test public void matchesHasInclusions() { final RegexMetricFilter filter = new RegexMetricFilter("rexster.server.http.*", null); Assert.assertTrue(filter.matches("rexster.server.http", null)); Assert.assertTrue(filter.matches("rexster.server.http.vertices", null)); Assert.assertTrue(filter.matches("rexster.server.http.edges", null)); Assert.assertFalse(filter.matches("rexster.server.rexpro.edges", null)); }
@Test public void matchesHasMultipleInclusions() { final RegexMetricFilter filter = new RegexMetricFilter("rexster.server.http.vertices|rexster.server.rexpro.*", null); Assert.assertFalse(filter.matches("rexster.server.http", null)); Assert.assertTrue(filter.matches("rexster.server.http.vertices", null)); Assert.assertFalse(filter.matches("rexster.server.http.edges", null)); Assert.assertTrue(filter.matches("rexster.server.rexpro.edges", null)); }
@Test public void matchesHasExclusion() { final RegexMetricFilter filter = new RegexMetricFilter(null, "rexster.server.rexpro.*"); Assert.assertTrue(filter.matches("rexster.server.http", null)); Assert.assertTrue(filter.matches("rexster.server.http.vertices", null)); Assert.assertTrue(filter.matches("rexster.server.http.edges", null)); Assert.assertFalse(filter.matches("rexster.server.rexpro.edges", null)); }
@Test public void matchesHasMultipleExclusions() { final RegexMetricFilter filter = new RegexMetricFilter(null, "rexster.server.rexpro.edges|rexster.server.http.edges"); Assert.assertTrue(filter.matches("rexster.server.http", null)); Assert.assertTrue(filter.matches("rexster.server.http.vertices", null)); Assert.assertFalse(filter.matches("rexster.server.http.edges", null)); Assert.assertFalse(filter.matches("rexster.server.rexpro.edges", null)); }
@Test public void matchesHasInclusionAndExclusion() { final RegexMetricFilter filter = new RegexMetricFilter("rexster.server.http.vertices", "rexster.server.rexpro.*"); Assert.assertFalse(filter.matches("rexster.server.http", null)); Assert.assertTrue(filter.matches("rexster.server.http.vertices", null)); Assert.assertFalse(filter.matches("rexster.server.http.edges", null)); Assert.assertFalse(filter.matches("rexster.server.rexpro.edges", null)); }
@Test public void matchesHasConflictingInclusionAndExclusion() { final RegexMetricFilter filter = new RegexMetricFilter("rexster.server.http.*", "rexster.server.http.*"); Assert.assertFalse(filter.matches("rexster.server.http", null)); Assert.assertFalse(filter.matches("rexster.server.http.vertices", null)); Assert.assertFalse(filter.matches("rexster.server.http.edges", null)); Assert.assertFalse(filter.matches("rexster.server.rexpro.edges", null)); }