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(impulseProducer, new Instant(0)).build();
context.handleResult(null, ImmutableList.of(), holdResult);
StructuralKey<?> key = StructuralKey.of("foo".length(), VarIntCoder.of());
TimerData toFire = TimerData.of(StateNamespaces.global(), new Instant(100L), 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, impulse).commit(Instant.now()), ImmutableList.of(), timerResult);
// timer hasn't fired
assertThat(context.extractFiredTimers(), emptyIterable());
TransformResult<?> advanceResult = StepTransformResult.withoutHold(impulseProducer).build();
// Should cause the downstream timer to fire
context.handleResult(null, ImmutableList.of(), advanceResult);
Collection<FiredTimers<AppliedPTransform<?, ?, ?>>> fired = context.extractFiredTimers();
assertThat(Iterables.getOnlyElement(fired).getKey(), equalTo(key));
FiredTimers<AppliedPTransform<?, ?, ?>> 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 InMemoryTimerInternalsTest method testFiringProcessingTimeTimers.
@Test
public void testFiringProcessingTimeTimers() throws Exception {
InMemoryTimerInternals underTest = new InMemoryTimerInternals();
TimerData processingTime1 = TimerData.of(NS1, new Instant(19), new Instant(19), TimeDomain.PROCESSING_TIME);
TimerData processingTime2 = TimerData.of(NS1, new Instant(29), new Instant(29), TimeDomain.PROCESSING_TIME);
underTest.setTimer(processingTime1);
underTest.setTimer(processingTime2);
underTest.advanceProcessingTime(new Instant(20));
assertThat(underTest.removeNextProcessingTimer(), equalTo(processingTime1));
assertThat(underTest.removeNextProcessingTimer(), nullValue());
// Advancing just a little shouldn't refire
underTest.advanceProcessingTime(new Instant(21));
assertThat(underTest.removeNextProcessingTimer(), nullValue());
// Adding the timer and advancing a little should fire again
underTest.setTimer(processingTime1);
underTest.advanceProcessingTime(new Instant(21));
assertThat(underTest.removeNextProcessingTimer(), equalTo(processingTime1));
assertThat(underTest.removeNextProcessingTimer(), nullValue());
// And advancing the rest of the way should still have the other timer
underTest.advanceProcessingTime(new Instant(30));
assertThat(underTest.removeNextProcessingTimer(), equalTo(processingTime2));
assertThat(underTest.removeNextProcessingTimer(), nullValue());
}
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), new Instant(19), TimeDomain.EVENT_TIME);
TimerData processingTime = TimerData.of(NS1, new Instant(19), 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 InMemoryTimerInternalsTest method testFiringEventTimers.
@Test
public void testFiringEventTimers() throws Exception {
InMemoryTimerInternals underTest = new InMemoryTimerInternals();
TimerData eventTimer1 = TimerData.of(ID1, NS1, new Instant(19), new Instant(19), TimeDomain.EVENT_TIME);
TimerData eventTimer2 = TimerData.of(ID2, NS1, new Instant(29), new Instant(29), TimeDomain.EVENT_TIME);
underTest.setTimer(eventTimer1);
underTest.setTimer(eventTimer2);
underTest.advanceInputWatermark(new Instant(20));
assertThat(underTest.removeNextEventTimer(), equalTo(eventTimer1));
assertThat(underTest.removeNextEventTimer(), nullValue());
// Advancing just a little shouldn't refire
underTest.advanceInputWatermark(new Instant(21));
assertThat(underTest.removeNextEventTimer(), nullValue());
// Adding the timer and advancing a little should refire
underTest.setTimer(eventTimer1);
assertThat(underTest.removeNextEventTimer(), equalTo(eventTimer1));
assertThat(underTest.removeNextEventTimer(), nullValue());
// And advancing the rest of the way should still have the other timer
underTest.advanceInputWatermark(new Instant(30));
assertThat(underTest.removeNextEventTimer(), equalTo(eventTimer2));
assertThat(underTest.removeNextEventTimer(), nullValue());
}
use of org.apache.beam.runners.core.TimerInternals.TimerData in project beam by apache.
the class InMemoryTimerInternalsTest method testTimerOrdering.
@Test
public void testTimerOrdering() throws Exception {
InMemoryTimerInternals underTest = new InMemoryTimerInternals();
TimerData eventTime1 = TimerData.of(NS1, new Instant(19), new Instant(19), TimeDomain.EVENT_TIME);
TimerData processingTime1 = TimerData.of(NS1, new Instant(19), new Instant(19), TimeDomain.PROCESSING_TIME);
TimerData synchronizedProcessingTime1 = TimerData.of(NS1, new Instant(19), new Instant(19), TimeDomain.SYNCHRONIZED_PROCESSING_TIME);
TimerData eventTime2 = TimerData.of(NS1, new Instant(29), new Instant(29), TimeDomain.EVENT_TIME);
TimerData processingTime2 = TimerData.of(NS1, new Instant(29), new Instant(29), TimeDomain.PROCESSING_TIME);
TimerData synchronizedProcessingTime2 = TimerData.of(NS1, new Instant(29), new Instant(29), TimeDomain.SYNCHRONIZED_PROCESSING_TIME);
underTest.setTimer(processingTime1);
underTest.setTimer(eventTime1);
underTest.setTimer(synchronizedProcessingTime1);
underTest.setTimer(processingTime2);
underTest.setTimer(eventTime2);
underTest.setTimer(synchronizedProcessingTime2);
assertThat(underTest.removeNextEventTimer(), nullValue());
underTest.advanceInputWatermark(new Instant(30));
assertThat(underTest.removeNextEventTimer(), equalTo(eventTime1));
assertThat(underTest.removeNextEventTimer(), equalTo(eventTime2));
assertThat(underTest.removeNextEventTimer(), nullValue());
assertThat(underTest.removeNextProcessingTimer(), nullValue());
underTest.advanceProcessingTime(new Instant(30));
assertThat(underTest.removeNextProcessingTimer(), equalTo(processingTime1));
assertThat(underTest.removeNextProcessingTimer(), equalTo(processingTime2));
assertThat(underTest.removeNextProcessingTimer(), nullValue());
assertThat(underTest.removeNextSynchronizedProcessingTimer(), nullValue());
underTest.advanceSynchronizedProcessingTime(new Instant(30));
assertThat(underTest.removeNextSynchronizedProcessingTimer(), equalTo(synchronizedProcessingTime1));
assertThat(underTest.removeNextSynchronizedProcessingTimer(), equalTo(synchronizedProcessingTime2));
assertThat(underTest.removeNextProcessingTimer(), nullValue());
}
Aggregations