Search in sources :

Example 51 with BufferOrEvent

use of org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent in project flink by apache.

the class BarrierTrackerTest method testMultiChannelNoBarriers.

@Test
public void testMultiChannelNoBarriers() {
    try {
        BufferOrEvent[] sequence = { createBuffer(2), createBuffer(2), createBuffer(0), createBuffer(1), createBuffer(0), createBuffer(3), createBuffer(1), createBuffer(1), createBuffer(2) };
        MockInputGate gate = new MockInputGate(PAGE_SIZE, 4, Arrays.asList(sequence));
        BarrierTracker tracker = new BarrierTracker(gate);
        for (BufferOrEvent boe : sequence) {
            assertEquals(boe, tracker.getNextNonBlocked());
        }
        assertNull(tracker.getNextNonBlocked());
        assertNull(tracker.getNextNonBlocked());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent) Test(org.junit.Test)

Example 52 with BufferOrEvent

use of org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent in project flink by apache.

the class BarrierTrackerTest method testMultiChannelWithBarriers.

@Test
public void testMultiChannelWithBarriers() {
    try {
        BufferOrEvent[] sequence = { createBuffer(0), createBuffer(2), createBuffer(0), createBarrier(1, 1), createBarrier(1, 2), createBuffer(2), createBuffer(1), createBarrier(1, 0), createBuffer(0), createBuffer(0), createBuffer(1), createBuffer(1), createBuffer(2), createBarrier(2, 0), createBarrier(2, 1), createBarrier(2, 2), createBuffer(2), createBuffer(2), createBarrier(3, 2), createBuffer(2), createBuffer(2), createBarrier(3, 0), createBarrier(3, 1), createBarrier(4, 1), createBarrier(4, 2), createBarrier(4, 0), createBuffer(0) };
        MockInputGate gate = new MockInputGate(PAGE_SIZE, 3, Arrays.asList(sequence));
        BarrierTracker tracker = new BarrierTracker(gate);
        CheckpointSequenceValidator validator = new CheckpointSequenceValidator(1, 2, 3, 4);
        tracker.registerCheckpointEventHandler(validator);
        for (BufferOrEvent boe : sequence) {
            if (boe.isBuffer() || boe.getEvent().getClass() != CheckpointBarrier.class) {
                assertEquals(boe, tracker.getNextNonBlocked());
            }
        }
        assertNull(tracker.getNextNonBlocked());
        assertNull(tracker.getNextNonBlocked());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent) Test(org.junit.Test)

Example 53 with BufferOrEvent

use of org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent in project flink by apache.

the class BufferSpillerTest method generateRandomBuffer.

private static BufferOrEvent generateRandomBuffer(int size, int channelIndex) {
    MemorySegment seg = MemorySegmentFactory.allocateUnpooledSegment(PAGE_SIZE);
    for (int i = 0; i < size; i++) {
        seg.put(i, (byte) i);
    }
    Buffer buf = new Buffer(seg, FreeingBufferRecycler.INSTANCE);
    buf.setSize(size);
    return new BufferOrEvent(buf, channelIndex);
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) MemorySegment(org.apache.flink.core.memory.MemorySegment) BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent)

Example 54 with BufferOrEvent

use of org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent in project flink by apache.

the class BufferSpillerTest method testHeaderSizeStaticField.

/**
	 * Tests that the static HEADER_SIZE field has valid header size.
	 */
@Test
public void testHeaderSizeStaticField() throws Exception {
    int size = 13;
    BufferOrEvent boe = generateRandomBuffer(size, 0);
    spiller.add(boe);
    assertEquals("Changed the header format, but did not adjust the HEADER_SIZE field", BufferSpiller.HEADER_SIZE + size, spiller.getBytesWritten());
}
Also used : BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent) Test(org.junit.Test)

Example 55 with BufferOrEvent

use of org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent in project flink by apache.

the class BufferSpillerTest method testSpillAndRollOverSimple.

@Test
public void testSpillAndRollOverSimple() {
    try {
        final Random rnd = new Random();
        final Random bufferRnd = new Random();
        final int maxNumEventsAndBuffers = 3000;
        final int maxNumChannels = 1656;
        // do multiple spilling / rolling over rounds
        for (int round = 0; round < 5; round++) {
            final long bufferSeed = rnd.nextLong();
            bufferRnd.setSeed(bufferSeed);
            final int numEventsAndBuffers = rnd.nextInt(maxNumEventsAndBuffers) + 1;
            final int numChannels = rnd.nextInt(maxNumChannels) + 1;
            final ArrayList<BufferOrEvent> events = new ArrayList<BufferOrEvent>(128);
            // generate sequence
            for (int i = 0; i < numEventsAndBuffers; i++) {
                boolean isEvent = rnd.nextDouble() < 0.05d;
                if (isEvent) {
                    BufferOrEvent evt = generateRandomEvent(rnd, numChannels);
                    events.add(evt);
                    spiller.add(evt);
                } else {
                    BufferOrEvent evt = generateRandomBuffer(bufferRnd.nextInt(PAGE_SIZE) + 1, bufferRnd.nextInt(numChannels));
                    spiller.add(evt);
                }
            }
            // reset and create reader
            bufferRnd.setSeed(bufferSeed);
            BufferSpiller.SpilledBufferOrEventSequence seq = spiller.rollOver();
            seq.open();
            // read and validate the sequence
            int numEvent = 0;
            for (int i = 0; i < numEventsAndBuffers; i++) {
                BufferOrEvent next = seq.getNext();
                assertNotNull(next);
                if (next.isEvent()) {
                    BufferOrEvent expected = events.get(numEvent++);
                    assertEquals(expected.getEvent(), next.getEvent());
                    assertEquals(expected.getChannelIndex(), next.getChannelIndex());
                } else {
                    validateBuffer(next, bufferRnd.nextInt(PAGE_SIZE) + 1, bufferRnd.nextInt(numChannels));
                }
            }
            // no further data
            assertNull(seq.getNext());
            // all events need to be consumed
            assertEquals(events.size(), numEvent);
            seq.cleanup();
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent) Test(org.junit.Test)

Aggregations

BufferOrEvent (org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent)73 Test (org.junit.Test)57 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)11 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)9 StatefulTask (org.apache.flink.runtime.jobgraph.tasks.StatefulTask)9 IOException (java.io.IOException)8 CheckpointMetrics (org.apache.flink.runtime.checkpoint.CheckpointMetrics)8 CheckpointDeclineOnCancellationBarrierException (org.apache.flink.runtime.checkpoint.decline.CheckpointDeclineOnCancellationBarrierException)8 Random (java.util.Random)7 ArrayList (java.util.ArrayList)6 CheckpointDeclineSubsumedException (org.apache.flink.runtime.checkpoint.decline.CheckpointDeclineSubsumedException)5 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)4 InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)4 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)4 MemorySegment (org.apache.flink.core.memory.MemorySegment)3 AbstractEvent (org.apache.flink.runtime.event.AbstractEvent)3 CancelCheckpointMarker (org.apache.flink.runtime.io.network.api.CancelCheckpointMarker)3 EndOfPartitionEvent (org.apache.flink.runtime.io.network.api.EndOfPartitionEvent)3 DeserializationResult (org.apache.flink.runtime.io.network.api.serialization.RecordDeserializer.DeserializationResult)3 NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)3