wsry commented on a change in pull request #13595: URL: https://github.com/apache/flink/pull/13595#discussion_r511625760
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/PartitionSortedBufferTest.java ########## @@ -0,0 +1,291 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.runtime.io.network.partition; + +import org.apache.flink.core.memory.MemorySegment; +import org.apache.flink.core.memory.MemorySegmentFactory; +import org.apache.flink.runtime.io.network.buffer.Buffer; +import org.apache.flink.runtime.io.network.buffer.BufferPool; +import org.apache.flink.runtime.io.network.buffer.NetworkBufferPool; + +import org.junit.Test; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Queue; +import java.util.Random; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Tests for {@link PartitionSortedBuffer}. + */ +public class PartitionSortedBufferTest { + + @Test + public void testWriteAndReadSortBuffer() throws Exception { + int numSubpartitions = 10; + int bufferSize = 1024; + int bufferPoolSize = 1000; + Random random = new Random(); + + // used to store data written to and read from sort buffer for correctness check + Queue<DataAndType>[] dataWritten = new Queue[numSubpartitions]; + Queue<Buffer>[] buffersRead = new Queue[numSubpartitions]; + for (int i = 0; i < numSubpartitions; ++i) { + dataWritten[i] = new ArrayDeque<>(); + buffersRead[i] = new ArrayDeque<>(); + } + + int[] numBytesWritten = new int[numSubpartitions]; + int[] numBytesRead = new int[numSubpartitions]; + Arrays.fill(numBytesWritten, 0); + Arrays.fill(numBytesRead, 0); + + // fill the sort buffer with randomly generated data + int totalBytesWritten = 0; + SortBuffer sortBuffer = createSortBuffer(bufferPoolSize, bufferSize, numSubpartitions); Review comment: I think there is no need to do that, because these resources will be cleared after test finishes. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
