use of org.apache.beam.runners.core.StateNamespace in project beam by apache.
the class SamzaTimerInternalsFactoryTest method testAllTimersAreFiredWithReload.
@Test
public void testAllTimersAreFiredWithReload() {
final SamzaPipelineOptions pipelineOptions = PipelineOptionsFactory.create().as(SamzaPipelineOptions.class);
pipelineOptions.setEventTimerBufferSize(2);
final KeyValueStore<ByteArray, StateValue<?>> store = createStore();
final SamzaTimerInternalsFactory<String> timerInternalsFactory = createTimerInternalsFactory(null, "timer", pipelineOptions, store);
final StateNamespace nameSpace = StateNamespaces.global();
final TimerInternals timerInternals = timerInternalsFactory.timerInternalsForKey("testKey");
// timers in store now are timestamped from 0 - 2.
for (int i = 0; i < 3; i++) {
timerInternals.setTimer(nameSpace, "timer" + i, "", new Instant(i), new Instant(i), TimeDomain.EVENT_TIME);
}
// total number of event time timers to fire equals to the number of timers in store
Collection<KeyedTimerData<String>> readyTimers;
timerInternalsFactory.setInputWatermark(new Instant(3));
readyTimers = timerInternalsFactory.removeReadyTimers();
// buffer should reload from store and all timers are supposed to be fired.
assertEquals(3, readyTimers.size());
store.close();
}
use of org.apache.beam.runners.core.StateNamespace in project beam by apache.
the class SamzaTimerInternalsFactoryTest method testEventTimeTimers.
@Test
public void testEventTimeTimers() {
final SamzaPipelineOptions pipelineOptions = PipelineOptionsFactory.create().as(SamzaPipelineOptions.class);
final KeyValueStore<ByteArray, StateValue<?>> store = createStore();
final SamzaTimerInternalsFactory<String> timerInternalsFactory = createTimerInternalsFactory(null, "timer", pipelineOptions, store);
final StateNamespace nameSpace = StateNamespaces.global();
final TimerInternals timerInternals = timerInternalsFactory.timerInternalsForKey("testKey");
final TimerInternals.TimerData timer1 = TimerInternals.TimerData.of("timer1", nameSpace, new Instant(10), new Instant(10), TimeDomain.EVENT_TIME);
timerInternals.setTimer(timer1);
final TimerInternals.TimerData timer2 = TimerInternals.TimerData.of("timer2", nameSpace, new Instant(100), new Instant(100), TimeDomain.EVENT_TIME);
timerInternals.setTimer(timer2);
timerInternalsFactory.setInputWatermark(new Instant(5));
Collection<KeyedTimerData<String>> readyTimers = timerInternalsFactory.removeReadyTimers();
assertTrue(readyTimers.isEmpty());
timerInternalsFactory.setInputWatermark(new Instant(20));
readyTimers = timerInternalsFactory.removeReadyTimers();
assertEquals(1, readyTimers.size());
assertEquals(timer1, readyTimers.iterator().next().getTimerData());
timerInternalsFactory.setInputWatermark(new Instant(150));
readyTimers = timerInternalsFactory.removeReadyTimers();
assertEquals(1, readyTimers.size());
assertEquals(timer2, readyTimers.iterator().next().getTimerData());
store.close();
}
use of org.apache.beam.runners.core.StateNamespace in project beam by apache.
the class SamzaTimerInternalsFactoryTest method testOverride.
@Test
public void testOverride() {
final SamzaPipelineOptions pipelineOptions = PipelineOptionsFactory.create().as(SamzaPipelineOptions.class);
KeyValueStore<ByteArray, StateValue<?>> store = createStore();
final SamzaTimerInternalsFactory<String> timerInternalsFactory = createTimerInternalsFactory(null, "timer", pipelineOptions, store);
final StateNamespace nameSpace = StateNamespaces.global();
final TimerInternals timerInternals = timerInternalsFactory.timerInternalsForKey("testKey");
final TimerInternals.TimerData timer1 = TimerInternals.TimerData.of("timerId", nameSpace, new Instant(10), new Instant(10), TimeDomain.EVENT_TIME);
timerInternals.setTimer(timer1);
// this timer should override the first timer
final TimerInternals.TimerData timer2 = TimerInternals.TimerData.of("timerId", nameSpace, new Instant(100), new Instant(100), TimeDomain.EVENT_TIME);
timerInternals.setTimer(timer2);
final TimerInternals.TimerData timer3 = TimerInternals.TimerData.of("timerId2", nameSpace, new Instant(200), new Instant(200), TimeDomain.EVENT_TIME);
timerInternals.setTimer(timer3);
// this timer shouldn't override since it has a different id
timerInternalsFactory.setInputWatermark(new Instant(50));
Collection<KeyedTimerData<String>> readyTimers = timerInternalsFactory.removeReadyTimers();
assertEquals(0, readyTimers.size());
timerInternalsFactory.setInputWatermark(new Instant(150));
readyTimers = timerInternalsFactory.removeReadyTimers();
assertEquals(1, readyTimers.size());
timerInternalsFactory.setInputWatermark(new Instant(250));
readyTimers = timerInternalsFactory.removeReadyTimers();
assertEquals(1, readyTimers.size());
store.close();
}
Aggregations