final ByteBuffer buf = ByteBuffer.allocate(bufSize);
for (int i = 0; i < bufSize; i ++) {
buf.put((byte) i);
}
buf.flip();
bufferChunk = new NioManagedBuffer(buf);
testFile = File.createTempFile("shuffle-test-file", "txt");
testFile.deleteOnExit();
RandomAccessFile fp = new RandomAccessFile(testFile, "rw");
byte[] fileContent = new byte[1024];
new Random().nextBytes(fileContent);
fp.write(fileContent);
fp.close();
fileChunk = new FileSegmentManagedBuffer(testFile, 10, testFile.length() - 25);
TransportConf conf = new TransportConf(new SystemPropertyConfigProvider());
streamManager = new StreamManager() {
@Override
public ManagedBuffer getChunk(long streamId, int chunkIndex) {
assertEquals(STREAM_ID, streamId);
if (chunkIndex == BUFFER_CHUNK_INDEX) {
return new NioManagedBuffer(buf);
} else if (chunkIndex == FILE_CHUNK_INDEX) {
return new FileSegmentManagedBuffer(testFile, 10, testFile.length() - 25);
} else {
throw new IllegalArgumentException("Invalid chunk index: " + chunkIndex);
}