@Test public void testThatPercolationNotificationWorks() throws IOException, InterruptedException { SimpleNotifier notifier = new SimpleNotifier(); MetricFilter percolationFilter = new MetricFilter() { @Override public boolean matches(String name, Metric metric) { return name.startsWith(prefix + ".foo"); } }; elasticsearchReporter = createElasticsearchReporterBuilder() .percolationFilter(percolationFilter) .percolationNotifier(notifier) .build(); final Counter evictions = registry.counter("foo"); evictions.inc(18); reportAndRefresh(); QueryBuilder queryBuilder = QueryBuilders.boolQuery() .must(QueryBuilders.matchAllQuery()) .filter( QueryBuilders.boolQuery() .must(QueryBuilders.rangeQuery("count").gte(20)) .must(QueryBuilders.termQuery("name", prefix + ".foo"))); String json = String.format("{ \"query\" : %s }", queryBuilder.buildAsBytes().toUtf8()); client() .prepareIndex(indexWithDate, ".percolator", "myName") .setRefresh(true) .setSource(json) .execute() .actionGet(); evictions.inc(1); reportAndRefresh(); assertThat(notifier.metrics.size(), is(0)); evictions.inc(2); reportAndRefresh(); org.assertj.core.api.Assertions.assertThat(notifier.metrics.size()).isEqualTo(1); org.assertj.core.api.Assertions.assertThat(notifier.metrics).containsKey("myName"); org.assertj.core.api.Assertions.assertThat(notifier.metrics.get("myName").name()) .isEqualTo(prefix + ".foo"); notifier.metrics.clear(); evictions.dec(2); reportAndRefresh(); org.assertj.core.api.Assertions.assertThat(notifier.metrics.size()).isEqualTo(0); }
@Test public void decrementsByAnArbitraryDelta() throws Exception { counter.dec(12); assertThat(counter.getCount()).isEqualTo(-12); }
@Test public void decrementsByOne() throws Exception { counter.dec(); assertThat(counter.getCount()).isEqualTo(-1); }