use of org.apache.flink.metrics.util.TestCounter in project flink by apache.
the class StatsDReporterTest method testStatsDCountersReporting.
/**
* Tests that counter are properly reported via the StatsD reporter.
*/
@Test
void testStatsDCountersReporting() throws Exception {
Set<String> expectedLines = new HashSet<>(2);
expectedLines.add("metric:100|g");
testMetricAndAssert(new TestCounter(100), "metric", expectedLines);
}
use of org.apache.flink.metrics.util.TestCounter in project flink by apache.
the class FlinkCounterWrapperTest method testWrapperIncDec.
@Test
void testWrapperIncDec() {
Counter counter = new TestCounter();
counter.inc();
FlinkCounterWrapper wrapper = new FlinkCounterWrapper(counter);
assertThat(wrapper.getCount()).isEqualTo(1L);
wrapper.dec();
assertThat(wrapper.getCount()).isEqualTo(0L);
wrapper.inc(2);
assertThat(wrapper.getCount()).isEqualTo(2L);
wrapper.dec(2);
assertThat(wrapper.getCount()).isEqualTo(0L);
}
use of org.apache.flink.metrics.util.TestCounter in project flink by apache.
the class StatsDReporterTest method testAddingMetrics.
/**
* Tests that the registered metrics' names don't contain invalid characters.
*/
@Test
void testAddingMetrics() {
String counterName = "testCounter";
final String scope = "scope";
final char delimiter = '_';
MetricGroup metricGroup = TestMetricGroup.newBuilder().setMetricIdentifierFunction((metricName, characterFilter) -> scope + delimiter + metricName).build();
TestingStatsDReporter reporter = new TestingStatsDReporter();
reporter.open(new MetricConfig());
SimpleCounter myCounter = new SimpleCounter();
reporter.notifyOfAddedMetric(myCounter, counterName, metricGroup);
Map<Counter, String> counters = reporter.getCounters();
assertThat(counters).containsKey(myCounter);
String expectedCounterName = reporter.filterCharacters(scope) + delimiter + reporter.filterCharacters(counterName);
assertThat(counters.get(myCounter)).isEqualTo(expectedCounterName);
}
use of org.apache.flink.metrics.util.TestCounter in project flink by apache.
the class StatsDReporterTest method testStatsDCountersReportingOfNegativeValues.
@Test
void testStatsDCountersReportingOfNegativeValues() throws Exception {
Set<String> expectedLines = new HashSet<>();
expectedLines.add("metric:0|g");
expectedLines.add("metric:-51|g");
testMetricAndAssert(new TestCounter(-51), "metric", expectedLines);
}
Aggregations