public static BufferConsumer toBufferConsumer(AbstractEvent event, boolean hasPriority)
            throws IOException {
        final ByteBuffer serializedEvent = EventSerializer.toSerializedEvent(event);

        MemorySegment data = MemorySegmentFactory.wrap(serializedEvent.array());

        return new BufferConsumer(
                new NetworkBuffer(
                        data, FreeingBufferRecycler.INSTANCE, getDataType(event, hasPriority)),
                data.size());
    }
@Test
    void testToBufferConsumer() throws IOException {
        for (AbstractEvent evt : events) {
            BufferConsumer bufferConsumer = EventSerializer.toBufferConsumer(evt, false);

            assertThat(bufferConsumer.isBuffer()).isFalse();
            assertThat(bufferConsumer.isFinished()).isTrue();
            assertThat(bufferConsumer.isDataAvailable()).isTrue();
            assertThat(bufferConsumer.isRecycled()).isFalse();

            if (evt instanceof CheckpointBarrier) {
                assertThat(bufferConsumer.build().getDataType().isBlockingUpstream()).isTrue();
            } else if (evt instanceof EndOfData) {
                assertThat(bufferConsumer.build().getDataType())
                        .isEqualTo(Buffer.DataType.END_OF_DATA);
            } else if (evt instanceof EndOfPartitionEvent) {
                assertThat(bufferConsumer.build().getDataType())
                        .isEqualTo(Buffer.DataType.END_OF_PARTITION);
            } else {
                assertThat(bufferConsumer.build().getDataType())
                        .isEqualTo(Buffer.DataType.EVENT_BUFFER);
            }
        }
    }