Search in sources :

Example 1 with LateDataFilter

use of org.apache.beam.runners.core.LateDataDroppingDoFnRunner.LateDataFilter in project beam by apache.

the class LateDataDroppingDoFnRunnerTest method testLateDataFilter.

@Test
public void testLateDataFilter() throws Exception {
    MetricsContainerImpl container = new MetricsContainerImpl("any");
    MetricsEnvironment.setCurrentContainer(container);
    when(mockTimerInternals.currentInputWatermarkTime()).thenReturn(new Instant(15L));
    LateDataFilter lateDataFilter = new LateDataFilter(WindowingStrategy.of(WINDOW_FN), mockTimerInternals);
    Iterable<WindowedValue<Integer>> actual = lateDataFilter.filter("a", ImmutableList.of(createDatum(13, 13L), // late element, earlier than 4L.
    createDatum(5, 5L), createDatum(16, 16L), createDatum(18, 18L)));
    Iterable<WindowedValue<Integer>> expected = ImmutableList.of(createDatum(13, 13L), createDatum(16, 16L), createDatum(18, 18L));
    assertThat(expected, containsInAnyOrder(Iterables.toArray(actual, WindowedValue.class)));
    long droppedValues = container.getCounter(MetricName.named(LateDataDroppingDoFnRunner.class, LateDataDroppingDoFnRunner.DROPPED_DUE_TO_LATENESS)).getCumulative().longValue();
    assertEquals(1, droppedValues);
    // Ensure that reiterating returns the same results and doesn't increment the counter again.
    assertThat(expected, containsInAnyOrder(Iterables.toArray(actual, WindowedValue.class)));
    droppedValues = container.getCounter(MetricName.named(LateDataDroppingDoFnRunner.class, LateDataDroppingDoFnRunner.DROPPED_DUE_TO_LATENESS)).getCumulative().longValue();
    assertEquals(1, droppedValues);
}
Also used : LateDataFilter(org.apache.beam.runners.core.LateDataDroppingDoFnRunner.LateDataFilter) MetricsContainerImpl(org.apache.beam.runners.core.metrics.MetricsContainerImpl) WindowedValue(org.apache.beam.sdk.util.WindowedValue) Instant(org.joda.time.Instant) Test(org.junit.Test)

Aggregations

LateDataFilter (org.apache.beam.runners.core.LateDataDroppingDoFnRunner.LateDataFilter)1 MetricsContainerImpl (org.apache.beam.runners.core.metrics.MetricsContainerImpl)1 WindowedValue (org.apache.beam.sdk.util.WindowedValue)1 Instant (org.joda.time.Instant)1 Test (org.junit.Test)1