Search in sources :

Example 16 with TimerData

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());
}
Also used : Instant(org.joda.time.Instant) TimerData(org.apache.beam.runners.core.TimerInternals.TimerData) Test(org.junit.Test)

Example 17 with TimerData

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();
}
Also used : Instant(org.joda.time.Instant) TimerData(org.apache.beam.runners.core.TimerInternals.TimerData) ArrayList(java.util.ArrayList)

Example 18 with TimerData

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));
}
Also used : Instant(org.joda.time.Instant) TimerData(org.apache.beam.runners.core.TimerInternals.TimerData) Test(org.junit.Test)

Example 19 with TimerData

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());
}
Also used : FiredTimers(org.apache.beam.runners.direct.WatermarkManager.FiredTimers) Instant(org.joda.time.Instant) TimerData(org.apache.beam.runners.core.TimerInternals.TimerData) Test(org.junit.Test)

Example 20 with TimerData

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));
}
Also used : Instant(org.joda.time.Instant) TimerData(org.apache.beam.runners.core.TimerInternals.TimerData) Test(org.junit.Test)

Aggregations

TimerData (org.apache.beam.runners.core.TimerInternals.TimerData)31 Test (org.junit.Test)24 Instant (org.joda.time.Instant)22 TimerUpdate (org.apache.beam.runners.direct.WatermarkManager.TimerUpdate)11 TimerUpdateBuilder (org.apache.beam.runners.direct.WatermarkManager.TimerUpdate.TimerUpdateBuilder)8 ReadableInstant (org.joda.time.ReadableInstant)8 FiredTimers (org.apache.beam.runners.direct.WatermarkManager.FiredTimers)5 ArrayList (java.util.ArrayList)3 WindowNamespace (org.apache.beam.runners.core.StateNamespaces.WindowNamespace)3 TimerDataCoder (org.apache.beam.runners.core.TimerInternals.TimerDataCoder)3 Set (java.util.Set)2 StateNamespace (org.apache.beam.runners.core.StateNamespace)2 TransformWatermarks (org.apache.beam.runners.direct.WatermarkManager.TransformWatermarks)2 BoundedWindow (org.apache.beam.sdk.transforms.windowing.BoundedWindow)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Nullable (javax.annotation.Nullable)1 TimerProcessor (org.apache.beam.runners.apex.translation.operators.ApexTimerInternals.TimerProcessor)1 StateInternalsProxy (org.apache.beam.runners.apex.translation.utils.StateInternalsProxy)1