Search in sources :

Example 1 with TestCounter

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);
}
Also used : TestCounter(org.apache.flink.metrics.util.TestCounter) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with TestCounter

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);
}
Also used : TestCounter(org.apache.flink.metrics.util.TestCounter) Counter(org.apache.flink.metrics.Counter) TestCounter(org.apache.flink.metrics.util.TestCounter) Test(org.junit.jupiter.api.Test)

Example 3 with TestCounter

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);
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) TestMeter(org.apache.flink.metrics.util.TestMeter) Metric(org.apache.flink.metrics.Metric) TestCounter(org.apache.flink.metrics.util.TestCounter) Test(org.junit.jupiter.api.Test) DatagramSocket(java.net.DatagramSocket) HashSet(java.util.HashSet) MetricGroup(org.apache.flink.metrics.MetricGroup) SocketException(java.net.SocketException) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Map(java.util.Map) ConfigConstants(org.apache.flink.configuration.ConfigConstants) Gauge(org.apache.flink.metrics.Gauge) SimpleCounter(org.apache.flink.metrics.SimpleCounter) DatagramPacket(java.net.DatagramPacket) Counter(org.apache.flink.metrics.Counter) MetricConfig(org.apache.flink.metrics.MetricConfig) TestCounter(org.apache.flink.metrics.util.TestCounter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) Test(org.junit.jupiter.api.Test)

Example 4 with TestCounter

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);
}
Also used : TestCounter(org.apache.flink.metrics.util.TestCounter) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

TestCounter (org.apache.flink.metrics.util.TestCounter)4 Test (org.junit.jupiter.api.Test)4 HashSet (java.util.HashSet)3 Counter (org.apache.flink.metrics.Counter)2 IOException (java.io.IOException)1 DatagramPacket (java.net.DatagramPacket)1 DatagramSocket (java.net.DatagramSocket)1 SocketException (java.net.SocketException)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TimeoutException (java.util.concurrent.TimeoutException)1 ConfigConstants (org.apache.flink.configuration.ConfigConstants)1 Gauge (org.apache.flink.metrics.Gauge)1 Metric (org.apache.flink.metrics.Metric)1 MetricConfig (org.apache.flink.metrics.MetricConfig)1 MetricGroup (org.apache.flink.metrics.MetricGroup)1 SimpleCounter (org.apache.flink.metrics.SimpleCounter)1 UnregisteredMetricsGroup (org.apache.flink.metrics.groups.UnregisteredMetricsGroup)1 TestHistogram (org.apache.flink.metrics.util.TestHistogram)1