Search in sources :

Example 1 with WatchGrowthFn

use of org.apache.beam.sdk.transforms.Watch.WatchGrowthFn in project beam by apache.

the class WatchTest method testPollingGrowthTrackerUsesElementTimestampIfNoWatermarkProvided.

@Test
public void testPollingGrowthTrackerUsesElementTimestampIfNoWatermarkProvided() throws Exception {
    Instant now = Instant.now();
    Watch.Growth<String, String, String> growth = Watch.growthOf(new Watch.Growth.PollFn<String, String>() {

        @Override
        public PollResult<String> apply(String element, Context c) throws Exception {
            // We specifically test an unsorted list.
            return PollResult.incomplete(Arrays.asList(TimestampedValue.of("d", now.plus(standardSeconds(4))), TimestampedValue.of("c", now.plus(standardSeconds(3))), TimestampedValue.of("a", now.plus(standardSeconds(1))), TimestampedValue.of("b", now.plus(standardSeconds(2)))));
        }
    }).withPollInterval(standardSeconds(10));
    WatchGrowthFn<String, String, String, Integer> growthFn = new WatchGrowthFn(growth, StringUtf8Coder.of(), SerializableFunctions.identity(), StringUtf8Coder.of());
    GrowthTracker<String, Integer> tracker = newPollingGrowthTracker();
    DoFn.ProcessContext context = mock(DoFn.ProcessContext.class);
    ManualWatermarkEstimator<Instant> watermarkEstimator = new WatermarkEstimators.Manual(BoundedWindow.TIMESTAMP_MIN_VALUE);
    ProcessContinuation processContinuation = growthFn.process(context, tracker, watermarkEstimator);
    assertEquals(now.plus(standardSeconds(1)), watermarkEstimator.currentWatermark());
    assertTrue(processContinuation.shouldResume());
}
Also used : Instant(org.joda.time.Instant) WatchGrowthFn(org.apache.beam.sdk.transforms.Watch.WatchGrowthFn) ProcessContinuation(org.apache.beam.sdk.transforms.DoFn.ProcessContinuation) PollFn(org.apache.beam.sdk.transforms.Watch.Growth.PollFn) Test(org.junit.Test)

Example 2 with WatchGrowthFn

use of org.apache.beam.sdk.transforms.Watch.WatchGrowthFn in project beam by apache.

the class WatchTest method testNonPollingGrowthTrackerIgnoresWatermark.

@Test
public void testNonPollingGrowthTrackerIgnoresWatermark() throws Exception {
    Instant now = Instant.now();
    PollResult<String> claim = PollResult.incomplete(Arrays.asList(TimestampedValue.of("d", now.plus(standardSeconds(4))), TimestampedValue.of("c", now.plus(standardSeconds(3))), TimestampedValue.of("a", now.plus(standardSeconds(1))), TimestampedValue.of("b", now.plus(standardSeconds(2))))).withWatermark(now.plus(standardSeconds(7)));
    Watch.Growth<String, String, String> growth = Watch.growthOf(new Watch.Growth.PollFn<String, String>() {

        @Override
        public PollResult<String> apply(String element, Context c) throws Exception {
            fail("Never expected to be invoked for NonPollingGrowthState.");
            return null;
        }
    }).withPollInterval(standardSeconds(10));
    GrowthTracker<String, Integer> tracker = newTracker(NonPollingGrowthState.of(claim));
    WatchGrowthFn<String, String, String, Integer> growthFn = new WatchGrowthFn(growth, StringUtf8Coder.of(), SerializableFunctions.identity(), StringUtf8Coder.of());
    DoFn.ProcessContext context = mock(DoFn.ProcessContext.class);
    ManualWatermarkEstimator<Instant> watermarkEstimator = new WatermarkEstimators.Manual(BoundedWindow.TIMESTAMP_MIN_VALUE);
    ProcessContinuation processContinuation = growthFn.process(context, tracker, watermarkEstimator);
    assertEquals(BoundedWindow.TIMESTAMP_MIN_VALUE, watermarkEstimator.currentWatermark());
    assertFalse(processContinuation.shouldResume());
}
Also used : Instant(org.joda.time.Instant) WatchGrowthFn(org.apache.beam.sdk.transforms.Watch.WatchGrowthFn) ProcessContinuation(org.apache.beam.sdk.transforms.DoFn.ProcessContinuation) PollFn(org.apache.beam.sdk.transforms.Watch.Growth.PollFn) Test(org.junit.Test)

Aggregations

ProcessContinuation (org.apache.beam.sdk.transforms.DoFn.ProcessContinuation)2 PollFn (org.apache.beam.sdk.transforms.Watch.Growth.PollFn)2 WatchGrowthFn (org.apache.beam.sdk.transforms.Watch.WatchGrowthFn)2 Instant (org.joda.time.Instant)2 Test (org.junit.Test)2