use of org.apache.beam.sdk.metrics.Counter in project beam by apache.
the class LabeledMetricsTest method testOperationsUpdateCounterFromContainerWhenContainerIsPresent.
@Test
public void testOperationsUpdateCounterFromContainerWhenContainerIsPresent() {
HashMap<String, String> labels = new HashMap<String, String>();
String urn = MonitoringInfoConstants.Urns.ELEMENT_COUNT;
MonitoringInfoMetricName name = MonitoringInfoMetricName.named(urn, labels);
MetricsContainer mockContainer = Mockito.mock(MetricsContainer.class);
Counter mockCounter = Mockito.mock(Counter.class);
when(mockContainer.getCounter(name)).thenReturn(mockCounter);
Counter counter = LabeledMetrics.counter(name);
MetricsEnvironment.setCurrentContainer(mockContainer);
counter.inc();
verify(mockCounter).inc(1);
counter.inc(47L);
verify(mockCounter).inc(47);
counter.dec(5L);
verify(mockCounter).inc(-5);
}
use of org.apache.beam.sdk.metrics.Counter in project beam by apache.
the class LabeledMetricsTest method testCounterDoesNotFailOperationsWhenNoMetricsContainerPresent.
@Test
public void testCounterDoesNotFailOperationsWhenNoMetricsContainerPresent() {
MetricsEnvironment.setCurrentContainer(null);
assertNull(MetricsEnvironment.getCurrentContainer());
HashMap<String, String> labels = new HashMap<String, String>();
String urn = MonitoringInfoConstants.Urns.ELEMENT_COUNT;
MonitoringInfoMetricName name = MonitoringInfoMetricName.named(urn, labels);
Counter counter = LabeledMetrics.counter(name);
counter.inc();
counter.inc(5L);
counter.dec();
counter.dec(5L);
}
use of org.apache.beam.sdk.metrics.Counter in project beam by apache.
the class FlinkMetricContainerTest method testCounter.
@Test
public void testCounter() {
SimpleCounter flinkCounter = new SimpleCounter();
when(metricGroup.counter("namespace.name")).thenReturn(flinkCounter);
MetricsContainer step = container.getMetricsContainer("step");
MetricName metricName = MetricName.named("namespace", "name");
Counter counter = step.getCounter(metricName);
counter.inc();
counter.inc();
assertThat(flinkCounter.getCount(), is(0L));
container.updateMetrics("step");
assertThat(flinkCounter.getCount(), is(2L));
}
use of org.apache.beam.sdk.metrics.Counter in project beam by apache.
the class PipelineRunnerTest method testRunPTransform.
@Test
@Category({ NeedsRunner.class, UsesCommittedMetrics.class, UsesCounterMetrics.class })
public void testRunPTransform() {
final String namespace = PipelineRunnerTest.class.getName();
final Counter counter = Metrics.counter(namespace, "count");
final PipelineResult result = PipelineRunner.fromOptions(p.getOptions()).run(new PTransform<PBegin, POutput>() {
@Override
public POutput expand(PBegin input) {
PCollection<Double> output = input.apply(Create.of(1, 2, 3, 4)).apply("ScaleByTwo", MapElements.via(new ScaleFn<>(2.0, counter)));
PAssert.that(output).containsInAnyOrder(2.0, 4.0, 6.0, 8.0);
return output;
}
});
// Checking counters to verify the pipeline actually ran.
assertThat(result.metrics().queryMetrics(MetricsFilter.builder().addNameFilter(MetricNameFilter.inNamespace(namespace)).build()).getCounters(), hasItem(metricsResult(namespace, "count", "ScaleByTwo", 4L, true)));
}
Aggregations