Search in sources :

Example 1 with EndOfPartitionEvent

use of org.apache.flink.runtime.io.network.api.EndOfPartitionEvent in project flink by apache.

the class EventSerializerTest method testIsEventPeakOnly.

/**
	 * Tests {@link EventSerializer#isEvent(Buffer, Class, ClassLoader)}
	 * whether it peaks into the buffer only, i.e. after the call, the buffer
	 * is still de-serializable.
	 *
	 * @throws Exception
	 */
@Test
public void testIsEventPeakOnly() throws Exception {
    final Buffer serializedEvent = EventSerializer.toBuffer(EndOfPartitionEvent.INSTANCE);
    try {
        final ClassLoader cl = getClass().getClassLoader();
        assertTrue(EventSerializer.isEvent(serializedEvent, EndOfPartitionEvent.class, cl));
        EndOfPartitionEvent event = (EndOfPartitionEvent) EventSerializer.fromBuffer(serializedEvent, cl);
        assertEquals(EndOfPartitionEvent.INSTANCE, event);
    } finally {
        serializedEvent.recycle();
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) EndOfPartitionEvent(org.apache.flink.runtime.io.network.api.EndOfPartitionEvent) Test(org.junit.Test)

Example 2 with EndOfPartitionEvent

use of org.apache.flink.runtime.io.network.api.EndOfPartitionEvent in project flink by apache.

the class MockInputGate method getNextBufferOrEvent.

@Override
public BufferOrEvent getNextBufferOrEvent() {
    BufferOrEvent next = boes.poll();
    if (next == null) {
        return null;
    }
    int channelIdx = next.getChannelIndex();
    if (closed[channelIdx]) {
        throw new RuntimeException("Inconsistent: Channel " + channelIdx + " has data even though it is already closed.");
    }
    if (next.isEvent() && next.getEvent() instanceof EndOfPartitionEvent) {
        closed[channelIdx] = true;
        closedChannels++;
    }
    return next;
}
Also used : EndOfPartitionEvent(org.apache.flink.runtime.io.network.api.EndOfPartitionEvent) BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent)

Aggregations

EndOfPartitionEvent (org.apache.flink.runtime.io.network.api.EndOfPartitionEvent)2 ByteBuffer (java.nio.ByteBuffer)1 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)1 BufferOrEvent (org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent)1 Test (org.junit.Test)1