Search in sources :

Example 1 with TestInfiniteBufferProvider

use of org.apache.flink.runtime.io.network.util.TestInfiniteBufferProvider in project flink by apache.

the class SubpartitionTestBase method verifyViewReleasedAfterParentRelease.

private void verifyViewReleasedAfterParentRelease(ResultSubpartition partition) throws Exception {
    // Add a buffer
    Buffer buffer = TestBufferFactory.createBuffer();
    partition.add(buffer);
    partition.finish();
    TestInfiniteBufferProvider buffers = new TestInfiniteBufferProvider();
    // Create the view
    BufferAvailabilityListener listener = mock(BufferAvailabilityListener.class);
    ResultSubpartitionView view = partition.createReadView(buffers, listener);
    // The added buffer and end-of-partition event
    assertNotNull(view.getNextBuffer());
    assertNotNull(view.getNextBuffer());
    // Release the parent
    assertFalse(view.isReleased());
    partition.release();
    // Verify that parent release is reflected at partition view
    assertTrue(view.isReleased());
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) TestInfiniteBufferProvider(org.apache.flink.runtime.io.network.util.TestInfiniteBufferProvider)

Example 2 with TestInfiniteBufferProvider

use of org.apache.flink.runtime.io.network.util.TestInfiniteBufferProvider in project flink by apache.

the class SpillableSubpartitionTest method testConsumeSpillablePartitionSpilledDuringConsume.

/**
	 * Tests that a spilled partition is correctly read back in via a spilled
	 * read view.
	 */
@Test
public void testConsumeSpillablePartitionSpilledDuringConsume() throws Exception {
    ResultPartition parent = mock(ResultPartition.class);
    SpillableSubpartition partition = new SpillableSubpartition(0, parent, ioManager);
    Buffer buffer = new Buffer(MemorySegmentFactory.allocateUnpooledSegment(4096), FreeingBufferRecycler.INSTANCE);
    buffer.retain();
    buffer.retain();
    partition.add(buffer);
    partition.add(buffer);
    partition.add(buffer);
    partition.finish();
    AwaitableBufferAvailablityListener listener = new AwaitableBufferAvailablityListener();
    SpillableSubpartitionView reader = (SpillableSubpartitionView) partition.createReadView(new TestInfiniteBufferProvider(), listener);
    // Initial notification
    assertEquals(1, listener.getNumNotifiedBuffers());
    Buffer read = reader.getNextBuffer();
    assertNotNull(read);
    read.recycle();
    assertEquals(2, listener.getNumNotifiedBuffers());
    // Spill now
    assertEquals(2, partition.releaseMemory());
    listener.awaitNotifications(4, 30_000);
    assertEquals(4, listener.getNumNotifiedBuffers());
    read = reader.getNextBuffer();
    assertNotNull(read);
    read.recycle();
    read = reader.getNextBuffer();
    assertNotNull(read);
    read.recycle();
    // End of partition
    read = reader.getNextBuffer();
    assertNotNull(read);
    assertEquals(EndOfPartitionEvent.class, EventSerializer.fromBuffer(read, ClassLoader.getSystemClassLoader()).getClass());
    read.recycle();
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) TestInfiniteBufferProvider(org.apache.flink.runtime.io.network.util.TestInfiniteBufferProvider) Test(org.junit.Test)

Example 3 with TestInfiniteBufferProvider

use of org.apache.flink.runtime.io.network.util.TestInfiniteBufferProvider in project flink by apache.

the class SpillableSubpartitionTest method testConsumeSpilledPartition.

/**
	 * Tests that a spilled partition is correctly read back in via a spilled
	 * read view.
	 */
@Test
public void testConsumeSpilledPartition() throws Exception {
    ResultPartition parent = mock(ResultPartition.class);
    SpillableSubpartition partition = new SpillableSubpartition(0, parent, ioManager);
    Buffer buffer = new Buffer(MemorySegmentFactory.allocateUnpooledSegment(4096), FreeingBufferRecycler.INSTANCE);
    buffer.retain();
    buffer.retain();
    partition.add(buffer);
    partition.add(buffer);
    partition.add(buffer);
    assertEquals(3, partition.releaseMemory());
    partition.finish();
    BufferAvailabilityListener listener = mock(BufferAvailabilityListener.class);
    SpilledSubpartitionView reader = (SpilledSubpartitionView) partition.createReadView(new TestInfiniteBufferProvider(), listener);
    verify(listener, times(1)).notifyBuffersAvailable(eq(4L));
    Buffer read = reader.getNextBuffer();
    assertNotNull(read);
    read.recycle();
    read = reader.getNextBuffer();
    assertNotNull(read);
    read.recycle();
    read = reader.getNextBuffer();
    assertNotNull(read);
    read.recycle();
    // End of partition
    read = reader.getNextBuffer();
    assertNotNull(read);
    assertEquals(EndOfPartitionEvent.class, EventSerializer.fromBuffer(read, ClassLoader.getSystemClassLoader()).getClass());
    read.recycle();
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) TestInfiniteBufferProvider(org.apache.flink.runtime.io.network.util.TestInfiniteBufferProvider) Test(org.junit.Test)

Aggregations

Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)3 TestInfiniteBufferProvider (org.apache.flink.runtime.io.network.util.TestInfiniteBufferProvider)3 Test (org.junit.Test)2