use of org.apache.flink.runtime.state.VoidNamespaceSerializer in project flink by apache.
the class TimerRegistration method setTimer.
public void setTimer(byte[] serializedTimerData) {
try {
bais.setBuffer(serializedTimerData, 0, serializedTimerData.length);
Row timerData = timerDataSerializer.deserialize(baisWrapper);
TimerOperandType operandType = TimerOperandType.valueOf((byte) timerData.getField(0));
long timestamp = (long) timerData.getField(2);
Row key = (Row) timerData.getField(3);
Object namespace;
if (namespaceSerializer instanceof VoidNamespaceSerializer) {
namespace = VoidNamespace.INSTANCE;
} else {
byte[] encodedNamespace = (byte[]) timerData.getField(4);
assert encodedNamespace != null;
bais.setBuffer(encodedNamespace, 0, encodedNamespace.length);
namespace = namespaceSerializer.deserialize(baisWrapper);
}
setTimer(operandType, timestamp, key, namespace);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
use of org.apache.flink.runtime.state.VoidNamespaceSerializer in project flink by apache.
the class BatchExecutionInternalTimeServiceTest method testIgnoringProcessingTimeTimersFromWithinCallback.
@Test
public void testIgnoringProcessingTimeTimersFromWithinCallback() {
BatchExecutionKeyedStateBackend<Integer> keyedStatedBackend = new BatchExecutionKeyedStateBackend<>(KEY_SERIALIZER, new KeyGroupRange(0, 1));
TestProcessingTimeService processingTimeService = new TestProcessingTimeService();
InternalTimeServiceManager<Integer> timeServiceManager = BatchExecutionInternalTimeServiceManager.create(keyedStatedBackend, this.getClass().getClassLoader(), new DummyKeyContext(), processingTimeService, Collections.emptyList());
List<Long> timers = new ArrayList<>();
TriggerWithTimerServiceAccess<Integer, VoidNamespace> trigger = TriggerWithTimerServiceAccess.processingTimeTrigger((timer, ts) -> {
timers.add(timer.getTimestamp());
ts.registerProcessingTimeTimer(VoidNamespace.INSTANCE, timer.getTimestamp() + 20);
});
InternalTimerService<VoidNamespace> timerService = timeServiceManager.getInternalTimerService("test", KEY_SERIALIZER, new VoidNamespaceSerializer(), trigger);
trigger.setTimerService(timerService);
keyedStatedBackend.setCurrentKey(1);
timerService.registerProcessingTimeTimer(VoidNamespace.INSTANCE, 150);
// we should never register physical timers
assertThat(processingTimeService.getNumActiveTimers(), equalTo(0));
// changing the current key fires all timers
keyedStatedBackend.setCurrentKey(2);
// We check that the timer from the callback is ignored
assertThat(timers, equalTo(Collections.singletonList(150L)));
}
use of org.apache.flink.runtime.state.VoidNamespaceSerializer in project flink by apache.
the class BatchExecutionInternalTimeServiceTest method testCurrentWatermark.
@Test
public void testCurrentWatermark() throws Exception {
BatchExecutionKeyedStateBackend<Integer> keyedStatedBackend = new BatchExecutionKeyedStateBackend<>(KEY_SERIALIZER, new KeyGroupRange(0, 1));
InternalTimeServiceManager<Integer> timeServiceManager = BatchExecutionInternalTimeServiceManager.create(keyedStatedBackend, this.getClass().getClassLoader(), new DummyKeyContext(), new TestProcessingTimeService(), Collections.emptyList());
List<Long> timers = new ArrayList<>();
TriggerWithTimerServiceAccess<Integer, VoidNamespace> eventTimeTrigger = TriggerWithTimerServiceAccess.eventTimeTrigger((timer, timerService) -> {
assertThat(timerService.currentWatermark(), equalTo(Long.MAX_VALUE));
timers.add(timer.getTimestamp());
});
InternalTimerService<VoidNamespace> timerService = timeServiceManager.getInternalTimerService("test", KEY_SERIALIZER, new VoidNamespaceSerializer(), eventTimeTrigger);
eventTimeTrigger.setTimerService(timerService);
assertThat(timerService.currentWatermark(), equalTo(Long.MIN_VALUE));
keyedStatedBackend.setCurrentKey(1);
timerService.registerEventTimeTimer(VoidNamespace.INSTANCE, 123);
assertThat(timerService.currentWatermark(), equalTo(Long.MIN_VALUE));
// advancing the watermark to a value different than Long.MAX_VALUE should have no effect
timeServiceManager.advanceWatermark(new Watermark(1000));
assertThat(timerService.currentWatermark(), equalTo(Long.MIN_VALUE));
// changing the current key fires all timers
keyedStatedBackend.setCurrentKey(2);
assertThat(timerService.currentWatermark(), equalTo(Long.MIN_VALUE));
timerService.registerEventTimeTimer(VoidNamespace.INSTANCE, 124);
// advancing the watermark to Long.MAX_VALUE should fire remaining key
timeServiceManager.advanceWatermark(Watermark.MAX_WATERMARK);
assertThat(timers, equalTo(Arrays.asList(123L, 124L)));
}
use of org.apache.flink.runtime.state.VoidNamespaceSerializer in project flink by apache.
the class BatchExecutionInternalTimeServiceTest method testIgnoringEventTimeTimersFromWithinCallback.
@Test
public void testIgnoringEventTimeTimersFromWithinCallback() {
BatchExecutionKeyedStateBackend<Integer> keyedStatedBackend = new BatchExecutionKeyedStateBackend<>(KEY_SERIALIZER, new KeyGroupRange(0, 1));
TestProcessingTimeService processingTimeService = new TestProcessingTimeService();
InternalTimeServiceManager<Integer> timeServiceManager = BatchExecutionInternalTimeServiceManager.create(keyedStatedBackend, this.getClass().getClassLoader(), new DummyKeyContext(), processingTimeService, Collections.emptyList());
List<Long> timers = new ArrayList<>();
TriggerWithTimerServiceAccess<Integer, VoidNamespace> trigger = TriggerWithTimerServiceAccess.eventTimeTrigger((timer, ts) -> {
timers.add(timer.getTimestamp());
ts.registerEventTimeTimer(VoidNamespace.INSTANCE, timer.getTimestamp() + 20);
});
InternalTimerService<VoidNamespace> timerService = timeServiceManager.getInternalTimerService("test", KEY_SERIALIZER, new VoidNamespaceSerializer(), trigger);
trigger.setTimerService(timerService);
keyedStatedBackend.setCurrentKey(1);
timerService.registerEventTimeTimer(VoidNamespace.INSTANCE, 150);
// we should never register physical timers
assertThat(processingTimeService.getNumActiveTimers(), equalTo(0));
// changing the current key fires all timers
keyedStatedBackend.setCurrentKey(2);
// We check that the timer from the callback is ignored
assertThat(timers, equalTo(Collections.singletonList(150L)));
}
use of org.apache.flink.runtime.state.VoidNamespaceSerializer in project flink by apache.
the class BatchExecutionInternalTimeServiceTest method testProcessingTimeTimers.
@Test
public void testProcessingTimeTimers() {
BatchExecutionKeyedStateBackend<Integer> keyedStatedBackend = new BatchExecutionKeyedStateBackend<>(KEY_SERIALIZER, new KeyGroupRange(0, 1));
TestProcessingTimeService processingTimeService = new TestProcessingTimeService();
InternalTimeServiceManager<Integer> timeServiceManager = BatchExecutionInternalTimeServiceManager.create(keyedStatedBackend, this.getClass().getClassLoader(), new DummyKeyContext(), processingTimeService, Collections.emptyList());
List<Long> timers = new ArrayList<>();
InternalTimerService<VoidNamespace> timerService = timeServiceManager.getInternalTimerService("test", KEY_SERIALIZER, new VoidNamespaceSerializer(), LambdaTrigger.processingTimeTrigger(timer -> timers.add(timer.getTimestamp())));
keyedStatedBackend.setCurrentKey(1);
timerService.registerProcessingTimeTimer(VoidNamespace.INSTANCE, 150);
// we should never register physical timers
assertThat(processingTimeService.getNumActiveTimers(), equalTo(0));
// changing the current key fires all timers
keyedStatedBackend.setCurrentKey(2);
assertThat(timers, equalTo(Collections.singletonList(150L)));
}
Aggregations