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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations