use of org.joda.time.Instant in project beam by apache.
the class AfterDelayFromFirstElementStateMachine method onMerge.
@Override
public void onMerge(OnMergeContext c) throws Exception {
// If the trigger is already finished, there is no way it will become re-activated
if (c.trigger().isFinished()) {
StateMerging.clear(c.state(), DELAYED_UNTIL_TAG);
// NOTE: We do not attempt to delete the timers.
return;
}
// Determine the earliest point across all the windows, and delay to that.
StateMerging.mergeCombiningValues(c.state(), DELAYED_UNTIL_TAG);
Instant earliestTargetTime = c.state().access(DELAYED_UNTIL_TAG).read();
if (earliestTargetTime != null) {
c.setTimer(earliestTargetTime, timeDomain);
}
}
use of org.joda.time.Instant in project beam by apache.
the class AfterDelayFromFirstElementStateMachine method onElement.
@Override
public void onElement(OnElementContext c) throws Exception {
GroupingState<Instant, Instant> delayUntilState = c.state().access(DELAYED_UNTIL_TAG);
Instant oldDelayUntil = delayUntilState.read();
// ignore anyhow, we don't bother with it if it is already set.
if (oldDelayUntil != null) {
return;
}
Instant targetTimestamp = getTargetTimestamp(c);
delayUntilState.add(targetTimestamp);
c.setTimer(targetTimestamp, timeDomain);
}
use of org.joda.time.Instant in project beam by apache.
the class InMemoryStateInternalsTest method testMergeEarliestWatermarkIntoSource.
@Test
public void testMergeEarliestWatermarkIntoSource() throws Exception {
WatermarkHoldState value1 = underTest.state(NAMESPACE_1, WATERMARK_EARLIEST_ADDR);
WatermarkHoldState value2 = underTest.state(NAMESPACE_2, WATERMARK_EARLIEST_ADDR);
value1.add(new Instant(3000));
value2.add(new Instant(5000));
value1.add(new Instant(4000));
value2.add(new Instant(2000));
// Merging clears the old values and updates the merged value.
StateMerging.mergeWatermarks(Arrays.asList(value1, value2), value1, WINDOW_1);
assertThat(value1.read(), equalTo(new Instant(2000)));
assertThat(value2.read(), equalTo(null));
}
use of org.joda.time.Instant in project beam by apache.
the class InMemoryStateInternalsTest method testWatermarkLatestState.
@Test
public void testWatermarkLatestState() throws Exception {
WatermarkHoldState value = underTest.state(NAMESPACE_1, WATERMARK_LATEST_ADDR);
// State instances are cached, but depend on the namespace.
assertEquals(value, underTest.state(NAMESPACE_1, WATERMARK_LATEST_ADDR));
assertFalse(value.equals(underTest.state(NAMESPACE_2, WATERMARK_LATEST_ADDR)));
assertThat(value.read(), Matchers.nullValue());
value.add(new Instant(2000));
assertThat(value.read(), equalTo(new Instant(2000)));
value.add(new Instant(3000));
assertThat(value.read(), equalTo(new Instant(3000)));
value.add(new Instant(1000));
assertThat(value.read(), equalTo(new Instant(3000)));
value.clear();
assertThat(value.read(), equalTo(null));
assertThat(underTest.state(NAMESPACE_1, WATERMARK_LATEST_ADDR), Matchers.sameInstance(value));
}
use of org.joda.time.Instant in project beam by apache.
the class InMemoryStateInternalsTest method testWatermarkEarliestState.
@Test
public void testWatermarkEarliestState() throws Exception {
WatermarkHoldState value = underTest.state(NAMESPACE_1, WATERMARK_EARLIEST_ADDR);
// State instances are cached, but depend on the namespace.
assertEquals(value, underTest.state(NAMESPACE_1, WATERMARK_EARLIEST_ADDR));
assertFalse(value.equals(underTest.state(NAMESPACE_2, WATERMARK_EARLIEST_ADDR)));
assertThat(value.read(), Matchers.nullValue());
value.add(new Instant(2000));
assertThat(value.read(), equalTo(new Instant(2000)));
value.add(new Instant(3000));
assertThat(value.read(), equalTo(new Instant(2000)));
value.add(new Instant(1000));
assertThat(value.read(), equalTo(new Instant(1000)));
value.clear();
assertThat(value.read(), equalTo(null));
assertThat(underTest.state(NAMESPACE_1, WATERMARK_EARLIEST_ADDR), Matchers.sameInstance(value));
}
Aggregations