Search in sources :

Example 1 with DataReader

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();
}
Also used : DataReader(alluxio.client.block.stream.DataReader) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) BlockWriter(alluxio.worker.block.io.BlockWriter) Test(org.junit.Test)

Example 2 with DataReader

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);
    }
}
Also used : DataReader(alluxio.client.block.stream.DataReader) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) BlockWriter(alluxio.worker.block.io.BlockWriter) Test(org.junit.Test)

Example 3 with DataReader

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());
    }
}
Also used : URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) InStreamOptions(alluxio.client.file.options.InStreamOptions) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) DataReader(alluxio.client.block.stream.DataReader) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) FileInfo(alluxio.wire.FileInfo) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) File(java.io.File) Test(org.junit.Test)

Example 4 with DataReader

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());
}
Also used : DataReader(alluxio.client.block.stream.DataReader) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) Test(org.junit.Test)

Example 5 with DataReader

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();
    }
}
Also used : BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) DataReader(alluxio.client.block.stream.DataReader) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) FileInfo(alluxio.wire.FileInfo) URIStatus(alluxio.client.file.URIStatus) InStreamOptions(alluxio.client.file.options.InStreamOptions) Test(org.junit.Test)

Aggregations

BlockWorkerDataReader (alluxio.client.block.stream.BlockWorkerDataReader)5 DataReader (alluxio.client.block.stream.DataReader)5 Test (org.junit.Test)5 URIStatus (alluxio.client.file.URIStatus)2 InStreamOptions (alluxio.client.file.options.InStreamOptions)2 FileInfo (alluxio.wire.FileInfo)2 BlockWriter (alluxio.worker.block.io.BlockWriter)2 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)1 BlockInfo (alluxio.wire.BlockInfo)1 FileBlockInfo (alluxio.wire.FileBlockInfo)1 File (java.io.File)1