use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.
the class RecordOrEventCollectingResultPartitionWriter method broadcastEvent.
@Override
public void broadcastEvent(AbstractEvent event, boolean isPriorityEvent) throws IOException {
// visible in ITCases or end to end tests.
try (BufferConsumer eventBufferConsumer = EventSerializer.toBufferConsumer(event, isPriorityEvent)) {
Buffer buffer = eventBufferConsumer.build();
try {
AbstractEvent deserializedEvent = EventSerializer.fromBuffer(buffer, getClass().getClassLoader());
output.add(deserializedEvent);
} finally {
buffer.recycleBuffer();
}
}
}
use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.
the class EventSerializerTest method testToBufferConsumer.
@Test
public void testToBufferConsumer() throws IOException {
for (AbstractEvent evt : events) {
BufferConsumer bufferConsumer = EventSerializer.toBufferConsumer(evt, false);
assertFalse(bufferConsumer.isBuffer());
assertTrue(bufferConsumer.isFinished());
assertTrue(bufferConsumer.isDataAvailable());
assertFalse(bufferConsumer.isRecycled());
if (evt instanceof CheckpointBarrier) {
assertTrue(bufferConsumer.build().getDataType().isBlockingUpstream());
} else {
assertEquals(Buffer.DataType.EVENT_BUFFER, bufferConsumer.build().getDataType());
}
}
}
use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.
the class EventSerializerTest method testToBuffer.
@Test
public void testToBuffer() throws IOException {
for (AbstractEvent evt : events) {
Buffer buffer = EventSerializer.toBuffer(evt, false);
assertFalse(buffer.isBuffer());
assertTrue(buffer.readableBytes() > 0);
assertFalse(buffer.isRecycled());
if (evt instanceof CheckpointBarrier) {
assertTrue(buffer.getDataType().isBlockingUpstream());
} else {
assertEquals(Buffer.DataType.EVENT_BUFFER, buffer.getDataType());
}
}
}
use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.
the class StreamTestSingleInputGate method setupInputChannels.
private TestInputChannel[] setupInputChannels() {
TestInputChannel[] inputChannels = new TestInputChannel[numInputChannels];
for (int i = 0; i < numInputChannels; i++) {
final int channelIndex = i;
final DataOutputSerializer dataOutputSerializer = new DataOutputSerializer(128);
final SerializationDelegate<StreamElement> delegate = new SerializationDelegate<>(new StreamElementSerializer<T>(serializer));
inputQueues[channelIndex] = new ConcurrentLinkedQueue<>();
inputChannels[channelIndex] = new TestInputChannel(inputGate, i);
final BufferAndAvailabilityProvider answer = () -> {
ConcurrentLinkedQueue<InputValue<Object>> inputQueue = inputQueues[channelIndex];
InputValue<Object> input;
Buffer.DataType nextType;
synchronized (inputQueue) {
input = inputQueue.poll();
nextType = !inputQueue.isEmpty() ? Buffer.DataType.DATA_BUFFER : Buffer.DataType.NONE;
}
if (input != null && input.isStreamEnd()) {
inputChannels[channelIndex].setReleased();
return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE, false), nextType, 0, 0));
} else if (input != null && input.isDataEnd()) {
return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(new EndOfData(StopMode.DRAIN), false), nextType, 0, 0));
} else if (input != null && input.isStreamRecord()) {
StreamElement inputElement = input.getStreamRecord();
delegate.setInstance(inputElement);
ByteBuffer serializedRecord = RecordWriter.serializeRecord(dataOutputSerializer, delegate);
BufferBuilder bufferBuilder = createBufferBuilder(bufferSize);
BufferConsumer bufferConsumer = bufferBuilder.createBufferConsumer();
bufferBuilder.appendAndCommit(serializedRecord);
bufferBuilder.finish();
bufferBuilder.close();
// Call getCurrentBuffer to ensure size is set
return Optional.of(new BufferAndAvailability(bufferConsumer.build(), nextType, 0, 0));
} else if (input != null && input.isEvent()) {
AbstractEvent event = input.getEvent();
if (event instanceof EndOfPartitionEvent) {
inputChannels[channelIndex].setReleased();
}
return Optional.of(new BufferAndAvailability(EventSerializer.toBuffer(event, false), nextType, 0, 0));
} else {
return Optional.empty();
}
};
inputChannels[channelIndex].addBufferAndAvailability(answer);
}
return inputChannels;
}
use of org.apache.flink.runtime.event.AbstractEvent in project flink by apache.
the class SubtaskCheckpointCoordinatorTest method testSavepointNotResultingInPriorityEvents.
@Test
public void testSavepointNotResultingInPriorityEvents() throws Exception {
MockEnvironment mockEnvironment = MockEnvironment.builder().build();
try (SubtaskCheckpointCoordinator coordinator = new MockSubtaskCheckpointCoordinatorBuilder().setUnalignedCheckpointEnabled(true).setEnvironment(mockEnvironment).build()) {
AtomicReference<Boolean> broadcastedPriorityEvent = new AtomicReference<>(null);
final OperatorChain<?, ?> operatorChain = new RegularOperatorChain(new MockStreamTaskBuilder(mockEnvironment).build(), new NonRecordWriter<>()) {
@Override
public void broadcastEvent(AbstractEvent event, boolean isPriorityEvent) throws IOException {
super.broadcastEvent(event, isPriorityEvent);
broadcastedPriorityEvent.set(isPriorityEvent);
}
};
coordinator.checkpointState(new CheckpointMetaData(0, 0), new CheckpointOptions(SavepointType.savepoint(SavepointFormatType.CANONICAL), CheckpointStorageLocationReference.getDefault()), new CheckpointMetricsBuilder(), operatorChain, false, () -> true);
assertEquals(false, broadcastedPriorityEvent.get());
}
}
Aggregations