@Override public void setTimer( StateNamespace namespace, String timerId, Instant target, TimeDomain timeDomain) { setTimer(TimerData.of(timerId, namespace, target, timeDomain)); }
@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()); } }
@Test public void testDeletionIdempotent() throws Exception { InMemoryTimerInternals underTest = new InMemoryTimerInternals(); Instant timestamp = new Instant(42); underTest.setTimer(NS1, ID1, timestamp, TimeDomain.EVENT_TIME); underTest.deleteTimer(NS1, ID1); underTest.deleteTimer(NS1, ID1); }
@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()); }
@Test public void testResetById() throws Exception { InMemoryTimerInternals underTest = new InMemoryTimerInternals(); Instant earlyTimestamp = new Instant(13); Instant laterTimestamp = new Instant(42); underTest.advanceInputWatermark(new Instant(0)); underTest.setTimer(NS1, ID1, earlyTimestamp, TimeDomain.EVENT_TIME); underTest.setTimer(NS1, ID1, laterTimestamp, TimeDomain.EVENT_TIME); underTest.advanceInputWatermark(earlyTimestamp.plus(1L)); assertThat(underTest.removeNextEventTimer(), nullValue()); underTest.advanceInputWatermark(laterTimestamp.plus(1L)); assertThat( underTest.removeNextEventTimer(), equalTo(TimerData.of(ID1, NS1, laterTimestamp, TimeDomain.EVENT_TIME))); }
@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()); }
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);
@Test public void testDeletionById() throws Exception { InMemoryTimerInternals underTest = new InMemoryTimerInternals(); Instant timestamp = new Instant(42); underTest.advanceInputWatermark(new Instant(0)); underTest.setTimer(NS1, ID1, timestamp, TimeDomain.EVENT_TIME); underTest.deleteTimer(NS1, ID1); underTest.advanceInputWatermark(new Instant(43)); assertThat(underTest.removeNextEventTimer(), nullValue()); }
(WindowedValue timerElement, TimerInternals.TimerData timerData) -> { currentTimerKey = ((KV) timerElement.getValue()).getKey(); timerInternals.setTimer(timerData); }, windowCoder));
(WindowedValue timerElement, TimerInternals.TimerData timerData) -> { currentTimerKey = (((KV) timerElement.getValue()).getKey()); timerInternals.setTimer(timerData); }, windowCoder));