use of org.joda.time.Instant in project beam by apache.
the class WatermarkManagerTest method timerUpdateBuilderWithSetAtEndOfTime.
@Test
public void timerUpdateBuilderWithSetAtEndOfTime() {
Instant timerStamp = BoundedWindow.TIMESTAMP_MAX_VALUE;
TimerData tooFar = TimerData.of(StateNamespaces.global(), timerStamp, TimeDomain.EVENT_TIME);
TimerUpdateBuilder builder = TimerUpdate.builder(StructuralKey.empty());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(timerStamp.toString());
builder.setTimer(tooFar);
}
use of org.joda.time.Instant in project beam by apache.
the class WatermarkManagerTest method extractFiredTimersReturnsFiredSynchronizedProcessingTimeTimers.
@Test
public void extractFiredTimersReturnsFiredSynchronizedProcessingTimeTimers() {
Collection<FiredTimers> initialTimers = manager.extractFiredTimers();
// Watermarks haven't advanced
assertThat(initialTimers, emptyIterable());
// Advance WM of keyed past the first timer, but ahead of the second and third
CommittedBundle<Integer> createdBundle = multiWindowedBundle(filtered);
manager.updateWatermarks(null, TimerUpdate.empty(), result(graph.getProducer(createdInts), null, Collections.singleton(createdBundle)), new Instant(1500L));
TimerData earliestTimer = TimerData.of(StateNamespaces.global(), new Instant(999L), TimeDomain.SYNCHRONIZED_PROCESSING_TIME);
TimerData middleTimer = TimerData.of(StateNamespaces.global(), new Instant(5000L), TimeDomain.SYNCHRONIZED_PROCESSING_TIME);
TimerData lastTimer = TimerData.of(StateNamespaces.global(), new Instant(10000L), TimeDomain.SYNCHRONIZED_PROCESSING_TIME);
StructuralKey<byte[]> key = StructuralKey.of(new byte[] { 2, -2, 22 }, ByteArrayCoder.of());
TimerUpdate update = TimerUpdate.builder(key).setTimer(lastTimer).setTimer(earliestTimer).setTimer(middleTimer).build();
manager.updateWatermarks(createdBundle, update, result(graph.getProducer(filtered), createdBundle.withElements(Collections.<WindowedValue<Integer>>emptyList()), Collections.<CommittedBundle<?>>singleton(multiWindowedBundle(intsToFlatten))), new Instant(1000L));
manager.refreshAll();
Collection<FiredTimers> firstFiredTimers = manager.extractFiredTimers();
assertThat(firstFiredTimers, not(Matchers.<FiredTimers>emptyIterable()));
FiredTimers firstFired = Iterables.getOnlyElement(firstFiredTimers);
assertThat(firstFired.getTimers(), contains(earliestTimer));
clock.set(new Instant(50_000L));
manager.updateWatermarks(null, TimerUpdate.empty(), result(graph.getProducer(createdInts), null, Collections.<CommittedBundle<?>>emptyList()), new Instant(50_000L));
manager.refreshAll();
Collection<FiredTimers> secondFiredTimers = manager.extractFiredTimers();
assertThat(secondFiredTimers, not(Matchers.<FiredTimers>emptyIterable()));
FiredTimers secondFired = Iterables.getOnlyElement(secondFiredTimers);
// Contains, in order, middleTimer and then lastTimer
assertThat(secondFired.getTimers(), contains(middleTimer, lastTimer));
}
use of org.joda.time.Instant in project beam by apache.
the class WatermarkManagerTest method timerUpdateBuilderWithSetPastEndOfTime.
@Test
public void timerUpdateBuilderWithSetPastEndOfTime() {
Instant timerStamp = BoundedWindow.TIMESTAMP_MAX_VALUE.plus(Duration.standardMinutes(2));
TimerData tooFar = TimerData.of(StateNamespaces.global(), timerStamp, TimeDomain.EVENT_TIME);
TimerUpdateBuilder builder = TimerUpdate.builder(StructuralKey.empty());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(timerStamp.toString());
builder.setTimer(tooFar);
}
use of org.joda.time.Instant in project beam by apache.
the class WatermarkManagerTest method getWatermarksAfterHoldAndEmptyOutput.
/**
* Demonstrates that after watermarks of an upstream transform are updated, but no output has been
* produced, and the downstream transform has a watermark hold, the watermark is held to the hold.
*/
@Test
public void getWatermarksAfterHoldAndEmptyOutput() {
CommittedBundle<Integer> firstCreateOutput = multiWindowedBundle(createdInts, 1, 2);
manager.updateWatermarks(null, TimerUpdate.empty(), result(graph.getProducer(createdInts), null, Collections.<CommittedBundle<?>>singleton(firstCreateOutput)), new Instant(12_000L));
CommittedBundle<Integer> firstFilterOutput = multiWindowedBundle(filtered);
manager.updateWatermarks(firstCreateOutput, TimerUpdate.empty(), result(graph.getProducer(filtered), firstCreateOutput.withElements(Collections.<WindowedValue<Integer>>emptyList()), Collections.<CommittedBundle<?>>singleton(firstFilterOutput)), new Instant(10_000L));
manager.refreshAll();
TransformWatermarks firstFilterWatermarks = manager.getWatermarks(graph.getProducer(filtered));
assertThat(firstFilterWatermarks.getInputWatermark(), not(earlierThan(new Instant(12_000L))));
assertThat(firstFilterWatermarks.getOutputWatermark(), not(laterThan(new Instant(10_000L))));
CommittedBundle<Integer> emptyCreateOutput = multiWindowedBundle(createdInts);
manager.updateWatermarks(null, TimerUpdate.empty(), result(graph.getProducer(createdInts), null, Collections.<CommittedBundle<?>>singleton(emptyCreateOutput)), BoundedWindow.TIMESTAMP_MAX_VALUE);
manager.refreshAll();
TransformWatermarks updatedSourceWatermarks = manager.getWatermarks(graph.getProducer(createdInts));
assertThat(updatedSourceWatermarks.getOutputWatermark(), not(earlierThan(BoundedWindow.TIMESTAMP_MAX_VALUE)));
TransformWatermarks finishedFilterWatermarks = manager.getWatermarks(graph.getProducer(filtered));
assertThat(finishedFilterWatermarks.getInputWatermark(), not(earlierThan(BoundedWindow.TIMESTAMP_MAX_VALUE)));
assertThat(finishedFilterWatermarks.getOutputWatermark(), not(laterThan(new Instant(10_000L))));
}
use of org.joda.time.Instant in project beam by apache.
the class WatermarkManagerTest method updateWatermarkWithWatermarkHolds.
/**
* Demonstrates that the watermark of an {@link AppliedPTransform} is held to the provided
* watermark hold.
*/
@Test
public void updateWatermarkWithWatermarkHolds() {
CommittedBundle<Integer> createdBundle = timestampedBundle(createdInts, TimestampedValue.of(1, new Instant(1_000_000L)), TimestampedValue.of(2, new Instant(1234L)), TimestampedValue.of(3, new Instant(-1000L)));
manager.updateWatermarks(null, TimerUpdate.empty(), result(graph.getProducer(createdInts), null, Collections.<CommittedBundle<?>>singleton(createdBundle)), new Instant(Long.MAX_VALUE));
CommittedBundle<KV<String, Integer>> keyBundle = timestampedBundle(keyed, TimestampedValue.of(KV.of("MyKey", 1), new Instant(1_000_000L)), TimestampedValue.of(KV.of("MyKey", 2), new Instant(1234L)), TimestampedValue.of(KV.of("MyKey", 3), new Instant(-1000L)));
manager.updateWatermarks(createdBundle, TimerUpdate.empty(), result(graph.getProducer(keyed), createdBundle.withElements(Collections.<WindowedValue<Integer>>emptyList()), Collections.<CommittedBundle<?>>singleton(keyBundle)), new Instant(500L));
manager.refreshAll();
TransformWatermarks keyedWatermarks = manager.getWatermarks(graph.getProducer(keyed));
assertThat(keyedWatermarks.getInputWatermark(), not(earlierThan(BoundedWindow.TIMESTAMP_MAX_VALUE)));
assertThat(keyedWatermarks.getOutputWatermark(), not(laterThan(new Instant(500L))));
}
Aggregations