Search in sources :

Example 11 with TimerData

use of org.apache.beam.runners.core.TimerInternals.TimerData in project beam by apache.

the class ApexTimerInternalsTest method testSerialization.

@Test
public void testSerialization() {
    TimerDataCoder timerDataCoder = TimerDataCoder.of(GlobalWindow.Coder.INSTANCE);
    TimerData timerData = TimerData.of("arbitrary-id", StateNamespaces.global(), new Instant(0), TimeDomain.EVENT_TIME);
    String key = "key";
    ApexTimerInternals<String> timerInternals = new ApexTimerInternals<>(timerDataCoder);
    timerInternals.setContext(key, StringUtf8Coder.of(), Instant.now(), null);
    timerInternals.setTimer(timerData);
    ApexTimerInternals<String> cloned;
    assertNotNull("Serialization", cloned = KryoCloneUtils.cloneObject(timerInternals));
    cloned.setContext(key, StringUtf8Coder.of(), Instant.now(), null);
    Map<?, Set<Slice>> timers = cloned.getTimerSet(TimeDomain.EVENT_TIME).getMap();
    assertEquals(1, timers.size());
}
Also used : Set(java.util.Set) TimerDataCoder(org.apache.beam.runners.core.TimerInternals.TimerDataCoder) Instant(org.joda.time.Instant) TimerData(org.apache.beam.runners.core.TimerInternals.TimerData) Test(org.junit.Test)

Example 12 with TimerData

use of org.apache.beam.runners.core.TimerInternals.TimerData in project beam by apache.

the class DoFnOperator method fireTimer.

// allow overriding this in WindowDoFnOperator
public void fireTimer(InternalTimer<?, TimerData> timer) {
    TimerInternals.TimerData timerData = timer.getNamespace();
    StateNamespace namespace = timerData.getNamespace();
    // This is a user timer, so namespace must be WindowNamespace
    checkArgument(namespace instanceof WindowNamespace);
    BoundedWindow window = ((WindowNamespace) namespace).getWindow();
    pushbackDoFnRunner.onTimer(timerData.getTimerId(), window, timerData.getTimestamp(), timerData.getDomain());
}
Also used : TimerInternals(org.apache.beam.runners.core.TimerInternals) WindowNamespace(org.apache.beam.runners.core.StateNamespaces.WindowNamespace) BoundedWindow(org.apache.beam.sdk.transforms.windowing.BoundedWindow) TimerData(org.apache.beam.runners.core.TimerInternals.TimerData) StateNamespace(org.apache.beam.runners.core.StateNamespace)

Example 13 with TimerData

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), TimeDomain.EVENT_TIME);
    TimerData eventTimer2 = TimerData.of(ID2, NS1, 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());
}
Also used : Instant(org.joda.time.Instant) TimerData(org.apache.beam.runners.core.TimerInternals.TimerData) Test(org.junit.Test)

Example 14 with TimerData

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), TimeDomain.EVENT_TIME);
    TimerData processingTime1 = TimerData.of(NS1, new Instant(19), TimeDomain.PROCESSING_TIME);
    TimerData synchronizedProcessingTime1 = TimerData.of(NS1, new Instant(19), TimeDomain.SYNCHRONIZED_PROCESSING_TIME);
    TimerData eventTime2 = TimerData.of(NS1, new Instant(29), TimeDomain.EVENT_TIME);
    TimerData processingTime2 = TimerData.of(NS1, new Instant(29), TimeDomain.PROCESSING_TIME);
    TimerData synchronizedProcessingTime2 = TimerData.of(NS1, 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());
}
Also used : Instant(org.joda.time.Instant) TimerData(org.apache.beam.runners.core.TimerInternals.TimerData) Test(org.junit.Test)

Example 15 with TimerData

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), TimeDomain.PROCESSING_TIME);
    TimerData processingTime2 = TimerData.of(NS1, 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());
}
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