use of alluxio.client.block.stream.DataReader in project alluxio by Alluxio.
the class BlockWorkerDataReaderTest method readChunkFullFile.
@Test
public void readChunkFullFile() throws Exception {
int len = CHUNK_SIZE * 2;
mBlockWorker.createBlock(SESSION_ID, BLOCK_ID, 0, Constants.MEDIUM_MEM, 1);
try (BlockWriter writer = mBlockWorker.createBlockWriter(SESSION_ID, BLOCK_ID)) {
writer.append(BufferUtils.getIncreasingByteBuffer(len));
}
mBlockWorker.commitBlock(SESSION_ID, BLOCK_ID, true);
DataReader dataReader = mDataReaderFactory.create(0, len);
validateBuffer(dataReader.readChunk(), 0, CHUNK_SIZE);
assertEquals(CHUNK_SIZE, dataReader.pos());
validateBuffer(dataReader.readChunk(), CHUNK_SIZE, CHUNK_SIZE);
assertEquals(len, dataReader.pos());
dataReader.close();
}
use of alluxio.client.block.stream.DataReader in project alluxio by Alluxio.
the class BlockWorkerDataReaderTest method readChunkPartial.
@Test
public void readChunkPartial() throws Exception {
int len = CHUNK_SIZE * 5;
mBlockWorker.createBlock(SESSION_ID, BLOCK_ID, 0, Constants.MEDIUM_MEM, 1);
try (BlockWriter writer = mBlockWorker.createBlockWriter(SESSION_ID, BLOCK_ID)) {
writer.append(BufferUtils.getIncreasingByteBuffer(len));
}
mBlockWorker.commitBlock(SESSION_ID, BLOCK_ID, true);
int start = len / 5 * 2;
int end = len / 5 * 4;
DataReader dataReader = mDataReaderFactory.create(start, end);
for (int s = start; s < end; s += CHUNK_SIZE) {
int currentLen = Math.min(CHUNK_SIZE, end - s);
validateBuffer(dataReader.readChunk(), s, currentLen);
}
}
use of alluxio.client.block.stream.DataReader in project alluxio by Alluxio.
the class BlockWorkerDataReaderTest method readChunkUfs.
@Test
public void readChunkUfs() throws Exception {
// Write an actual file to UFS
String testFilePath = File.createTempFile("temp", null, new File(mRootUfs)).getAbsolutePath();
byte[] buffer = BufferUtils.getIncreasingByteArray(CHUNK_SIZE * 5);
BufferUtils.writeBufferToFile(testFilePath, buffer);
BlockInfo info = new BlockInfo().setBlockId(BLOCK_ID).setLength(CHUNK_SIZE * 5);
URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(true).setUfsPath(testFilePath).setBlockIds(Collections.singletonList(BLOCK_ID)).setLength(CHUNK_SIZE * 5).setBlockSizeBytes(CHUNK_SIZE).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
OpenFilePOptions readOptions = OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build();
InStreamOptions options = new InStreamOptions(dummyStatus, readOptions, mConf);
BlockWorkerDataReader.Factory factory = new BlockWorkerDataReader.Factory(mBlockWorker, BLOCK_ID, CHUNK_SIZE, options);
int len = CHUNK_SIZE * 3 / 2;
try (DataReader dataReader = factory.create(0, len)) {
validateBuffer(dataReader.readChunk(), 0, CHUNK_SIZE);
assertEquals(CHUNK_SIZE, dataReader.pos());
validateBuffer(dataReader.readChunk(), CHUNK_SIZE, len - CHUNK_SIZE);
assertEquals(len, dataReader.pos());
}
}
use of alluxio.client.block.stream.DataReader in project alluxio by Alluxio.
the class BlockWorkerDataReaderTest method create.
@Test
public void create() throws Exception {
mBlockWorker.createBlock(SESSION_ID, BLOCK_ID, 0, Constants.MEDIUM_MEM, 1);
mBlockWorker.commitBlock(SESSION_ID, BLOCK_ID, true);
DataReader dataReader = mDataReaderFactory.create(100, 200);
assertEquals(100, dataReader.pos());
}
use of alluxio.client.block.stream.DataReader in project alluxio by Alluxio.
the class BlockWorkerDataReaderTest method createAndCloseManyReader.
// See https://github.com/Alluxio/alluxio/issues/13255
@Test
public void createAndCloseManyReader() throws Exception {
for (int i = 0; i < LOCK_NUM * 10; i++) {
long blockId = i;
mBlockWorker.createBlock(SESSION_ID, blockId, 0, Constants.MEDIUM_MEM, 1);
mBlockWorker.commitBlock(SESSION_ID, blockId, true);
InStreamOptions inStreamOptions = new InStreamOptions(new URIStatus(new FileInfo().setBlockIds(Collections.singletonList(blockId))), FileSystemOptions.openFileDefaults(mConf), mConf);
mDataReaderFactory = new BlockWorkerDataReader.Factory(mBlockWorker, blockId, CHUNK_SIZE, inStreamOptions);
DataReader dataReader = mDataReaderFactory.create(0, 100);
dataReader.close();
}
}
Aggregations