Search in sources :

Example 1 with IntType

use of org.apache.flink.testutils.serialization.types.IntType in project flink by apache.

the class BroadcastRecordWriterTest method testRandomEmitAndBufferRecycling.

/**
 * FLINK-17780: Tests that a shared buffer(or memory segment) of a buffer builder is only freed
 * when all consumers are closed.
 */
@Test
public void testRandomEmitAndBufferRecycling() throws Exception {
    int recordSize = 8;
    int numberOfChannels = 2;
    ResultPartition partition = createResultPartition(2 * recordSize, numberOfChannels);
    BufferPool bufferPool = partition.getBufferPool();
    BroadcastRecordWriter<SerializationTestType> writer = new BroadcastRecordWriter<>(partition, -1, "test");
    // force materialization of both buffers for easier availability tests
    List<Buffer> buffers = Arrays.asList(bufferPool.requestBuffer(), bufferPool.requestBuffer());
    buffers.forEach(Buffer::recycleBuffer);
    assertEquals(3, bufferPool.getNumberOfAvailableMemorySegments());
    // fill first buffer
    writer.broadcastEmit(new IntType(1));
    writer.broadcastEmit(new IntType(2));
    assertEquals(2, bufferPool.getNumberOfAvailableMemorySegments());
    // simulate consumption of first buffer consumer; this should not free buffers
    assertEquals(1, partition.getNumberOfQueuedBuffers(0));
    ResultSubpartitionView view0 = partition.createSubpartitionView(0, new NoOpBufferAvailablityListener());
    closeConsumer(view0, 2 * recordSize);
    assertEquals(2, bufferPool.getNumberOfAvailableMemorySegments());
    // use second buffer
    writer.emit(new IntType(3), 0);
    assertEquals(1, bufferPool.getNumberOfAvailableMemorySegments());
    // fully free first buffer
    assertEquals(1, partition.getNumberOfQueuedBuffers(1));
    ResultSubpartitionView view1 = partition.createSubpartitionView(1, new NoOpBufferAvailablityListener());
    closeConsumer(view1, 2 * recordSize);
    assertEquals(2, bufferPool.getNumberOfAvailableMemorySegments());
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) SerializationTestType(org.apache.flink.testutils.serialization.types.SerializationTestType) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) NoOpBufferAvailablityListener(org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) IntType(org.apache.flink.testutils.serialization.types.IntType) Test(org.junit.Test)

Example 2 with IntType

use of org.apache.flink.testutils.serialization.types.IntType in project flink by apache.

the class SpanningRecordSerializationTest method testHandleMixedLargeRecords.

@Test
public void testHandleMixedLargeRecords() throws Exception {
    final int numValues = 99;
    final int segmentSize = 32 * 1024;
    List<SerializationTestType> originalRecords = new ArrayList<>((numValues + 1) / 2);
    LargeObjectType genLarge = new LargeObjectType();
    Random rnd = new Random();
    for (int i = 0; i < numValues; i++) {
        if (i % 2 == 0) {
            originalRecords.add(new IntType(42));
        } else {
            originalRecords.add(genLarge.getRandom(rnd));
        }
    }
    testSerializationRoundTrip(originalRecords, segmentSize);
}
Also used : SerializationTestType(org.apache.flink.testutils.serialization.types.SerializationTestType) Random(java.util.Random) LargeObjectType(org.apache.flink.runtime.io.network.serialization.types.LargeObjectType) ArrayList(java.util.ArrayList) IntType(org.apache.flink.testutils.serialization.types.IntType) Test(org.junit.Test)

Aggregations

IntType (org.apache.flink.testutils.serialization.types.IntType)2 SerializationTestType (org.apache.flink.testutils.serialization.types.SerializationTestType)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)1 BufferPool (org.apache.flink.runtime.io.network.buffer.BufferPool)1 NoOpBufferAvailablityListener (org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener)1 ResultPartition (org.apache.flink.runtime.io.network.partition.ResultPartition)1 ResultSubpartitionView (org.apache.flink.runtime.io.network.partition.ResultSubpartitionView)1 LargeObjectType (org.apache.flink.runtime.io.network.serialization.types.LargeObjectType)1