use of org.apache.beam.runners.core.TimerInternals.TimerData in project beam by apache.
the class InMemoryTimerInternalsTest method testDeduplicate.
@Test
public void testDeduplicate() throws Exception {
InMemoryTimerInternals underTest = new InMemoryTimerInternals();
TimerData eventTime = TimerData.of(NS1, new Instant(19), TimeDomain.EVENT_TIME);
TimerData processingTime = TimerData.of(NS1, new Instant(19), TimeDomain.PROCESSING_TIME);
underTest.setTimer(eventTime);
underTest.setTimer(eventTime);
underTest.setTimer(processingTime);
underTest.setTimer(processingTime);
underTest.advanceProcessingTime(new Instant(20));
underTest.advanceInputWatermark(new Instant(20));
assertThat(underTest.removeNextProcessingTimer(), equalTo(processingTime));
assertThat(underTest.removeNextProcessingTimer(), nullValue());
assertThat(underTest.removeNextEventTimer(), equalTo(eventTime));
assertThat(underTest.removeNextEventTimer(), nullValue());
}
use of org.apache.beam.runners.core.TimerInternals.TimerData in project beam by apache.
the class ReduceFnTester method advanceInputWatermark.
/**
* Advance the input watermark to the specified time, firing any timers that should
* fire. Then advance the output watermark as far as possible.
*/
public void advanceInputWatermark(Instant newInputWatermark) throws Exception {
timerInternals.advanceInputWatermark(newInputWatermark);
ReduceFnRunner<String, InputT, OutputT, W> runner = createRunner();
while (true) {
TimerData timer;
List<TimerInternals.TimerData> timers = new ArrayList<>();
while ((timer = timerInternals.removeNextEventTimer()) != null) {
timers.add(timer);
}
if (timers.isEmpty()) {
break;
}
runner.onTimers(timers);
}
if (autoAdvanceOutputWatermark) {
Instant hold = stateInternals.earliestWatermarkHold();
if (hold == null) {
WindowTracing.trace("TestInMemoryTimerInternals.advanceInputWatermark: no holds, " + "so output watermark = input watermark");
hold = timerInternals.currentInputWatermarkTime();
}
advanceOutputWatermark(hold);
}
runner.persist();
}
use of org.apache.beam.runners.core.TimerInternals.TimerData in project beam by apache.
the class DirectTimerInternalsTest method deleteTimerDeletesOnBuilder.
@Test
public void deleteTimerDeletesOnBuilder() {
TimerData eventTimer = TimerData.of(StateNamespaces.global(), new Instant(20145L), TimeDomain.EVENT_TIME);
TimerData processingTimer = TimerData.of(StateNamespaces.global(), new Instant(125555555L), TimeDomain.PROCESSING_TIME);
TimerData synchronizedProcessingTimer = TimerData.of(StateNamespaces.global(), new Instant(98745632189L), TimeDomain.SYNCHRONIZED_PROCESSING_TIME);
internals.deleteTimer(eventTimer);
internals.deleteTimer(processingTimer);
internals.deleteTimer(synchronizedProcessingTimer);
assertThat(internals.getTimerUpdate().getDeletedTimers(), containsInAnyOrder(eventTimer, synchronizedProcessingTimer, processingTimer));
}
use of org.apache.beam.runners.core.TimerInternals.TimerData in project beam by apache.
the class EvaluationContextTest method extractFiredTimersExtractsTimers.
@Test
public void extractFiredTimersExtractsTimers() {
TransformResult<?> holdResult = StepTransformResult.withHold(createdProducer, new Instant(0)).build();
context.handleResult(null, ImmutableList.<TimerData>of(), holdResult);
StructuralKey<?> key = StructuralKey.of("foo".length(), VarIntCoder.of());
TimerData toFire = TimerData.of(StateNamespaces.global(), new Instant(100L), TimeDomain.EVENT_TIME);
TransformResult<?> timerResult = StepTransformResult.withoutHold(downstreamProducer).withState(CopyOnAccessInMemoryStateInternals.withUnderlying(key, null)).withTimerUpdate(TimerUpdate.builder(key).setTimer(toFire).build()).build();
// haven't added any timers, must be empty
assertThat(context.extractFiredTimers(), emptyIterable());
context.handleResult(context.createKeyedBundle(key, created).commit(Instant.now()), ImmutableList.<TimerData>of(), timerResult);
// timer hasn't fired
assertThat(context.extractFiredTimers(), emptyIterable());
TransformResult<?> advanceResult = StepTransformResult.withoutHold(createdProducer).build();
// Should cause the downstream timer to fire
context.handleResult(null, ImmutableList.<TimerData>of(), advanceResult);
Collection<FiredTimers> fired = context.extractFiredTimers();
assertThat(Iterables.getOnlyElement(fired).getKey(), Matchers.<StructuralKey<?>>equalTo(key));
FiredTimers firedForKey = Iterables.getOnlyElement(fired);
// Contains exclusively the fired timer
assertThat(firedForKey.getTimers(), contains(toFire));
// Don't reextract timers
assertThat(context.extractFiredTimers(), emptyIterable());
}
use of org.apache.beam.runners.core.TimerInternals.TimerData in project beam by apache.
the class DirectTimerInternalsTest method setTimerAddsToBuilder.
@Test
public void setTimerAddsToBuilder() {
TimerData eventTimer = TimerData.of(StateNamespaces.global(), new Instant(20145L), TimeDomain.EVENT_TIME);
TimerData processingTimer = TimerData.of(StateNamespaces.global(), new Instant(125555555L), TimeDomain.PROCESSING_TIME);
TimerData synchronizedProcessingTimer = TimerData.of(StateNamespaces.global(), new Instant(98745632189L), TimeDomain.SYNCHRONIZED_PROCESSING_TIME);
internals.setTimer(eventTimer);
internals.setTimer(processingTimer);
internals.setTimer(synchronizedProcessingTimer);
assertThat(internals.getTimerUpdate().getSetTimers(), containsInAnyOrder(eventTimer, synchronizedProcessingTimer, processingTimer));
}
Aggregations