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());
}
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);
}
Aggregations