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());
}
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());
}
Aggregations