使用Aggregator测试Metrics.Counter值的方法

时间:2023-01-07 15:34:40

With Aggregators being removed as of Beam 2, is there a preferred way to test Counter value, like I did with Aggregators:

从Beam 2开始删除Aggregators,是否有一种测试Counter值的首选方法,就像我使用Aggregators一样:

assertThat(tester.getAggregatorValue(fn.success)).isEqualTo(1);
assertThat(tester.getAggregatorValue(fn.failure)).isEqualTo(0);
assertThat(tester.getAggregatorValue(fn.empty)).isEqualTo(0);

Where tester is an instance od DoFnTester class and fn instance of my DoFn implementation, with aggregators success, failure and empty being final package-private visible fields.

其中tester是DoFnTester类的实例和我的DoFn实现的实例,聚合器成功,失败和空是最终的包 - 私有可见字段。

1 个解决方案

#1


1  

This is similar to a question asked on the user@beam.apache.org list recently.

这类似于最近在user@beam.apache.org列表中提出的问题。

The answer there suggested installing a MetricsContainerImpl before running the test, and interacting with that, like Beam does for its existing tests (eg., LateDataDroppingDoFnRunnerTest).

答案是建议在运行测试之前安装MetricsContainerImpl,并与之进行交互,就像Beam对其现有的测试(例如,LateDataDroppingDoFnRunnerTest)进行交互。

They also encapsulated it in a TestRule:

他们还将其封装在TestRule中:

@Rule TestMetrics metrics = new TestMetrics();

@Test
public void invalids() {
  final DoFnTester<InputT, OutputT> doFnTester =
    DoFnTester.of(fixture);
  doFnTester.processElement(input);

  assertThat(metrics,counterValue(fixture.ctr), is(1L));
}

#1


1  

This is similar to a question asked on the user@beam.apache.org list recently.

这类似于最近在user@beam.apache.org列表中提出的问题。

The answer there suggested installing a MetricsContainerImpl before running the test, and interacting with that, like Beam does for its existing tests (eg., LateDataDroppingDoFnRunnerTest).

答案是建议在运行测试之前安装MetricsContainerImpl,并与之进行交互,就像Beam对其现有的测试(例如,LateDataDroppingDoFnRunnerTest)进行交互。

They also encapsulated it in a TestRule:

他们还将其封装在TestRule中:

@Rule TestMetrics metrics = new TestMetrics();

@Test
public void invalids() {
  final DoFnTester<InputT, OutputT> doFnTester =
    DoFnTester.of(fixture);
  doFnTester.processElement(input);

  assertThat(metrics,counterValue(fixture.ctr), is(1L));
}